1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package de.desy.acop.demo;
24
25 import java.awt.Color;
26
27 import javax.swing.JFrame;
28 import javax.swing.JPanel;
29
30 import de.desy.acop.chart.Acop;
31
32 public class AcopStyleDemo extends JPanel {
33
34 private static final long serialVersionUID = 1L;
35
36 private Acop acop;
37 private int handle = -1;
38 double[] x;
39 double[] y;
40
41 public AcopStyleDemo() {
42 acop = new Acop();
43 add(acop);
44 }
45
46 public void drawData(double[] x, double[] y) {
47 this.x = x;
48 this.y = y;
49 if (handle < 0) {
50 handle = acop.draw(y, x);
51 } else {
52 acop.refreshScreen(y, handle, y.length, 0, x);
53 }
54 acop.autoScale(true, true, true, true);
55 }
56
57 public void changeStyleRefresh(int drawWidth, int displayMode, Color color) {
58 acop.setDrawWidth(drawWidth);
59 acop.setDisplayMode(displayMode);
60 acop.setForeground(color);
61 acop.refreshScreen(y, handle, y.length, 0, x);
62 }
63
64 public void changeStyleReinitialize(int drawWidth, int displayMode, Color color) {
65 acop.clearScreen(handle);
66 handle = -1;
67 acop.setDrawWidth(drawWidth);
68 acop.setDisplayMode(displayMode);
69 acop.setForeground(color);
70 drawData(x, y);
71 }
72
73 public static void main(String[] args) {
74 AcopStyleDemo acm = new AcopStyleDemo();
75 JFrame appFrame = new JFrame();
76 appFrame.setContentPane(acm);
77 appFrame.setSize(600, 400);
78 appFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
79 appFrame.setVisible(true);
80
81 try {
82 acm.drawData(new double[]{0,1,2,3,4,5,6,7,8,9}, new double[]{2.12, 3.2, 5.3, 2.5, 5.34, 7, 3.4, 7.2, 9.34, 1.3});
83 Thread.sleep(5000);
84 System.out.println("Try to change the plot with refresh...");
85
86 acm.changeStyleRefresh(5, 3, Color.red);
87 Thread.sleep(5000);
88 System.out.println("Try to change the plot by reinitializing...");
89 acm.changeStyleReinitialize(5, 3, Color.blue);
90 } catch (InterruptedException e) {
91 e.printStackTrace();
92 }
93
94 }
95
96 }