Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

MeasurementGraphsPanel.java

Go to the documentation of this file.
00001 /*
00002  * MeasurementGraphsPanel.java
00003  *
00004  * Copyright (C) 2005 Project SQUID, http://www.cs.helsinki.fi/group/squid/
00005  *
00006  * This file is part of Ikayaki.
00007  *
00008  * Ikayaki is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * Ikayaki is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with Ikayaki; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00021  */
00022 
00023 package ikayaki.gui;
00024 
00025 import ikayaki.MeasurementEvent;
00026 import ikayaki.Project;
00027 import ikayaki.ProjectEvent;
00028 import ikayaki.ProjectListener;
00029 
00030 import javax.swing.*;
00031 import java.awt.*;
00032 import java.awt.event.ActionEvent;
00033 import java.awt.event.ActionListener;
00034 import java.awt.event.KeyEvent;
00035 import java.util.Vector;
00036 
00040 public class MeasurementGraphsPanel extends ProjectComponent implements ProjectListener {
00044     private Vector<Plot> plots = new Vector<Plot>();
00045 
00046     private JTabbedPane tabs;
00047 
00051     public MeasurementGraphsPanel() {
00052 
00053         IntensityPlot intensityPlot = new IntensityPlot();
00054         StereoPlot stereoPlot = new StereoPlot();
00055 
00056         plots.add(intensityPlot);
00057         plots.add(stereoPlot);
00058         //stereoPlot.setEnabled(true);
00059         //intensityPlot.setEnabled(true);
00060 
00061         JButton bigGraphsButton = new JButton();
00062 
00063         tabs = new JTabbedPane();
00064 
00065         Box b = new Box(BoxLayout.X_AXIS);
00066         b.add(intensityPlot);
00067         b.add(stereoPlot);
00068         tabs.addTab("1: Intensity & Stereo", b);
00069         tabs.setMnemonicAt(0, KeyEvent.VK_1);
00070 
00071         // TODO Add Zijderweld plot here
00072         //tabs.addTab("2: Zijderweld", new JPanel());
00073         //tabs.setMnemonicAt(1, KeyEvent.VK_2);
00074 
00075         setLayout(new BorderLayout());
00076         add(bigGraphsButton, "North"); // TODO: make this button look nicer
00077         add(tabs, "Center");
00078 
00079         bigGraphsButton.addActionListener(new ActionListener() {
00080             public void actionPerformed(ActionEvent e) {
00081                 JDialog gd = new JDialog(getParentFrame(), "Graphs", false);
00082                 MeasurementGraphsPanel mgp = new MeasurementGraphsPanel();
00083                 mgp.setProject(getProject());
00084                 gd.add(mgp.tabs, BorderLayout.CENTER);
00085                 gd.pack();
00086                 Rectangle maxBounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
00087                 gd.setSize((int) (maxBounds.width * 0.5), (int) (maxBounds.height * 0.5));
00088                 gd.setLocationRelativeTo(getParentFrame());
00089                 gd.setVisible(true);
00090             }
00091         });
00092 
00093         // initialize with no project
00094         setProject(null);
00095     }
00096 
00100     private void updatePlots() {
00101         // update all plots with the MeasurementSteps from the project
00102         for (Plot plot : plots) {
00103             plot.reset();
00104             if (getProject() != null) {
00105                 for (int i = 0; i < getProject().getSteps(); i++) {
00106                     plot.add(getProject().getStep(i));
00107                 }
00108             }
00109         }
00110     }
00111 
00115     public void projectUpdated(ProjectEvent event) {
00116         if (event.getType() == ProjectEvent.Type.STATE_CHANGED || event.getType() == ProjectEvent.Type.DATA_CHANGED) {
00117             updatePlots();
00118         }
00119     }
00120 
00124     public void measurementUpdated(MeasurementEvent event) {
00125         if (event.getType() == MeasurementEvent.Type.VALUE_MEASURED) {
00126             updatePlots();
00127         }
00128     }
00129 
00136     @Override public void setProject(Project project) {
00137         super.setProject(project);
00138         updatePlots();
00139     }
00140 
00141 
00142     public static void main(String args[]) {
00143         JFrame f = new JFrame();
00144         f.setLayout(new BorderLayout());
00145         f.setContentPane(new MeasurementGraphsPanel());
00146         f.setLocationByPlatform(true);
00147         f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
00148         f.pack();
00149         f.setVisible(true);
00150     }
00151 }

Generated on Fri May 6 16:00:31 2005 for Squid by  doxygen 1.4.1