/** 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;
/** 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;
*/
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;
*/
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;
/** 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())
/** 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())
/** 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
/** 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
/** 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;
/** 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;
/** 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;
/** 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;
/** 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;
/** 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
/** 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;
/** 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;
/** Essentially clones the Regex object */
public Regex(Regex r)
{
- super((RegRes) r);
+ super(r);
dontMatchInQuotes = r.dontMatchInQuotes;
esc = r.esc;
ignoreCase = r.ignoreCase;
* 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)
}
/** A clone by any other name would smell as sweet. */
+ @Override
public Object clone()
{
return new Regex(this);
{
try
{
- return (Regex) getClass().newInstance();
+ return getClass().getDeclaredConstructor().newInstance();
} catch (InstantiationException ie)
{
return null;
} catch (IllegalAccessException iae)
{
return null;
+ } catch (ReflectiveOperationException roe)
+ {
+ return null;
}
}
{
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);
* representations. Also be prepared to see some strange output if your
* characters are not printable.
*/
+ @Override
public String toString()
{
if (false && thePattern == null)
*
* @see com.stevesoft.pat.FileRegex
*/
+ @Override
public boolean accept(File dir, String s)
{
return search(s);
public static Iterator<Reader> getRNAMLForPDBFileAsString(String pdbfile)
throws Exception
{
- List<NameValuePair> vals = new ArrayList<NameValuePair>();
+ List<NameValuePair> 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<Reader> readers = new ArrayList<Reader>();
+ ArrayList<Reader> readers = new ArrayList<>();
final BufferedReader postResponse = HttpClientUtils
.doHttpUrlPost(twoDtoolsURL, vals, 0, 0);
readers.add(postResponse);
try
{
final JSONArray responses = (JSONArray) jp.parse(respons);
- final Iterator rvals = responses.iterator();
- return new Iterator<Reader>()
- {
- @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(
public static Iterator<Reader> getRNAMLForPDBId(String pdbid)
throws Exception
{
- List<NameValuePair> vals = new ArrayList<NameValuePair>();
+ List<NameValuePair> vals = new ArrayList<>();
vals.add(new BasicNameValuePair("tool", "rnaview"));
vals.add(new BasicNameValuePair("pdbid", pdbid));
vals.add(new BasicNameValuePair("output", "rnaml"));
+ pdbid + "&output=rnaml");
// return processJsonResponseFor(new
// InputStreamReader(geturl.openStream()));
- ArrayList<Reader> readers = new ArrayList<Reader>();
+ ArrayList<Reader> 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();
+ }
+ }
+}
*
*/
public class EpsGraphics2D extends java.awt.Graphics2D
+ implements AutoCloseable
{
public static final String VERSION = "0.8.8";
* 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();
* 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();
* 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();
/**
* Draws a Shape on the EPS document.
*/
+ @Override
public void draw(Shape s)
{
draw(s, "stroke");
/**
* Draws an Image on the EPS document.
*/
+ @Override
public boolean drawImage(Image img, AffineTransform xform,
ImageObserver obs)
{
/**
* 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);
/**
* Draws a RenderedImage on the EPS document.
*/
+ @Override
public void drawRenderedImage(RenderedImage img, AffineTransform xform)
{
Hashtable properties = new Hashtable();
/**
* Draws a RenderableImage by invoking its createDefaultRendering method.
*/
+ @Override
public void drawRenderableImage(RenderableImage img, AffineTransform xform)
{
drawRenderedImage(img.createDefaultRendering(), xform);
/**
* Draws a string at (x,y)
*/
+ @Override
public void drawString(String str, int x, int y)
{
drawString(str, (float) x, (float) y);
/**
* Draws a string at (x,y)
*/
+ @Override
public void drawString(String s, float x, float y)
{
if (s != null && s.length() > 0)
* 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);
* Draws the characters of an AttributedCharacterIterator, starting from
* (x,y).
*/
+ @Override
public void drawString(AttributedCharacterIterator iterator, float x,
float y)
{
/**
* Draws a GlyphVector at (x,y)
*/
+ @Override
public void drawGlyphVector(GlyphVector g, float x, float y)
{
Shape shape = g.getOutline(x, y);
/**
* Fills a Shape on the EPS document.
*/
+ @Override
public void fill(Shape s)
{
draw(s, "fill");
* 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);
/**
* Returns the device configuration associated with this EpsGraphics2D object.
*/
+ @Override
public GraphicsConfiguration getDeviceConfiguration()
{
GraphicsConfiguration gc = null;
* Sets the Composite to be used by this EpsGraphics2D. EpsGraphics2D does not
* make use of these.
*/
+ @Override
public void setComposite(Composite comp)
{
_composite = comp;
* 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;
* Sets the stroke. Only accepts BasicStroke objects (or subclasses of
* BasicStroke).
*/
+ @Override
public void setStroke(Stroke s)
{
if (s instanceof BasicStroke)
/**
* Sets a rendering hint. These are not used by EpsGraphics2D.
*/
+ @Override
public void setRenderingHint(RenderingHints.Key hintKey, Object hintValue)
{
// Do nothing.
* 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;
/**
* Sets the rendering hints. These are ignored by EpsGraphics2D.
*/
+ @Override
public void setRenderingHints(Map hints)
{
// Do nothing.
/**
* Adds rendering hints. These are ignored by EpsGraphics2D.
*/
+ @Override
public void addRenderingHints(Map hints)
{
// Do nothing.
/**
* Returns the preferences for the rendering algorithms.
*/
+ @Override
public RenderingHints getRenderingHints()
{
return new RenderingHints(null);
* 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);
* Concatenates the current EpsGraphics2D Transformation with a translation
* transform.
*/
+ @Override
public void translate(double tx, double ty)
{
transform(AffineTransform.getTranslateInstance(tx, ty));
/**
* Concatenates the current EpsGraphics2D Transform with a rotation transform.
*/
+ @Override
public void rotate(double theta)
{
rotate(theta, 0, 0);
* 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));
* Concatenates the current EpsGraphics2D Transform with a scaling
* transformation.
*/
+ @Override
public void scale(double sx, double sy)
{
transform(AffineTransform.getScaleInstance(sx, sy));
/**
* Concatenates the current EpsGraphics2D Transform with a shearing transform.
*/
+ @Override
public void shear(double shx, double shy)
{
transform(AffineTransform.getShearInstance(shx, shy));
* 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);
/**
* Sets the AffineTransform to be used by this EpsGraphics2D.
*/
+ @Override
public void setTransform(AffineTransform Tx)
{
if (Tx == null)
/**
* Gets the AffineTransform used by this EpsGraphics2D.
*/
+ @Override
public AffineTransform getTransform()
{
return new AffineTransform(_transform);
/**
* Returns the current Paint of the EpsGraphics2D object.
*/
+ @Override
public Paint getPaint()
{
return _paint;
/**
* returns the current Composite of the EpsGraphics2D object.
*/
+ @Override
public Composite getComposite()
{
return _composite;
/**
* Sets the background color to be used by the clearRect method.
*/
+ @Override
public void setBackground(Color color)
{
if (color == null)
/**
* Gets the background color that is used by the clearRect method.
*/
+ @Override
public Color getBackground()
{
return _backgroundColor;
* Returns the Stroke currently used. Guaranteed to be an instance of
* BasicStroke.
*/
+ @Override
public Stroke getStroke()
{
return _stroke;
* 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)
/**
* Returns the FontRenderContext.
*/
+ @Override
public FontRenderContext getFontRenderContext()
{
return _fontRenderContext;
/**
* Returns a new Graphics object that is identical to this EpsGraphics2D.
*/
+ @Override
public Graphics create()
{
return new EpsGraphics2D(this);
* 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();
* 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;
/**
* Sets the Color to be used when drawing all future shapes, text, etc.
*/
+ @Override
public void setColor(Color c)
{
if (c == null)
* 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.
* <b><i><font color="red">Not implemented</font></i></b> - performs no
* action.
*/
+ @Override
public void setXORMode(Color c1)
{
methodNotSupported();
/**
* Returns the Font currently being used.
*/
+ @Override
public Font getFont()
{
return _font;
/**
* Sets the Font to be used in future text.
*/
+ @Override
public void setFont(Font font)
{
if (font == null)
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());
/**
* Gets the font metrics for the specified font.
*/
+ @Override
public FontMetrics getFontMetrics(Font f)
{
BufferedImage image = new BufferedImage(1, 1,
/**
* Returns the bounding rectangle of the current clipping area.
*/
+ @Override
public Rectangle getClipBounds()
{
if (_clip == null)
/**
* 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));
/**
* 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));
/**
* Gets the current clipping area.
*/
+ @Override
public Shape getClip()
{
if (_clip == null)
/**
* Sets the current clipping area to an arbitrary clip shape.
*/
+ @Override
public void setClip(Shape clip)
{
if (clip != null)
* <b><i><font color="red">Not implemented</font></i></b> - performs no
* action.
*/
+ @Override
public void copyArea(int x, int y, int width, int height, int dx, int dy)
{
methodNotSupported();
/**
* 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);
/**
* 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);
/**
* 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);
* 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();
/**
* Draws a rounded rectangle.
*/
+ @Override
public void drawRoundRect(int x, int y, int width, int height,
int arcWidth, int arcHeight)
{
/**
* Fills a rounded rectangle.
*/
+ @Override
public void fillRoundRect(int x, int y, int width, int height,
int arcWidth, int arcHeight)
{
/**
* Draws an oval.
*/
+ @Override
public void drawOval(int x, int y, int width, int height)
{
Shape shape = new Ellipse2D.Float(x, y, width, height);
/**
* Fills an oval.
*/
+ @Override
public void fillOval(int x, int y, int width, int height)
{
Shape shape = new Ellipse2D.Float(x, y, width, height);
/**
* Draws an arc.
*/
+ @Override
public void drawArc(int x, int y, int width, int height, int startAngle,
int arcAngle)
{
/**
* Fills an arc.
*/
+ @Override
public void fillArc(int x, int y, int width, int height, int startAngle,
int arcAngle)
{
/**
* Draws a polyline.
*/
+ @Override
public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints)
{
if (nPoints > 0)
/**
* 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);
/**
* Draws a polygon.
*/
+ @Override
public void drawPolygon(Polygon p)
{
draw(p);
/**
* 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);
/**
* Fills a polygon.
*/
+ @Override
public void fillPolygon(Polygon p)
{
draw(p, "fill");
/**
* 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);
/**
* 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);
/**
* Draws an image.
*/
+ @Override
public boolean drawImage(Image img, int x, int y, ImageObserver observer)
{
return drawImage(img, x, y, Color.white, observer);
/**
* Draws an image.
*/
+ @Override
public boolean drawImage(Image img, int x, int y, int width, int height,
ImageObserver observer)
{
/**
* Draws an image.
*/
+ @Override
public boolean drawImage(Image img, int x, int y, Color bgcolor,
ImageObserver observer)
{
/**
* Draws an image.
*/
+ @Override
public boolean drawImage(Image img, int x, int y, int width, int height,
Color bgcolor, ImageObserver observer)
{
/**
* 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)
{
/**
* 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)
* 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();
* 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)
/**
* Returns the bounding rectangle of the current clipping area.
*/
+ @Override
public Rectangle getClipBounds(Rectangle r)
{
if (_clip == null)