[Date Prev][Date Next][Index][Thread]
[SGT Mail Archive]
[SGT Main Page]
Multiple JPlotLayouts per Frame
OK, I'm trying to put two JPlotLayouts in a JFrame, using a GridLayout.
I wrote a test program that puts a JPlotLayout in the frame by itself
with some dummy data. It works fine. I then added a second plot, and
it appears, sort of. The second plot's axes aren't there, and the
titles don't appear either. There are three sets of data in the first
plot, and three in the second, but the only data that appears in the
second plot is the third data set from the first plot (got all that? :-)
).
I've attached the source code I'm using. It's short, so I hope this
doesn't spam the list too much.
My questions are:
1) Why don't the titles for the second plot appear?
2) Why doesn't the child label appear in the second plot? (The one with
the "CHILD LABEL" text)
3) Why don't the axes appear in the second plot?
4) Why does one data set appear in the second plot, but not the others?
Thanks for your help!
Chris Yee
package test;
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import java.util.*;
import javax.swing.*;
import gov.noaa.pmel.sgt.*;
import gov.noaa.pmel.sgt.dm.*;
import gov.noaa.pmel.sgt.swing.*;
import gov.noaa.pmel.util.*;
public class GraphTest2 implements PropertyChangeListener {
JFrame jfrmMain;
JPlotLayout jpl;
JPlotLayout jpl2;
SimpleLine sl, sl2, sl3;
SimpleLine sl4, sl5, sl6;
public static void main(String[] args) {
GraphTest2 gt2 = new GraphTest2();
} // End main method definition
public GraphTest2() {
jfrmMain = new JFrame("Test");
jfrmMain.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jfrmMain.setSize(800, 600);
jfrmMain.getContentPane().setLayout(new GridLayout(0, 1));
jpl = new JPlotLayout(false, true, false, "Test", null, false);
jpl.setClipping(true);
jpl.setBatch(true);
jpl.init();
jpl.setTitles("FIRST PLOT", "Secondary title", "");
jpl.setBackground(Color.black);
jpl.setForeground(Color.white);
GeoDate[] gdArr = new GeoDate[100];
double[] dArr = new double[100];
gdArr[0] = new GeoDate();
dArr[0] = 5.0;
for (int i = 1; i < gdArr.length; i++) {
gdArr[i] = new GeoDate(gdArr[0].getTime() + 850 * i);
dArr[i] = Math.random() * 2;
}
sl = new SimpleLine(gdArr, dArr, "Data Set 1");
sl.setXMetaData(new SGTMetaData("time", "s"));
sl.setYMetaData(new SGTMetaData("error", "m"));
sl.addPropertyChangeListener(this);
gdArr = new GeoDate[100];
dArr = new double[100];
dArr[0] = -4.3;
gdArr[0] = new GeoDate();
for (int i = 1; i < gdArr.length; i++) {
gdArr[i] = new GeoDate(gdArr[0].getTime() + 650 * i);
dArr[i] = Math.random() * 3;
}
sl2 = new SimpleLine(gdArr, dArr, "Data Set 2");
sl2.setXMetaData(new SGTMetaData("time", "s"));
sl2.setYMetaData(new SGTMetaData("error", "m"));
sl2.addPropertyChangeListener(this);
gdArr = new GeoDate[100];
dArr = new double[100];
dArr[0] = 0;
gdArr[0] = new GeoDate();
for (int i = 1; i < gdArr.length; i++) {
gdArr[i] = new GeoDate(gdArr[0].getTime() + 950 * i);
dArr[i] = Math.random() * 4;
}
sl3 = new SimpleLine(gdArr, dArr, "Data Set 3");
sl3.setXMetaData(new SGTMetaData("time", "s"));
sl3.setYMetaData(new SGTMetaData("error", "m"));
sl3.addPropertyChangeListener(this);
LineAttribute attr = new LineAttribute(LineAttribute.HEAVY, Color.red);
jpl.addData(sl, attr, "Platform 1");
attr = new LineAttribute(LineAttribute.HEAVY,Color.green);
jpl.addData(sl2, attr, "Platform 2");
attr = new LineAttribute(LineAttribute.HEAVY,Color.yellow);
jpl.addData(sl3, attr, "Platform 3");
jpl.setBatch(false);
jpl.setKeyLocationP(new Point2D.Double(3, 4));
SGLabel label = new SGLabel("LABEL ID", "CHILD LABEL",
new Point2D.Double(4, 4));
label.setFont(new Font("SansSerif", Font.BOLD, 11));
jpl.getFirstLayer().addChild(label);
GeoDate gdNow;
Layer layer;
AxisTransform ltX, ltY;
CartesianGraph cg;
TimeAxis timeAxis;
PlainAxis plainAxis;
layer = jpl.getFirstLayer();
cg = (CartesianGraph)layer.getGraph();
ltX = cg.getXTransform();
ltY = cg.getYTransform();
try {
timeAxis = (TimeAxis) cg.getXAxis("Bottom Axis");
timeAxis.setMajorLabelFormat("HH:mm");
timeAxis.setMinorLabelFormat("ss");
SGLabel sgXAxis = new SGLabel("X AXIS LABEL ID",
"Time (s)",
new Point2D.Double(2.8, 0.13));
sgXAxis.setHeightP(0.2);
sgXAxis.setColor(Color.white);
timeAxis.setTitle(sgXAxis);
layer.addChild(sgXAxis);
timeAxis.setStyle(TimeAxis.MINUTE_HOUR);
timeAxis.setLabelColor(Color.white);
timeAxis.setLabelFont(new Font("SansSerif", Font.BOLD, 14));
timeAxis.setNumberSmallTics(60);
plainAxis = (PlainAxis) cg.getYAxis("Left Axis");
plainAxis.setLabelColor(Color.white);
plainAxis.setLabelFont(new Font("SansSerif", Font.BOLD, 14));
} catch (Exception e) {
e.printStackTrace();
}
jfrmMain.getContentPane().add(jpl);
jpl2 = new JPlotLayout(false, true, false, "Test2", null, false);
jpl2.setClipping(true);
jpl2.setBatch(true);
jpl2.init();
jpl2.setTitles("SECOND PLOT", "I love Java", "");
jpl2.setBackground(Color.black);
jpl2.setForeground(Color.white);
gdArr = new GeoDate[100];
dArr = new double[100];
gdArr[0] = new GeoDate();
dArr[0] = 5.0;
for (int i = 1; i < gdArr.length; i++) {
gdArr[i] = new GeoDate(gdArr[0].getTime() + 850 * i);
dArr[i] = Math.random() * 2;
}
sl4 = new SimpleLine(gdArr, dArr, "Data Set 4");
sl4.setXMetaData(new SGTMetaData("time", "s"));
sl4.setYMetaData(new SGTMetaData("error", "m/s"));
sl4.addPropertyChangeListener(this);
gdArr = new GeoDate[100];
dArr = new double[100];
dArr[0] = -4.3;
gdArr[0] = new GeoDate();
for (int i = 1; i < gdArr.length; i++) {
gdArr[i] = new GeoDate(gdArr[0].getTime() + 650 * i);
dArr[i] = Math.random() * 3;
}
sl5 = new SimpleLine(gdArr, dArr, "Data Set 5");
sl5.setXMetaData(new SGTMetaData("time", "s"));
sl5.setYMetaData(new SGTMetaData("error", "m/s"));
sl5.addPropertyChangeListener(this);
gdArr = new GeoDate[100];
dArr = new double[100];
dArr[0] = 0;
gdArr[0] = new GeoDate();
for (int i = 1; i < gdArr.length; i++) {
gdArr[i] = new GeoDate(gdArr[0].getTime() + 950 * i);
dArr[i] = Math.random() * 4;
}
sl6 = new SimpleLine(gdArr, dArr, "Data Set 6");
sl6.setXMetaData(new SGTMetaData("time", "s"));
sl6.setYMetaData(new SGTMetaData("error", "m/s"));
sl6.addPropertyChangeListener(this);
attr = new LineAttribute(LineAttribute.HEAVY, Color.red);
jpl2.addData(sl4, attr, "Platform 1");
attr = new LineAttribute(LineAttribute.HEAVY,Color.green);
jpl2.addData(sl5, attr, "Platform 2");
attr = new LineAttribute(LineAttribute.HEAVY,Color.yellow);
jpl2.addData(sl6, attr, "Platform 3");
jpl2.setBatch(false);
jpl2.setKeyLocationP(new Point2D.Double(3, 4));
label = new SGLabel("LABEL ID", "CHILD LABEL",
new Point2D.Double(4, 4));
label.setFont(new Font("SansSerif", Font.BOLD, 11));
System.out.println("label color" + label.getColor());
label.setColor(Color.white);
System.out.println("label color" + label.getColor());
jpl2.getFirstLayer().addChild(label);
layer = jpl2.getFirstLayer();
cg = (CartesianGraph)layer.getGraph();
ltX = cg.getXTransform();
ltY = cg.getYTransform();
try {
timeAxis = (TimeAxis) cg.getXAxis("Bottom Axis");
timeAxis.setMajorLabelFormat("HH:mm");
timeAxis.setMinorLabelFormat("ss");
SGLabel sgXAxis = new SGLabel("X AXIS LABEL ID",
"Time (s)",
new Point2D.Double(2.8, 0.13));
sgXAxis.setHeightP(0.2);
sgXAxis.setColor(Color.white);
timeAxis.setTitle(sgXAxis);
layer.addChild(sgXAxis);
timeAxis.setStyle(TimeAxis.MINUTE_HOUR);
timeAxis.setLabelColor(Color.white);
timeAxis.setLabelFont(new Font("SansSerif", Font.BOLD, 14));
timeAxis.setNumberSmallTics(60);
plainAxis = (PlainAxis) cg.getYAxis("Left Axis");
plainAxis.setLabelColor(Color.white);
plainAxis.setLabelFont(new Font("SansSerif", Font.BOLD, 14));
} catch (Exception e) {
e.printStackTrace();
}
jfrmMain.getContentPane().add(jpl2);
jfrmMain.setVisible(true);
} // End default constructor definition
public void propertyChange(PropertyChangeEvent pce) {
// Stuff deleted
} // End propertyChange method definition
} // End GraphTest2 class definition