Back to index

wims  3.65+svn20090927
EditablePlotApplet.java
Go to the documentation of this file.
00001 /* Applet containing the EditablePlot class.
00002 
00003  @Copyright (c) 1997-2005 The Regents of the University of California.
00004  All rights reserved.
00005 
00006  Permission is hereby granted, without written agreement and without
00007  license or royalty fees, to use, copy, modify, and distribute this
00008  software and its documentation for any purpose, provided that the
00009  above copyright notice and the following two paragraphs appear in all
00010  copies of this software.
00011 
00012  IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
00013  FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
00014  ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
00015  THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
00016  SUCH DAMAGE.
00017 
00018  THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
00019  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00020  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
00021  PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
00022  CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
00023  ENHANCEMENTS, OR MODIFICATIONS.
00024 
00025  PT_COPYRIGHT_VERSION_2
00026  COPYRIGHTENDKEY
00027  */
00028 package ptolemy.plot;
00029 import java.awt.BorderLayout;
00030 import java.awt.event.ActionEvent;
00031 import java.awt.event.ActionListener;
00032 
00033 import javax.swing.JComboBox;
00034 import javax.swing.JLabel;
00035 import javax.swing.JPanel;
00036 
00037 import ptolemy.plot.EditablePlot;
00038 import ptolemy.plot.Plot;
00039 import ptolemy.plot.PlotBox;
00040 
00043 
00055 public class EditablePlotApplet extends PlotApplet {
00058 
00062     public void init() {
00063         super.init();
00064 
00065         JPanel controlPanel = new JPanel();
00066 
00067         // Make the panel transparent so that the background shows through.
00068         controlPanel.setOpaque(false);
00069         getContentPane().add(controlPanel, BorderLayout.SOUTH);
00070 
00071         controlPanel.add(new JLabel("Data set to edit:"));
00072 
00073         _choice = new JComboBox();
00074         controlPanel.add(_choice);
00075 
00076         for (int i = 0; i < ((Plot) plot()).getNumDataSets(); i++) {
00077             _choice.addItem(plot().getLegend(i));
00078         }
00079 
00080         _choice.addActionListener(new ChoiceListener());
00081     }
00082 
00086     public String getAppletInfo() {
00087         return "EditablePlotDemo "
00088                 + ": Demo of EditablePlot.\n"
00089                 + "By: Edward A. Lee\n "
00090                 + "($Id: EditablePlotApplet.java,v 1.31 2005/07/08 19:59:37 cxh Exp $)";
00091     }
00092 
00096     public PlotBox newPlot() {
00097         return new EditablePlot();
00098     }
00099 
00102 
00109     protected void _setPlotSize(int appletWidth, int appletHeight) {
00110         if (appletHeight > 50) {
00111             plot().setSize(appletWidth, appletHeight - 50);
00112         } else {
00113             plot().setSize(appletWidth, appletHeight);
00114         }
00115     }
00116 
00119     // Choice widget for selecting the editable data set.
00120     private JComboBox _choice;
00121 
00124     private class ChoiceListener implements ActionListener {
00125         public void actionPerformed(ActionEvent e) {
00126             ((EditablePlot) plot()).setEditable(_choice.getSelectedIndex());
00127         }
00128     }
00129 }