001/* Applet containing the EditablePlot class. 002 003 @Copyright (c) 1997-2014 The Regents of the University of California. 004 All rights reserved. 005 006 Permission is hereby granted, without written agreement and without 007 license or royalty fees, to use, copy, modify, and distribute this 008 software and its documentation for any purpose, provided that the 009 above copyright notice and the following two paragraphs appear in all 010 copies of this software. 011 012 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 013 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 014 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 015 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 016 SUCH DAMAGE. 017 018 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 019 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 020 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 021 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 022 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 023 ENHANCEMENTS, OR MODIFICATIONS. 024 025 PT_COPYRIGHT_VERSION_2 026 COPYRIGHTENDKEY 027 */ 028package ptolemy.plot.plotml; 029 030import java.awt.BorderLayout; 031import java.awt.event.ActionEvent; 032import java.awt.event.ActionListener; 033 034import javax.swing.JComboBox; 035import javax.swing.JLabel; 036import javax.swing.JPanel; 037 038import ptolemy.plot.EditablePlot; 039import ptolemy.plot.Plot; 040import ptolemy.plot.PlotBox; 041 042/////////////////////////////////////////////////////////////////// 043//// EditablePlotMLApplet 044 045/** 046 This applet reads a URL giving a PlotML file for a plot and places 047 the data into an editable plot. 048 049 @see EditablePlot 050 @author Edward A. Lee 051 @version $Id$ 052 @since Ptolemy II 0.4 053 @Pt.ProposedRating red (eal) 054 @Pt.AcceptedRating red (cxh) 055 */ 056@SuppressWarnings("serial") 057public class EditablePlotMLApplet extends PlotMLApplet { 058 /////////////////////////////////////////////////////////////////// 059 //// public methods //// 060 061 /** Initialize the applet. Place an instance of EditablePlot 062 * and a widget for selecting the data set to edit. 063 */ 064 @Override 065 public void init() { 066 super.init(); 067 068 JPanel controlPanel = new JPanel(); 069 070 // Make the panel transparent so that the background shows through. 071 controlPanel.setOpaque(false); 072 getContentPane().add(controlPanel, BorderLayout.SOUTH); 073 074 controlPanel.add(new JLabel("Data set to edit:")); 075 076 _choice = new JComboBox(); 077 controlPanel.add(_choice); 078 079 for (int i = 0; i < ((Plot) plot()).getNumDataSets(); i++) { 080 _choice.addItem(plot().getLegend(i)); 081 } 082 083 _choice.addActionListener(new ChoiceListener()); 084 } 085 086 /** 087 * Return a string describing this applet. 088 */ 089 @Override 090 public String getAppletInfo() { 091 return "EditablePlotDemo " + PlotBox.PTPLOT_RELEASE 092 + ": Demo of EditablePlot.\n" + "By: Edward A. Lee\n " 093 + "($Id$)"; 094 } 095 096 /** Create a new Plot object for the applet. Derived classes can 097 * redefine this method to return a different type of plot object. 098 */ 099 @Override 100 public PlotBox newPlot() { 101 return new EditablePlot(); 102 } 103 104 /////////////////////////////////////////////////////////////////// 105 //// protected methods //// 106 107 /** Given the size of the applet, set the size of the plot. 108 * Derived classes may override this to allow room for other 109 * widgets below the plot. 110 * @param appletWidth The width of the applet. 111 * @param appletHeight The height of the applet. 112 */ 113 @Override 114 protected void _setPlotSize(int appletWidth, int appletHeight) { 115 if (appletHeight > 50) { 116 plot().setSize(appletWidth, appletHeight - 50); 117 } else { 118 plot().setSize(appletWidth, appletHeight); 119 } 120 } 121 122 /////////////////////////////////////////////////////////////////// 123 //// private variables //// 124 // Choice widget for selecting the editable data set. 125 private JComboBox _choice; 126 127 /////////////////////////////////////////////////////////////////// 128 //// inner classes //// 129 private class ChoiceListener implements ActionListener { 130 @Override 131 public void actionPerformed(ActionEvent e) { 132 ((EditablePlot) plot()).setEditable(_choice.getSelectedIndex()); 133 } 134 } 135}