Skip to content

Commit 7b634f8

Browse files
maarztctrueden
authored andcommitted
Add converters XYPlot, CategoryChart -> JFreeChart
1 parent f192490 commit 7b634f8

File tree

9 files changed

+979
-0
lines changed

9 files changed

+979
-0
lines changed

pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,15 @@
156156
<artifactId>jdatepicker</artifactId>
157157
<version>${jdatepicker.version}</version>
158158
</dependency>
159+
<dependency>
160+
<groupId>org.jfree</groupId>
161+
<artifactId>jfreechart</artifactId>
162+
</dependency>
163+
<dependency>
164+
<groupId>org.jfree</groupId>
165+
<artifactId>jfreesvg</artifactId>
166+
<version>3.2</version>
167+
</dependency>
159168

160169
<!-- Test scope dependencies -->
161170
<dependency>
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* #%L
3+
* ImageJ software for multidimensional image processing and analysis.
4+
* %%
5+
* Copyright (C) 2009 - 2016 Board of Regents of the University of
6+
* Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck
7+
* Institute of Molecular Cell Biology and Genetics.
8+
* %%
9+
* Redistribution and use in source and binary forms, with or without
10+
* modification, are permitted provided that the following conditions are met:
11+
*
12+
* 1. Redistributions of source code must retain the above copyright notice,
13+
* this list of conditions and the following disclaimer.
14+
* 2. Redistributions in binary form must reproduce the above copyright notice,
15+
* this list of conditions and the following disclaimer in the documentation
16+
* and/or other materials provided with the distribution.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
22+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
* POSSIBILITY OF SUCH DAMAGE.
29+
* #L%
30+
*/
31+
32+
package org.scijava.ui.swing.viewer.plot.jfreechart;
33+
34+
import org.scijava.plot.LineStyle;
35+
36+
import java.awt.*;
37+
38+
/**
39+
* @author Matthias Arzt
40+
*/
41+
42+
class AwtLineStyles {
43+
44+
private final boolean visible;
45+
46+
private final BasicStroke stroke;
47+
48+
private AwtLineStyles(boolean visible, BasicStroke stroke) {
49+
this.visible = visible;
50+
this.stroke = stroke;
51+
}
52+
53+
public boolean isVisible() {
54+
return visible;
55+
}
56+
57+
public BasicStroke getStroke() {
58+
return stroke;
59+
}
60+
61+
public static AwtLineStyles getInstance(LineStyle style) {
62+
if(style != null)
63+
switch (style) {
64+
case SOLID:
65+
return solid;
66+
case DASH:
67+
return dash;
68+
case DOT:
69+
return dot;
70+
case NONE:
71+
return none;
72+
}
73+
return solid;
74+
}
75+
76+
// --- Helper Constants ---
77+
78+
private static AwtLineStyles solid = new AwtLineStyles(true, Strokes.solid);
79+
80+
private static AwtLineStyles dash = new AwtLineStyles(true, Strokes.dash);
81+
82+
private static AwtLineStyles dot = new AwtLineStyles(true, Strokes.dot);
83+
84+
private static AwtLineStyles none = new AwtLineStyles(false, Strokes.none);
85+
86+
static class Strokes {
87+
88+
private static BasicStroke solid = new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
89+
90+
private static BasicStroke dash = new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
91+
.0f, new float[]{6.0f, 6.0f}, 0.0f);
92+
93+
private static BasicStroke dot = new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
94+
.0f, new float[]{0.6f, 4.0f}, 0.0f);
95+
96+
private static BasicStroke none = new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
97+
.0f, new float[]{0.0f, 100.0f}, 0.0f);
98+
}
99+
100+
}
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/*
2+
* #%L
3+
* ImageJ software for multidimensional image processing and analysis.
4+
* %%
5+
* Copyright (C) 2009 - 2016 Board of Regents of the University of
6+
* Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck
7+
* Institute of Molecular Cell Biology and Genetics.
8+
* %%
9+
* Redistribution and use in source and binary forms, with or without
10+
* modification, are permitted provided that the following conditions are met:
11+
*
12+
* 1. Redistributions of source code must retain the above copyright notice,
13+
* this list of conditions and the following disclaimer.
14+
* 2. Redistributions in binary form must reproduce the above copyright notice,
15+
* this list of conditions and the following disclaimer in the documentation
16+
* and/or other materials provided with the distribution.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
22+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
* POSSIBILITY OF SUCH DAMAGE.
29+
* #L%
30+
*/
31+
32+
package org.scijava.ui.swing.viewer.plot.jfreechart;
33+
34+
import org.scijava.plot.MarkerStyle;
35+
36+
import java.awt.*;
37+
import java.awt.geom.Ellipse2D;
38+
import java.awt.geom.Path2D;
39+
import java.awt.geom.Rectangle2D;
40+
41+
/**
42+
* @author Matthias Arzt
43+
*/
44+
45+
class AwtMarkerStyles {
46+
47+
private final boolean visible;
48+
49+
private final boolean filled;
50+
51+
private final Shape shape;
52+
53+
private AwtMarkerStyles(boolean visible, boolean filled, Shape shape) {
54+
this.visible = visible;
55+
this.filled = filled;
56+
this.shape = shape;
57+
}
58+
59+
public boolean isVisible() {
60+
return visible;
61+
}
62+
63+
public boolean isFilled() {
64+
return filled;
65+
}
66+
67+
public Shape getShape() {
68+
return shape;
69+
}
70+
71+
public static AwtMarkerStyles getInstance(MarkerStyle style) {
72+
if(style != null)
73+
switch (style) {
74+
case NONE:
75+
return none;
76+
case PLUS:
77+
return plus;
78+
case X:
79+
return x;
80+
case STAR:
81+
return star;
82+
case SQUARE:
83+
return square;
84+
case FILLEDSQUARE:
85+
return filledSquare;
86+
case CIRCLE:
87+
return circle;
88+
case FILLEDCIRCLE:
89+
return filledCircle;
90+
}
91+
return square;
92+
}
93+
94+
// --- Helper Constants ---
95+
96+
private static AwtMarkerStyles none = new AwtMarkerStyles(false, false, null);
97+
98+
private static AwtMarkerStyles plus = new AwtMarkerStyles(true, false, Shapes.plus);
99+
100+
private static AwtMarkerStyles x = new AwtMarkerStyles(true, false, Shapes.x);
101+
102+
private static AwtMarkerStyles star = new AwtMarkerStyles(true, false, Shapes.star);
103+
104+
private static AwtMarkerStyles square = new AwtMarkerStyles(true, false, Shapes.square);
105+
106+
private static AwtMarkerStyles filledSquare = new AwtMarkerStyles(true, true, Shapes.square);
107+
108+
private static AwtMarkerStyles circle = new AwtMarkerStyles(true, false, Shapes.circle);
109+
110+
private static AwtMarkerStyles filledCircle = new AwtMarkerStyles(true, true, Shapes.circle);
111+
112+
113+
static private class Shapes {
114+
115+
private static Shape x = getAwtXShape();
116+
117+
private static Shape plus = getAwtPlusShape();
118+
119+
private static Shape star = getAwtStarShape();
120+
121+
private static Shape square = new Rectangle2D.Double(-3.0, -3.0, 6.0, 6.0);
122+
123+
private static Shape circle = new Ellipse2D.Double(-3.0, -3.0, 6.0, 6.0);
124+
125+
private static Shape getAwtXShape() {
126+
final Path2D p = new Path2D.Double();
127+
final double s = 3.0;
128+
p.moveTo(-s, -s);
129+
p.lineTo(s, s);
130+
p.moveTo(s, -s);
131+
p.lineTo(-s, s);
132+
return p;
133+
}
134+
135+
private static Shape getAwtPlusShape() {
136+
final Path2D p = new Path2D.Double();
137+
final double t = 4.0;
138+
p.moveTo(0, -t);
139+
p.lineTo(0, t);
140+
p.moveTo(t, 0);
141+
p.lineTo(-t, 0);
142+
return p;
143+
}
144+
145+
private static Shape getAwtStarShape() {
146+
final Path2D p = new Path2D.Double();
147+
final double s = 3.0;
148+
p.moveTo(-s, -s);
149+
p.lineTo(s, s);
150+
p.moveTo(s, -s);
151+
p.lineTo(-s, s);
152+
final double t = 4.0;
153+
p.moveTo(0, -t);
154+
p.lineTo(0, t);
155+
p.moveTo(t, 0);
156+
p.lineTo(-t, 0);
157+
return p;
158+
}
159+
160+
}
161+
162+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* #%L
3+
* ImageJ software for multidimensional image processing and analysis.
4+
* %%
5+
* Copyright (C) 2009 - 2016 Board of Regents of the University of
6+
* Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck
7+
* Institute of Molecular Cell Biology and Genetics.
8+
* %%
9+
* Redistribution and use in source and binary forms, with or without
10+
* modification, are permitted provided that the following conditions are met:
11+
*
12+
* 1. Redistributions of source code must retain the above copyright notice,
13+
* this list of conditions and the following disclaimer.
14+
* 2. Redistributions in binary form must reproduce the above copyright notice,
15+
* this list of conditions and the following disclaimer in the documentation
16+
* and/or other materials provided with the distribution.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
22+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
* POSSIBILITY OF SUCH DAMAGE.
29+
* #L%
30+
*/
31+
32+
package org.scijava.ui.swing.viewer.plot.jfreechart;
33+
34+
import org.scijava.plot.CategoryChart;
35+
import org.jfree.chart.JFreeChart;
36+
import org.scijava.Priority;
37+
import org.scijava.convert.AbstractConverter;
38+
import org.scijava.convert.Converter;
39+
import org.scijava.plugin.Plugin;
40+
41+
/**
42+
* @author Matthias Arzt
43+
*/
44+
@Plugin(type = Converter.class, priority = Priority.NORMAL_PRIORITY)
45+
public class CategoryChartConverter extends AbstractConverter<CategoryChart, JFreeChart> {
46+
@SuppressWarnings("unchecked")
47+
@Override
48+
public <T> T convert(Object o, Class<T> aClass) {
49+
return (T) CategoryChartGenerator.run((CategoryChart) o);
50+
}
51+
52+
@Override
53+
public Class<JFreeChart> getOutputType() {
54+
return JFreeChart.class;
55+
}
56+
57+
@Override
58+
public Class<CategoryChart> getInputType() {
59+
return CategoryChart.class;
60+
}
61+
}

0 commit comments

Comments
 (0)