PageRenderTime 26ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/platform/platform-tests/testSrc/com/intellij/openapi/editor/NullGraphics2D.java

http://github.com/JetBrains/intellij-community
Java | 426 lines | 346 code | 75 blank | 5 comment | 5 complexity | 20d5de549c0cba379a6b4158b50a2b72 MD5 | raw file
Possible License(s): BSD-3-Clause, Apache-2.0, MPL-2.0-no-copyleft-exception, MIT, EPL-1.0, AGPL-1.0
  1. // Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
  2. package com.intellij.openapi.editor;
  3. import java.awt.*;
  4. import java.awt.font.FontRenderContext;
  5. import java.awt.font.GlyphVector;
  6. import java.awt.geom.AffineTransform;
  7. import java.awt.geom.Point2D;
  8. import java.awt.image.BufferedImage;
  9. import java.awt.image.BufferedImageOp;
  10. import java.awt.image.ImageObserver;
  11. import java.awt.image.RenderedImage;
  12. import java.awt.image.renderable.RenderableImage;
  13. import java.text.AttributedCharacterIterator;
  14. import java.util.Map;
  15. import java.util.Objects;
  16. /**
  17. * For use in painting tests. To make sure drawing method calls are not optimized away on execution, they all change an internal state,
  18. * which should be retrieved on painting finish using {@link #getResult()} method.
  19. */
  20. public class NullGraphics2D extends Graphics2D {
  21. private final FontRenderContext myFontRenderContext = new FontRenderContext(null, false, false);
  22. private final AffineTransform myTransform = new AffineTransform();
  23. private final Rectangle myClip;
  24. private Composite myComposite = AlphaComposite.SrcOver;
  25. private final RenderingHints myRenderingHints = new RenderingHints(null);
  26. private Color myColor = Color.black;
  27. private Font myFont = Font.decode(null);
  28. private Stroke myStroke = new BasicStroke();
  29. private int myResult;
  30. public NullGraphics2D(Rectangle clip) {
  31. myClip = clip;
  32. }
  33. public int getResult() {
  34. return myResult;
  35. }
  36. @Override
  37. public void draw(Shape s) {
  38. throw new UnsupportedOperationException();
  39. }
  40. @Override
  41. public boolean drawImage(Image img, AffineTransform xform, ImageObserver obs) {
  42. throw new UnsupportedOperationException();
  43. }
  44. @Override
  45. public void drawImage(BufferedImage img, BufferedImageOp op, int x, int y) {
  46. throw new UnsupportedOperationException();
  47. }
  48. @Override
  49. public void drawRenderedImage(RenderedImage img, AffineTransform xform) {
  50. throw new UnsupportedOperationException();
  51. }
  52. @Override
  53. public void drawRenderableImage(RenderableImage img, AffineTransform xform) {
  54. throw new UnsupportedOperationException();
  55. }
  56. @Override
  57. public void drawString(String str, int x, int y) {
  58. myResult += x;
  59. myResult += y;
  60. for (int i = 0; i < str.length(); i++) {
  61. myResult += str.charAt(i);
  62. }
  63. }
  64. @Override
  65. public void drawString(String str, float x, float y) {
  66. throw new UnsupportedOperationException();
  67. }
  68. @Override
  69. public void drawString(AttributedCharacterIterator iterator, int x, int y) {
  70. throw new UnsupportedOperationException();
  71. }
  72. @Override
  73. public boolean drawImage(Image img, int x, int y, ImageObserver observer) {
  74. throw new UnsupportedOperationException();
  75. }
  76. @Override
  77. public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer) {
  78. throw new UnsupportedOperationException();
  79. }
  80. @Override
  81. public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) {
  82. throw new UnsupportedOperationException();
  83. }
  84. @Override
  85. public boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer) {
  86. throw new UnsupportedOperationException();
  87. }
  88. @Override
  89. public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) {
  90. throw new UnsupportedOperationException();
  91. }
  92. @Override
  93. public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor,
  94. ImageObserver observer) {
  95. throw new UnsupportedOperationException();
  96. }
  97. @Override
  98. public void dispose() {
  99. throw new UnsupportedOperationException();
  100. }
  101. @Override
  102. public void drawString(AttributedCharacterIterator iterator, float x, float y) {
  103. throw new UnsupportedOperationException();
  104. }
  105. @Override
  106. public void drawGlyphVector(GlyphVector g, float x, float y) {
  107. myResult += x;
  108. myResult += y;
  109. for (int i = 0; i < g.getNumGlyphs(); i++) {
  110. myResult += g.getGlyphCode(i);
  111. Point2D position = g.getGlyphPosition(i);
  112. myResult += position.getX();
  113. myResult += position.getY();
  114. }
  115. }
  116. @Override
  117. public void fill(Shape s) {
  118. Rectangle bounds = s.getBounds();
  119. myResult += bounds.x;
  120. myResult += bounds.y;
  121. myResult += bounds.width;
  122. myResult += bounds.height;
  123. }
  124. @Override
  125. public boolean hit(Rectangle rect, Shape s, boolean onStroke) {
  126. throw new UnsupportedOperationException();
  127. }
  128. @Override
  129. public GraphicsConfiguration getDeviceConfiguration() {
  130. return null;
  131. }
  132. @Override
  133. public void setComposite(Composite comp) {
  134. myComposite = comp;
  135. myResult += Objects.hashCode(comp);
  136. }
  137. @Override
  138. public void setPaint(Paint paint) {
  139. throw new UnsupportedOperationException();
  140. }
  141. @Override
  142. public void setRenderingHint(RenderingHints.Key hintKey, Object hintValue) {
  143. myRenderingHints.put(hintKey, hintValue);
  144. myResult += Objects.hashCode(hintKey);
  145. myResult += Objects.hashCode(hintValue);
  146. }
  147. @Override
  148. public Object getRenderingHint(RenderingHints.Key hintKey) {
  149. return myRenderingHints.get(hintKey);
  150. }
  151. @Override
  152. public void setRenderingHints(Map<?, ?> hints) {
  153. myRenderingHints.clear();
  154. addRenderingHints(hints);
  155. myResult += Objects.hashCode(hints);
  156. }
  157. @Override
  158. public void addRenderingHints(Map<?, ?> hints) {
  159. for (Map.Entry<?, ?> entry : hints.entrySet()) {
  160. myRenderingHints.put(entry.getKey(), entry.getValue());
  161. }
  162. myResult += Objects.hashCode(hints);
  163. }
  164. @Override
  165. public RenderingHints getRenderingHints() {
  166. return (RenderingHints)myRenderingHints.clone();
  167. }
  168. @Override
  169. public Graphics create() {
  170. throw new UnsupportedOperationException();
  171. }
  172. @Override
  173. public void translate(int x, int y) {
  174. myResult += x;
  175. myResult += y;
  176. }
  177. @Override
  178. public Color getColor() {
  179. return myColor;
  180. }
  181. @Override
  182. public void setColor(Color c) {
  183. myColor = c;
  184. myResult += Objects.hashCode(c);
  185. }
  186. @Override
  187. public void setPaintMode() {
  188. throw new UnsupportedOperationException();
  189. }
  190. @Override
  191. public void setXORMode(Color c1) {
  192. throw new UnsupportedOperationException();
  193. }
  194. @Override
  195. public Font getFont() {
  196. return myFont;
  197. }
  198. @Override
  199. public void setFont(Font font) {
  200. myFont = font;
  201. myResult += Objects.hashCode(font);
  202. }
  203. @Override
  204. public void setStroke(Stroke s) {
  205. myStroke = s;
  206. myResult += Objects.hashCode(s);
  207. }
  208. @Override
  209. public Stroke getStroke() {
  210. return myStroke;
  211. }
  212. @Override
  213. public FontMetrics getFontMetrics(Font f) {
  214. throw new UnsupportedOperationException();
  215. }
  216. @Override
  217. public Rectangle getClipBounds() {
  218. return myClip == null ? null : new Rectangle(myClip);
  219. }
  220. @Override
  221. public void clipRect(int x, int y, int width, int height) {
  222. throw new UnsupportedOperationException();
  223. }
  224. @Override
  225. public void setClip(int x, int y, int width, int height) {
  226. throw new UnsupportedOperationException();
  227. }
  228. @Override
  229. public Shape getClip() {
  230. return myClip == null ? null : new Rectangle(myClip);
  231. }
  232. @Override
  233. public void setClip(Shape clip) {
  234. throw new UnsupportedOperationException();
  235. }
  236. @Override
  237. public void copyArea(int x, int y, int width, int height, int dx, int dy) {
  238. throw new UnsupportedOperationException();
  239. }
  240. @Override
  241. public void drawLine(int x1, int y1, int x2, int y2) {
  242. myResult += x1;
  243. myResult += x2;
  244. myResult += y1;
  245. myResult += y2;
  246. }
  247. @Override
  248. public void fillRect(int x, int y, int width, int height) {
  249. myResult += x;
  250. myResult += y;
  251. myResult += width;
  252. myResult += height;
  253. }
  254. @Override
  255. public void clearRect(int x, int y, int width, int height) {
  256. throw new UnsupportedOperationException();
  257. }
  258. @Override
  259. public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
  260. throw new UnsupportedOperationException();
  261. }
  262. @Override
  263. public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
  264. throw new UnsupportedOperationException();
  265. }
  266. @Override
  267. public void drawOval(int x, int y, int width, int height) {
  268. throw new UnsupportedOperationException();
  269. }
  270. @Override
  271. public void fillOval(int x, int y, int width, int height) {
  272. throw new UnsupportedOperationException();
  273. }
  274. @Override
  275. public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
  276. throw new UnsupportedOperationException();
  277. }
  278. @Override
  279. public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
  280. throw new UnsupportedOperationException();
  281. }
  282. @Override
  283. public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) {
  284. throw new UnsupportedOperationException();
  285. }
  286. @Override
  287. public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) {
  288. throw new UnsupportedOperationException();
  289. }
  290. @Override
  291. public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints) {
  292. throw new UnsupportedOperationException();
  293. }
  294. @Override
  295. public void translate(double tx, double ty) {
  296. throw new UnsupportedOperationException();
  297. }
  298. @Override
  299. public void rotate(double theta) {
  300. throw new UnsupportedOperationException();
  301. }
  302. @Override
  303. public void rotate(double theta, double x, double y) {
  304. throw new UnsupportedOperationException();
  305. }
  306. @Override
  307. public void scale(double sx, double sy) {
  308. throw new UnsupportedOperationException();
  309. }
  310. @Override
  311. public void shear(double shx, double shy) {
  312. throw new UnsupportedOperationException();
  313. }
  314. @Override
  315. public void transform(AffineTransform Tx) {
  316. throw new UnsupportedOperationException();
  317. }
  318. @Override
  319. public void setTransform(AffineTransform Tx) {
  320. myTransform.setTransform(Tx);
  321. myResult += Tx.hashCode();
  322. }
  323. @Override
  324. public AffineTransform getTransform() {
  325. return new AffineTransform(myTransform);
  326. }
  327. @Override
  328. public Paint getPaint() {
  329. throw new UnsupportedOperationException();
  330. }
  331. @Override
  332. public Composite getComposite() {
  333. return myComposite;
  334. }
  335. @Override
  336. public void setBackground(Color color) {
  337. throw new UnsupportedOperationException();
  338. }
  339. @Override
  340. public Color getBackground() {
  341. throw new UnsupportedOperationException();
  342. }
  343. @Override
  344. public void clip(Shape s) {
  345. throw new UnsupportedOperationException();
  346. }
  347. @Override
  348. public FontRenderContext getFontRenderContext() {
  349. return myFontRenderContext;
  350. }
  351. }