Skip to content

Commit a751558

Browse files
committed
copy to clipboard button, Refs #351
1 parent 415cfe5 commit a751558

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/creation/CommandDisplayMediator.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import java.awt.Dimension;
77
import java.awt.GridBagConstraints;
88
import java.awt.GridBagLayout;
9+
import java.awt.Toolkit;
10+
import java.awt.datatransfer.Clipboard;
11+
import java.awt.datatransfer.StringSelection;
912
import java.nio.file.Path;
1013
import java.util.List;
1114

@@ -141,15 +144,18 @@ private static String generateCommand(
141144

142145
private class CommandDisplayDialog extends JDialog {
143146

147+
private final String command;
148+
144149
public CommandDisplayDialog(JDialog parent, String command) {
145150
super(parent);
151+
this.command = command;
146152
setResizable(true);
147153
setTitle("EnrichmentMap: Command");
148154
setMinimumSize(new Dimension(500, 300));
149155
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
150156

151157
JPanel messagePanel = createMessagePanel();
152-
JPanel commandPanel = createCommandPanel(command);
158+
JPanel commandPanel = createCommandPanel();
153159
JPanel buttonPanel = createButtonPanel();
154160

155161
messagePanel.setBorder(BorderFactory.createEmptyBorder(8,8,8,8));
@@ -185,7 +191,7 @@ private JPanel createMessagePanel() {
185191
}
186192

187193

188-
private JPanel createCommandPanel(String command) {
194+
private JPanel createCommandPanel() {
189195
JTextArea textArea = new JTextArea(command);
190196
textArea.setEditable(false);
191197
textArea.setLineWrap(true);
@@ -197,12 +203,20 @@ private JPanel createCommandPanel(String command) {
197203
return panel;
198204
}
199205

206+
200207
private JPanel createButtonPanel() {
201208
JButton okButton = new JButton("Close");
202209
okButton.addActionListener(e -> dispose());
203-
return LookAndFeelUtil.createOkCancelPanel(okButton, null);
210+
211+
JButton clipboardButton = new JButton("Copy to Clipboard");
212+
clipboardButton.addActionListener(e -> {
213+
StringSelection stringSelection = new StringSelection(command);
214+
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
215+
clipboard.setContents(stringSelection, null);
216+
});
217+
218+
return LookAndFeelUtil.createOkCancelPanel(okButton, null, clipboardButton);
204219
}
205220
}
206221

207-
208222
}

0 commit comments

Comments
 (0)