You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SLGraphics.java 75KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.sl.draw;
  16. import java.awt.*;
  17. import java.awt.font.FontRenderContext;
  18. import java.awt.font.GlyphVector;
  19. import java.awt.font.TextLayout;
  20. import java.awt.geom.AffineTransform;
  21. import java.awt.geom.Arc2D;
  22. import java.awt.geom.Ellipse2D;
  23. import java.awt.geom.GeneralPath;
  24. import java.awt.geom.Line2D;
  25. import java.awt.geom.Path2D;
  26. import java.awt.geom.RoundRectangle2D;
  27. import java.awt.image.BufferedImage;
  28. import java.awt.image.BufferedImageOp;
  29. import java.awt.image.ImageObserver;
  30. import java.awt.image.RenderedImage;
  31. import java.awt.image.renderable.RenderableImage;
  32. import java.text.AttributedCharacterIterator;
  33. import java.util.Map;
  34. import org.apache.logging.log4j.LogManager;
  35. import org.apache.logging.log4j.Logger;
  36. import org.apache.poi.sl.usermodel.FreeformShape;
  37. import org.apache.poi.sl.usermodel.GroupShape;
  38. import org.apache.poi.sl.usermodel.Insets2D;
  39. import org.apache.poi.sl.usermodel.SimpleShape;
  40. import org.apache.poi.sl.usermodel.StrokeStyle;
  41. import org.apache.poi.sl.usermodel.TextBox;
  42. import org.apache.poi.sl.usermodel.TextRun;
  43. import org.apache.poi.sl.usermodel.VerticalAlignment;
  44. import org.apache.poi.util.NotImplemented;
  45. import org.apache.poi.util.SuppressForbidden;
  46. /**
  47. * Translates Graphics2D calls into PowerPoint.
  48. */
  49. public class SLGraphics extends Graphics2D implements Cloneable {
  50. private static final Logger LOG = LogManager.getLogger(SLGraphics.class);
  51. //The ppt object to write into.
  52. private GroupShape<?,?> _group;
  53. private AffineTransform _transform;
  54. private Stroke _stroke;
  55. private Paint _paint;
  56. private Font _font;
  57. private Color _foreground;
  58. private Color _background;
  59. private RenderingHints _hints;
  60. /**
  61. * Construct Java Graphics object which translates graphic calls in ppt drawing layer.
  62. *
  63. * @param group The shape group to write the graphics calls into.
  64. */
  65. public SLGraphics(GroupShape<?,?> group){
  66. this._group = group;
  67. _transform = new AffineTransform();
  68. _stroke = new BasicStroke();
  69. _paint = Color.black;
  70. _font = new Font("Arial", Font.PLAIN, 12);
  71. _background = Color.black;
  72. _foreground = Color.white;
  73. _hints = new RenderingHints(null);
  74. }
  75. /**
  76. * @return the shape group being used for drawing
  77. */
  78. public GroupShape<?,?> getShapeGroup(){
  79. return _group;
  80. }
  81. /**
  82. * Gets the current font.
  83. * @return this graphics context's current font.
  84. * @see Font
  85. * @see Graphics#setFont(Font)
  86. */
  87. public Font getFont(){
  88. return _font;
  89. }
  90. /**
  91. * Sets this graphics context's font to the specified font.
  92. * All subsequent text operations using this graphics context
  93. * use this font.
  94. * @param font the font.
  95. * @see Graphics#getFont
  96. * @see Graphics#drawString(String, int, int)
  97. * @see Graphics#drawBytes(byte[], int, int, int, int)
  98. * @see Graphics#drawChars(char[], int, int, int, int)
  99. */
  100. public void setFont(Font font){
  101. this._font = font;
  102. }
  103. /**
  104. * Gets this graphics context's current color.
  105. * @return this graphics context's current color.
  106. * @see Color
  107. * @see Graphics#setColor
  108. */
  109. public Color getColor(){
  110. return _foreground;
  111. }
  112. /**
  113. * Sets this graphics context's current color to the specified
  114. * color. All subsequent graphics operations using this graphics
  115. * context use this specified color.
  116. * @param c the new rendering color.
  117. * @see Color
  118. * @see Graphics#getColor
  119. */
  120. public void setColor(Color c) {
  121. setPaint(c);
  122. }
  123. /**
  124. * Returns the current <code>Stroke</code> in the
  125. * <code>Graphics2D</code> context.
  126. * @return the current <code>Graphics2D</code> <code>Stroke</code>,
  127. * which defines the line style.
  128. * @see #setStroke
  129. */
  130. public Stroke getStroke(){
  131. return _stroke;
  132. }
  133. /**
  134. * Sets the <code>Stroke</code> for the <code>Graphics2D</code> context.
  135. * @param s the <code>Stroke</code> object to be used to stroke a
  136. * <code>Shape</code> during the rendering process
  137. */
  138. public void setStroke(Stroke s){
  139. this._stroke = s;
  140. }
  141. /**
  142. * Returns the current <code>Paint</code> of the
  143. * <code>Graphics2D</code> context.
  144. * @return the current <code>Graphics2D</code> <code>Paint</code>,
  145. * which defines a color or pattern.
  146. * @see #setPaint
  147. * @see Graphics#setColor
  148. */
  149. public Paint getPaint(){
  150. return _paint;
  151. }
  152. /**
  153. * Sets the <code>Paint</code> attribute for the
  154. * <code>Graphics2D</code> context. Calling this method
  155. * with a <code>null</code> <code>Paint</code> object does
  156. * not have any effect on the current <code>Paint</code> attribute
  157. * of this <code>Graphics2D</code>.
  158. * @param paint the <code>Paint</code> object to be used to generate
  159. * color during the rendering process, or <code>null</code>
  160. * @see Graphics#setColor
  161. */
  162. public void setPaint(Paint paint){
  163. if(paint == null) return;
  164. this._paint = paint;
  165. if (paint instanceof Color) _foreground = (Color)paint;
  166. }
  167. /**
  168. * Returns a copy of the current <code>Transform</code> in the
  169. * <code>Graphics2D</code> context.
  170. * @return the current <code>AffineTransform</code> in the
  171. * <code>Graphics2D</code> context.
  172. * @see #_transform
  173. * @see #setTransform
  174. */
  175. public AffineTransform getTransform(){
  176. return new AffineTransform(_transform);
  177. }
  178. /**
  179. * Sets the <code>Transform</code> in the <code>Graphics2D</code>
  180. * context.
  181. * @param Tx the <code>AffineTransform</code> object to be used in the
  182. * rendering process
  183. * @see #_transform
  184. * @see AffineTransform
  185. */
  186. public void setTransform(AffineTransform Tx) {
  187. _transform = new AffineTransform(Tx);
  188. }
  189. /**
  190. * Strokes the outline of a <code>Shape</code> using the settings of the
  191. * current <code>Graphics2D</code> context. The rendering attributes
  192. * applied include the <code>Clip</code>, <code>Transform</code>,
  193. * <code>Paint</code>, <code>Composite</code> and
  194. * <code>Stroke</code> attributes.
  195. * @param shape the <code>Shape</code> to be rendered
  196. * @see #setStroke
  197. * @see #setPaint
  198. * @see Graphics#setColor
  199. * @see #_transform
  200. * @see #setTransform
  201. * @see #clip
  202. * @see #setClip
  203. * @see #setComposite
  204. */
  205. public void draw(Shape shape){
  206. Path2D.Double path = new Path2D.Double(_transform.createTransformedShape(shape));
  207. FreeformShape<?,?> p = _group.createFreeform();
  208. p.setPath(path);
  209. p.setFillColor(null);
  210. applyStroke(p);
  211. if (_paint instanceof Color) {
  212. p.setStrokeStyle((Color)_paint);
  213. }
  214. }
  215. /**
  216. * Renders the text specified by the specified <code>String</code>,
  217. * using the current text attribute state in the <code>Graphics2D</code> context.
  218. * The baseline of the first character is at position
  219. * (<i>x</i>,&nbsp;<i>y</i>) in the User Space.
  220. * The rendering attributes applied include the <code>Clip</code>,
  221. * <code>Transform</code>, <code>Paint</code>, <code>Font</code> and
  222. * <code>Composite</code> attributes. For characters in script systems
  223. * such as Hebrew and Arabic, the glyphs can be rendered from right to
  224. * left, in which case the coordinate supplied is the location of the
  225. * leftmost character on the baseline.
  226. * @param s the <code>String</code> to be rendered
  227. * @param x the x coordinate of the location where the
  228. * <code>String</code> should be rendered
  229. * @param y the y coordinate of the location where the
  230. * <code>String</code> should be rendered
  231. * @throws NullPointerException if <code>str</code> is
  232. * <code>null</code>
  233. * @see #setPaint
  234. * @see Graphics#setColor
  235. * @see Graphics#setFont
  236. * @see #setTransform
  237. * @see #setComposite
  238. * @see #setClip
  239. */
  240. public void drawString(String s, float x, float y) {
  241. TextBox<?,?> txt = _group.createTextBox();
  242. TextRun rt = txt.getTextParagraphs().get(0).getTextRuns().get(0);
  243. rt.setFontSize((double)_font.getSize());
  244. rt.setFontFamily(_font.getFamily());
  245. if (getColor() != null) rt.setFontColor(DrawPaint.createSolidPaint(getColor()));
  246. if (_font.isBold()) rt.setBold(true);
  247. if (_font.isItalic()) rt.setItalic(true);
  248. txt.setText(s);
  249. txt.setInsets(new Insets2D(0,0,0,0));
  250. txt.setWordWrap(false);
  251. txt.setHorizontalCentered(false);
  252. txt.setVerticalAlignment(VerticalAlignment.MIDDLE);
  253. TextLayout layout = new TextLayout(s, _font, getFontRenderContext());
  254. float ascent = layout.getAscent();
  255. float width = (float) Math.floor(layout.getAdvance());
  256. /*
  257. * Even if top and bottom margins are set to 0 PowerPoint
  258. * always sets extra space between the text and its bounding box.
  259. *
  260. * The approximation height = ascent*2 works good enough in most cases
  261. */
  262. float height = ascent * 2;
  263. /*
  264. In powerpoint anchor of a shape is its top left corner.
  265. Java graphics sets string coordinates by the baseline of the first character
  266. so we need to shift up by the height of the textbox
  267. */
  268. y -= height / 2 + ascent / 2;
  269. /*
  270. In powerpoint anchor of a shape is its top left corner.
  271. Java graphics sets string coordinates by the baseline of the first character
  272. so we need to shift down by the height of the textbox
  273. */
  274. txt.setAnchor(new Rectangle((int)x, (int)y, (int)width, (int)height));
  275. }
  276. /**
  277. * Fills the interior of a <code>Shape</code> using the settings of the
  278. * <code>Graphics2D</code> context. The rendering attributes applied
  279. * include the <code>Clip</code>, <code>Transform</code>,
  280. * <code>Paint</code>, and <code>Composite</code>.
  281. * @param shape the <code>Shape</code> to be filled
  282. * @see #setPaint
  283. * @see Graphics#setColor
  284. * @see #_transform
  285. * @see #setTransform
  286. * @see #setComposite
  287. * @see #clip
  288. * @see #setClip
  289. */
  290. public void fill(Shape shape){
  291. Path2D.Double path = new Path2D.Double(_transform.createTransformedShape(shape));
  292. FreeformShape<?,?> p = _group.createFreeform();
  293. p.setPath(path);
  294. applyPaint(p);
  295. p.setStrokeStyle(); //Fills must be "No Line"
  296. }
  297. /**
  298. * Translates the origin of the graphics context to the point
  299. * (<i>x</i>,&nbsp;<i>y</i>) in the current coordinate system.
  300. * Modifies this graphics context so that its new origin corresponds
  301. * to the point (<i>x</i>,&nbsp;<i>y</i>) in this graphics context's
  302. * original coordinate system. All coordinates used in subsequent
  303. * rendering operations on this graphics context will be relative
  304. * to this new origin.
  305. * @param x the <i>x</i> coordinate.
  306. * @param y the <i>y</i> coordinate.
  307. */
  308. public void translate(int x, int y){
  309. _transform.translate(x, y);
  310. }
  311. /**
  312. * Intersects the current <code>Clip</code> with the interior of the
  313. * specified <code>Shape</code> and sets the <code>Clip</code> to the
  314. * resulting intersection. The specified <code>Shape</code> is
  315. * transformed with the current <code>Graphics2D</code>
  316. * <code>Transform</code> before being intersected with the current
  317. * <code>Clip</code>. This method is used to make the current
  318. * <code>Clip</code> smaller.
  319. * To make the <code>Clip</code> larger, use <code>setClip</code>.
  320. * The <i>user clip</i> modified by this method is independent of the
  321. * clipping associated with device bounds and visibility. If no clip has
  322. * previously been set, or if the clip has been cleared using
  323. * {@link Graphics#setClip(Shape) setClip} with a
  324. * <code>null</code> argument, the specified <code>Shape</code> becomes
  325. * the new user clip.
  326. * @param s the <code>Shape</code> to be intersected with the current
  327. * <code>Clip</code>. If <code>s</code> is <code>null</code>,
  328. * this method clears the current <code>Clip</code>.
  329. */
  330. @NotImplemented
  331. public void clip(Shape s){
  332. logNotImplemented();
  333. }
  334. /**
  335. * Gets the current clipping area.
  336. * This method returns the user clip, which is independent of the
  337. * clipping associated with device bounds and window visibility.
  338. * If no clip has previously been set, or if the clip has been
  339. * cleared using <code>setClip(null)</code>, this method returns
  340. * <code>null</code>.
  341. * @return a <code>Shape</code> object representing the
  342. * current clipping area, or <code>null</code> if
  343. * no clip is set.
  344. * @see Graphics#getClipBounds()
  345. * @see Graphics#clipRect
  346. * @see Graphics#setClip(int, int, int, int)
  347. * @see Graphics#setClip(Shape)
  348. * @since JDK1.1
  349. */
  350. @NotImplemented
  351. public Shape getClip(){
  352. logNotImplemented();
  353. return null;
  354. }
  355. /**
  356. * Concatenates the current <code>Graphics2D</code>
  357. * <code>Transform</code> with a scaling transformation
  358. * Subsequent rendering is resized according to the specified scaling
  359. * factors relative to the previous scaling.
  360. * This is equivalent to calling <code>transform(S)</code>, where S is an
  361. * <code>AffineTransform</code> represented by the following matrix:
  362. * <pre>
  363. * [ sx 0 0 ]
  364. * [ 0 sy 0 ]
  365. * [ 0 0 1 ]
  366. * </pre>
  367. * @param sx the amount by which X coordinates in subsequent
  368. * rendering operations are multiplied relative to previous
  369. * rendering operations.
  370. * @param sy the amount by which Y coordinates in subsequent
  371. * rendering operations are multiplied relative to previous
  372. * rendering operations.
  373. */
  374. public void scale(double sx, double sy){
  375. _transform.scale(sx, sy);
  376. }
  377. /**
  378. * Draws an outlined round-cornered rectangle using this graphics
  379. * context's current color. The left and right edges of the rectangle
  380. * are at <code>x</code> and <code>x&nbsp;+&nbsp;width</code>,
  381. * respectively. The top and bottom edges of the rectangle are at
  382. * <code>y</code> and <code>y&nbsp;+&nbsp;height</code>.
  383. * @param x the <i>x</i> coordinate of the rectangle to be drawn.
  384. * @param y the <i>y</i> coordinate of the rectangle to be drawn.
  385. * @param width the width of the rectangle to be drawn.
  386. * @param height the height of the rectangle to be drawn.
  387. * @param arcWidth the horizontal diameter of the arc
  388. * at the four corners.
  389. * @param arcHeight the vertical diameter of the arc
  390. * at the four corners.
  391. * @see Graphics#fillRoundRect
  392. */
  393. public void drawRoundRect(int x, int y, int width, int height,
  394. int arcWidth, int arcHeight){
  395. RoundRectangle2D rect = new RoundRectangle2D.Double(x, y, width, height, arcWidth, arcHeight);
  396. draw(rect);
  397. }
  398. /**
  399. * Draws the text given by the specified string, using this
  400. * graphics context's current font and color. The baseline of the
  401. * first character is at position (<i>x</i>,&nbsp;<i>y</i>) in this
  402. * graphics context's coordinate system.
  403. * @param str the string to be drawn.
  404. * @param x the <i>x</i> coordinate.
  405. * @param y the <i>y</i> coordinate.
  406. * @see Graphics#drawBytes
  407. * @see Graphics#drawChars
  408. */
  409. public void drawString(String str, int x, int y){
  410. drawString(str, (float)x, (float)y);
  411. }
  412. /**
  413. * Fills an oval bounded by the specified rectangle with the
  414. * current color.
  415. * @param x the <i>x</i> coordinate of the upper left corner
  416. * of the oval to be filled.
  417. * @param y the <i>y</i> coordinate of the upper left corner
  418. * of the oval to be filled.
  419. * @param width the width of the oval to be filled.
  420. * @param height the height of the oval to be filled.
  421. * @see Graphics#drawOval
  422. */
  423. public void fillOval(int x, int y, int width, int height){
  424. Ellipse2D oval = new Ellipse2D.Double(x, y, width, height);
  425. fill(oval);
  426. }
  427. /**
  428. * Fills the specified rounded corner rectangle with the current color.
  429. * The left and right edges of the rectangle
  430. * are at <code>x</code> and <code>x&nbsp;+&nbsp;width&nbsp;-&nbsp;1</code>,
  431. * respectively. The top and bottom edges of the rectangle are at
  432. * <code>y</code> and <code>y&nbsp;+&nbsp;height&nbsp;-&nbsp;1</code>.
  433. * @param x the <i>x</i> coordinate of the rectangle to be filled.
  434. * @param y the <i>y</i> coordinate of the rectangle to be filled.
  435. * @param width the width of the rectangle to be filled.
  436. * @param height the height of the rectangle to be filled.
  437. * @param arcWidth the horizontal diameter
  438. * of the arc at the four corners.
  439. * @param arcHeight the vertical diameter
  440. * of the arc at the four corners.
  441. * @see Graphics#drawRoundRect
  442. */
  443. public void fillRoundRect(int x, int y, int width, int height,
  444. int arcWidth, int arcHeight){
  445. RoundRectangle2D rect = new RoundRectangle2D.Double(x, y, width, height, arcWidth, arcHeight);
  446. fill(rect);
  447. }
  448. /**
  449. * Fills a circular or elliptical arc covering the specified rectangle.
  450. * <p>
  451. * The resulting arc begins at <code>startAngle</code> and extends
  452. * for <code>arcAngle</code> degrees.
  453. * Angles are interpreted such that 0&nbsp;degrees
  454. * is at the 3&nbsp;o'clock position.
  455. * A positive value indicates a counter-clockwise rotation
  456. * while a negative value indicates a clockwise rotation.
  457. * <p>
  458. * The center of the arc is the center of the rectangle whose origin
  459. * is (<i>x</i>,&nbsp;<i>y</i>) and whose size is specified by the
  460. * <code>width</code> and <code>height</code> arguments.
  461. * <p>
  462. * The resulting arc covers an area
  463. * <code>width&nbsp;+&nbsp;1</code> pixels wide
  464. * by <code>height&nbsp;+&nbsp;1</code> pixels tall.
  465. * <p>
  466. * The angles are specified relative to the non-square extents of
  467. * the bounding rectangle such that 45 degrees always falls on the
  468. * line from the center of the ellipse to the upper right corner of
  469. * the bounding rectangle. As a result, if the bounding rectangle is
  470. * noticeably longer in one axis than the other, the angles to the
  471. * start and end of the arc segment will be skewed farther along the
  472. * longer axis of the bounds.
  473. * @param x the <i>x</i> coordinate of the
  474. * upper-left corner of the arc to be filled.
  475. * @param y the <i>y</i> coordinate of the
  476. * upper-left corner of the arc to be filled.
  477. * @param width the width of the arc to be filled.
  478. * @param height the height of the arc to be filled.
  479. * @param startAngle the beginning angle.
  480. * @param arcAngle the angular extent of the arc,
  481. * relative to the start angle.
  482. * @see Graphics#drawArc
  483. */
  484. public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle){
  485. Arc2D arc = new Arc2D.Double(x, y, width, height, startAngle, arcAngle, Arc2D.PIE);
  486. fill(arc);
  487. }
  488. /**
  489. * Draws the outline of a circular or elliptical arc
  490. * covering the specified rectangle.
  491. * <p>
  492. * The resulting arc begins at <code>startAngle</code> and extends
  493. * for <code>arcAngle</code> degrees, using the current color.
  494. * Angles are interpreted such that 0&nbsp;degrees
  495. * is at the 3&nbsp;o'clock position.
  496. * A positive value indicates a counter-clockwise rotation
  497. * while a negative value indicates a clockwise rotation.
  498. * <p>
  499. * The center of the arc is the center of the rectangle whose origin
  500. * is (<i>x</i>,&nbsp;<i>y</i>) and whose size is specified by the
  501. * <code>width</code> and <code>height</code> arguments.
  502. * <p>
  503. * The resulting arc covers an area
  504. * <code>width&nbsp;+&nbsp;1</code> pixels wide
  505. * by <code>height&nbsp;+&nbsp;1</code> pixels tall.
  506. * <p>
  507. * The angles are specified relative to the non-square extents of
  508. * the bounding rectangle such that 45 degrees always falls on the
  509. * line from the center of the ellipse to the upper right corner of
  510. * the bounding rectangle. As a result, if the bounding rectangle is
  511. * noticeably longer in one axis than the other, the angles to the
  512. * start and end of the arc segment will be skewed farther along the
  513. * longer axis of the bounds.
  514. * @param x the <i>x</i> coordinate of the
  515. * upper-left corner of the arc to be drawn.
  516. * @param y the <i>y</i> coordinate of the
  517. * upper-left corner of the arc to be drawn.
  518. * @param width the width of the arc to be drawn.
  519. * @param height the height of the arc to be drawn.
  520. * @param startAngle the beginning angle.
  521. * @param arcAngle the angular extent of the arc,
  522. * relative to the start angle.
  523. * @see Graphics#fillArc
  524. */
  525. public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
  526. Arc2D arc = new Arc2D.Double(x, y, width, height, startAngle, arcAngle, Arc2D.OPEN);
  527. draw(arc);
  528. }
  529. /**
  530. * Draws a sequence of connected lines defined by
  531. * arrays of <i>x</i> and <i>y</i> coordinates.
  532. * Each pair of (<i>x</i>,&nbsp;<i>y</i>) coordinates defines a point.
  533. * The figure is not closed if the first point
  534. * differs from the last point.
  535. * @param xPoints an array of <i>x</i> points
  536. * @param yPoints an array of <i>y</i> points
  537. * @param nPoints the total number of points
  538. * @see Graphics#drawPolygon(int[], int[], int)
  539. * @since JDK1.1
  540. */
  541. public void drawPolyline(int[] xPoints, int[] yPoints,
  542. int nPoints){
  543. if(nPoints > 0){
  544. GeneralPath path = new GeneralPath();
  545. path.moveTo(xPoints[0], yPoints[0]);
  546. for(int i=1; i<nPoints; i++)
  547. path.lineTo(xPoints[i], yPoints[i]);
  548. draw(path);
  549. }
  550. }
  551. /**
  552. * Draws the outline of an oval.
  553. * The result is a circle or ellipse that fits within the
  554. * rectangle specified by the <code>x</code>, <code>y</code>,
  555. * <code>width</code>, and <code>height</code> arguments.
  556. * <p>
  557. * The oval covers an area that is
  558. * <code>width&nbsp;+&nbsp;1</code> pixels wide
  559. * and <code>height&nbsp;+&nbsp;1</code> pixels tall.
  560. * @param x the <i>x</i> coordinate of the upper left
  561. * corner of the oval to be drawn.
  562. * @param y the <i>y</i> coordinate of the upper left
  563. * corner of the oval to be drawn.
  564. * @param width the width of the oval to be drawn.
  565. * @param height the height of the oval to be drawn.
  566. * @see Graphics#fillOval
  567. */
  568. public void drawOval(int x, int y, int width, int height){
  569. Ellipse2D oval = new Ellipse2D.Double(x, y, width, height);
  570. draw(oval);
  571. }
  572. /**
  573. * Draws as much of the specified image as is currently available.
  574. * The image is drawn with its top-left corner at
  575. * (<i>x</i>,&nbsp;<i>y</i>) in this graphics context's coordinate
  576. * space. Transparent pixels are drawn in the specified
  577. * background color.
  578. * <p>
  579. * This operation is equivalent to filling a rectangle of the
  580. * width and height of the specified image with the given color and then
  581. * drawing the image on top of it, but possibly more efficient.
  582. * <p>
  583. * This method returns immediately in all cases, even if the
  584. * complete image has not yet been loaded, and it has not been dithered
  585. * and converted for the current output device.
  586. * <p>
  587. * If the image has not yet been completely loaded, then
  588. * <code>drawImage</code> returns <code>false</code>. As more of
  589. * the image becomes available, the process that draws the image notifies
  590. * the specified image observer.
  591. * @param img the specified image to be drawn.
  592. * @param x the <i>x</i> coordinate.
  593. * @param y the <i>y</i> coordinate.
  594. * @param bgcolor the background color to paint under the
  595. * non-opaque portions of the image.
  596. * @param observer object to be notified as more of
  597. * the image is converted.
  598. * @see Image
  599. * @see ImageObserver
  600. * @see ImageObserver#imageUpdate(Image, int, int, int, int, int)
  601. */
  602. @NotImplemented
  603. public boolean drawImage(Image img, int x, int y,
  604. Color bgcolor,
  605. ImageObserver observer){
  606. logNotImplemented();
  607. return false;
  608. }
  609. /**
  610. * Draws as much of the specified image as has already been scaled
  611. * to fit inside the specified rectangle.
  612. * <p>
  613. * The image is drawn inside the specified rectangle of this
  614. * graphics context's coordinate space, and is scaled if
  615. * necessary. Transparent pixels are drawn in the specified
  616. * background color.
  617. * This operation is equivalent to filling a rectangle of the
  618. * width and height of the specified image with the given color and then
  619. * drawing the image on top of it, but possibly more efficient.
  620. * <p>
  621. * This method returns immediately in all cases, even if the
  622. * entire image has not yet been scaled, dithered, and converted
  623. * for the current output device.
  624. * If the current output representation is not yet complete then
  625. * <code>drawImage</code> returns <code>false</code>. As more of
  626. * the image becomes available, the process that draws the image notifies
  627. * the specified image observer.
  628. * <p>
  629. * A scaled version of an image will not necessarily be
  630. * available immediately just because an unscaled version of the
  631. * image has been constructed for this output device. Each size of
  632. * the image may be cached separately and generated from the original
  633. * data in a separate image production sequence.
  634. * @param img the specified image to be drawn.
  635. * @param x the <i>x</i> coordinate.
  636. * @param y the <i>y</i> coordinate.
  637. * @param width the width of the rectangle.
  638. * @param height the height of the rectangle.
  639. * @param bgcolor the background color to paint under the
  640. * non-opaque portions of the image.
  641. * @param observer object to be notified as more of
  642. * the image is converted.
  643. * @see Image
  644. * @see ImageObserver
  645. * @see ImageObserver#imageUpdate(Image, int, int, int, int, int)
  646. */
  647. @NotImplemented
  648. public boolean drawImage(Image img, int x, int y,
  649. int width, int height,
  650. Color bgcolor,
  651. ImageObserver observer){
  652. logNotImplemented();
  653. return false;
  654. }
  655. /**
  656. * Draws as much of the specified area of the specified image as is
  657. * currently available, scaling it on the fly to fit inside the
  658. * specified area of the destination drawable surface. Transparent pixels
  659. * do not affect whatever pixels are already there.
  660. * <p>
  661. * This method returns immediately in all cases, even if the
  662. * image area to be drawn has not yet been scaled, dithered, and converted
  663. * for the current output device.
  664. * If the current output representation is not yet complete then
  665. * <code>drawImage</code> returns <code>false</code>. As more of
  666. * the image becomes available, the process that draws the image notifies
  667. * the specified image observer.
  668. * <p>
  669. * This method always uses the unscaled version of the image
  670. * to render the scaled rectangle and performs the required
  671. * scaling on the fly. It does not use a cached, scaled version
  672. * of the image for this operation. Scaling of the image from source
  673. * to destination is performed such that the first coordinate
  674. * of the source rectangle is mapped to the first coordinate of
  675. * the destination rectangle, and the second source coordinate is
  676. * mapped to the second destination coordinate. The subimage is
  677. * scaled and flipped as needed to preserve those mappings.
  678. * @param img the specified image to be drawn
  679. * @param dx1 the <i>x</i> coordinate of the first corner of the
  680. * destination rectangle.
  681. * @param dy1 the <i>y</i> coordinate of the first corner of the
  682. * destination rectangle.
  683. * @param dx2 the <i>x</i> coordinate of the second corner of the
  684. * destination rectangle.
  685. * @param dy2 the <i>y</i> coordinate of the second corner of the
  686. * destination rectangle.
  687. * @param sx1 the <i>x</i> coordinate of the first corner of the
  688. * source rectangle.
  689. * @param sy1 the <i>y</i> coordinate of the first corner of the
  690. * source rectangle.
  691. * @param sx2 the <i>x</i> coordinate of the second corner of the
  692. * source rectangle.
  693. * @param sy2 the <i>y</i> coordinate of the second corner of the
  694. * source rectangle.
  695. * @param observer object to be notified as more of the image is
  696. * scaled and converted.
  697. * @see Image
  698. * @see ImageObserver
  699. * @see ImageObserver#imageUpdate(Image, int, int, int, int, int)
  700. * @since JDK1.1
  701. */
  702. @NotImplemented
  703. public boolean drawImage(Image img,
  704. int dx1, int dy1, int dx2, int dy2,
  705. int sx1, int sy1, int sx2, int sy2,
  706. ImageObserver observer){
  707. logNotImplemented();
  708. return false;
  709. }
  710. /**
  711. * Draws as much of the specified area of the specified image as is
  712. * currently available, scaling it on the fly to fit inside the
  713. * specified area of the destination drawable surface.
  714. * <p>
  715. * Transparent pixels are drawn in the specified background color.
  716. * This operation is equivalent to filling a rectangle of the
  717. * width and height of the specified image with the given color and then
  718. * drawing the image on top of it, but possibly more efficient.
  719. * <p>
  720. * This method returns immediately in all cases, even if the
  721. * image area to be drawn has not yet been scaled, dithered, and converted
  722. * for the current output device.
  723. * If the current output representation is not yet complete then
  724. * <code>drawImage</code> returns <code>false</code>. As more of
  725. * the image becomes available, the process that draws the image notifies
  726. * the specified image observer.
  727. * <p>
  728. * This method always uses the unscaled version of the image
  729. * to render the scaled rectangle and performs the required
  730. * scaling on the fly. It does not use a cached, scaled version
  731. * of the image for this operation. Scaling of the image from source
  732. * to destination is performed such that the first coordinate
  733. * of the source rectangle is mapped to the first coordinate of
  734. * the destination rectangle, and the second source coordinate is
  735. * mapped to the second destination coordinate. The subimage is
  736. * scaled and flipped as needed to preserve those mappings.
  737. * @param img the specified image to be drawn
  738. * @param dx1 the <i>x</i> coordinate of the first corner of the
  739. * destination rectangle.
  740. * @param dy1 the <i>y</i> coordinate of the first corner of the
  741. * destination rectangle.
  742. * @param dx2 the <i>x</i> coordinate of the second corner of the
  743. * destination rectangle.
  744. * @param dy2 the <i>y</i> coordinate of the second corner of the
  745. * destination rectangle.
  746. * @param sx1 the <i>x</i> coordinate of the first corner of the
  747. * source rectangle.
  748. * @param sy1 the <i>y</i> coordinate of the first corner of the
  749. * source rectangle.
  750. * @param sx2 the <i>x</i> coordinate of the second corner of the
  751. * source rectangle.
  752. * @param sy2 the <i>y</i> coordinate of the second corner of the
  753. * source rectangle.
  754. * @param bgcolor the background color to paint under the
  755. * non-opaque portions of the image.
  756. * @param observer object to be notified as more of the image is
  757. * scaled and converted.
  758. * @see Image
  759. * @see ImageObserver
  760. * @see ImageObserver#imageUpdate(Image, int, int, int, int, int)
  761. * @since JDK1.1
  762. */
  763. @NotImplemented
  764. public boolean drawImage(Image img,
  765. int dx1, int dy1, int dx2, int dy2,
  766. int sx1, int sy1, int sx2, int sy2,
  767. Color bgcolor,
  768. ImageObserver observer){
  769. logNotImplemented();
  770. return false;
  771. }
  772. /**
  773. * Draws as much of the specified image as is currently available.
  774. * The image is drawn with its top-left corner at
  775. * (<i>x</i>,&nbsp;<i>y</i>) in this graphics context's coordinate
  776. * space. Transparent pixels in the image do not affect whatever
  777. * pixels are already there.
  778. * <p>
  779. * This method returns immediately in all cases, even if the
  780. * complete image has not yet been loaded, and it has not been dithered
  781. * and converted for the current output device.
  782. * <p>
  783. * If the image has completely loaded and its pixels are
  784. * no longer being changed, then
  785. * <code>drawImage</code> returns <code>true</code>.
  786. * Otherwise, <code>drawImage</code> returns <code>false</code>
  787. * and as more of
  788. * the image becomes available
  789. * or it is time to draw another frame of animation,
  790. * the process that loads the image notifies
  791. * the specified image observer.
  792. * @param img the specified image to be drawn. This method does
  793. * nothing if <code>img</code> is null.
  794. * @param x the <i>x</i> coordinate.
  795. * @param y the <i>y</i> coordinate.
  796. * @param observer object to be notified as more of
  797. * the image is converted.
  798. * @return <code>false</code> if the image pixels are still changing;
  799. * <code>true</code> otherwise.
  800. * @see Image
  801. * @see ImageObserver
  802. * @see ImageObserver#imageUpdate(Image, int, int, int, int, int)
  803. */
  804. @NotImplemented
  805. public boolean drawImage(Image img, int x, int y,
  806. ImageObserver observer) {
  807. logNotImplemented();
  808. return false;
  809. }
  810. /**
  811. * Disposes of this graphics context and releases
  812. * any system resources that it is using.
  813. * A <code>Graphics</code> object cannot be used after
  814. * <code>dispose</code>has been called.
  815. * <p>
  816. * When a Java program runs, a large number of <code>Graphics</code>
  817. * objects can be created within a short time frame.
  818. * Although the finalization process of the garbage collector
  819. * also disposes of the same system resources, it is preferable
  820. * to manually free the associated resources by calling this
  821. * method rather than to rely on a finalization process which
  822. * may not run to completion for a long period of time.
  823. * <p>
  824. * Graphics objects which are provided as arguments to the
  825. * <code>paint</code> and <code>update</code> methods
  826. * of components are automatically released by the system when
  827. * those methods return. For efficiency, programmers should
  828. * call <code>dispose</code> when finished using
  829. * a <code>Graphics</code> object only if it was created
  830. * directly from a component or another <code>Graphics</code> object.
  831. * @see Graphics#finalize
  832. * @see Component#paint
  833. * @see Component#update
  834. * @see Component#getGraphics
  835. * @see Graphics#create
  836. */
  837. public void dispose() {
  838. }
  839. /**
  840. * Draws a line, using the current color, between the points
  841. * <code>(x1,&nbsp;y1)</code> and <code>(x2,&nbsp;y2)</code>
  842. * in this graphics context's coordinate system.
  843. * @param x1 the first point's <i>x</i> coordinate.
  844. * @param y1 the first point's <i>y</i> coordinate.
  845. * @param x2 the second point's <i>x</i> coordinate.
  846. * @param y2 the second point's <i>y</i> coordinate.
  847. */
  848. public void drawLine(int x1, int y1, int x2, int y2){
  849. Line2D line = new Line2D.Double(x1, y1, x2, y2);
  850. draw(line);
  851. }
  852. /**
  853. * Fills a closed polygon defined by
  854. * arrays of <i>x</i> and <i>y</i> coordinates.
  855. * <p>
  856. * This method draws the polygon defined by <code>nPoint</code> line
  857. * segments, where the first <code>nPoint&nbsp;-&nbsp;1</code>
  858. * line segments are line segments from
  859. * <code>(xPoints[i&nbsp;-&nbsp;1],&nbsp;yPoints[i&nbsp;-&nbsp;1])</code>
  860. * to <code>(xPoints[i],&nbsp;yPoints[i])</code>, for
  861. * 1&nbsp;&le;&nbsp;<i>i</i>&nbsp;&le;&nbsp;<code>nPoints</code>.
  862. * The figure is automatically closed by drawing a line connecting
  863. * the final point to the first point, if those points are different.
  864. * <p>
  865. * The area inside the polygon is defined using an
  866. * even-odd fill rule, also known as the alternating rule.
  867. * @param xPoints a an array of <code>x</code> coordinates.
  868. * @param yPoints a an array of <code>y</code> coordinates.
  869. * @param nPoints a the total number of points.
  870. * @see Graphics#drawPolygon(int[], int[], int)
  871. */
  872. public void fillPolygon(int[] xPoints, int[] yPoints,
  873. int nPoints){
  874. Polygon polygon = new Polygon(xPoints, yPoints, nPoints);
  875. fill(polygon);
  876. }
  877. /**
  878. * Fills the specified rectangle.
  879. * The left and right edges of the rectangle are at
  880. * <code>x</code> and <code>x&nbsp;+&nbsp;width&nbsp;-&nbsp;1</code>.
  881. * The top and bottom edges are at
  882. * <code>y</code> and <code>y&nbsp;+&nbsp;height&nbsp;-&nbsp;1</code>.
  883. * The resulting rectangle covers an area
  884. * <code>width</code> pixels wide by
  885. * <code>height</code> pixels tall.
  886. * The rectangle is filled using the graphics context's current color.
  887. * @param x the <i>x</i> coordinate
  888. * of the rectangle to be filled.
  889. * @param y the <i>y</i> coordinate
  890. * of the rectangle to be filled.
  891. * @param width the width of the rectangle to be filled.
  892. * @param height the height of the rectangle to be filled.
  893. * @see Graphics#clearRect
  894. * @see Graphics#drawRect
  895. */
  896. public void fillRect(int x, int y, int width, int height){
  897. Rectangle rect = new Rectangle(x, y, width, height);
  898. fill(rect);
  899. }
  900. /**
  901. * Draws the outline of the specified rectangle.
  902. * The left and right edges of the rectangle are at
  903. * <code>x</code> and <code>x&nbsp;+&nbsp;width</code>.
  904. * The top and bottom edges are at
  905. * <code>y</code> and <code>y&nbsp;+&nbsp;height</code>.
  906. * The rectangle is drawn using the graphics context's current color.
  907. * @param x the <i>x</i> coordinate
  908. * of the rectangle to be drawn.
  909. * @param y the <i>y</i> coordinate
  910. * of the rectangle to be drawn.
  911. * @param width the width of the rectangle to be drawn.
  912. * @param height the height of the rectangle to be drawn.
  913. * @see Graphics#fillRect
  914. * @see Graphics#clearRect
  915. */
  916. public void drawRect(int x, int y, int width, int height) {
  917. Rectangle rect = new Rectangle(x, y, width, height);
  918. draw(rect);
  919. }
  920. /**
  921. * Draws a closed polygon defined by
  922. * arrays of <i>x</i> and <i>y</i> coordinates.
  923. * Each pair of (<i>x</i>,&nbsp;<i>y</i>) coordinates defines a point.
  924. * <p>
  925. * This method draws the polygon defined by <code>nPoint</code> line
  926. * segments, where the first <code>nPoint&nbsp;-&nbsp;1</code>
  927. * line segments are line segments from
  928. * <code>(xPoints[i&nbsp;-&nbsp;1],&nbsp;yPoints[i&nbsp;-&nbsp;1])</code>
  929. * to <code>(xPoints[i],&nbsp;yPoints[i])</code>, for
  930. * 1&nbsp;&le;&nbsp;<i>i</i>&nbsp;&le;&nbsp;<code>nPoints</code>.
  931. * The figure is automatically closed by drawing a line connecting
  932. * the final point to the first point, if those points are different.
  933. * @param xPoints a an array of <code>x</code> coordinates.
  934. * @param yPoints a an array of <code>y</code> coordinates.
  935. * @param nPoints a the total number of points.
  936. * @see Graphics#fillPolygon(int[],int[],int)
  937. * @see Graphics#drawPolyline
  938. */
  939. public void drawPolygon(int[] xPoints, int[] yPoints,
  940. int nPoints){
  941. Polygon polygon = new Polygon(xPoints, yPoints, nPoints);
  942. draw(polygon);
  943. }
  944. /**
  945. * Intersects the current clip with the specified rectangle.
  946. * The resulting clipping area is the intersection of the current
  947. * clipping area and the specified rectangle. If there is no
  948. * current clipping area, either because the clip has never been
  949. * set, or the clip has been cleared using <code>setClip(null)</code>,
  950. * the specified rectangle becomes the new clip.
  951. * This method sets the user clip, which is independent of the
  952. * clipping associated with device bounds and window visibility.
  953. * This method can only be used to make the current clip smaller.
  954. * To set the current clip larger, use any of the setClip methods.
  955. * Rendering operations have no effect outside of the clipping area.
  956. * @param x the x coordinate of the rectangle to intersect the clip with
  957. * @param y the y coordinate of the rectangle to intersect the clip with
  958. * @param width the width of the rectangle to intersect the clip with
  959. * @param height the height of the rectangle to intersect the clip with
  960. * @see #setClip(int, int, int, int)
  961. * @see #setClip(Shape)
  962. */
  963. public void clipRect(int x, int y, int width, int height){
  964. clip(new Rectangle(x, y, width, height));
  965. }
  966. /**
  967. * Sets the current clipping area to an arbitrary clip shape.
  968. * Not all objects that implement the <code>Shape</code>
  969. * interface can be used to set the clip. The only
  970. * <code>Shape</code> objects that are guaranteed to be
  971. * supported are <code>Shape</code> objects that are
  972. * obtained via the <code>getClip</code> method and via
  973. * <code>Rectangle</code> objects. This method sets the
  974. * user clip, which is independent of the clipping associated
  975. * with device bounds and window visibility.
  976. * @param clip the <code>Shape</code> to use to set the clip
  977. * @see Graphics#getClip()
  978. * @see Graphics#clipRect
  979. * @see Graphics#setClip(int, int, int, int)
  980. * @since JDK1.1
  981. */
  982. @NotImplemented
  983. public void setClip(Shape clip) {
  984. logNotImplemented();
  985. }
  986. /**
  987. * Returns the bounding rectangle of the current clipping area.
  988. * This method refers to the user clip, which is independent of the
  989. * clipping associated with device bounds and window visibility.
  990. * If no clip has previously been set, or if the clip has been
  991. * cleared using <code>setClip(null)</code>, this method returns
  992. * <code>null</code>.
  993. * The coordinates in the rectangle are relative to the coordinate
  994. * system origin of this graphics context.
  995. * @return the bounding rectangle of the current clipping area,
  996. * or <code>null</code> if no clip is set.
  997. * @see Graphics#getClip
  998. * @see Graphics#clipRect
  999. * @see Graphics#setClip(int, int, int, int)
  1000. * @see Graphics#setClip(Shape)
  1001. * @since JDK1.1
  1002. */
  1003. public Rectangle getClipBounds(){
  1004. logNotImplemented();
  1005. return null;
  1006. }
  1007. /**
  1008. * Draws the text given by the specified iterator, using this
  1009. * graphics context's current color. The iterator has to specify a font
  1010. * for each character. The baseline of the
  1011. * first character is at position (<i>x</i>,&nbsp;<i>y</i>) in this
  1012. * graphics context's coordinate system.
  1013. * @param iterator the iterator whose text is to be drawn
  1014. * @param x the <i>x</i> coordinate.
  1015. * @param y the <i>y</i> coordinate.
  1016. * @see Graphics#drawBytes
  1017. * @see Graphics#drawChars
  1018. */
  1019. public void drawString(AttributedCharacterIterator iterator,
  1020. int x, int y){
  1021. drawString(iterator, (float)x, (float)y);
  1022. }
  1023. /**
  1024. * Clears the specified rectangle by filling it with the background
  1025. * color of the current drawing surface. This operation does not
  1026. * use the current paint mode.
  1027. * <p>
  1028. * Beginning with Java&nbsp;1.1, the background color
  1029. * of offscreen images may be system dependent. Applications should
  1030. * use <code>setColor</code> followed by <code>fillRect</code> to
  1031. * ensure that an offscreen image is cleared to a specific color.
  1032. * @param x the <i>x</i> coordinate of the rectangle to clear.
  1033. * @param y the <i>y</i> coordinate of the rectangle to clear.
  1034. * @param width the width of the rectangle to clear.
  1035. * @param height the height of the rectangle to clear.
  1036. * @see Graphics#fillRect(int, int, int, int)
  1037. * @see Graphics#drawRect
  1038. * @see Graphics#setColor(Color)
  1039. * @see Graphics#setPaintMode
  1040. * @see Graphics#setXORMode(Color)
  1041. */
  1042. public void clearRect(int x, int y, int width, int height) {
  1043. Paint paint = getPaint();
  1044. setColor(getBackground());
  1045. fillRect(x, y, width, height);
  1046. setPaint(paint);
  1047. }
  1048. public void copyArea(int x, int y, int width, int height, int dx, int dy) {
  1049. }
  1050. /**
  1051. * Sets the current clip to the rectangle specified by the given
  1052. * coordinates. This method sets the user clip, which is
  1053. * independent of the clipping associated with device bounds
  1054. * and window visibility.
  1055. * Rendering operations have no effect outside of the clipping area.
  1056. * @param x the <i>x</i> coordinate of the new clip rectangle.
  1057. * @param y the <i>y</i> coordinate of the new clip rectangle.
  1058. * @param width the width of the new clip rectangle.
  1059. * @param height the height of the new clip rectangle.
  1060. * @see Graphics#clipRect
  1061. * @see Graphics#setClip(Shape)
  1062. * @since JDK1.1
  1063. */
  1064. public void setClip(int x, int y, int width, int height){
  1065. setClip(new Rectangle(x, y, width, height));
  1066. }
  1067. /**
  1068. * Concatenates the current <code>Graphics2D</code>
  1069. * <code>Transform</code> with a rotation transform.
  1070. * Subsequent rendering is rotated by the specified radians relative
  1071. * to the previous origin.
  1072. * This is equivalent to calling <code>transform(R)</code>, where R is an
  1073. * <code>AffineTransform</code> represented by the following matrix:
  1074. * <pre>
  1075. * [ cos(theta) -sin(theta) 0 ]
  1076. * [ sin(theta) cos(theta) 0 ]
  1077. * [ 0 0 1 ]
  1078. * </pre>
  1079. * Rotating with a positive angle theta rotates points on the positive
  1080. * x axis toward the positive y axis.
  1081. * @param theta the angle of rotation in radians
  1082. */
  1083. public void rotate(double theta){
  1084. _transform.rotate(theta);
  1085. }
  1086. /**
  1087. * Concatenates the current <code>Graphics2D</code>
  1088. * <code>Transform</code> with a translated rotation
  1089. * transform. Subsequent rendering is transformed by a transform
  1090. * which is constructed by translating to the specified location,
  1091. * rotating by the specified radians, and translating back by the same
  1092. * amount as the original translation. This is equivalent to the
  1093. * following sequence of calls:
  1094. * <pre>
  1095. * translate(x, y);
  1096. * rotate(theta);
  1097. * translate(-x, -y);
  1098. * </pre>
  1099. * Rotating with a positive angle theta rotates points on the positive
  1100. * x axis toward the positive y axis.
  1101. * @param theta the angle of rotation in radians
  1102. * @param x x coordinate of the origin of the rotation
  1103. * @param y y coordinate of the origin of the rotation
  1104. */
  1105. public void rotate(double theta, double x, double y){
  1106. _transform.rotate(theta, x, y);
  1107. }
  1108. /**
  1109. * Concatenates the current <code>Graphics2D</code>
  1110. * <code>Transform</code> with a shearing transform.
  1111. * Subsequent renderings are sheared by the specified
  1112. * multiplier relative to the previous position.
  1113. * This is equivalent to calling <code>transform(SH)</code>, where SH
  1114. * is an <code>AffineTransform</code> represented by the following
  1115. * matrix:
  1116. * <pre>
  1117. * [ 1 shx 0 ]
  1118. * [ shy 1 0 ]
  1119. * [ 0 0 1 ]
  1120. * </pre>
  1121. * @param shx the multiplier by which coordinates are shifted in
  1122. * the positive X axis direction as a function of their Y coordinate
  1123. * @param shy the multiplier by which coordinates are shifted in
  1124. * the positive Y axis direction as a function of their X coordinate
  1125. */
  1126. public void shear(double shx, double shy){
  1127. _transform.shear(shx, shy);
  1128. }
  1129. /**
  1130. * Get the rendering context of the <code>Font</code> within this
  1131. * <code>Graphics2D</code> context.
  1132. * The {@link FontRenderContext}
  1133. * encapsulates application hints such as anti-aliasing and
  1134. * fractional metrics, as well as target device specific information
  1135. * such as dots-per-inch. This information should be provided by the
  1136. * application when using objects that perform typographical
  1137. * formatting, such as <code>Font</code> and
  1138. * <code>TextLayout</code>. This information should also be provided
  1139. * by applications that perform their own layout and need accurate
  1140. * measurements of various characteristics of glyphs such as advance
  1141. * and line height when various rendering hints have been applied to
  1142. * the text rendering.
  1143. *
  1144. * @return a reference to an instance of FontRenderContext.
  1145. * @see FontRenderContext
  1146. * @see Font#createGlyphVector(FontRenderContext,char[])
  1147. * @see TextLayout
  1148. * @since JDK1.2
  1149. */
  1150. public FontRenderContext getFontRenderContext() {
  1151. boolean isAntiAliased = RenderingHints.VALUE_TEXT_ANTIALIAS_ON.equals(
  1152. getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING));
  1153. boolean usesFractionalMetrics = RenderingHints.VALUE_FRACTIONALMETRICS_ON.equals(
  1154. getRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS));
  1155. return new FontRenderContext(new AffineTransform(), isAntiAliased, usesFractionalMetrics);
  1156. }
  1157. /**
  1158. * Composes an <code>AffineTransform</code> object with the
  1159. * <code>Transform</code> in this <code>Graphics2D</code> according
  1160. * to the rule last-specified-first-applied. If the current
  1161. * <code>Transform</code> is Cx, the result of composition
  1162. * with Tx is a new <code>Transform</code> Cx'. Cx' becomes the
  1163. * current <code>Transform</code> for this <code>Graphics2D</code>.
  1164. * Transforming a point p by the updated <code>Transform</code> Cx' is
  1165. * equivalent to first transforming p by Tx and then transforming
  1166. * the result by the original <code>Transform</code> Cx. In other
  1167. * words, Cx'(p) = Cx(Tx(p)). A copy of the Tx is made, if necessary,
  1168. * so further modifications to Tx do not affect rendering.
  1169. * @param Tx the <code>AffineTransform</code> object to be composed with
  1170. * the current <code>Transform</code>
  1171. * @see #setTransform
  1172. * @see AffineTransform
  1173. */
  1174. public void transform(AffineTransform Tx) {
  1175. _transform.concatenate(Tx);
  1176. }
  1177. /**
  1178. * Renders a <code>BufferedImage</code> that is
  1179. * filtered with a
  1180. * {@link BufferedImageOp}.
  1181. * The rendering attributes applied include the <code>Clip</code>,
  1182. * <code>Transform</code>
  1183. * and <code>Composite</code> attributes. This is equivalent to:
  1184. * <pre>
  1185. * img1 = op.filter(img, null);
  1186. * drawImage(img1, new AffineTransform(1f,0f,0f,1f,x,y), null);
  1187. * </pre>
  1188. * @param img the <code>BufferedImage</code> to be rendered
  1189. * @param op the filter to be applied to the image before rendering
  1190. * @param x the x coordinate in user space where the image is rendered
  1191. * @param y the y coordinate in user space where the image is rendered
  1192. * @see #_transform
  1193. * @see #setTransform
  1194. * @see #setComposite
  1195. * @see #clip
  1196. * @see #setClip(Shape)
  1197. */
  1198. public void drawImage(BufferedImage img,
  1199. BufferedImageOp op,
  1200. int x,
  1201. int y){
  1202. img = op.filter(img, null);
  1203. drawImage(img, x, y, null);
  1204. }
  1205. /**
  1206. * Sets the background color for the <code>Graphics2D</code> context.
  1207. * The background color is used for clearing a region.
  1208. * When a <code>Graphics2D</code> is constructed for a
  1209. * <code>Component</code>, the background color is
  1210. * inherited from the <code>Component</code>. Setting the background color
  1211. * in the <code>Graphics2D</code> context only affects the subsequent
  1212. * <code>clearRect</code> calls and not the background color of the
  1213. * <code>Component</code>. To change the background
  1214. * of the <code>Component</code>, use appropriate methods of
  1215. * the <code>Component</code>.
  1216. * @param color the background color that isused in
  1217. * subsequent calls to <code>clearRect</code>
  1218. * @see #getBackground
  1219. * @see Graphics#clearRect
  1220. */
  1221. public void setBackground(Color color) {
  1222. if(color == null)
  1223. return;
  1224. _background = color;
  1225. }
  1226. /**
  1227. * Returns the background color used for clearing a region.
  1228. * @return the current <code>Graphics2D</code> <code>Color</code>,
  1229. * which defines the background color.
  1230. * @see #setBackground
  1231. */
  1232. public Color getBackground(){
  1233. return _background;
  1234. }
  1235. /**
  1236. * Sets the <code>Composite</code> for the <code>Graphics2D</code> context.
  1237. * The <code>Composite</code> is used in all drawing methods such as
  1238. * <code>drawImage</code>, <code>drawString</code>, <code>draw</code>,
  1239. * and <code>fill</code>. It specifies how new pixels are to be combined
  1240. * with the existing pixels on the graphics device during the rendering
  1241. * process.
  1242. * <p>If this <code>Graphics2D</code> context is drawing to a
  1243. * <code>Component</code> on the display screen and the
  1244. * <code>Composite</code> is a custom object rather than an
  1245. * instance of the <code>AlphaComposite</code> class, and if
  1246. * there is a security manager, its <code>checkPermission</code>
  1247. * method is called with an <code>AWTPermission("readDisplayPixels")</code>
  1248. * permission.
  1249. *
  1250. * @param comp the <code>Composite</code> object to be used for rendering
  1251. * @throws SecurityException
  1252. * if a custom <code>Composite</code> object is being
  1253. * used to render to the screen and a security manager
  1254. * is set and its <code>checkPermission</code> method
  1255. * does not allow the operation.
  1256. * @see Graphics#setXORMode
  1257. * @see Graphics#setPaintMode
  1258. * @see AlphaComposite
  1259. */
  1260. @NotImplemented
  1261. public void setComposite(Composite comp){
  1262. logNotImplemented();
  1263. }
  1264. /**
  1265. * Returns the current <code>Composite</code> in the
  1266. * <code>Graphics2D</code> context.
  1267. * @return the current <code>Graphics2D</code> <code>Composite</code>,
  1268. * which defines a compositing style.
  1269. * @see #setComposite
  1270. */
  1271. @NotImplemented
  1272. public Composite getComposite(){
  1273. logNotImplemented();
  1274. return null;
  1275. }
  1276. /**
  1277. * Returns the value of a single preference for the rendering algorithms.
  1278. * Hint categories include controls for rendering quality and overall
  1279. * time/quality trade-off in the rendering process. Refer to the
  1280. * <code>RenderingHints</code> class for definitions of some common
  1281. * keys and values.
  1282. * @param hintKey the key corresponding to the hint to get.
  1283. * @return an object representing the value for the specified hint key.
  1284. * Some of the keys and their associated values are defined in the
  1285. * <code>RenderingHints</code> class.
  1286. * @see RenderingHints
  1287. */
  1288. public Object getRenderingHint(RenderingHints.Key hintKey){
  1289. return _hints.get(hintKey);
  1290. }
  1291. /**
  1292. * Sets the value of a single preference for the rendering algorithms.
  1293. * Hint categories include controls for rendering quality and overall
  1294. * time/quality trade-off in the rendering process. Refer to the
  1295. * <code>RenderingHints</code> class for definitions of some common
  1296. * keys and values.
  1297. * @param hintKey the key of the hint to be set.
  1298. * @param hintValue the value indicating preferences for the specified
  1299. * hint category.
  1300. * @see RenderingHints
  1301. */
  1302. public void setRenderingHint(RenderingHints.Key hintKey, Object hintValue){
  1303. _hints.put(hintKey, hintValue);
  1304. }
  1305. /**
  1306. * Renders the text of the specified
  1307. * {@link GlyphVector} using
  1308. * the <code>Graphics2D</code> context's rendering attributes.
  1309. * The rendering attributes applied include the <code>Clip</code>,
  1310. * <code>Transform</code>, <code>Paint</code>, and
  1311. * <code>Composite</code> attributes. The <code>GlyphVector</code>
  1312. * specifies individual glyphs from a {@link Font}.
  1313. * The <code>GlyphVector</code> can also contain the glyph positions.
  1314. * This is the fastest way to render a set of characters to the
  1315. * screen.
  1316. *
  1317. * @param g the <code>GlyphVector</code> to be rendered
  1318. * @param x the x position in user space where the glyphs should be
  1319. * rendered
  1320. * @param y the y position in user space where the glyphs should be
  1321. * rendered
  1322. *
  1323. * @see Font#createGlyphVector(FontRenderContext, char[])
  1324. * @see GlyphVector
  1325. * @see #setPaint
  1326. * @see Graphics#setColor
  1327. * @see #setTransform
  1328. * @see #setComposite
  1329. * @see #setClip(Shape)
  1330. */
  1331. public void drawGlyphVector(GlyphVector g, float x, float y) {
  1332. Shape glyphOutline = g.getOutline(x, y);
  1333. fill(glyphOutline);
  1334. }
  1335. /**
  1336. * Returns the device configuration associated with this
  1337. * <code>Graphics2D</code>.
  1338. * @return the device configuration
  1339. */
  1340. public GraphicsConfiguration getDeviceConfiguration() {
  1341. return GraphicsEnvironment.getLocalGraphicsEnvironment().
  1342. getDefaultScreenDevice().getDefaultConfiguration();
  1343. }
  1344. /**
  1345. * Sets the values of an arbitrary number of preferences for the
  1346. * rendering algorithms.
  1347. * Only values for the rendering hints that are present in the
  1348. * specified <code>Map</code> object are modified.
  1349. * All other preferences not present in the specified
  1350. * object are left unmodified.
  1351. * Hint categories include controls for rendering quality and
  1352. * overall time/quality trade-off in the rendering process.
  1353. * Refer to the <code>RenderingHints</code> class for definitions of
  1354. * some common keys and values.
  1355. * @param hints the rendering hints to be set
  1356. * @see RenderingHints
  1357. */
  1358. public void addRenderingHints(Map<?,?> hints){
  1359. this._hints.putAll(hints);
  1360. }
  1361. /**
  1362. * Concatenates the current
  1363. * <code>Graphics2D</code> <code>Transform</code>
  1364. * with a translation transform.
  1365. * Subsequent rendering is translated by the specified
  1366. * distance relative to the previous position.
  1367. * This is equivalent to calling transform(T), where T is an
  1368. * <code>AffineTransform</code> represented by the following matrix:
  1369. * <pre>
  1370. * [ 1 0 tx ]
  1371. * [ 0 1 ty ]
  1372. * [ 0 0 1 ]
  1373. * </pre>
  1374. * @param tx the distance to translate along the x-axis
  1375. * @param ty the distance to translate along the y-axis
  1376. */
  1377. public void translate(double tx, double ty){
  1378. _transform.translate(tx, ty);
  1379. }
  1380. /**
  1381. * Renders the text of the specified iterator, using the
  1382. * <code>Graphics2D</code> context's current <code>Paint</code>. The
  1383. * iterator must specify a font
  1384. * for each character. The baseline of the
  1385. * first character is at position (<i>x</i>,&nbsp;<i>y</i>) in the
  1386. * User Space.
  1387. * The rendering attributes applied include the <code>Clip</code>,
  1388. * <code>Transform</code>, <code>Paint</code>, and
  1389. * <code>Composite</code> attributes.
  1390. * For characters in script systems such as Hebrew and Arabic,
  1391. * the glyphs can be rendered from right to left, in which case the
  1392. * coordinate supplied is the location of the leftmost character
  1393. * on the baseline.
  1394. * @param iterator the iterator whose text is to be rendered
  1395. * @param x the x coordinate where the iterator's text is to be
  1396. * rendered
  1397. * @param y the y coordinate where the iterator's text is to be
  1398. * rendered
  1399. * @see #setPaint
  1400. * @see Graphics#setColor
  1401. * @see #setTransform
  1402. * @see #setComposite
  1403. * @see #setClip
  1404. */
  1405. @NotImplemented
  1406. public void drawString(AttributedCharacterIterator iterator, float x, float y) {
  1407. logNotImplemented();
  1408. }
  1409. /**
  1410. * Checks whether or not the specified <code>Shape</code> intersects
  1411. * the specified {@link Rectangle}, which is in device
  1412. * space. If <code>onStroke</code> is false, this method checks
  1413. * whether or not the interior of the specified <code>Shape</code>
  1414. * intersects the specified <code>Rectangle</code>. If
  1415. * <code>onStroke</code> is <code>true</code>, this method checks
  1416. * whether or not the <code>Stroke</code> of the specified
  1417. * <code>Shape</code> outline intersects the specified
  1418. * <code>Rectangle</code>.
  1419. * The rendering attributes taken into account include the
  1420. * <code>Clip</code>, <code>Transform</code>, and <code>Stroke</code>
  1421. * attributes.
  1422. * @param rect the area in device space to check for a hit
  1423. * @param s the <code>Shape</code> to check for a hit
  1424. * @param onStroke flag used to choose between testing the
  1425. * stroked or the filled shape. If the flag is <code>true</code>, the
  1426. * <code>Stroke</code> oultine is tested. If the flag is
  1427. * <code>false</code>, the filled <code>Shape</code> is tested.
  1428. * @return <code>true</code> if there is a hit; <code>false</code>
  1429. * otherwise.
  1430. * @see #setStroke
  1431. * @see #fill(Shape)
  1432. * @see #draw(Shape)
  1433. * @see #_transform
  1434. * @see #setTransform
  1435. * @see #clip
  1436. * @see #setClip(Shape)
  1437. */
  1438. public boolean hit(Rectangle rect,
  1439. Shape s,
  1440. boolean onStroke){
  1441. if (onStroke) {
  1442. s = getStroke().createStrokedShape(s);
  1443. }
  1444. s = getTransform().createTransformedShape(s);
  1445. return s.intersects(rect);
  1446. }
  1447. /**
  1448. * Gets the preferences for the rendering algorithms. Hint categories
  1449. * include controls for rendering quality and overall time/quality
  1450. * trade-off in the rendering process.
  1451. * Returns all of the hint key/value pairs that were ever specified in
  1452. * one operation. Refer to the
  1453. * <code>RenderingHints</code> class for definitions of some common
  1454. * keys and values.
  1455. * @return a reference to an instance of <code>RenderingHints</code>
  1456. * that contains the current preferences.
  1457. * @see RenderingHints
  1458. */
  1459. public RenderingHints getRenderingHints(){
  1460. return _hints;
  1461. }
  1462. /**
  1463. * Replaces the values of all preferences for the rendering
  1464. * algorithms with the specified <code>hints</code>.
  1465. * The existing values for all rendering hints are discarded and
  1466. * the new set of known hints and values are initialized from the
  1467. * specified {@link Map} object.
  1468. * Hint categories include controls for rendering quality and
  1469. * overall time/quality trade-off in the rendering process.
  1470. * Refer to the <code>RenderingHints</code> class for definitions of
  1471. * some common keys and values.
  1472. * @param hints the rendering hints to be set
  1473. * @see RenderingHints
  1474. */
  1475. public void setRenderingHints(Map<?,?> hints){
  1476. this._hints = new RenderingHints(null);
  1477. this._hints.putAll(hints);
  1478. }
  1479. /**
  1480. * Renders an image, applying a transform from image space into user space
  1481. * before drawing.
  1482. * The transformation from user space into device space is done with
  1483. * the current <code>Transform</code> in the <code>Graphics2D</code>.
  1484. * The specified transformation is applied to the image before the
  1485. * transform attribute in the <code>Graphics2D</code> context is applied.
  1486. * The rendering attributes applied include the <code>Clip</code>,
  1487. * <code>Transform</code>, and <code>Composite</code> attributes.
  1488. * Note that no rendering is done if the specified transform is
  1489. * noninvertible.
  1490. * @param img the <code>Image</code> to be rendered
  1491. * @param xform the transformation from image space into user space
  1492. * @param obs the {@link ImageObserver}
  1493. * to be notified as more of the <code>Image</code>
  1494. * is converted
  1495. * @return <code>true</code> if the <code>Image</code> is
  1496. * fully loaded and completely rendered;
  1497. * <code>false</code> if the <code>Image</code> is still being loaded.
  1498. * @see #_transform
  1499. * @see #setTransform
  1500. * @see #setComposite
  1501. * @see #clip
  1502. * @see #setClip(Shape)
  1503. */
  1504. @NotImplemented
  1505. public boolean drawImage(Image img, AffineTransform xform, ImageObserver obs) {
  1506. logNotImplemented();
  1507. return false;
  1508. }
  1509. /**
  1510. * Draws as much of the specified image as has already been scaled
  1511. * to fit inside the specified rectangle.
  1512. * <p>
  1513. * The image is drawn inside the specified rectangle of this
  1514. * graphics context's coordinate space, and is scaled if
  1515. * necessary. Transparent pixels do not affect whatever pixels
  1516. * are already there.
  1517. * <p>
  1518. * This method returns immediately in all cases, even if the
  1519. * entire image has not yet been scaled, dithered, and converted
  1520. * for the current output device.
  1521. * If the current output representation is not yet complete, then
  1522. * <code>drawImage</code> returns <code>false</code>. As more of
  1523. * the image becomes available, the process that loads the image notifies
  1524. * the image observer by calling its <code>imageUpdate</code> method.
  1525. * <p>
  1526. * A scaled version of an image will not necessarily be
  1527. * available immediately just because an unscaled version of the
  1528. * image has been constructed for this output device. Each size of
  1529. * the image may be cached separately and generated from the original
  1530. * data in a separate image production sequence.
  1531. * @param img the specified image to be drawn. This method does
  1532. * nothing if <code>img</code> is null.
  1533. * @param x the <i>x</i> coordinate.
  1534. * @param y the <i>y</i> coordinate.
  1535. * @param width the width of the rectangle.
  1536. * @param height the height of the rectangle.
  1537. * @param observer object to be notified as more of
  1538. * the image is converted.
  1539. * @return <code>false</code> if the image pixels are still changing;
  1540. * <code>true</code> otherwise.
  1541. * @see Image
  1542. * @see ImageObserver
  1543. * @see ImageObserver#imageUpdate(Image, int, int, int, int, int)
  1544. */
  1545. @NotImplemented
  1546. public boolean drawImage(Image img, int x, int y,
  1547. int width, int height,
  1548. ImageObserver observer) {
  1549. logNotImplemented();
  1550. return false;
  1551. }
  1552. /**
  1553. * Creates a new <code>Graphics</code> object that is
  1554. * a copy of this <code>Graphics</code> object.
  1555. * @return a new graphics context that is a copy of
  1556. * this graphics context.
  1557. */
  1558. public Graphics create() {
  1559. try {
  1560. return (Graphics)clone();
  1561. } catch (CloneNotSupportedException e){
  1562. throw new RuntimeException(e);
  1563. }
  1564. }
  1565. /**
  1566. * Gets the font metrics for the specified font.
  1567. * @return the font metrics for the specified font.
  1568. * @param f the specified font
  1569. * @see Graphics#getFont
  1570. * @see FontMetrics
  1571. * @see Graphics#getFontMetrics()
  1572. */
  1573. @SuppressWarnings("deprecation")
  1574. @SuppressForbidden
  1575. public FontMetrics getFontMetrics(Font f) {
  1576. return Toolkit.getDefaultToolkit().getFontMetrics(f);
  1577. }
  1578. /**
  1579. * Sets the paint mode of this graphics context to alternate between
  1580. * this graphics context's current color and the new specified color.
  1581. * This specifies that logical pixel operations are performed in the
  1582. * XOR mode, which alternates pixels between the current color and
  1583. * a specified XOR color.
  1584. * <p>
  1585. * When drawing operations are performed, pixels which are the
  1586. * current color are changed to the specified color, and vice versa.
  1587. * <p>
  1588. * Pixels that are of colors other than those two colors are changed
  1589. * in an unpredictable but reversible manner; if the same figure is
  1590. * drawn twice, then all pixels are restored to their original values.
  1591. * @param c1 the XOR alternation color
  1592. */
  1593. @NotImplemented
  1594. public void setXORMode(Color c1) {
  1595. logNotImplemented();
  1596. }
  1597. /**
  1598. * Sets the paint mode of this graphics context to overwrite the
  1599. * destination with this graphics context's current color.
  1600. * This sets the logical pixel operation function to the paint or
  1601. * overwrite mode. All subsequent rendering operations will
  1602. * overwrite the destination with the current color.
  1603. */
  1604. @NotImplemented
  1605. public void setPaintMode() {
  1606. logNotImplemented();
  1607. }
  1608. /**
  1609. * Renders a
  1610. * {@link RenderableImage},
  1611. * applying a transform from image space into user space before drawing.
  1612. * The transformation from user space into device space is done with
  1613. * the current <code>Transform</code> in the <code>Graphics2D</code>.
  1614. * The specified transformation is applied to the image before the
  1615. * transform attribute in the <code>Graphics2D</code> context is applied.
  1616. * The rendering attributes applied include the <code>Clip</code>,
  1617. * <code>Transform</code>, and <code>Composite</code> attributes. Note
  1618. * that no rendering is done if the specified transform is
  1619. * noninvertible.
  1620. *<p>
  1621. * Rendering hints set on the <code>Graphics2D</code> object might
  1622. * be used in rendering the <code>RenderableImage</code>.
  1623. * If explicit control is required over specific hints recognized by a
  1624. * specific <code>RenderableImage</code>, or if knowledge of which hints
  1625. * are used is required, then a <code>RenderedImage</code> should be
  1626. * obtained directly from the <code>RenderableImage</code>
  1627. * and rendered using
  1628. *{@link #drawRenderedImage(RenderedImage, AffineTransform) drawRenderedImage}.
  1629. * @param img the image to be rendered. This method does
  1630. * nothing if <code>img</code> is null.
  1631. * @param xform the transformation from image space into user space
  1632. * @see #_transform
  1633. * @see #setTransform
  1634. * @see #setComposite
  1635. * @see #clip
  1636. * @see #setClip
  1637. * @see #drawRenderedImage
  1638. */
  1639. @NotImplemented
  1640. public void drawRenderedImage(RenderedImage img, AffineTransform xform) {
  1641. logNotImplemented();
  1642. }
  1643. /**
  1644. * Renders a {@link RenderedImage},
  1645. * applying a transform from image
  1646. * space into user space before drawing.
  1647. * The transformation from user space into device space is done with
  1648. * the current <code>Transform</code> in the <code>Graphics2D</code>.
  1649. * The specified transformation is applied to the image before the
  1650. * transform attribute in the <code>Graphics2D</code> context is applied.
  1651. * The rendering attributes applied include the <code>Clip</code>,
  1652. * <code>Transform</code>, and <code>Composite</code> attributes. Note
  1653. * that no rendering is done if the specified transform is
  1654. * noninvertible.
  1655. * @param img the image to be rendered. This method does
  1656. * nothing if <code>img</code> is null.
  1657. * @param xform the transformation from image space into user space
  1658. * @see #_transform
  1659. * @see #setTransform
  1660. * @see #setComposite
  1661. * @see #clip
  1662. * @see #setClip
  1663. */
  1664. @NotImplemented
  1665. public void drawRenderableImage(RenderableImage img, AffineTransform xform) {
  1666. logNotImplemented();
  1667. }
  1668. protected void applyStroke(SimpleShape<?,?> shape) {
  1669. if (_stroke instanceof BasicStroke){
  1670. BasicStroke bs = (BasicStroke)_stroke;
  1671. shape.setStrokeStyle((double)bs.getLineWidth());
  1672. float[] dash = bs.getDashArray();
  1673. if (dash != null) {
  1674. //TODO: implement more dashing styles
  1675. shape.setStrokeStyle(StrokeStyle.LineDash.DASH);
  1676. }
  1677. }
  1678. }
  1679. protected void applyPaint(SimpleShape<?,?> shape) {
  1680. if (_paint instanceof Color) {
  1681. shape.setFillColor((Color)_paint);
  1682. }
  1683. }
  1684. private void logNotImplemented() {
  1685. LOG.atWarn().log("Not implemented");
  1686. }
  1687. }