From: Ben Soares Date: Thu, 21 Mar 2019 15:31:15 +0000 (+0000) Subject: JAL-3130 Replaced deprecated Class.newInstance() with Class.getDeclaredConstructor... X-Git-Tag: Release_2_11_0~17^2~7^2~55 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=f3fa435d421eb9f071a526f802801c4a21ee2dc4;hp=3027bfb4b1b13af8686abcd419888e03141bd672;p=jalview.git JAL-3130 Replaced deprecated Class.newInstance() with Class.getDeclaredConstructor().newInstance(). Some eclipse fixes have appeared too. --- diff --git a/src/com/stevesoft/pat/Regex.java b/src/com/stevesoft/pat/Regex.java index c00ddad..6d07427 100755 --- a/src/com/stevesoft/pat/Regex.java +++ b/src/com/stevesoft/pat/Regex.java @@ -19,6 +19,7 @@ import com.stevesoft.pat.wrap.StringWrap; /** Matches a Unicode punctuation character. */ class UnicodePunct extends UniValidator { + @Override public int validate(StringLike s, int from, int to) { return from < s.length() && Prop.isPunct(s.charAt(from)) ? to : -1; @@ -28,6 +29,7 @@ class UnicodePunct extends UniValidator /** Matches a Unicode white space character. */ class UnicodeWhite extends UniValidator { + @Override public int validate(StringLike s, int from, int to) { return from < s.length() && Prop.isWhite(s.charAt(from)) ? to : -1; @@ -39,6 +41,7 @@ class UnicodeWhite extends UniValidator */ class NUnicodePunct extends UniValidator { + @Override public int validate(StringLike s, int from, int to) { return from < s.length() && !Prop.isPunct(s.charAt(from)) ? to : -1; @@ -50,6 +53,7 @@ class NUnicodePunct extends UniValidator */ class NUnicodeWhite extends UniValidator { + @Override public int validate(StringLike s, int from, int to) { return from < s.length() && !Prop.isWhite(s.charAt(from)) ? to : -1; @@ -59,6 +63,7 @@ class NUnicodeWhite extends UniValidator /** Matches a Unicode word character: an alphanumeric or underscore. */ class UnicodeW extends UniValidator { + @Override public int validate(StringLike s, int from, int to) { if (from >= s.length()) @@ -74,6 +79,7 @@ class UnicodeW extends UniValidator /** Matches a character that is not a Unicode alphanumeric or underscore. */ class NUnicodeW extends UniValidator { + @Override public int validate(StringLike s, int from, int to) { if (from >= s.length()) @@ -89,6 +95,7 @@ class NUnicodeW extends UniValidator /** Matches a Unicode decimal digit. */ class UnicodeDigit extends UniValidator { + @Override public int validate(StringLike s, int from, int to) { return from < s.length() && Prop.isDecimalDigit(s.charAt(from)) ? to @@ -99,6 +106,7 @@ class UnicodeDigit extends UniValidator /** Matches a character that is not a Unicode digit. */ class NUnicodeDigit extends UniValidator { + @Override public int validate(StringLike s, int from, int to) { return from < s.length() && !Prop.isDecimalDigit(s.charAt(from)) ? to @@ -109,6 +117,7 @@ class NUnicodeDigit extends UniValidator /** Matches a Unicode math character. */ class UnicodeMath extends UniValidator { + @Override public int validate(StringLike s, int from, int to) { return from < s.length() && Prop.isMath(s.charAt(from)) ? to : -1; @@ -118,6 +127,7 @@ class UnicodeMath extends UniValidator /** Matches a non-math Unicode character. */ class NUnicodeMath extends UniValidator { + @Override public int validate(StringLike s, int from, int to) { return from < s.length() && !Prop.isMath(s.charAt(from)) ? to : -1; @@ -127,6 +137,7 @@ class NUnicodeMath extends UniValidator /** Matches a Unicode currency symbol. */ class UnicodeCurrency extends UniValidator { + @Override public int validate(StringLike s, int from, int to) { return from < s.length() && Prop.isCurrency(s.charAt(from)) ? to : -1; @@ -136,6 +147,7 @@ class UnicodeCurrency extends UniValidator /** Matches a non-currency symbol Unicode character. */ class NUnicodeCurrency extends UniValidator { + @Override public int validate(StringLike s, int from, int to) { return from < s.length() && !Prop.isCurrency(s.charAt(from)) ? to : -1; @@ -145,6 +157,7 @@ class NUnicodeCurrency extends UniValidator /** Matches a Unicode alphabetic character. */ class UnicodeAlpha extends UniValidator { + @Override public int validate(StringLike s, int from, int to) { return from < s.length() && Prop.isAlphabetic(s.charAt(from)) ? to : -1; @@ -154,6 +167,7 @@ class UnicodeAlpha extends UniValidator /** Matches a non-alphabetic Unicode character. */ class NUnicodeAlpha extends UniValidator { + @Override public int validate(StringLike s, int from, int to) { return from < s.length() && !Prop.isAlphabetic(s.charAt(from)) ? to @@ -164,6 +178,7 @@ class NUnicodeAlpha extends UniValidator /** Matches an upper case Unicode character. */ class UnicodeUpper extends UniValidator { + @Override public int validate(StringLike s, int from, int to) { return from < s.length() && isUpper(s.charAt(from)) ? to : -1; @@ -178,6 +193,7 @@ class UnicodeUpper extends UniValidator /** Matches an upper case Unicode character. */ class UnicodeLower extends UniValidator { + @Override public int validate(StringLike s, int from, int to) { return from < s.length() && isLower(s.charAt(from)) ? to : -1; @@ -599,7 +615,7 @@ public class Regex extends RegRes implements FilenameFilter /** Essentially clones the Regex object */ public Regex(Regex r) { - super((RegRes) r); + super(r); dontMatchInQuotes = r.dontMatchInQuotes; esc = r.esc; ignoreCase = r.ignoreCase; @@ -674,6 +690,7 @@ public class Regex extends RegRes implements FilenameFilter * patterns are equal as well as the most recent match. If a Regex is compare * with a RegRes, only the result of the most recent match is compared. */ + @Override public boolean equals(Object o) { if (o instanceof Regex) @@ -694,6 +711,7 @@ public class Regex extends RegRes implements FilenameFilter } /** A clone by any other name would smell as sweet. */ + @Override public Object clone() { return new Regex(this); @@ -1077,13 +1095,16 @@ public class Regex extends RegRes implements FilenameFilter { try { - return (Regex) getClass().newInstance(); + return getClass().getDeclaredConstructor().newInstance(); } catch (InstantiationException ie) { return null; } catch (IllegalAccessException iae) { return null; + } catch (ReflectiveOperationException roe) + { + return null; } } @@ -1641,7 +1662,7 @@ public class Regex extends RegRes implements FilenameFilter { if (p instanceof Any && p.next == null) { - return (Pattern) new DotMulti(lo, hi); + return new DotMulti(lo, hi); } return RegOpt.safe4fm(p) ? (Pattern) new FastMulti(lo, hi, p) : (Pattern) new Multi(lo, hi, p); @@ -1801,6 +1822,7 @@ public class Regex extends RegRes implements FilenameFilter * representations. Also be prepared to see some strange output if your * characters are not printable. */ + @Override public String toString() { if (false && thePattern == null) @@ -1901,6 +1923,7 @@ public class Regex extends RegRes implements FilenameFilter * * @see com.stevesoft.pat.FileRegex */ + @Override public boolean accept(File dir, String s) { return search(s); diff --git a/src/jalview/analysis/scoremodels/FeatureDistanceModel.java b/src/jalview/analysis/scoremodels/FeatureDistanceModel.java index e506be2..8545e94 100644 --- a/src/jalview/analysis/scoremodels/FeatureDistanceModel.java +++ b/src/jalview/analysis/scoremodels/FeatureDistanceModel.java @@ -58,7 +58,7 @@ public class FeatureDistanceModel extends DistanceScoreModel FeatureDistanceModel instance; try { - instance = this.getClass().newInstance(); + instance = this.getClass().getDeclaredConstructor().newInstance(); instance.configureFromAlignmentView(view); return instance; } catch (InstantiationException | IllegalAccessException e) @@ -66,6 +66,9 @@ public class FeatureDistanceModel extends DistanceScoreModel System.err.println("Error in " + getClass().getName() + ".getInstance(): " + e.getMessage()); return null; + } catch (ReflectiveOperationException roe) + { + return null; } } @@ -188,7 +191,7 @@ public class FeatureDistanceModel extends DistanceScoreModel protected Map> findFeatureTypesAtColumn( SeqCigar[] seqs, int columnPosition) { - Map> sfap = new HashMap>(); + Map> sfap = new HashMap<>(); for (SeqCigar seq : seqs) { int spos = seq.findPosition(columnPosition); @@ -197,7 +200,7 @@ public class FeatureDistanceModel extends DistanceScoreModel /* * position is not a gap */ - Set types = new HashSet(); + Set types = new HashSet<>(); List sfs = fr.findFeaturesAtResidue( seq.getRefSeq(), spos); for (SequenceFeature sf : sfs) diff --git a/src/jalview/appletgui/EmbmenuFrame.java b/src/jalview/appletgui/EmbmenuFrame.java index 53782c0..7b489ea 100644 --- a/src/jalview/appletgui/EmbmenuFrame.java +++ b/src/jalview/appletgui/EmbmenuFrame.java @@ -49,7 +49,8 @@ import java.util.Map; * @author Jim Procter and Andrew Waterhouse * */ -public class EmbmenuFrame extends Frame implements MouseListener +public class EmbmenuFrame extends Frame + implements MouseListener, AutoCloseable { protected static final Font FONT_ARIAL_PLAIN_11 = new Font("Arial", Font.PLAIN, 11); @@ -59,7 +60,7 @@ public class EmbmenuFrame extends Frame implements MouseListener /** * map from labels to popup menus for the embedded menubar */ - protected Map embeddedPopup = new HashMap(); + protected Map embeddedPopup = new HashMap<>(); /** * the embedded menu is built on this and should be added to the frame at the @@ -199,6 +200,7 @@ public class EmbmenuFrame extends Frame implements MouseListener return embeddedMenu; } + @Override public void mousePressed(MouseEvent evt) { PopupMenu popup = null; @@ -223,18 +225,22 @@ public class EmbmenuFrame extends Frame implements MouseListener return embeddedPopup.get(source); } + @Override public void mouseClicked(MouseEvent evt) { } + @Override public void mouseReleased(MouseEvent evt) { } + @Override public void mouseEntered(MouseEvent evt) { } + @Override public void mouseExited(MouseEvent evt) { } @@ -262,11 +268,13 @@ public class EmbmenuFrame extends Frame implements MouseListener /** * calls destroyMenus() */ - public void finalize() throws Throwable + @Override + public void close() { destroyMenus(); embeddedPopup = null; embeddedMenu = null; - super.finalize(); + // no close for Frame + // super.finalize(); } } diff --git a/src/jalview/appletgui/TreePanel.java b/src/jalview/appletgui/TreePanel.java index b5e3342..671fee1 100644 --- a/src/jalview/appletgui/TreePanel.java +++ b/src/jalview/appletgui/TreePanel.java @@ -46,7 +46,7 @@ import java.awt.event.ItemEvent; import java.awt.event.ItemListener; public class TreePanel extends EmbmenuFrame - implements ActionListener, ItemListener + implements ActionListener, ItemListener, AutoCloseable { SequenceI[] seq; @@ -72,11 +72,11 @@ public class TreePanel extends EmbmenuFrame } @Override - public void finalize() throws Throwable + public void close() { ap = null; av = null; - super.finalize(); + super.close(); } /** diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index ac00fa2..3b0ca46 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -47,7 +47,7 @@ import java.util.Vector; * @author JimP * */ -public class Alignment implements AlignmentI +public class Alignment implements AlignmentI, AutoCloseable { private Alignment dataset; @@ -302,15 +302,20 @@ public class Alignment implements AlignmentI } @Override - public void finalize() throws Throwable + public void close() { if (getDataset() != null) { - getDataset().removeAlignmentRef(); + try + { + getDataset().removeAlignmentRef(); + } catch (Throwable e) + { + e.printStackTrace(); + } } nullReferences(); - super.finalize(); } /** diff --git a/src/jalview/ext/paradise/Annotate3D.java b/src/jalview/ext/paradise/Annotate3D.java index d50ad87..b8ba847 100644 --- a/src/jalview/ext/paradise/Annotate3D.java +++ b/src/jalview/ext/paradise/Annotate3D.java @@ -137,13 +137,13 @@ public class Annotate3D public static Iterator getRNAMLForPDBFileAsString(String pdbfile) throws Exception { - List vals = new ArrayList(); + List vals = new ArrayList<>(); vals.add(new BasicNameValuePair("tool", "rnaview")); vals.add(new BasicNameValuePair("data", pdbfile)); vals.add(new BasicNameValuePair("output", "rnaml")); // return processJsonResponseFor(HttpClientUtils.doHttpUrlPost(twoDtoolsURL, // vals)); - ArrayList readers = new ArrayList(); + ArrayList readers = new ArrayList<>(); final BufferedReader postResponse = HttpClientUtils .doHttpUrlPost(twoDtoolsURL, vals, 0, 0); readers.add(postResponse); @@ -158,74 +158,8 @@ public class Annotate3D try { final JSONArray responses = (JSONArray) jp.parse(respons); - final Iterator rvals = responses.iterator(); - return new Iterator() - { - @Override - public boolean hasNext() - { - return rvals.hasNext(); - } - - @Override - public Reader next() - { - JSONObject val = (JSONObject) rvals.next(); - - Object sval = null; - try - { - sval = val.get("2D"); - } catch (Exception x) - { - x.printStackTrace(); - } - ; - if (sval == null) - { - System.err.println( - "DEVELOPER WARNING: Annotate3d didn't return a '2D' tag in its response. Consider checking output of server. Response was :" - + val.toString()); - - sval = ""; - } - return new StringReader((sval instanceof JSONObject) - ? ((JSONObject) sval).toString() - : sval.toString()); - - } - - @Override - public void remove() - { - throw new Error( - MessageManager.getString("error.not_implemented_remove")); - - } - - @Override - protected Object clone() throws CloneNotSupportedException - { - throw new CloneNotSupportedException( - MessageManager.getString("error.not_implemented_clone")); - } - - @Override - public boolean equals(Object obj) - { - return super.equals(obj); - } - - @Override - protected void finalize() throws Throwable - { - while (rvals.hasNext()) - { - rvals.next(); - } - super.finalize(); - } - }; + final RvalsIterator rvals = new RvalsIterator(responses); + return rvals; } catch (Exception foo) { throw new Exception(MessageManager.getString( @@ -238,7 +172,7 @@ public class Annotate3D public static Iterator getRNAMLForPDBId(String pdbid) throws Exception { - List vals = new ArrayList(); + List vals = new ArrayList<>(); vals.add(new BasicNameValuePair("tool", "rnaview")); vals.add(new BasicNameValuePair("pdbid", pdbid)); vals.add(new BasicNameValuePair("output", "rnaml")); @@ -246,9 +180,83 @@ public class Annotate3D + pdbid + "&output=rnaml"); // return processJsonResponseFor(new // InputStreamReader(geturl.openStream())); - ArrayList readers = new ArrayList(); + ArrayList readers = new ArrayList<>(); readers.add(new InputStreamReader(geturl.openStream())); return readers.iterator(); } } + +class RvalsIterator implements Iterator, AutoCloseable +{ + private Iterator rvals; + + protected RvalsIterator(JSONArray responses) + { + this.rvals = responses.iterator(); + } + + @Override + public boolean hasNext() + { + return rvals.hasNext(); + } + + @Override + public Reader next() + { + JSONObject val = (JSONObject) rvals.next(); + + Object sval = null; + try + { + sval = val.get("2D"); + } catch (Exception x) + { + x.printStackTrace(); + } + ; + if (sval == null) + { + System.err.println( + "DEVELOPER WARNING: Annotate3d didn't return a '2D' tag in its response. Consider checking output of server. Response was :" + + val.toString()); + + sval = ""; + } + return new StringReader( + (sval instanceof JSONObject) ? ((JSONObject) sval).toString() + : sval.toString()); + + } + + @Override + public void remove() + { + throw new Error( + MessageManager.getString("error.not_implemented_remove")); + + } + + @Override + protected Object clone() throws CloneNotSupportedException + { + throw new CloneNotSupportedException( + MessageManager.getString("error.not_implemented_clone")); + } + + @Override + public boolean equals(Object obj) + { + return super.equals(obj); + } + + @Override + public void close() + { + while (rvals.hasNext()) + { + rvals.next(); + } + } +} diff --git a/src/jalview/io/vamsas/DatastoreRegistry.java b/src/jalview/io/vamsas/DatastoreRegistry.java index ff7a764..b53de08 100644 --- a/src/jalview/io/vamsas/DatastoreRegistry.java +++ b/src/jalview/io/vamsas/DatastoreRegistry.java @@ -24,7 +24,7 @@ import java.util.IdentityHashMap; import java.util.Iterator; import java.util.Map; -public class DatastoreRegistry +public class DatastoreRegistry implements AutoCloseable { protected static org.apache.log4j.Logger log = org.apache.log4j.Logger .getLogger(DatastoreRegistry.class); @@ -153,7 +153,7 @@ public class DatastoreRegistry } @Override - protected void finalize() throws Throwable + public void close() { if (dsObjReg != null) { @@ -172,6 +172,6 @@ public class DatastoreRegistry { dsItemReg.clear(); } - super.finalize(); + // super.finalize(); } } diff --git a/src/jalview/schemes/ColourSchemes.java b/src/jalview/schemes/ColourSchemes.java index 42465f2..d31fbba 100644 --- a/src/jalview/schemes/ColourSchemes.java +++ b/src/jalview/schemes/ColourSchemes.java @@ -72,12 +72,16 @@ public class ColourSchemes { try { - registerColourScheme(cs.getSchemeClass().newInstance()); + registerColourScheme( + cs.getSchemeClass().getDeclaredConstructor().newInstance()); } catch (InstantiationException | IllegalAccessException e) { System.err.println("Error instantiating colour scheme for " + cs.toString() + " " + e.getMessage()); e.printStackTrace(); + } catch (ReflectiveOperationException roe) + { + roe.printStackTrace(); } } } diff --git a/src/jalview/structure/StructureSelectionManager.java b/src/jalview/structure/StructureSelectionManager.java index cd986c0..9513220 100644 --- a/src/jalview/structure/StructureSelectionManager.java +++ b/src/jalview/structure/StructureSelectionManager.java @@ -1343,7 +1343,10 @@ public class StructureSelectionManager instances.remove(jalviewLite); try { - mnger.finalize(); + /* bsoares 2019-03-20 finalize deprecated, no apparent external + * resources to close + */ + // mnger.finalize(); } catch (Throwable x) { } diff --git a/src/jalview/ws/jws2/jabaws2/Jws2Instance.java b/src/jalview/ws/jws2/jabaws2/Jws2Instance.java index 2f3c298..e092192 100644 --- a/src/jalview/ws/jws2/jabaws2/Jws2Instance.java +++ b/src/jalview/ws/jws2/jabaws2/Jws2Instance.java @@ -38,7 +38,7 @@ import compbio.data.msa.SequenceAnnotation; import compbio.metadata.PresetManager; import compbio.metadata.RunnerConfig; -public class Jws2Instance +public class Jws2Instance implements AutoCloseable { public String hosturl; @@ -164,7 +164,7 @@ public class Jws2Instance } @Override - protected void finalize() throws Throwable + public void close() { if (service != null) { @@ -176,7 +176,7 @@ public class Jws2Instance // ignore } } - super.finalize(); + // super.finalize(); } public ParamDatastoreI getParamStore() diff --git a/src/jalview/ws/rest/HttpResultSet.java b/src/jalview/ws/rest/HttpResultSet.java index 4d5a2aa..5bfe3b5 100644 --- a/src/jalview/ws/rest/HttpResultSet.java +++ b/src/jalview/ws/rest/HttpResultSet.java @@ -50,7 +50,7 @@ import org.apache.james.mime4j.parser.MimeStreamParser; * */ -public class HttpResultSet extends FileParse +public class HttpResultSet extends FileParse implements AutoCloseable { private HttpRequestBase cachedRequest; @@ -89,7 +89,7 @@ public class HttpResultSet extends FileParse */ public List createResultDataProviders() { - List dp = new ArrayList(); + List dp = new ArrayList<>(); for (JvDataType type : restJob.rsd.getResultDataTypes()) { dp.add(new SimpleDataProvider(type, this, null)); @@ -106,7 +106,7 @@ public class HttpResultSet extends FileParse */ public Object[] parseResultSet() throws Exception, Error { - List dp = new ArrayList(); + List dp = new ArrayList<>(); Object[] results = null; if (en == null) @@ -200,7 +200,7 @@ public class HttpResultSet extends FileParse } @Override - protected void finalize() throws Throwable + public void close() { dataIn = null; cachedRequest = null; @@ -215,7 +215,8 @@ public class HttpResultSet extends FileParse } catch (Error ex) { } - super.finalize(); + // no finalize for FileParse + // super.close(); } /** diff --git a/src/org/jibble/epsgraphics/EpsGraphics2D.java b/src/org/jibble/epsgraphics/EpsGraphics2D.java index 313ec1c..fe6d962 100755 --- a/src/org/jibble/epsgraphics/EpsGraphics2D.java +++ b/src/org/jibble/epsgraphics/EpsGraphics2D.java @@ -119,6 +119,7 @@ import java.util.Map; * */ public class EpsGraphics2D extends java.awt.Graphics2D + implements AutoCloseable { public static final String VERSION = "0.8.8"; @@ -250,6 +251,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D * OutputStream is automatically flushed before being closed. If you forget to * do this, the file may be incomplete. */ + @Override public void close() throws IOException { flush(); @@ -402,6 +404,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D * Draws a 3D rectangle outline. If it is raised, light appears to come from * the top left. */ + @Override public void draw3DRect(int x, int y, int width, int height, boolean raised) { Color originalColor = getColor(); @@ -441,6 +444,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D * Fills a 3D rectangle. If raised, it has bright fill and light appears to * come from the top left. */ + @Override public void fill3DRect(int x, int y, int width, int height, boolean raised) { Color originalColor = getColor(); @@ -461,6 +465,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Draws a Shape on the EPS document. */ + @Override public void draw(Shape s) { draw(s, "stroke"); @@ -469,6 +474,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Draws an Image on the EPS document. */ + @Override public boolean drawImage(Image img, AffineTransform xform, ImageObserver obs) { @@ -482,6 +488,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Draws a BufferedImage on the EPS document. */ + @Override public void drawImage(BufferedImage img, BufferedImageOp op, int x, int y) { BufferedImage img1 = op.filter(img, null); @@ -491,6 +498,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Draws a RenderedImage on the EPS document. */ + @Override public void drawRenderedImage(RenderedImage img, AffineTransform xform) { Hashtable properties = new Hashtable(); @@ -513,6 +521,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Draws a RenderableImage by invoking its createDefaultRendering method. */ + @Override public void drawRenderableImage(RenderableImage img, AffineTransform xform) { drawRenderedImage(img.createDefaultRendering(), xform); @@ -521,6 +530,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Draws a string at (x,y) */ + @Override public void drawString(String str, int x, int y) { drawString(str, (float) x, (float) y); @@ -529,6 +539,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Draws a string at (x,y) */ + @Override public void drawString(String s, float x, float y) { if (s != null && s.length() > 0) @@ -543,6 +554,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D * Draws the characters of an AttributedCharacterIterator, starting from * (x,y). */ + @Override public void drawString(AttributedCharacterIterator iterator, int x, int y) { drawString(iterator, (float) x, (float) y); @@ -552,6 +564,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D * Draws the characters of an AttributedCharacterIterator, starting from * (x,y). */ + @Override public void drawString(AttributedCharacterIterator iterator, float x, float y) { @@ -584,6 +597,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Draws a GlyphVector at (x,y) */ + @Override public void drawGlyphVector(GlyphVector g, float x, float y) { Shape shape = g.getOutline(x, y); @@ -593,6 +607,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Fills a Shape on the EPS document. */ + @Override public void fill(Shape s) { draw(s, "fill"); @@ -602,6 +617,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D * Checks whether or not the specified Shape intersects the specified * Rectangle, which is in device space. */ + @Override public boolean hit(Rectangle rect, Shape s, boolean onStroke) { return s.intersects(rect); @@ -610,6 +626,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Returns the device configuration associated with this EpsGraphics2D object. */ + @Override public GraphicsConfiguration getDeviceConfiguration() { GraphicsConfiguration gc = null; @@ -632,6 +649,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D * Sets the Composite to be used by this EpsGraphics2D. EpsGraphics2D does not * make use of these. */ + @Override public void setComposite(Composite comp) { _composite = comp; @@ -641,6 +659,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D * Sets the Paint attribute for the EpsGraphics2D object. Only Paint objects * of type Color are respected by EpsGraphics2D. */ + @Override public void setPaint(Paint paint) { _paint = paint; @@ -654,6 +673,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D * Sets the stroke. Only accepts BasicStroke objects (or subclasses of * BasicStroke). */ + @Override public void setStroke(Stroke s) { if (s instanceof BasicStroke) @@ -688,6 +708,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Sets a rendering hint. These are not used by EpsGraphics2D. */ + @Override public void setRenderingHint(RenderingHints.Key hintKey, Object hintValue) { // Do nothing. @@ -697,6 +718,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D * Returns the value of a single preference for the rendering algorithms. * Rendering hints are not used by EpsGraphics2D. */ + @Override public Object getRenderingHint(RenderingHints.Key hintKey) { return null; @@ -705,6 +727,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Sets the rendering hints. These are ignored by EpsGraphics2D. */ + @Override public void setRenderingHints(Map hints) { // Do nothing. @@ -713,6 +736,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Adds rendering hints. These are ignored by EpsGraphics2D. */ + @Override public void addRenderingHints(Map hints) { // Do nothing. @@ -721,6 +745,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Returns the preferences for the rendering algorithms. */ + @Override public RenderingHints getRenderingHints() { return new RenderingHints(null); @@ -730,6 +755,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D * Translates the origin of the EpsGraphics2D context to the point (x,y) in * the current coordinate system. */ + @Override public void translate(int x, int y) { translate((double) x, (double) y); @@ -739,6 +765,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D * Concatenates the current EpsGraphics2D Transformation with a translation * transform. */ + @Override public void translate(double tx, double ty) { transform(AffineTransform.getTranslateInstance(tx, ty)); @@ -747,6 +774,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Concatenates the current EpsGraphics2D Transform with a rotation transform. */ + @Override public void rotate(double theta) { rotate(theta, 0, 0); @@ -756,6 +784,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D * Concatenates the current EpsGraphics2D Transform with a translated rotation * transform. */ + @Override public void rotate(double theta, double x, double y) { transform(AffineTransform.getRotateInstance(theta, x, y)); @@ -765,6 +794,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D * Concatenates the current EpsGraphics2D Transform with a scaling * transformation. */ + @Override public void scale(double sx, double sy) { transform(AffineTransform.getScaleInstance(sx, sy)); @@ -773,6 +803,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Concatenates the current EpsGraphics2D Transform with a shearing transform. */ + @Override public void shear(double shx, double shy) { transform(AffineTransform.getShearInstance(shx, shy)); @@ -782,6 +813,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D * Composes an AffineTransform object with the Transform in this EpsGraphics2D * according to the rule last-specified-first-applied. */ + @Override public void transform(AffineTransform Tx) { _transform.concatenate(Tx); @@ -791,6 +823,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Sets the AffineTransform to be used by this EpsGraphics2D. */ + @Override public void setTransform(AffineTransform Tx) { if (Tx == null) @@ -809,6 +842,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Gets the AffineTransform used by this EpsGraphics2D. */ + @Override public AffineTransform getTransform() { return new AffineTransform(_transform); @@ -817,6 +851,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Returns the current Paint of the EpsGraphics2D object. */ + @Override public Paint getPaint() { return _paint; @@ -825,6 +860,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * returns the current Composite of the EpsGraphics2D object. */ + @Override public Composite getComposite() { return _composite; @@ -833,6 +869,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Sets the background color to be used by the clearRect method. */ + @Override public void setBackground(Color color) { if (color == null) @@ -845,6 +882,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Gets the background color that is used by the clearRect method. */ + @Override public Color getBackground() { return _backgroundColor; @@ -854,6 +892,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D * Returns the Stroke currently used. Guaranteed to be an instance of * BasicStroke. */ + @Override public Stroke getStroke() { return _stroke; @@ -863,6 +902,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D * Intersects the current clip with the interior of the specified Shape and * sets the clip to the resulting intersection. */ + @Override public void clip(Shape s) { if (_clip == null) @@ -880,6 +920,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Returns the FontRenderContext. */ + @Override public FontRenderContext getFontRenderContext() { return _fontRenderContext; @@ -890,6 +931,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Returns a new Graphics object that is identical to this EpsGraphics2D. */ + @Override public Graphics create() { return new EpsGraphics2D(this); @@ -899,6 +941,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D * Returns an EpsGraphics2D object based on this Graphics object, but with a * new translation and clip area. */ + @Override public Graphics create(int x, int y, int width, int height) { Graphics g = create(); @@ -911,6 +954,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D * Returns the current Color. This will be a default value (black) until it is * changed using the setColor method. */ + @Override public Color getColor() { return _color; @@ -919,6 +963,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Sets the Color to be used when drawing all future shapes, text, etc. */ + @Override public void setColor(Color c) { if (c == null) @@ -934,6 +979,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D * Sets the paint mode of this EpsGraphics2D object to overwrite the * destination EpsDocument with the current color. */ + @Override public void setPaintMode() { // Do nothing - paint mode is the only method supported anyway. @@ -943,6 +989,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D * Not implemented - performs no * action. */ + @Override public void setXORMode(Color c1) { methodNotSupported(); @@ -951,6 +998,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Returns the Font currently being used. */ + @Override public Font getFont() { return _font; @@ -959,6 +1007,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Sets the Font to be used in future text. */ + @Override public void setFont(Font font) { if (font == null) @@ -966,13 +1015,14 @@ public class EpsGraphics2D extends java.awt.Graphics2D font = Font.decode(null); } _font = font; - append("/" + _font.getPSName() + " findfont " + ((int) _font.getSize()) + append("/" + _font.getPSName() + " findfont " + (_font.getSize()) + " scalefont setfont"); } /** * Gets the font metrics of the current font. */ + @Override public FontMetrics getFontMetrics() { return getFontMetrics(getFont()); @@ -981,6 +1031,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Gets the font metrics for the specified font. */ + @Override public FontMetrics getFontMetrics(Font f) { BufferedImage image = new BufferedImage(1, 1, @@ -992,6 +1043,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Returns the bounding rectangle of the current clipping area. */ + @Override public Rectangle getClipBounds() { if (_clip == null) @@ -1005,6 +1057,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Intersects the current clip with the specified rectangle. */ + @Override public void clipRect(int x, int y, int width, int height) { clip(new Rectangle(x, y, width, height)); @@ -1013,6 +1066,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Sets the current clip to the rectangle specified by the given coordinates. */ + @Override public void setClip(int x, int y, int width, int height) { setClip(new Rectangle(x, y, width, height)); @@ -1021,6 +1075,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Gets the current clipping area. */ + @Override public Shape getClip() { if (_clip == null) @@ -1046,6 +1101,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Sets the current clipping area to an arbitrary clip shape. */ + @Override public void setClip(Shape clip) { if (clip != null) @@ -1079,6 +1135,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D * Not implemented - performs no * action. */ + @Override public void copyArea(int x, int y, int width, int height, int dx, int dy) { methodNotSupported(); @@ -1087,6 +1144,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Draws a straight line from (x1,y1) to (x2,y2). */ + @Override public void drawLine(int x1, int y1, int x2, int y2) { Shape shape = new Line2D.Float(x1, y1, x2, y2); @@ -1096,6 +1154,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Fills a rectangle with top-left corner placed at (x,y). */ + @Override public void fillRect(int x, int y, int width, int height) { Shape shape = new Rectangle(x, y, width, height); @@ -1105,6 +1164,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Draws a rectangle with top-left corner placed at (x,y). */ + @Override public void drawRect(int x, int y, int width, int height) { Shape shape = new Rectangle(x, y, width, height); @@ -1115,6 +1175,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D * Clears a rectangle with top-left corner placed at (x,y) using the current * background color. */ + @Override public void clearRect(int x, int y, int width, int height) { Color originalColor = getColor(); @@ -1129,6 +1190,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Draws a rounded rectangle. */ + @Override public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { @@ -1140,6 +1202,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Fills a rounded rectangle. */ + @Override public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { @@ -1151,6 +1214,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Draws an oval. */ + @Override public void drawOval(int x, int y, int width, int height) { Shape shape = new Ellipse2D.Float(x, y, width, height); @@ -1160,6 +1224,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Fills an oval. */ + @Override public void fillOval(int x, int y, int width, int height) { Shape shape = new Ellipse2D.Float(x, y, width, height); @@ -1169,6 +1234,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Draws an arc. */ + @Override public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) { @@ -1180,6 +1246,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Fills an arc. */ + @Override public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) { @@ -1191,6 +1258,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Draws a polyline. */ + @Override public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) { if (nPoints > 0) @@ -1208,6 +1276,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Draws a polygon made with the specified points. */ + @Override public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) { Shape shape = new Polygon(xPoints, yPoints, nPoints); @@ -1217,6 +1286,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Draws a polygon. */ + @Override public void drawPolygon(Polygon p) { draw(p); @@ -1225,6 +1295,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Fills a polygon made with the specified points. */ + @Override public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints) { Shape shape = new Polygon(xPoints, yPoints, nPoints); @@ -1234,6 +1305,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Fills a polygon. */ + @Override public void fillPolygon(Polygon p) { draw(p, "fill"); @@ -1242,6 +1314,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Draws the specified characters, starting from (x,y) */ + @Override public void drawChars(char[] data, int offset, int length, int x, int y) { String string = new String(data, offset, length); @@ -1251,6 +1324,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Draws the specified bytes, starting from (x,y) */ + @Override public void drawBytes(byte[] data, int offset, int length, int x, int y) { String string = new String(data, offset, length); @@ -1260,6 +1334,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Draws an image. */ + @Override public boolean drawImage(Image img, int x, int y, ImageObserver observer) { return drawImage(img, x, y, Color.white, observer); @@ -1268,6 +1343,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Draws an image. */ + @Override public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer) { @@ -1277,6 +1353,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Draws an image. */ + @Override public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) { @@ -1288,6 +1365,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Draws an image. */ + @Override public boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer) { @@ -1298,6 +1376,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Draws an image. */ + @Override public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) { @@ -1308,6 +1387,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Draws an image. */ + @Override public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer) @@ -1403,24 +1483,29 @@ public class EpsGraphics2D extends java.awt.Graphics2D * only remaining EpsGraphics2D instance pointing at a EpsDocument object, * then the EpsDocument object shall become eligible for garbage collection. */ + @Override public void dispose() { _document = null; } + /* bsoares 2019-03-20 + * finalize is now deprecated. Implementing AutoCloseable instead /** * Finalizes the object. - */ + @Override public void finalize() { super.finalize(); } + */ /** * Returns the entire contents of the EPS document, complete with headers and * bounding box. The returned String is suitable for being written directly to * disk as an EPS file. */ + @Override public String toString() { StringWriter writer = new StringWriter(); @@ -1440,6 +1525,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D * Returns true if the specified rectangular area might intersect the current * clipping area. */ + @Override public boolean hitClip(int x, int y, int width, int height) { if (_clip == null) @@ -1453,6 +1539,7 @@ public class EpsGraphics2D extends java.awt.Graphics2D /** * Returns the bounding rectangle of the current clipping area. */ + @Override public Rectangle getClipBounds(Rectangle r) { if (_clip == null)