Skip to content

Commit 342eb5f

Browse files
committed
Add display for plots
1 parent abfbf28 commit 342eb5f

15 files changed

Lines changed: 1407 additions & 0 deletions
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 net.imagej.ui.swing.viewer.plot;
33+
34+
import net.imagej.plot.AbstractPlot;
35+
import org.scijava.display.AbstractDisplay;
36+
import org.scijava.display.Display;
37+
import org.scijava.plugin.Plugin;
38+
39+
/**
40+
* Default display for {@link AbstractPlot}s.
41+
*
42+
* @author Curtis Rueden
43+
*/
44+
@Plugin(type = Display.class)
45+
public class DefaultPlotDisplay extends AbstractDisplay<AbstractPlot> implements
46+
PlotDisplay
47+
{
48+
public DefaultPlotDisplay() {
49+
super(AbstractPlot.class);
50+
}
51+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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 net.imagej.ui.swing.viewer.plot;
33+
34+
import net.imagej.plot.AbstractPlot;
35+
import org.scijava.display.Display;
36+
37+
/**
38+
* Interface for {@link AbstractPlot} {@link Display}s.
39+
*
40+
* @author Curtis Rueden
41+
*/
42+
public interface PlotDisplay extends Display<AbstractPlot> {
43+
// This interface intentionally left blank.
44+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 net.imagej.ui.swing.viewer.plot;
33+
34+
import org.scijava.ui.viewer.DisplayPanel;
35+
36+
/**
37+
* This is a panel that can go inside a display window. It displays
38+
* {@link net.imagej.plot.AbstractPlot}s.
39+
*
40+
* @author Curtis Rueden
41+
*/
42+
public interface PlotDisplayPanel extends DisplayPanel {
43+
44+
@Override
45+
PlotDisplay getDisplay();
46+
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 net.imagej.ui.swing.viewer.plot;
33+
34+
import net.imagej.plot.AbstractPlot;
35+
import org.scijava.ui.viewer.DisplayViewer;
36+
37+
/**
38+
* A display viewer for a display of {@link AbstractPlot}s.
39+
*
40+
* @author Curtis Rueden
41+
*/
42+
public interface PlotDisplayViewer extends DisplayViewer<AbstractPlot> {
43+
44+
@Override
45+
PlotDisplay getDisplay();
46+
47+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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 net.imagej.ui.swing.viewer.plot;
33+
34+
import net.imagej.plot.AbstractPlot;
35+
import org.jfree.chart.ChartPanel;
36+
import org.jfree.chart.JFreeChart;
37+
import org.scijava.convert.ConvertService;
38+
import org.scijava.ui.viewer.DisplayWindow;
39+
40+
import javax.swing.*;
41+
import java.awt.*;
42+
import java.util.Objects;
43+
44+
/**
45+
* A JFreeChart-driven display panel for {@link AbstractPlot}s.
46+
*
47+
* @author Curtis Rueden
48+
*/
49+
public class SwingPlotDisplayPanel extends JPanel implements PlotDisplayPanel {
50+
51+
// -- instance variables --
52+
53+
private final DisplayWindow window;
54+
private final PlotDisplay display;
55+
private final ConvertService convertService;
56+
private Dimension prefferedSize;
57+
58+
// -- constructor --
59+
60+
public SwingPlotDisplayPanel(final PlotDisplay display,
61+
final DisplayWindow window, final ConvertService convertService)
62+
{
63+
this.display = display;
64+
this.window = window;
65+
this.convertService = convertService;
66+
setLayout(new BorderLayout());
67+
initPreferredSize();
68+
setupChart();
69+
window.setContent(this);
70+
}
71+
72+
private void initPreferredSize() {
73+
AbstractPlot plot = display.get(0);
74+
prefferedSize = new Dimension(plot.getPreferredWidth(), plot.getPreferredHeight());
75+
}
76+
77+
private void setupChart() {
78+
final JFreeChart chart = convertToJFreeChart(display.get(0));
79+
add(new ChartPanel(chart));
80+
}
81+
82+
private JFreeChart convertToJFreeChart(AbstractPlot plot) {
83+
return Objects.requireNonNull(convertService.convert(plot, JFreeChart.class));
84+
}
85+
86+
public static boolean supports(AbstractPlot abstractPlot, ConvertService convertService) {
87+
return convertService.supports(abstractPlot, JFreeChart.class);
88+
}
89+
90+
// -- PlotDisplayPanel methods --
91+
92+
@Override
93+
public PlotDisplay getDisplay() {
94+
return display;
95+
}
96+
97+
// -- DisplayPanel methods --
98+
99+
@Override
100+
public DisplayWindow getWindow() {
101+
return window;
102+
}
103+
104+
@Override
105+
public void redoLayout() { }
106+
107+
@Override
108+
public void setLabel(final String s) { }
109+
110+
@Override
111+
public void redraw() { }
112+
113+
@Override
114+
public Dimension getPreferredSize() {
115+
return prefferedSize;
116+
}
117+
118+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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 net.imagej.ui.swing.viewer.plot;
33+
34+
import net.imagej.plot.AbstractPlot;
35+
import net.imagej.ui.viewer.plot.AbstractPlotDisplayViewer;
36+
import org.scijava.convert.ConvertService;
37+
import org.scijava.display.Display;
38+
import org.scijava.plugin.Parameter;
39+
import org.scijava.plugin.Plugin;
40+
import org.scijava.ui.UserInterface;
41+
import org.scijava.ui.swing.SwingUI;
42+
import org.scijava.ui.viewer.DisplayViewer;
43+
import org.scijava.ui.viewer.DisplayWindow;
44+
45+
/**
46+
* A Swing {@link AbstractPlot} display viewer, which displays plots using JFreeChart.
47+
*
48+
* @author Curtis Rueden
49+
*/
50+
@Plugin(type = DisplayViewer.class)
51+
public class SwingPlotDisplayViewer extends AbstractPlotDisplayViewer {
52+
53+
@Parameter
54+
ConvertService convertService;
55+
56+
@Override
57+
public boolean isCompatible(final UserInterface ui) {
58+
return ui instanceof SwingUI;
59+
}
60+
61+
@Override
62+
public boolean canView(final Display<?> d) {
63+
if(! (d instanceof PlotDisplay))
64+
return false;
65+
AbstractPlot plot = ((PlotDisplay) d).get(0);
66+
return SwingPlotDisplayPanel.supports(plot, convertService);
67+
}
68+
69+
@Override
70+
public void view(final DisplayWindow w, final Display<?> d) {
71+
super.view(w, d);
72+
setPanel(new SwingPlotDisplayPanel(getDisplay(), w, convertService));
73+
}
74+
75+
}

0 commit comments

Comments
 (0)