Skip to content

Commit 383798e

Browse files
committed
added graph button and graphmonitor
1 parent 1627fd3 commit 383798e

23 files changed

+315
-13
lines changed

app/build.xml

100644100755
+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
encoding="UTF-8"
4545
includeAntRuntime="false"
4646
debug="true"
47-
classpath="../core/core.jar; ${env.JAVA_HOME}/lib/tools.jar; lib/ant.jar; lib/ant-launcher.jar; lib/apple.jar; lib/ecj.jar; lib/jna.jar; lib/RXTXcomm.jar" />
47+
classpath="../core/core.jar; ${env.JAVA_HOME}/lib/tools.jar; lib/ant.jar; lib/ant-launcher.jar; lib/apple.jar; lib/ecj.jar; lib/jna.jar; lib/RXTXcomm.jar; lib/jfreechart.jar; lib/jcommon.jar; lib/iText.jar; lib/swtgraphics2d.jar; lib/servlet.jar; lib/jfreechart-swt.jar; lib/gnujaxp.jar" />
4848
</target>
4949

5050
<target name="build" depends="compile" description="Build PDE">

app/lib/RXTXcomm.jar

100644100755
File mode changed.

app/lib/antlr.jar

100644100755
File mode changed.

app/lib/ecj.jar

100644100755
File mode changed.

app/lib/gnujaxp.jar

226 KB
Binary file not shown.

app/lib/iText.jar

1.07 MB
Binary file not shown.

app/lib/jcommon.jar

302 KB
Binary file not shown.

app/lib/jfreechart-experimental.jar

13.1 KB
Binary file not shown.

app/lib/jfreechart-swt.jar

71 KB
Binary file not shown.

app/lib/jfreechart.jar

1.36 MB
Binary file not shown.

app/lib/jna.jar

100644100755
File mode changed.

app/lib/junit.jar

118 KB
Binary file not shown.

app/lib/servlet.jar

78.2 KB
Binary file not shown.

app/lib/swtgraphics2d.jar

15.2 KB
Binary file not shown.

app/src/processing/app/Editor.java

100644100755
+17-3
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public class Editor extends JFrame implements RunnerListener {
9999

100100
static SerialMenuListener serialMenuListener;
101101
static SerialMonitor serialMonitor;
102+
static GraphMonitor graphMonitor;
102103

103104
EditorHeader header;
104105
EditorStatus status;
@@ -200,7 +201,10 @@ public void windowDeactivated(WindowEvent e) {
200201
serialMonitor = new SerialMonitor(Preferences.get("serial.port"));
201202
serialMonitor.setIconImage(getIconImage());
202203
}
203-
204+
if(graphMonitor == null){
205+
graphMonitor = new GraphMonitor(Preferences.get("serial.port"));
206+
graphMonitor.setIconImage(getIconImage());
207+
}
204208
buildMenuBar();
205209

206210
// For rev 0120, placing things inside a JPanel
@@ -2391,7 +2395,8 @@ public void run() {
23912395
try {
23922396
serialMonitor.closeSerialPort();
23932397
serialMonitor.setVisible(false);
2394-
2398+
graphMonitor.closeSerialPort();
2399+
graphMonitor.setVisible(false);
23952400
uploading = true;
23962401

23972402
boolean success = sketch.exportApplet(true);
@@ -2465,7 +2470,16 @@ public void handleSerial() {
24652470
statusError(e);
24662471
}
24672472
}
2468-
2473+
public void handleGraph(){
2474+
if (uploading) return;
2475+
try{
2476+
graphMonitor.openSerialPort();
2477+
graphMonitor.setVisible(true);
2478+
} catch(SerialException e){
2479+
statusError(e);
2480+
}
2481+
2482+
}
24692483

24702484
protected void handleBurnBootloader() {
24712485
console.clear();

app/src/processing/app/EditorToolbar.java

100644100755
+18-8
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key
3737

3838
/** Rollover titles for each button. */
3939
static final String title[] = {
40-
"Verify", "Upload", "New", "Open", "Save", "Serial Monitor"
40+
"Verify", "Upload", "New", "Open", "Save", "Serial Monitor" , "graph"
4141
};
4242

4343
/** Titles for each button when the shift key is pressed. */
4444
static final String titleShift[] = {
45-
"Verify", "Upload Using Programmer", "New Editor Window", "Open in Another Window", "Save", "Serial Monitor"
45+
"Verify", "Upload Using Programmer", "New Editor Window", "Open in Another Window", "Save", "Serial Monitor" , "graph"
4646
};
4747

4848
static final int BUTTON_COUNT = title.length;
@@ -64,7 +64,8 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key
6464
static final int SAVE = 4;
6565

6666
static final int SERIAL = 5;
67-
67+
static final int GRAPH = 6;
68+
6869
static final int INACTIVE = 0;
6970
static final int ROLLOVER = 1;
7071
static final int ACTIVE = 2;
@@ -108,8 +109,9 @@ public EditorToolbar(Editor editor, JMenu menu) {
108109
which[buttonCount++] = NEW;
109110
which[buttonCount++] = OPEN;
110111
which[buttonCount++] = SAVE;
111-
which[buttonCount++] = SERIAL;
112112

113+
which[buttonCount++] = SERIAL;
114+
which[buttonCount++] = GRAPH;
113115
currentRollover = -1;
114116

115117
bgcolor = Theme.getColor("buttons.bgcolor");
@@ -172,8 +174,12 @@ public void paintComponent(Graphics screen) {
172174
}
173175

174176
// Serial button must be on the right
175-
x1[SERIAL] = width - BUTTON_WIDTH - 14;
176-
x2[SERIAL] = width - 14;
177+
x1[GRAPH] = width - BUTTON_WIDTH - 14;//change this to the graph button and add the serial button to the left of the graph button(2*BUTTON_WIDTH for SERIAL)
178+
x2[GRAPH] = width - 14;
179+
180+
x1[SERIAL] = width - 2*BUTTON_WIDTH - 14;//change this to the graph button and add the serial button to the left of the graph button(2*BUTTON_WIDTH for SERIAL)
181+
x2[SERIAL] = width - BUTTON_WIDTH-14;
182+
177183
}
178184
Graphics g = offscreen.getGraphics();
179185
g.setColor(bgcolor); //getBackground());
@@ -200,8 +206,8 @@ public void paintComponent(Graphics screen) {
200206
if (currentRollover != -1) {
201207
int statusY = (BUTTON_HEIGHT + g.getFontMetrics().getAscent()) / 2;
202208
String status = shiftPressed ? titleShift[currentRollover] : title[currentRollover];
203-
if (currentRollover != SERIAL)
204-
g.drawString(status, (buttonCount-1) * BUTTON_WIDTH + 3 * BUTTON_GAP, statusY);
209+
if (currentRollover != SERIAL && currentRollover!= GRAPH)
210+
g.drawString(status, (buttonCount-2) * BUTTON_WIDTH + 3 * BUTTON_GAP, statusY);
205211
else {
206212
int statusX = x1[SERIAL] - BUTTON_GAP;
207213
statusX -= g.getFontMetrics().stringWidth(status);
@@ -351,6 +357,10 @@ public void mousePressed(MouseEvent e) {
351357
case SERIAL:
352358
editor.handleSerial();
353359
break;
360+
case GRAPH:
361+
editor.handleGraph();
362+
break;
363+
354364
}
355365
}
356366

+264
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2+
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
15+
along with this program; if not, write to the Free Software Foundation,
16+
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17+
*/
18+
//TODO: change to Graphmonitor it is still a copy of serialmonitor, also create 1 virtual class for handling serial displaying.
19+
package processing.app;
20+
21+
import processing.app.debug.MessageConsumer;
22+
import processing.core.*;
23+
24+
import java.awt.*;
25+
import java.util.Date;
26+
import java.awt.event.*;
27+
import javax.swing.*;
28+
import javax.swing.border.*;
29+
import javax.swing.event.*;
30+
import javax.swing.text.*;
31+
import org.jfree.chart.*;
32+
import org.jfree.chart.ChartFactory;
33+
import org.jfree.chart.ChartPanel;
34+
import org.jfree.chart.JFreeChart;
35+
import org.jfree.chart.axis.NumberTickUnit;
36+
import org.jfree.chart.axis.TickUnits;
37+
import org.jfree.chart.axis.ValueAxis;
38+
import org.jfree.chart.plot.DatasetRenderingOrder;
39+
import org.jfree.chart.plot.PlotOrientation;
40+
import org.jfree.chart.plot.XYPlot;
41+
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
42+
import org.jfree.chart.renderer.xy.XYStepRenderer;
43+
import org.jfree.data.time.Second;
44+
import org.jfree.data.time.TimeTableXYDataset;
45+
public class GraphMonitor extends JFrame implements MessageConsumer {
46+
private Serial serial;
47+
private String port;
48+
private JTextArea textArea;
49+
private JTextArea graphArea;
50+
private JScrollPane scrollPane;
51+
private JScrollPane graphScrollPane;
52+
53+
private JTextField textField;
54+
private JButton sendButton;
55+
private JCheckBox autoscrollBox;
56+
private JComboBox lineEndings;
57+
private JComboBox serialRates;
58+
private int serialRate;
59+
60+
public GraphMonitor(String port) {
61+
super(port);
62+
63+
this.port = port;
64+
65+
addWindowListener(new WindowAdapter() {
66+
public void windowClosing(WindowEvent e) {
67+
closeSerialPort();
68+
}
69+
});
70+
71+
// obvious, no?
72+
KeyStroke wc = Editor.WINDOW_CLOSE_KEYSTROKE;
73+
getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(wc, "close");
74+
getRootPane().getActionMap().put("close", new AbstractAction() {
75+
public void actionPerformed(ActionEvent e) {
76+
closeSerialPort();
77+
setVisible(false);
78+
}});
79+
80+
getContentPane().setLayout(new BorderLayout());
81+
82+
Font font = Theme.getFont("console.font");
83+
84+
textArea = new JTextArea(16, 20);
85+
textArea.setEditable(false);
86+
textArea.setFont(font);
87+
// don't automatically update the caret. that way we can manually decide
88+
// whether or not to do so based on the autoscroll checkbox.
89+
((DefaultCaret)textArea.getCaret()).setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
90+
91+
scrollPane = new JScrollPane(textArea);
92+
JPanel pane = new JPanel();
93+
pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
94+
pane.setBorder(new EmptyBorder(4, 4, 4, 4));
95+
pane.add(this.graph());
96+
pane.add(scrollPane);
97+
getContentPane().add(pane, BorderLayout.CENTER);
98+
99+
100+
pane = new JPanel();
101+
pane.setLayout(new BoxLayout(pane, BoxLayout.X_AXIS));
102+
pane.setBorder(new EmptyBorder(4, 4, 4, 4));
103+
104+
// textField = new JTextField(40);
105+
// textField.addActionListener(new ActionListener() {
106+
// public void actionPerformed(ActionEvent e) {
107+
// send(textField.getText());
108+
// textField.setText("");
109+
// }});
110+
111+
// sendButton = new JButton("Send");
112+
// sendButton.addActionListener(new ActionListener() {
113+
// public void actionPerformed(ActionEvent e) {
114+
// send(textField.getText());
115+
// textField.setText("");
116+
// }});
117+
118+
// pane.add(textField);
119+
// pane.add(Box.createRigidArea(new Dimension(4, 0)));
120+
// pane.add(sendButton);
121+
//
122+
// getContentPane().add(pane, BorderLayout.NORTH);
123+
124+
// pane = new JPanel();
125+
// pane.setLayout(new BoxLayout(pane, BoxLayout.X_AXIS));
126+
// pane.setBorder(new EmptyBorder(4, 4, 4, 4));
127+
//
128+
// autoscrollBox = new JCheckBox("Autoscroll", true);
129+
//
130+
// lineEndings = new JComboBox(new String[] { "No line ending", "Newline", "Carriage return", "Both NL & CR" });
131+
// lineEndings.addActionListener(new ActionListener() {
132+
// public void actionPerformed(ActionEvent event) {
133+
// Preferences.setInteger("serial.line_ending", lineEndings.getSelectedIndex());
134+
// }
135+
// });
136+
// if (Preferences.get("serial.line_ending") != null) {
137+
// lineEndings.setSelectedIndex(Preferences.getInteger("serial.line_ending"));
138+
// }
139+
// lineEndings.setMaximumSize(lineEndings.getMinimumSize());
140+
//
141+
// String[] serialRateStrings = {
142+
// "300","1200","2400","4800","9600","14400",
143+
// "19200","28800","38400","57600","115200"
144+
// };
145+
//
146+
// serialRates = new JComboBox();
147+
// for (int i = 0; i < serialRateStrings.length; i++)
148+
// serialRates.addItem(serialRateStrings[i] + " baud");
149+
//
150+
// serialRate = Preferences.getInteger("serial.debug_rate");
151+
// serialRates.setSelectedItem(serialRate + " baud");
152+
// serialRates.addActionListener(new ActionListener() {
153+
// public void actionPerformed(ActionEvent event) {
154+
// String wholeString = (String) serialRates.getSelectedItem();
155+
// String rateString = wholeString.substring(0, wholeString.indexOf(' '));
156+
// serialRate = Integer.parseInt(rateString);
157+
// Preferences.set("serial.debug_rate", rateString);
158+
// closeSerialPort();
159+
// try {
160+
// openSerialPort();
161+
// } catch (SerialException e) {
162+
// System.err.println(e);
163+
// }
164+
// }});
165+
//
166+
// serialRates.setMaximumSize(serialRates.getMinimumSize());
167+
//
168+
// pane.add(autoscrollBox);
169+
// pane.add(Box.createHorizontalGlue());
170+
// pane.add(lineEndings);
171+
// pane.add(Box.createRigidArea(new Dimension(8, 0)));
172+
// pane.add(serialRates);
173+
//
174+
// getContentPane().add(pane, BorderLayout.SOUTH);
175+
176+
pack();
177+
178+
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
179+
if (Preferences.get("last.screen.height") != null) {
180+
// if screen size has changed, the window coordinates no longer
181+
// make sense, so don't use them unless they're identical
182+
int screenW = Preferences.getInteger("last.screen.width");
183+
int screenH = Preferences.getInteger("last.screen.height");
184+
if ((screen.width == screenW) && (screen.height == screenH)) {
185+
String locationStr = Preferences.get("last.serial.location");
186+
if (locationStr != null) {
187+
int[] location = PApplet.parseInt(PApplet.split(locationStr, ','));
188+
setPlacement(location);
189+
}
190+
}
191+
}
192+
}
193+
194+
protected void setPlacement(int[] location) {
195+
setBounds(location[0], location[1], location[2], location[3]);
196+
}
197+
198+
protected int[] getPlacement() {
199+
int[] location = new int[4];
200+
201+
// Get the dimensions of the Frame
202+
Rectangle bounds = getBounds();
203+
location[0] = bounds.x;
204+
location[1] = bounds.y;
205+
location[2] = bounds.width;
206+
location[3] = bounds.height;
207+
208+
return location;
209+
}
210+
211+
private void send(String s) {
212+
if (serial != null) {
213+
switch (lineEndings.getSelectedIndex()) {
214+
case 1: s += "\n"; break;
215+
case 2: s += "\r"; break;
216+
case 3: s += "\r\n"; break;
217+
}
218+
serial.write(s);
219+
}
220+
}
221+
222+
public void openSerialPort() throws SerialException {
223+
if (serial != null) return;
224+
225+
serial = new Serial(port, 9600);
226+
serial.addListener(this);
227+
}
228+
229+
public void closeSerialPort() {
230+
if (serial != null) {
231+
int[] location = getPlacement();
232+
String locationStr = PApplet.join(PApplet.str(location), ",");
233+
Preferences.set("last.serial.location", locationStr);
234+
textArea.setText("");
235+
serial.dispose();
236+
serial = null;
237+
}
238+
}
239+
240+
public void message(final String s) {
241+
SwingUtilities.invokeLater(new Runnable() {
242+
public void run() {
243+
textArea.append(s);
244+
if (autoscrollBox.isSelected()) {
245+
textArea.setCaretPosition(textArea.getDocument().getLength());
246+
}
247+
}});
248+
}
249+
public ChartPanel graph(){
250+
TimeTableXYDataset data = new TimeTableXYDataset();
251+
Second second = new Second(new Date(System.currentTimeMillis() + 1000));
252+
data.add(second, 20.0,"a");
253+
Second second2 = new Second(new Date(System.currentTimeMillis() + 2000));
254+
data.add(second2, 30.8,"a");
255+
Second second3 = new Second(new Date(System.currentTimeMillis() + 3000));
256+
data.add(second3, 60.5,"a");
257+
JFreeChart chart = ChartFactory.createXYLineChart(null, null, null,
258+
data, PlotOrientation.VERTICAL,
259+
false, false, false);
260+
ChartPanel panel = new ChartPanel(chart);
261+
262+
return panel;
263+
}
264+
}

0 commit comments

Comments
 (0)