annotate at/ofai/music/worm/Plot.java @ 2:4c3f5bc01c97

* Import BeatRoot v0.5.7
author Chris Cannam
date Fri, 08 Oct 2010 16:11:06 +0100
parents
children
rev   line source
Chris@2 1 /* Performance Worm: Visualisation of Expressive Musical Performance
Chris@2 2 Copyright (C) 2001, 2006 by Simon Dixon
Chris@2 3
Chris@2 4 This program is free software; you can redistribute it and/or modify
Chris@2 5 it under the terms of the GNU General Public License as published by
Chris@2 6 the Free Software Foundation; either version 2 of the License, or
Chris@2 7 (at your option) any later version.
Chris@2 8
Chris@2 9 This program is distributed in the hope that it will be useful,
Chris@2 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@2 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@2 12 GNU General Public License for more details.
Chris@2 13
Chris@2 14 You should have received a copy of the GNU General Public License along
Chris@2 15 with this program (the file gpl.txt); if not, download it from
Chris@2 16 http://www.gnu.org/licenses/gpl.txt or write to the
Chris@2 17 Free Software Foundation, Inc.,
Chris@2 18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Chris@2 19 */
Chris@2 20
Chris@2 21 package at.ofai.music.worm;
Chris@2 22
Chris@2 23 import java.awt.Color;
Chris@2 24 import java.awt.Dimension;
Chris@2 25 import java.awt.GraphicsConfiguration;
Chris@2 26 import java.awt.Rectangle;
Chris@2 27 import java.awt.event.WindowAdapter;
Chris@2 28 import java.awt.event.WindowEvent;
Chris@2 29
Chris@2 30 import javax.swing.BoxLayout;
Chris@2 31 import javax.swing.JFrame;
Chris@2 32 import javax.swing.WindowConstants;
Chris@2 33
Chris@2 34 import at.ofai.music.util.FrameMargins;
Chris@2 35
Chris@2 36 public class Plot extends JFrame {
Chris@2 37
Chris@2 38 static final long serialVersionUID = 0; // silence compiler warning
Chris@2 39
Chris@2 40 JFrame frame;
Chris@2 41 public PlotPanel panel;
Chris@2 42
Chris@2 43 public Plot(double[] xData, double[] yData) {
Chris@2 44 this();
Chris@2 45 panel.addPlot(xData, yData);
Chris@2 46 }
Chris@2 47
Chris@2 48 public Plot() {
Chris@2 49 frame = new JFrame();
Chris@2 50 panel = new PlotPanel(frame);
Chris@2 51 frame.getContentPane().setBackground(WormConstants.backgroundColor);
Chris@2 52 frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(),
Chris@2 53 BoxLayout.Y_AXIS));
Chris@2 54 frame.getContentPane().add(panel);
Chris@2 55 panel.addHierarchyBoundsListener(panel);
Chris@2 56 Dimension borderSize = FrameMargins.get(false);
Chris@2 57 frame.setSize(panel.getWidth() + borderSize.width,
Chris@2 58 panel.getHeight() + borderSize.height);
Chris@2 59 // + WormConstants.cpHeight);
Chris@2 60 GraphicsConfiguration gc = frame.getGraphicsConfiguration();
Chris@2 61 Rectangle bounds = gc.getBounds(); // [x=0 y=0 w=1280 h=1024]
Chris@2 62 frame.setLocation(bounds.x + (bounds.width - frame.getWidth()) / 2,
Chris@2 63 bounds.height - frame.getHeight());
Chris@2 64 // bounds.y + (bounds.height - frame.getHeight()) / 2);
Chris@2 65 frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
Chris@2 66 frame.setVisible(true);
Chris@2 67 frame.setIconImage(WormIcon.getWormIcon(1, frame));
Chris@2 68 }
Chris@2 69
Chris@2 70 public void setTitle(String s) { panel.setTitle(s); }
Chris@2 71 public void setAxis(String s) { panel.setAxis(s); }
Chris@2 72 public void setXAxis(double min, double max) { panel.setXAxis(min, max); }
Chris@2 73 public void setYAxis(double min, double max) { panel.setYAxis(min, max); }
Chris@2 74 public void setLength(int i, int l) { panel.setLength(i, l); }
Chris@2 75 public void rotateCurrent() { panel.rotateCurrent(); }
Chris@2 76 public void update() { panel.update(); }
Chris@2 77 public void fitAxes() { panel.fitAxes(); }
Chris@2 78 public void fitAxes(int current) { panel.fitAxes(current); }
Chris@2 79 public void setMode(int m) { panel.setMode(m); }
Chris@2 80 public void clear() { panel.clear(); }
Chris@2 81 public void close() { frame.setVisible(false); }
Chris@2 82 public void addPlot(double[] x, double[] y) {
Chris@2 83 addPlot(x, y, Color.blue);
Chris@2 84 }
Chris@2 85 public void addPlot(double[] x, double[] y, Color c) {
Chris@2 86 addPlot(x, y, c, PlotPanel.IMPULSE | PlotPanel.HOLLOW);
Chris@2 87 }
Chris@2 88 public void addPlot(double[] x, double[] y, Color c, int mode) {
Chris@2 89 panel.addPlot(x, y, c, mode);
Chris@2 90 }
Chris@2 91
Chris@2 92 public static void main(String[] args) { // simple test of this class
Chris@2 93 double[] x = new double[100];
Chris@2 94 double[] y = new double[100];
Chris@2 95 for (int i = 0; i < 100; i++) {
Chris@2 96 x[i] = i;
Chris@2 97 y[i] = Math.sin(2 * Math.PI * i / 50);
Chris@2 98 }
Chris@2 99 Plot testPlot = new Plot(x, y);
Chris@2 100 testPlot.panel.xAxis.test(); //SD: remove
Chris@2 101 testPlot.frame.addWindowListener(new WindowAdapter() {
Chris@2 102 public void windowClosed(WindowEvent e) { System.exit(0); } });
Chris@2 103 } // main()
Chris@2 104
Chris@2 105 } // class Plot