Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9a606c0

Browse files
Adding plotting functionality to the editor
1 parent 015f952 commit 9a606c0

File tree

10 files changed

+695
-145
lines changed

10 files changed

+695
-145
lines changed

‎app/src/processing/app/AbstractMonitor.java

Lines changed: 12 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static processing.app.I18n._;
44

55
import java.awt.BorderLayout;
6+
import java.awt.Container;
67
import java.awt.Dimension;
78
import java.awt.Font;
89
import java.awt.Rectangle;
@@ -15,15 +16,10 @@
1516
import javax.swing.AbstractAction;
1617
import javax.swing.Box;
1718
import javax.swing.BoxLayout;
18-
import javax.swing.JButton;
19-
import javax.swing.JCheckBox;
20-
import javax.swing.JComboBox;
2119
import javax.swing.JComponent;
2220
import javax.swing.JFrame;
2321
import javax.swing.JLabel;
2422
import javax.swing.JPanel;
25-
import javax.swing.JScrollPane;
26-
import javax.swing.JTextField;
2723
import javax.swing.KeyStroke;
2824
import javax.swing.SwingUtilities;
2925
import javax.swing.Timer;
@@ -36,19 +32,11 @@
3632
@SuppressWarnings("serial")
3733
public abstract class AbstractMonitor extends JFrame implements ActionListener {
3834

39-
protected final JLabel noLineEndingAlert;
40-
protected TextAreaFIFO textArea;
41-
protected JScrollPane scrollPane;
42-
protected JTextField textField;
43-
protected JButton sendButton;
44-
protected JCheckBox autoscrollBox;
45-
protected JComboBox lineEndings;
46-
protected JComboBox serialRates;
4735
private boolean monitorEnabled;
4836
private boolean closed;
4937

50-
private Timer updateTimer;
5138
private StringBuffer updateBuffer;
39+
private Timer updateTimer;
5240

5341
public AbstractMonitor(String title) {
5442
super(title);
@@ -78,87 +66,10 @@ public void actionPerformed(ActionEvent event) {
7866
}
7967
}));
8068

81-
getContentPane().setLayout(new BorderLayout());
82-
83-
Font consoleFont = Theme.getFont("console.font");
84-
Font editorFont = PreferencesData.getFont("editor.font");
85-
Font font = new Font(consoleFont.getName(), consoleFont.getStyle(), editorFont.getSize());
86-
87-
textArea = new TextAreaFIFO(8000000);
88-
textArea.setRows(16);
89-
textArea.setColumns(40);
90-
textArea.setEditable(false);
91-
textArea.setFont(font);
92-
93-
// don't automatically update the caret. that way we can manually decide
94-
// whether or not to do so based on the autoscroll checkbox.
95-
((DefaultCaret) textArea.getCaret()).setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
96-
97-
scrollPane = new JScrollPane(textArea);
98-
99-
getContentPane().add(scrollPane, BorderLayout.CENTER);
100-
101-
JPanel upperPane = new JPanel();
102-
upperPane.setLayout(new BoxLayout(upperPane, BoxLayout.X_AXIS));
103-
upperPane.setBorder(new EmptyBorder(4, 4, 4, 4));
104-
105-
textField = new JTextField(40);
106-
sendButton = new JButton(_("Send"));
107-
108-
upperPane.add(textField);
109-
upperPane.add(Box.createRigidArea(new Dimension(4, 0)));
110-
upperPane.add(sendButton);
111-
112-
getContentPane().add(upperPane, BorderLayout.NORTH);
113-
114-
final JPanel pane = new JPanel();
115-
pane.setLayout(new BoxLayout(pane, BoxLayout.X_AXIS));
116-
pane.setBorder(new EmptyBorder(4, 4, 4, 4));
117-
118-
autoscrollBox = new JCheckBox(_("Autoscroll"), true);
119-
120-
noLineEndingAlert = new JLabel(I18n.format(_("You've pressed {0} but nothing was sent. Should you select a line ending?"), _("Send")));
121-
noLineEndingAlert.setToolTipText(noLineEndingAlert.getText());
122-
noLineEndingAlert.setForeground(pane.getBackground());
123-
Dimension minimumSize = new Dimension(noLineEndingAlert.getMinimumSize());
124-
minimumSize.setSize(minimumSize.getWidth() / 3, minimumSize.getHeight());
125-
noLineEndingAlert.setMinimumSize(minimumSize);
126-
127-
lineEndings = new JComboBox(new String[]{_("No line ending"), _("Newline"), _("Carriage return"), _("Both NL & CR")});
128-
lineEndings.addActionListener(new ActionListener() {
129-
public void actionPerformed(ActionEvent event) {
130-
PreferencesData.setInteger("serial.line_ending", lineEndings.getSelectedIndex());
131-
noLineEndingAlert.setForeground(pane.getBackground());
132-
}
133-
});
134-
if (PreferencesData.get("serial.line_ending") != null) {
135-
lineEndings.setSelectedIndex(PreferencesData.getInteger("serial.line_ending"));
136-
}
137-
lineEndings.setMaximumSize(lineEndings.getMinimumSize());
138-
139-
String[] serialRateStrings = {
140-
"300", "1200", "2400", "4800", "9600",
141-
"19200", "38400", "57600", "115200", "230400", "250000"
142-
};
143-
144-
serialRates = new JComboBox();
145-
for (String rate : serialRateStrings) {
146-
serialRates.addItem(rate + " " + _("baud"));
147-
}
148-
149-
serialRates.setMaximumSize(serialRates.getMinimumSize());
15069

151-
pane.add(autoscrollBox);
152-
pane.add(Box.createHorizontalGlue());
153-
pane.add(noLineEndingAlert);
154-
pane.add(Box.createRigidArea(new Dimension(8, 0)));
155-
pane.add(lineEndings);
156-
pane.add(Box.createRigidArea(new Dimension(8, 0)));
157-
pane.add(serialRates);
70+
onCreateWindow(getContentPane());
15871

159-
this.setMinimumSize(new Dimension(pane.getMinimumSize().width, this.getPreferredSize().height));
160-
161-
getContentPane().add(pane, BorderLayout.SOUTH);
72+
this.setMinimumSize(new Dimension(getContentPane().getMinimumSize().width, this.getPreferredSize().height));
16273

16374
pack();
16475

@@ -184,19 +95,16 @@ public void actionPerformed(ActionEvent event) {
18495
monitorEnabled = true;
18596
closed = false;
18697
}
98+
99+
protected abstract void onCreateWindow(Container mainPane);
187100

188101
public void enableWindow(boolean enable)
189102
{
190-
textArea.setEnabled(enable);
191-
scrollPane.setEnabled(enable);
192-
textField.setEnabled(enable);
193-
sendButton.setEnabled(enable);
194-
autoscrollBox.setEnabled(enable);
195-
lineEndings.setEnabled(enable);
196-
serialRates.setEnabled(enable);
197-
103+
onEnableWindow(enable);
198104
monitorEnabled = enable;
199105
}
106+
107+
protected abstract void onEnableWindow(boolean enable);
200108

201109
// Puts the window in suspend state, closing the serial port
202110
// to allow other entity (the programmer) to use it
@@ -229,15 +137,6 @@ public void resume() throws SerialException
229137

230138
}
231139

232-
public void onSerialRateChange(ActionListener listener) {
233-
serialRates.addActionListener(listener);
234-
}
235-
236-
public void onSendCommand(ActionListener listener) {
237-
textField.addActionListener(listener);
238-
sendButton.addActionListener(listener);
239-
}
240-
241140
protected void setPlacement(int[] location) {
242141
setBounds(location[0], location[1], location[2], location[3]);
243142
}
@@ -255,16 +154,7 @@ protected int[] getPlacement() {
255154
return location;
256155
}
257156

258-
public void message(final String s) {
259-
SwingUtilities.invokeLater(new Runnable() {
260-
public void run() {
261-
textArea.append(s);
262-
if (autoscrollBox.isSelected()) {
263-
textArea.setCaretPosition(textArea.getDocument().getLength());
264-
}
265-
}
266-
});
267-
}
157+
public abstract void message(final String s);
268158

269159
public boolean requiresAuthorization() {
270160
return false;
@@ -291,18 +181,11 @@ private synchronized String consumeUpdateBuffer() {
291181
updateBuffer.setLength(0);
292182
return s;
293183
}
294-
184+
295185
public void actionPerformed(ActionEvent e) {
296186
final String s = consumeUpdateBuffer();
297187
if (s.length() > 0) {
298-
//System.out.println("gui append " + s.length());
299-
if (autoscrollBox.isSelected()) {
300-
textArea.appendTrim(s);
301-
textArea.setCaretPosition(textArea.getDocument().getLength());
302-
} else {
303-
textArea.appendNoTrim(s);
304-
}
188+
message(s);
305189
}
306190
}
307-
308191
}
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
package processing.app;
2+
3+
import static processing.app.I18n._;
4+
5+
import java.awt.BorderLayout;
6+
import java.awt.Container;
7+
import java.awt.Dimension;
8+
import java.awt.Font;
9+
import java.awt.Rectangle;
10+
import java.awt.Toolkit;
11+
import java.awt.event.ActionEvent;
12+
import java.awt.event.ActionListener;
13+
import java.awt.event.WindowAdapter;
14+
import java.awt.event.WindowEvent;
15+
16+
import javax.swing.AbstractAction;
17+
import javax.swing.Box;
18+
import javax.swing.BoxLayout;
19+
import javax.swing.JButton;
20+
import javax.swing.JCheckBox;
21+
import javax.swing.JComboBox;
22+
import javax.swing.JComponent;
23+
import javax.swing.JFrame;
24+
import javax.swing.JLabel;
25+
import javax.swing.JPanel;
26+
import javax.swing.JScrollPane;
27+
import javax.swing.JTextField;
28+
import javax.swing.KeyStroke;
29+
import javax.swing.SwingUtilities;
30+
import javax.swing.border.EmptyBorder;
31+
import javax.swing.text.DefaultCaret;
32+
33+
import processing.app.debug.TextAreaFIFO;
34+
import processing.app.legacy.PApplet;
35+
36+
@SuppressWarnings("serial")
37+
public abstract class AbstractTextMonitor extends AbstractMonitor {
38+
39+
protected JLabel noLineEndingAlert;
40+
protected TextAreaFIFO textArea;
41+
protected JScrollPane scrollPane;
42+
protected JTextField textField;
43+
protected JButton sendButton;
44+
protected JCheckBox autoscrollBox;
45+
protected JComboBox lineEndings;
46+
protected JComboBox serialRates;
47+
48+
public AbstractTextMonitor(String title) {
49+
super(title);
50+
}
51+
52+
protected void onCreateWindow(Container mainPane) {
53+
Font consoleFont = Theme.getFont("console.font");
54+
Font editorFont = PreferencesData.getFont("editor.font");
55+
Font font = new Font(consoleFont.getName(), consoleFont.getStyle(), editorFont.getSize());
56+
57+
mainPane.setLayout(new BorderLayout());
58+
59+
textArea = new TextAreaFIFO(8000000);
60+
textArea.setRows(16);
61+
textArea.setColumns(40);
62+
textArea.setEditable(false);
63+
textArea.setFont(font);
64+
65+
// don't automatically update the caret. that way we can manually decide
66+
// whether or not to do so based on the autoscroll checkbox.
67+
((DefaultCaret) textArea.getCaret()).setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
68+
69+
scrollPane = new JScrollPane(textArea);
70+
71+
mainPane.add(scrollPane, BorderLayout.CENTER);
72+
73+
JPanel upperPane = new JPanel();
74+
upperPane.setLayout(new BoxLayout(upperPane, BoxLayout.X_AXIS));
75+
upperPane.setBorder(new EmptyBorder(4, 4, 4, 4));
76+
77+
textField = new JTextField(40);
78+
sendButton = new JButton(_("Send"));
79+
80+
upperPane.add(textField);
81+
upperPane.add(Box.createRigidArea(new Dimension(4, 0)));
82+
upperPane.add(sendButton);
83+
84+
mainPane.add(upperPane, BorderLayout.NORTH);
85+
86+
final JPanel pane = new JPanel();
87+
pane.setLayout(new BoxLayout(pane, BoxLayout.X_AXIS));
88+
pane.setBorder(new EmptyBorder(4, 4, 4, 4));
89+
90+
autoscrollBox = new JCheckBox(_("Autoscroll"), true);
91+
92+
noLineEndingAlert = new JLabel(I18n.format(_("You've pressed {0} but nothing was sent. Should you select a line ending?"), _("Send")));
93+
noLineEndingAlert.setToolTipText(noLineEndingAlert.getText());
94+
noLineEndingAlert.setForeground(pane.getBackground());
95+
Dimension minimumSize = new Dimension(noLineEndingAlert.getMinimumSize());
96+
minimumSize.setSize(minimumSize.getWidth() / 3, minimumSize.getHeight());
97+
noLineEndingAlert.setMinimumSize(minimumSize);
98+
99+
lineEndings = new JComboBox(new String[]{_("No line ending"), _("Newline"), _("Carriage return"), _("Both NL & CR")});
100+
lineEndings.addActionListener(new ActionListener() {
101+
public void actionPerformed(ActionEvent event) {
102+
PreferencesData.setInteger("serial.line_ending", lineEndings.getSelectedIndex());
103+
noLineEndingAlert.setForeground(pane.getBackground());
104+
}
105+
});
106+
if (PreferencesData.get("serial.line_ending") != null) {
107+
lineEndings.setSelectedIndex(PreferencesData.getInteger("serial.line_ending"));
108+
}
109+
lineEndings.setMaximumSize(lineEndings.getMinimumSize());
110+
111+
String[] serialRateStrings = {
112+
"300", "1200", "2400", "4800", "9600",
113+
"19200", "38400", "57600", "115200", "230400", "250000"
114+
};
115+
116+
serialRates = new JComboBox();
117+
for (String rate : serialRateStrings) {
118+
serialRates.addItem(rate + " " + _("baud"));
119+
}
120+
121+
serialRates.setMaximumSize(serialRates.getMinimumSize());
122+
123+
pane.add(autoscrollBox);
124+
pane.add(Box.createHorizontalGlue());
125+
pane.add(noLineEndingAlert);
126+
pane.add(Box.createRigidArea(new Dimension(8, 0)));
127+
pane.add(lineEndings);
128+
pane.add(Box.createRigidArea(new Dimension(8, 0)));
129+
pane.add(serialRates);
130+
131+
mainPane.add(pane, BorderLayout.SOUTH);
132+
}
133+
134+
protected void onEnableWindow(boolean enable)
135+
{
136+
textArea.setEnabled(enable);
137+
scrollPane.setEnabled(enable);
138+
textField.setEnabled(enable);
139+
sendButton.setEnabled(enable);
140+
autoscrollBox.setEnabled(enable);
141+
lineEndings.setEnabled(enable);
142+
serialRates.setEnabled(enable);
143+
}
144+
145+
public void onSendCommand(ActionListener listener) {
146+
textField.addActionListener(listener);
147+
sendButton.addActionListener(listener);
148+
}
149+
150+
public void onSerialRateChange(ActionListener listener) {
151+
serialRates.addActionListener(listener);
152+
}
153+
154+
public void message(final String s) {
155+
SwingUtilities.invokeLater(new Runnable() {
156+
public void run() {
157+
textArea.append(s);
158+
if (autoscrollBox.isSelected()) {
159+
textArea.setCaretPosition(textArea.getDocument().getLength());
160+
}
161+
}
162+
});
163+
}
164+
165+
public abstract void open() throws Exception;
166+
167+
public abstract void close() throws Exception;
168+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /