[Swift-commit] r7474 - usertools/plotter/src/plotter
wozniak at ci.uchicago.edu
wozniak at ci.uchicago.edu
Tue Jan 14 12:48:29 CST 2014
Author: wozniak
Date: 2014-01-14 12:48:29 -0600 (Tue, 14 Jan 2014)
New Revision: 7474
Modified:
usertools/plotter/src/plotter/Lines.java
usertools/plotter/src/plotter/Plots.java
usertools/plotter/src/plotter/Util.java
Log:
New feature for drawing rectangles
Modified: usertools/plotter/src/plotter/Lines.java
===================================================================
--- usertools/plotter/src/plotter/Lines.java 2014-01-14 17:33:03 UTC (rev 7473)
+++ usertools/plotter/src/plotter/Lines.java 2014-01-14 18:48:29 UTC (rev 7474)
@@ -1,10 +1,12 @@
package plotter;
+import static plotter.Util.matches;
import gnu.getopt.Getopt;
import java.awt.BasicStroke;
import java.awt.Color;
+import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.io.*;
import java.util.ArrayList;
@@ -144,10 +146,12 @@
@param ylabel Y label text.
@param output EPS filename.
@return true/false depending if the method completed without error or not
+ * @throws UserInputException
*/
public static boolean plot(XYSeriesCollection collection,
- String title, String xlabel,
- String ylabel, String output)
+ String title, String xlabel,
+ String ylabel, String output)
+ throws UserInputException
{
EPSDocumentGraphics2D g2d = null;
Rectangle2D.Double rectangle = null;
@@ -182,6 +186,8 @@
chart.draw(g2d, rectangle);
+ drawGraphics(g2d);
+
try
{
g2d.finish();
@@ -457,6 +463,40 @@
renderer.setSeriesStroke(i, dottedStroke);
}
+ static void drawGraphics(Graphics2D g2d)
+ throws UserInputException
+ {
+ String s = properties.getProperty("graphics");
+ int count = Integer.parseInt(s);
+ for (int i = 0; i < count; i++)
+ {
+ String p = "graphic."+i;
+ String d = properties.getProperty(p);
+ if (d == null)
+ throw new UserInputException("no such property: " + p);
+ String[] tokens = d.split("\\s");
+ if (tokens.length == 0)
+ throw new UserInputException("property too short: " + p);
+ String shape = tokens[0];
+ if (matches(shape, "rectangle"))
+ drawRectangle(g2d, tokens);
+ else
+ throw new UserInputException("unknown shape: " + shape);
+ }
+ }
+
+ static void drawRectangle(Graphics2D g2d, String[] tokens)
+ throws UserInputException
+ {
+ Color color = Plots.string2color(tokens[1]);
+ double x0 = Integer.parseInt(tokens[2]);
+ double y0 = Integer.parseInt(tokens[3]);
+ double x1 = Integer.parseInt(tokens[4]);
+ double y1 = Integer.parseInt(tokens[5]);
+ g2d.setColor(color);
+ g2d.fill(new Rectangle2D.Double(x0, y0, x1, y1));
+ }
+
static String toString(double[][] array)
{
StringBuilder sb = new StringBuilder();
Modified: usertools/plotter/src/plotter/Plots.java
===================================================================
--- usertools/plotter/src/plotter/Plots.java 2014-01-14 17:33:03 UTC (rev 7473)
+++ usertools/plotter/src/plotter/Plots.java 2014-01-14 18:48:29 UTC (rev 7474)
@@ -1,7 +1,7 @@
package plotter;
+import java.awt.Color;
import java.awt.Font;
-
import java.util.Properties;
import org.jfree.chart.JFreeChart;
@@ -32,4 +32,20 @@
result = new Font(name, Font.PLAIN, 12);
return result;
}
+
+ static Color string2color(String s)
+ throws UserInputException
+ {
+ Color result = null;
+
+ if (s.compareToIgnoreCase("black") == 0)
+ result = Color.BLACK;
+ if (s.compareToIgnoreCase("white") == 0)
+ result = Color.WHITE;
+
+ if (result == null)
+ throw new UserInputException("unknown color: " + s);
+
+ return result;
+ }
}
Modified: usertools/plotter/src/plotter/Util.java
===================================================================
--- usertools/plotter/src/plotter/Util.java 2014-01-14 17:33:03 UTC (rev 7473)
+++ usertools/plotter/src/plotter/Util.java 2014-01-14 18:48:29 UTC (rev 7474)
@@ -72,6 +72,15 @@
return sb.toString();
}
+ public static boolean matches(String s1, String s2)
+ {
+ assert(s1 != null);
+ assert(s2 != null);
+ if (s1.compareToIgnoreCase(s2) == 0)
+ return true;
+ return false;
+ }
+
public static void fatal(String s)
{
System.err.println(s);
More information about the Swift-commit
mailing list