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 97e979c

Browse files
Add copy button to the serial monitor
Add a copy button to the serial monitor that copies the text in the serial monitor output area to the system clipboard.
1 parent 74f93fe commit 97e979c

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

‎app/src/processing/app/AbstractTextMonitor.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public abstract class AbstractTextMonitor extends AbstractMonitor {
3838
protected JTextField textField;
3939
protected JButton sendButton;
4040
protected JButton clearButton;
41+
protected JButton copyButton;
4142
protected JCheckBox autoscrollBox;
4243
protected JCheckBox addTimeStampBox;
4344
protected JComboBox lineEndings;
@@ -82,6 +83,7 @@ public void windowGainedFocus(WindowEvent e) {
8283

8384
sendButton = new JButton(tr("Send"));
8485
clearButton = new JButton(tr("Clear output"));
86+
copyButton = new JButton(tr("Copy output"));
8587

8688
upperPane.add(textField);
8789
upperPane.add(Box.createRigidArea(new Dimension(4, 0)));
@@ -140,6 +142,8 @@ public void actionPerformed(ActionEvent e) {
140142
pane.add(Box.createRigidArea(new Dimension(8, 0)));
141143
pane.add(serialRates);
142144
pane.add(Box.createRigidArea(new Dimension(8, 0)));
145+
pane.add(copyButton);
146+
pane.add(Box.createRigidArea(new Dimension(8, 0)));
143147
pane.add(clearButton);
144148

145149
mainPane.add(pane, BorderLayout.SOUTH);
@@ -149,6 +153,7 @@ protected void onEnableWindow(boolean enable)
149153
{
150154
textArea.setEnabled(enable);
151155
clearButton.setEnabled(enable);
156+
copyButton.setEnabled(enable);
152157
scrollPane.setEnabled(enable);
153158
textField.setEnabled(enable);
154159
sendButton.setEnabled(enable);
@@ -167,6 +172,10 @@ public void onClearCommand(ActionListener listener) {
167172
clearButton.addActionListener(listener);
168173
}
169174

175+
public void onCopyCommand(ActionListener listener) {
176+
copyButton.addActionListener(listener);
177+
}
178+
170179
public void onSerialRateChange(ActionListener listener) {
171180
serialRates.addActionListener(listener);
172181
}

‎app/src/processing/app/SerialMonitor.java‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import processing.app.legacy.PApplet;
2323

2424
import java.awt.*;
25+
import java.awt.datatransfer.Clipboard;
26+
import java.awt.datatransfer.StringSelection;
2527
import java.awt.event.ActionEvent;
2628
import java.awt.event.ActionListener;
2729

@@ -62,12 +64,20 @@ public void actionPerformed(ActionEvent e) {
6264
textField.setText("");
6365
}
6466
});
65-
67+
6668
onClearCommand(new ActionListener() {
6769
public void actionPerformed(ActionEvent e) {
6870
textArea.setText("");
6971
}
7072
});
73+
74+
onCopyCommand(new ActionListener() {
75+
public void actionPerformed(ActionEvent e) {
76+
String text = textArea.getText();
77+
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
78+
clipboard.setContents(new StringSelection(text), null);
79+
}
80+
});
7181
}
7282

7383
private void send(String s) {

0 commit comments

Comments
(0)

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