Skip to content

Commit b3beda7

Browse files
committed
Adding plotting functionality to the editor
1 parent faa0845 commit b3beda7

File tree

7 files changed

+444
-11
lines changed

7 files changed

+444
-11
lines changed

Diff for: app/src/processing/app/Editor.java

+29-1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ public class Editor extends JFrame implements RunnerListener {
100100

101101
static SerialMenuListener serialMenuListener;
102102
static SerialMonitor serialMonitor;
103+
104+
static SerialPlotter serialPlotter;
103105

104106
EditorHeader header;
105107
EditorStatus status;
@@ -201,6 +203,11 @@ public void windowDeactivated(WindowEvent e) {
201203
serialMonitor = new SerialMonitor(Preferences.get("serial.port"));
202204
serialMonitor.setIconImage(getIconImage());
203205
}
206+
207+
if (serialPlotter == null) {
208+
serialPlotter = new SerialPlotter(Preferences.get("serial.port"));
209+
serialPlotter.setIconImage(getIconImage());
210+
}
204211

205212
buildMenuBar();
206213

@@ -668,7 +675,15 @@ public void actionPerformed(ActionEvent e) {
668675
}
669676
});
670677
menu.add(item);
671-
678+
679+
item = newJMenuItemShift(_("Serial Plotter"), 'L');
680+
item.addActionListener(new ActionListener() {
681+
public void actionPerformed(ActionEvent e) {
682+
handlePlotter();
683+
}
684+
});
685+
menu.add(item);
686+
672687
addTools(menu, Base.getToolsFolder());
673688
File sketchbookTools = new File(Base.getSketchbookFolder(), "tools");
674689
addTools(menu, sketchbookTools);
@@ -945,6 +960,9 @@ protected void selectSerialPort(String name) {
945960
serialMonitor.closeSerialPort();
946961
serialMonitor.setVisible(false);
947962
serialMonitor = new SerialMonitor(Preferences.get("serial.port"));
963+
serialPlotter.closeSerialPort();
964+
serialPlotter.setVisible(false);
965+
serialPlotter = new SerialPlotter(Preferences.get("serial.port"));
948966
//System.out.println("set to " + get("serial.port"));
949967
}
950968

@@ -2487,6 +2505,16 @@ public void handleSerial() {
24872505
}
24882506
}
24892507

2508+
public void handlePlotter() {
2509+
if(uploading) return;
2510+
2511+
try {
2512+
serialPlotter.openSerialPort();
2513+
serialPlotter.setVisible(true);
2514+
} catch (SerialException e) {
2515+
statusError(e);
2516+
}
2517+
}
24902518

24912519
protected void handleBurnBootloader() {
24922520
console.clear();

Diff for: app/src/processing/app/EditorToolbar.java

+22-10
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key
3838

3939
/** Rollover titles for each button. */
4040
static final String title[] = {
41-
_("Verify"), _("Upload"), _("New"), _("Open"), _("Save"), _("Serial Monitor")
41+
_("Verify"), _("Upload"), _("New"), _("Open"), _("Save"), _("Serial Monitor"), _("Serial Plotter")
4242
};
4343

4444
/** Titles for each button when the shift key is pressed. */
4545
static final String titleShift[] = {
46-
_("Verify"), _("Upload Using Programmer"), _("New Editor Window"), _("Open in Another Window"), _("Save"), _("Serial Monitor")
46+
_("Verify"), _("Upload Using Programmer"), _("New Editor Window"), _("Open in Another Window"), _("Save"), _("Serial Monitor"), _("Serial Plotter")
4747
};
4848

4949
static final int BUTTON_COUNT = title.length;
@@ -65,6 +65,7 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key
6565
static final int SAVE = 4;
6666

6767
static final int SERIAL = 5;
68+
static final int PLOTTER = 6;
6869

6970
static final int INACTIVE = 0;
7071
static final int ROLLOVER = 1;
@@ -110,6 +111,7 @@ public EditorToolbar(Editor editor, JMenu menu) {
110111
which[buttonCount++] = OPEN;
111112
which[buttonCount++] = SAVE;
112113
which[buttonCount++] = SERIAL;
114+
which[buttonCount++] = PLOTTER;
113115

114116
currentRollover = -1;
115117

@@ -173,8 +175,11 @@ public void paintComponent(Graphics screen) {
173175
}
174176

175177
// Serial button must be on the right
176-
x1[SERIAL] = width - BUTTON_WIDTH - 14;
177-
x2[SERIAL] = width - 14;
178+
x1[SERIAL] = width - 2 * BUTTON_WIDTH - 14;
179+
x2[SERIAL] = width - BUTTON_WIDTH - 14;
180+
// Plotter button too
181+
x1[PLOTTER] = width - BUTTON_WIDTH - 14;
182+
x2[PLOTTER] = width - 14;
178183
}
179184
Graphics g = offscreen.getGraphics();
180185
g.setColor(bgcolor); //getBackground());
@@ -201,12 +206,15 @@ public void paintComponent(Graphics screen) {
201206
if (currentRollover != -1) {
202207
int statusY = (BUTTON_HEIGHT + g.getFontMetrics().getAscent()) / 2;
203208
String status = shiftPressed ? titleShift[currentRollover] : title[currentRollover];
204-
if (currentRollover != SERIAL)
205-
g.drawString(status, (buttonCount-1) * BUTTON_WIDTH + 3 * BUTTON_GAP, statusY);
206-
else {
207-
int statusX = x1[SERIAL] - BUTTON_GAP;
208-
statusX -= g.getFontMetrics().stringWidth(status);
209-
g.drawString(status, statusX, statusY);
209+
switch (currentRollover) {
210+
case SERIAL:
211+
case PLOTTER:
212+
int statusX = x1[SERIAL] - BUTTON_GAP;
213+
statusX -= g.getFontMetrics().stringWidth(status);
214+
g.drawString(status, statusX, statusY);
215+
break;
216+
default:
217+
g.drawString(status, (buttonCount-1) * BUTTON_WIDTH + 3 * BUTTON_GAP, statusY);
210218
}
211219
}
212220

@@ -352,6 +360,10 @@ public void mousePressed(MouseEvent e) {
352360
case SERIAL:
353361
editor.handleSerial();
354362
break;
363+
364+
case PLOTTER:
365+
editor.handlePlotter();
366+
break;
355367
}
356368
}
357369

Diff for: app/src/processing/app/Resources_en.po

+4
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ msgstr ""
115115
msgid "Serial Monitor"
116116
msgstr ""
117117

118+
#: Editor.java:666
119+
msgid "Serial Plotter"
120+
msgstr ""
121+
118122
#: Editor.java:682
119123
msgid "Board"
120124
msgstr ""

0 commit comments

Comments
 (0)