import java.awt.*; import java.awt.event.*; import java.applet.*; import java.util.*; import sieve.phys.lwblockandplane.*; import sieve.sluice.views.*; import sieve.nuggets.LineGraph.*; import sieve.nuggets.*; import sieve.workbench.*; // for the unnecessary BnPPropertyPanel class import java.util.*; import java.beans.*; public class CompositeBnP extends Applet { ScrollPane scroller = null; // BnPPropertyPanel pPanel = null; PropertyPanel pPanel = null; public CompositeBnP() { // generates data from a sim. of sliding a block down an incline plane BlockAndPlane bnp = new BlockAndPlane(); // displays and allows user selection of a data run (table) TableSelectionView tableSelector = new TableSelectionView(true); TableSelectionViewCustomizer tableSelectionCust = new TableSelectionViewCustomizer(); tableSelectionCust.setObject(tableSelector); tableSelectionCust.setBackground(Color.white); // displays and allows user selection of fields in a data run (table) FieldNameSelectionView fieldSelector = new FieldNameSelectionView(); FieldNameSelectionViewCustomizer fieldSelectionCust = new FieldNameSelectionViewCustomizer(); fieldSelectionCust.setObject(fieldSelector); fieldSelectionCust.setBackground(Color.white); // displays the parameters of a data run (table) AttributeViewer attrViewer = new AttributeViewer(); attrViewer.setBackground(Color.white); // graphs the data of a run LineGraph grapher = new LineGraph(); // raw numbers of a run TextTable textTable = new TextTable(); textTable.setBackground(Color.white); // attach the output of one component to the input of the next try { // add bnp as the source for tableSelector tableSelector.addSourceView(bnp); // add tableSelector as a listener to bnp bnp.addTableViewListener(tableSelector); // add tableSelector as the source for attrView and fieldSelector attrViewer.addSourceView(tableSelector); fieldSelector.addSourceView(tableSelector); // add attrView and fieldSelector as listeners to tableSelector tableSelector.addTableViewListener(fieldSelector); tableSelector.addTableViewListener(attrViewer); grapher.addSourceView(fieldSelector); fieldSelector.addTableViewListener(grapher); tableSelector.addTableViewListener(grapher); textTable.addSourceView(fieldSelector); fieldSelector.addTableViewListener(textTable); tableSelector.addTableViewListener(textTable); } catch (sieve.sluice.TooManySourcesException ex) { System.err.println("Error combining components: "+ex); ex.printStackTrace(); } // put them in the applet setLayout(new BorderLayout()); Container p = new BogusContainer(); p.setLayout(new BorderLayout()); Container p3 = new BogusContainer(); p3.setLayout(new BorderLayout()); p3.add("North", new Label("Block and Plane Simulation")); p3.add("Center", bnp); p.add("Center", p3); // next 3 lines avoid NullPointerException in PropertyPanel bnp.setBackground(Color.lightGray); bnp.setForeground(Color.black); bnp.setFont(new Font("SansSerif", Font.PLAIN, 12)); // pPanel = new BnPPropertyPanel(bnp); pPanel = new PropertyPanel(bnp); scroller = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS); // scroller.add(pPanel); SizedContainer szCont = new SizedContainer(300, 200); szCont.add("North", new Label("Set Parameters")); szCont.add("Center", scroller); p.add("East", szCont); add("North", p); p = new BogusContainer(); p.setLayout(new GridLayout(1,0)); p3 = new BogusContainer(); p3.setLayout(new BorderLayout()); p3.add("North", new Label("Select a run")); p3.add("Center", tableSelectionCust); p.add(p3); p3 = new BogusContainer(); p3.setLayout(new BorderLayout()); p3.add("North", new Label("Select fields")); p3.add("Center", fieldSelectionCust); p.add(p3); p3 = new BogusContainer(); p3.setLayout(new BorderLayout()); p3.add("North", new Label("Parameters")); p3.add("Center", attrViewer); p.add("East", p3); add("Center", p); p = new BogusContainer(); p.setLayout(new BorderLayout()); p3 = new BogusContainer(); p3.setLayout(new BorderLayout()); p3.add("North", new Label("Graphed Data")); p3.add("Center", grapher); p.add("Center", p3); p3 = new BogusContainer(); p3.setLayout(new BorderLayout()); p3.add("North", new Label("Raw Data")); p3.add("Center", textTable); p.add("East", p3); add("South", p); } public void init() { scroller.add(pPanel); } public void update(Graphics g) { // System.out.println("CompositeBnP.update"); paint(g); } public static void main(String [] args) { Frame frame = new Frame(); frame.setLayout(new BorderLayout()); CompositeBnP cbnp = (CompositeBnP)frame.add("Center", new CompositeBnP()); WindowListener l = new WindowAdapter() { public void windowClosing(WindowEvent e) {System.exit(0);} }; frame.addWindowListener(l); frame.pack(); frame.show(); cbnp.init(); } } class BogusContainer extends Panel { // This class prevents flickering in embedded lightweight components, // like BlockAndPlane's SimCanvas public void update(Graphics g) { paint(g); } } class SizedContainer extends Panel { Dimension mySize = null; SizedContainer(int width, int height) { this(new Dimension(width, height)); } SizedContainer(Dimension size) { mySize = size; setLayout(new BorderLayout()); } public void update(Graphics g) { paint(g); } public Dimension getPreferredSize() { return getMinimumSize(); } public Dimension getMinimumSize() { return mySize; } }