Skip to content

Commit 54f47b3

Browse files
committed
build GUI for PlotComposite tool
Build the actual GUI for the composite plot image generating tool (#96). Include JavaDocs linking to other classes. GUI, unlike CLI, does not yet offer color customization options or title customization.
1 parent 897856b commit 54f47b3

4 files changed

Lines changed: 428 additions & 4 deletions

File tree

src/main/ScriptManagerGUI.java

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import window_interface.Figure_Generation.TwoColorHeatMapWindow;
5757
import window_interface.Figure_Generation.ThreeColorHeatMapWindow;
5858
import window_interface.Figure_Generation.MergeHeatMapWindow;
59+
import window_interface.Figure_Generation.PlotCompositeWindow;
5960
import window_interface.Figure_Generation.LabelHeatMapWindow;
6061

6162
public class ScriptManagerGUI {
@@ -1347,12 +1348,40 @@ public void run() {
13471348
});
13481349
}
13491350
});
1350-
sl_pnlFigure.putConstraint(SpringLayout.NORTH, btncolorSequencePlot, 0, SpringLayout.NORTH,
1351-
txtcolorSequencePlot);
1351+
sl_pnlFigure.putConstraint(SpringLayout.NORTH, btncolorSequencePlot, 0, SpringLayout.NORTH, txtcolorSequencePlot);
13521352
sl_pnlFigure.putConstraint(SpringLayout.WEST, btncolorSequencePlot, 10, SpringLayout.WEST, pnlFigure);
1353-
sl_pnlFigure.putConstraint(SpringLayout.WEST, txtcolorSequencePlot, 10, SpringLayout.EAST,
1354-
btncolorSequencePlot);
1353+
sl_pnlFigure.putConstraint(SpringLayout.WEST, txtcolorSequencePlot, 10, SpringLayout.EAST, btncolorSequencePlot);
13551354
pnlFigure.add(btncolorSequencePlot);
1355+
1356+
1357+
// >FourColorPlot
1358+
JTextArea txtMakeCompositePlot = new JTextArea();
1359+
initializeTextArea(txtMakeCompositePlot);
1360+
txtMakeCompositePlot.setText(ToolDescriptions.composite_description);
1361+
sl_pnlFigure.putConstraint(SpringLayout.NORTH, txtMakeCompositePlot, 10, SpringLayout.SOUTH, txtcolorSequencePlot);
1362+
sl_pnlFigure.putConstraint(SpringLayout.NORTH, txtMakeCompositePlot, 10, SpringLayout.SOUTH, btncolorSequencePlot);
1363+
sl_pnlFigure.putConstraint(SpringLayout.EAST, txtMakeCompositePlot, -10, SpringLayout.EAST, pnlFigure);
1364+
pnlFigure.add(txtMakeCompositePlot);
1365+
1366+
JButton btnMakeCompositePlot = new JButton("Composite Plot");
1367+
btnMakeCompositePlot.addActionListener(new ActionListener() {
1368+
public void actionPerformed(ActionEvent e) {
1369+
EventQueue.invokeLater(new Runnable() {
1370+
public void run() {
1371+
try {
1372+
PlotCompositeWindow frame = new PlotCompositeWindow();
1373+
frame.setVisible(true);
1374+
} catch (Exception e) {
1375+
e.printStackTrace();
1376+
}
1377+
}
1378+
});
1379+
}
1380+
});
1381+
sl_pnlFigure.putConstraint(SpringLayout.NORTH, btnMakeCompositePlot, 0, SpringLayout.NORTH, txtMakeCompositePlot);
1382+
sl_pnlFigure.putConstraint(SpringLayout.WEST, btnMakeCompositePlot, 10, SpringLayout.WEST, pnlFigure);
1383+
sl_pnlFigure.putConstraint(SpringLayout.WEST, txtMakeCompositePlot, 10, SpringLayout.EAST, btnMakeCompositePlot);
1384+
pnlFigure.add(btnMakeCompositePlot);
13561385

13571386
// Set default tab to open to...
13581387
// 0=BAM_Statistics 5=Peak_Analysis

src/scripts/Figure_Generation/PlotComposite.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ public static JFreeChart plotCompositeFile(File input, File OUT_PATH, boolean ou
111111
// set default output filename
112112
if (OUT_PATH == null) {
113113
OUT_PATH = new File(ExtensionFileFilter.stripExtension(input) + "_plot.png");
114+
} else if (OUT_PATH.isDirectory()) {
115+
OUT_PATH = new File(OUT_PATH.getCanonicalFile() + File.separator + ExtensionFileFilter.stripExtension(input) + "_plot.png");
116+
114117
}
115118
ChartUtils.writeChartAsPNG(new FileOutputStream(OUT_PATH), chart, pxWidth, pxHeight);
116119
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package window_interface.Figure_Generation;
2+
3+
import java.io.File;
4+
import java.io.IOException;
5+
import java.sql.Timestamp;
6+
import java.util.ArrayList;
7+
import java.util.Date;
8+
9+
import javax.swing.JFrame;
10+
import javax.swing.JOptionPane;
11+
import javax.swing.JTabbedPane;
12+
13+
import org.jfree.chart.ChartPanel;
14+
15+
import scripts.Figure_Generation.PlotComposite;
16+
17+
/**
18+
* Initialize a tabbed window where all composite data images are displayed for each file input from a window_interface.Figure_Generation.PlotCompositeWindow instance.
19+
*
20+
* The object will loop through and call the scripts.Figure_Generation.PlotComposite script on each input file to generate the line charts. Each chart's title will be the filename. Legend will be included if indicated by input. Default colors will be used for the chart (see scripts.Figure_Generation.PlotComposite for details). If specified by the input parameter values, a PNG image is saved to the indicated output directory with the passed pixel values for the saved file dimensions.
21+
* @author Olivia Lang
22+
* @see window_interface.Figure_Generation.PlotCompositeWindow
23+
* @see scripts.Figure_Generation.PlotComposite
24+
*
25+
*/
26+
@SuppressWarnings("serial")
27+
public class PlotCompositeOutput extends JFrame {
28+
29+
protected static ArrayList<File> SAMPLE = null;
30+
protected static File OUT_DIR;
31+
protected static boolean outputImg;
32+
33+
protected static boolean includeLegend = true;
34+
protected static int pxHeight;
35+
protected static int pxWidth;
36+
37+
JTabbedPane newpane;
38+
39+
public PlotCompositeOutput(ArrayList<File> in, File o_dir, boolean o, boolean l, int ph, int pw) {
40+
setTitle("Composite");
41+
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
42+
setBounds(150, 150, 800, 600);
43+
44+
newpane = new JTabbedPane(JTabbedPane.TOP);
45+
this.getContentPane().add(newpane);
46+
47+
SAMPLE = in;
48+
OUT_DIR = o_dir;
49+
outputImg = o;
50+
includeLegend = l;
51+
pxHeight = ph;
52+
pxWidth = pw;
53+
}
54+
55+
public void run() throws IOException {
56+
for (int x = 0; x < SAMPLE.size(); x++) {
57+
try {
58+
// Execute script
59+
ChartPanel chart = new ChartPanel(PlotComposite.plotCompositeFile(SAMPLE.get(x), OUT_DIR, outputImg, SAMPLE.get(x).getName(), null, includeLegend, pxHeight, pxWidth));
60+
chart.setPreferredSize(new java.awt.Dimension(500, 270));
61+
// Output image/error to GUI
62+
newpane.addTab(SAMPLE.get(x).getName(), chart);
63+
} catch (Exception e) {
64+
JOptionPane.showMessageDialog(null, e.getMessage());
65+
}
66+
67+
firePropertyChange("composite", x, x + 1);
68+
}
69+
System.out.println("Program Complete");
70+
System.out.println(getTimeStamp());
71+
}
72+
73+
private static String getTimeStamp() {
74+
Date date = new Date();
75+
String time = new Timestamp(date.getTime()).toString();
76+
return time;
77+
}
78+
}

0 commit comments

Comments
 (0)