Chris@2: /* Performance Worm: Visualisation of Expressive Musical Performance Chris@2: Copyright (C) 2001, 2006 by Simon Dixon Chris@2: Chris@2: This program is free software; you can redistribute it and/or modify Chris@2: it under the terms of the GNU General Public License as published by Chris@2: the Free Software Foundation; either version 2 of the License, or Chris@2: (at your option) any later version. Chris@2: Chris@2: This program is distributed in the hope that it will be useful, Chris@2: but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@2: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@2: GNU General Public License for more details. Chris@2: Chris@2: You should have received a copy of the GNU General Public License along Chris@2: with this program (the file gpl.txt); if not, download it from Chris@2: http://www.gnu.org/licenses/gpl.txt or write to the Chris@2: Free Software Foundation, Inc., Chris@2: 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Chris@2: */ Chris@2: Chris@2: package at.ofai.music.worm; Chris@2: Chris@2: import java.awt.Color; Chris@2: import java.awt.Dimension; Chris@2: import java.awt.GraphicsConfiguration; Chris@2: import java.awt.Rectangle; Chris@2: import java.awt.event.WindowAdapter; Chris@2: import java.awt.event.WindowEvent; Chris@2: Chris@2: import javax.swing.BoxLayout; Chris@2: import javax.swing.JFrame; Chris@2: import javax.swing.WindowConstants; Chris@2: Chris@2: import at.ofai.music.util.FrameMargins; Chris@2: Chris@2: public class Plot extends JFrame { Chris@2: Chris@2: static final long serialVersionUID = 0; // silence compiler warning Chris@2: Chris@2: JFrame frame; Chris@2: public PlotPanel panel; Chris@2: Chris@2: public Plot(double[] xData, double[] yData) { Chris@2: this(); Chris@2: panel.addPlot(xData, yData); Chris@2: } Chris@2: Chris@2: public Plot() { Chris@2: frame = new JFrame(); Chris@2: panel = new PlotPanel(frame); Chris@2: frame.getContentPane().setBackground(WormConstants.backgroundColor); Chris@2: frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(), Chris@2: BoxLayout.Y_AXIS)); Chris@2: frame.getContentPane().add(panel); Chris@2: panel.addHierarchyBoundsListener(panel); Chris@2: Dimension borderSize = FrameMargins.get(false); Chris@2: frame.setSize(panel.getWidth() + borderSize.width, Chris@2: panel.getHeight() + borderSize.height); Chris@2: // + WormConstants.cpHeight); Chris@2: GraphicsConfiguration gc = frame.getGraphicsConfiguration(); Chris@2: Rectangle bounds = gc.getBounds(); // [x=0 y=0 w=1280 h=1024] Chris@2: frame.setLocation(bounds.x + (bounds.width - frame.getWidth()) / 2, Chris@2: bounds.height - frame.getHeight()); Chris@2: // bounds.y + (bounds.height - frame.getHeight()) / 2); Chris@2: frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); Chris@2: frame.setVisible(true); Chris@2: frame.setIconImage(WormIcon.getWormIcon(1, frame)); Chris@2: } Chris@2: Chris@2: public void setTitle(String s) { panel.setTitle(s); } Chris@2: public void setAxis(String s) { panel.setAxis(s); } Chris@2: public void setXAxis(double min, double max) { panel.setXAxis(min, max); } Chris@2: public void setYAxis(double min, double max) { panel.setYAxis(min, max); } Chris@2: public void setLength(int i, int l) { panel.setLength(i, l); } Chris@2: public void rotateCurrent() { panel.rotateCurrent(); } Chris@2: public void update() { panel.update(); } Chris@2: public void fitAxes() { panel.fitAxes(); } Chris@2: public void fitAxes(int current) { panel.fitAxes(current); } Chris@2: public void setMode(int m) { panel.setMode(m); } Chris@2: public void clear() { panel.clear(); } Chris@2: public void close() { frame.setVisible(false); } Chris@2: public void addPlot(double[] x, double[] y) { Chris@2: addPlot(x, y, Color.blue); Chris@2: } Chris@2: public void addPlot(double[] x, double[] y, Color c) { Chris@2: addPlot(x, y, c, PlotPanel.IMPULSE | PlotPanel.HOLLOW); Chris@2: } Chris@2: public void addPlot(double[] x, double[] y, Color c, int mode) { Chris@2: panel.addPlot(x, y, c, mode); Chris@2: } Chris@2: Chris@2: public static void main(String[] args) { // simple test of this class Chris@2: double[] x = new double[100]; Chris@2: double[] y = new double[100]; Chris@2: for (int i = 0; i < 100; i++) { Chris@2: x[i] = i; Chris@2: y[i] = Math.sin(2 * Math.PI * i / 50); Chris@2: } Chris@2: Plot testPlot = new Plot(x, y); Chris@2: testPlot.panel.xAxis.test(); //SD: remove Chris@2: testPlot.frame.addWindowListener(new WindowAdapter() { Chris@2: public void windowClosed(WindowEvent e) { System.exit(0); } }); Chris@2: } // main() Chris@2: Chris@2: } // class Plot