/* Copyright 2000 Charles G. Wright * This software may be distributed under the terms of the * GNU General Public License. * * $Id: GRAgraphs.java,v 1.1 2000-06-15 10:14:56-05 chuckles Exp chuckles $ */ import java.awt.*; import java.awt.event.*; import java.io.*; import java.util.*; /**

Class implementing several graphs and a data selector. * There are two subpanels. One of these is a List object * that shows all displayable data elements. *

The other of these is a panel that shows one of * several graphs, plus buttons that page through the various * available graphs. */ public class GRAgraphs extends Panel implements ActionListener, ItemListener, TMYgraphMaster { public CWObservable obs; private Button next; private Button previous; private java.awt.List fieldList; public TMYdata tmystuff; private Panel graph_panel_top; private Panel graph_panel; private Panel title_panel; private Label graph_title; private Label l1; private Color[] colors; private CardLayout graph_panel_layout; /** Creates a panel containing a selection list on the left, * plus a panel on the right that shows one of several graphs. */ public GRAgraphs(Color[] colors){ // This CWObservable keeps track of the GRAgraph objects that // are managed by this GRAgraphs, and handles updates that // are required when the fieldList selections are changed. obs = new CWObservable(); fieldList = new java.awt.List(10, true); // Register it to receive monitorable elements CWmonitoredElements.addList(fieldList); fieldList.addItemListener(this); this.colors = colors; //------------------------------------------------- // title panel creation FlowLayout fl = new FlowLayout(FlowLayout.LEFT, 2, 2); title_panel = new Panel(fl); l1 = new Label("Graph selection:"); title_panel.add(l1); previous = new Button("<"); previous.addActionListener(this); title_panel.add(previous); next = new Button(">"); next.addActionListener(this); title_panel.add(next); // End of title panel definition //---------------------------------------------- // graph panel definition graph_panel = new Panel(); graph_panel_layout = new CardLayout(); graph_panel.setLayout(graph_panel_layout); // We don't add anything to it right away. //End of graph panel definition //-------- top graph panel definition ----------- graph_panel_top = new Panel(); GridBagLayout top_graph_layout = new GridBagLayout(); graph_panel_top.setLayout(top_graph_layout); GridBagConstraints ct = new GridBagConstraints(); ct.fill = GridBagConstraints.BOTH; ct.gridwidth = GridBagConstraints.REMAINDER; ct.weightx = 1.0; ct.weighty = 0.0; ct.gridx = 0; top_graph_layout.setConstraints(title_panel, ct); ct.fill = GridBagConstraints.BOTH; ct.weighty = 1.0; top_graph_layout.setConstraints(graph_panel, ct); graph_panel_top.add(title_panel); graph_panel_top.add(graph_panel); //-------- end of top graph panel layout -------- //--------- top level layout -------------------- GridBagLayout top_layout = new GridBagLayout(); setLayout(top_layout); // put field list on the left GridBagConstraints c0l = new GridBagConstraints(); c0l.fill = GridBagConstraints.BOTH; c0l.weightx = 0.3; c0l.weighty = 1.0; c0l.gridx = 0; c0l.insets = new Insets(3,3,3,3); top_layout.setConstraints(fieldList, c0l); // put graph panel on the right c0l.weightx = 1.0; top_layout.setConstraints(graph_panel_top, c0l); //--------- End of top level layout add(fieldList); add(graph_panel_top); } public TMYdata getTMY(){ return(tmystuff); } public java.awt.List getFieldList(){ return(fieldList); } public void paint(Graphics g){ setForeground(Color.black); Dimension d = getSize(); g.drawRect(0, 0, d.width - 1, d.height - 1); } /** Adds a graph to be displayed. */ public void addGraph(GRAgraph graph, String name){ graph_panel.add(graph, name); obs.addObserver(graph); } /** Event handler to handle button presses. In this case, * the class has 2 buttons, to left or right scroll through * the available graphs. */ public void actionPerformed(ActionEvent ae){ Object sel = ae.getSource(); // Handle interactions between month and day selectors. if (sel == previous){ graph_panel_layout.previous(graph_panel); } else if (sel == next){ graph_panel_layout.next(graph_panel); } } /** Event handler for changes to the list of displayable elements. */ public void itemStateChanged(ItemEvent e){ obs.setChanged(); obs.notifyObservers(this); // This will cause obs to issue an update(obs, this) to each of // the graphs owned by this. System.out.println("item listener invoked"); } }