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