use of java.awt.datatransfer.Clipboard in project kotlin by JetBrains.
the class CopyAsDiagnosticTestAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
Editor editor = e.getData(CommonDataKeys.EDITOR);
PsiFile psiFile = e.getData(CommonDataKeys.PSI_FILE);
assert editor != null && psiFile != null;
BindingContext bindingContext = ResolutionUtils.analyzeFully((KtFile) psiFile);
List<CheckerTestUtil.ActualDiagnostic> diagnostics = CheckerTestUtil.getDiagnosticsIncludingSyntaxErrors(bindingContext, psiFile, false, null, null);
String result = CheckerTestUtil.addDiagnosticMarkersToText(psiFile, diagnostics).toString();
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(new StringSelection(result), new ClipboardOwner() {
@Override
public void lostOwnership(Clipboard clipboard, Transferable contents) {
}
});
}
use of java.awt.datatransfer.Clipboard in project azure-tools-for-java by Microsoft.
the class ProjectUtil method createSparkSDKTipsPanel.
public static JPanel createSparkSDKTipsPanel() {
final JPanel panel = new JPanel();
GridBagLayout layout = new GridBagLayout();
JLabel[] labels = new JLabel[] { new JLabel("You can either download Spark library from"), new JLabel("<HTML><FONT color=\"#000099\"><U>here</U></FONT>,</HTML>"), new JLabel("or add Apache Spark packages from Maven repository in the project manually.") };
for (int i = 0; i < labels.length; ++i) {
panel.add(labels[i]);
}
labels[1].setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
labels[1].setToolTipText(downloadSparkSDKUrl);
labels[1].addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
if (SwingUtilities.isRightMouseButton(e)) {
StringSelection stringSelection = new StringSelection(downloadSparkSDKUrl);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(stringSelection, null);
JOptionPane.showMessageDialog(panel, "Already copy Download URL to Clipboard");
} else if (SwingUtilities.isLeftMouseButton(e)) {
try {
URI uri = new URI(downloadSparkSDKUrl);
Desktop.getDesktop().browse(uri);
} catch (Exception exception) {
DefaultLoader.getUIHelper().showError(exception.getMessage(), exception.getClass().getName());
}
}
}
});
GridBagConstraints constraints = new GridBagConstraints(GridBagConstraints.RELATIVE, GridBagConstraints.RELATIVE, 1, 1, 1, 1, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0);
layout.setConstraints(labels[0], constraints);
layout.setConstraints(labels[1], constraints);
layout.setConstraints(labels[2], constraints);
JPanel mainPanel = new JPanel();
GridBagLayout mainLayout = new GridBagLayout();
mainPanel.setLayout(mainLayout);
mainPanel.add(panel, new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
//make sure label message on the head of left
mainPanel.add(new JLabel(), new GridBagConstraints(1, 0, 1, 1, 1, 1, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
return mainPanel;
}
use of java.awt.datatransfer.Clipboard in project pcgen by PCGen.
the class NameGenPanel method jButton1ActionPerformed.
//GEN-END:initComponents
private void jButton1ActionPerformed(ActionEvent evt) {
//GEN-FIRST:event_jButton1ActionPerformed
Clipboard cb = getToolkit().getSystemClipboard();
StringSelection ss = new StringSelection(name.getText());
cb.setContents(ss, ss);
}
use of java.awt.datatransfer.Clipboard in project JMRI by JMRI.
the class SystemConsole method createFrame.
/**
* Layout the console frame
*/
private void createFrame() {
// Use a JmriJFrame to ensure that we fit on the screen
frame = new JmriJFrame(Bundle.getMessage("TitleConsole"));
pref = jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class);
// Add Help menu (Windows menu automaitically added)
// NOI18N
frame.addHelpMenu("package.apps.SystemConsole", true);
// Grab a reference to the system clipboard
final Clipboard clipboard = frame.getToolkit().getSystemClipboard();
// Setup the scroll pane
JScrollPane scroll = new JScrollPane(console);
frame.add(scroll, BorderLayout.CENTER);
// Add button to allow copy to clipboard
JPanel p = new JPanel();
JButton copy = new JButton(Bundle.getMessage("ButtonCopyClip"));
copy.addActionListener((ActionEvent event) -> {
StringSelection text = new StringSelection(console.getText());
clipboard.setContents(text, text);
});
p.add(copy);
// Add button to allow console window to be closed
JButton close = new JButton(Bundle.getMessage("ButtonClose"));
close.addActionListener((ActionEvent event) -> {
frame.setVisible(false);
frame.dispose();
});
p.add(close);
JButton stackTrace = new JButton(Bundle.getMessage("ButtonStackTrace"));
stackTrace.addActionListener((ActionEvent event) -> {
performStackTrace();
});
p.add(stackTrace);
// Add checkbox to enable/disable auto-scrolling
// Use the inverted SimplePreferenceState to default as enabled
p.add(autoScroll = new JCheckBox(Bundle.getMessage("CheckBoxAutoScroll"), !pref.getSimplePreferenceState(alwaysScrollCheck)));
autoScroll.addActionListener((ActionEvent event) -> {
doAutoScroll(console, autoScroll.isSelected());
pref.setSimplePreferenceState(alwaysScrollCheck, !autoScroll.isSelected());
});
// Add checkbox to enable/disable always on top
p.add(alwaysOnTop = new JCheckBox(Bundle.getMessage("CheckBoxOnTop"), pref.getSimplePreferenceState(alwaysOnTopCheck)));
alwaysOnTop.setVisible(true);
alwaysOnTop.setToolTipText(Bundle.getMessage("ToolTipOnTop"));
alwaysOnTop.addActionListener((ActionEvent event) -> {
frame.setAlwaysOnTop(alwaysOnTop.isSelected());
pref.setSimplePreferenceState(alwaysOnTopCheck, alwaysOnTop.isSelected());
});
frame.setAlwaysOnTop(alwaysOnTop.isSelected());
// Define the pop-up menu
copySelection = new JMenuItem(Bundle.getMessage("MenuItemCopy"));
copySelection.addActionListener((ActionEvent event) -> {
StringSelection text = new StringSelection(console.getSelectedText());
clipboard.setContents(text, text);
});
popup.add(copySelection);
JMenuItem menuItem = new JMenuItem(Bundle.getMessage("ButtonCopyClip"));
menuItem.addActionListener((ActionEvent event) -> {
StringSelection text = new StringSelection(console.getText());
clipboard.setContents(text, text);
});
popup.add(menuItem);
popup.add(new JSeparator());
JRadioButtonMenuItem rbMenuItem;
// Define the colour scheme sub-menu
schemeMenu = new JMenu(rbc.getString("ConsoleSchemeMenu"));
schemeGroup = new ButtonGroup();
for (final Scheme s : schemes) {
rbMenuItem = new JRadioButtonMenuItem(s.description);
rbMenuItem.addActionListener((ActionEvent event) -> {
setScheme(schemes.indexOf(s));
});
rbMenuItem.setSelected(getScheme() == schemes.indexOf(s));
schemeMenu.add(rbMenuItem);
schemeGroup.add(rbMenuItem);
}
popup.add(schemeMenu);
// Define the wrap style sub-menu
wrapMenu = new JMenu(rbc.getString("ConsoleWrapStyleMenu"));
wrapGroup = new ButtonGroup();
rbMenuItem = new JRadioButtonMenuItem(rbc.getString("ConsoleWrapStyleNone"));
rbMenuItem.addActionListener((ActionEvent event) -> {
setWrapStyle(WRAP_STYLE_NONE);
});
rbMenuItem.setSelected(getWrapStyle() == WRAP_STYLE_NONE);
wrapMenu.add(rbMenuItem);
wrapGroup.add(rbMenuItem);
rbMenuItem = new JRadioButtonMenuItem(rbc.getString("ConsoleWrapStyleLine"));
rbMenuItem.addActionListener((ActionEvent event) -> {
setWrapStyle(WRAP_STYLE_LINE);
});
rbMenuItem.setSelected(getWrapStyle() == WRAP_STYLE_LINE);
wrapMenu.add(rbMenuItem);
wrapGroup.add(rbMenuItem);
rbMenuItem = new JRadioButtonMenuItem(rbc.getString("ConsoleWrapStyleWord"));
rbMenuItem.addActionListener((ActionEvent event) -> {
setWrapStyle(WRAP_STYLE_WORD);
});
rbMenuItem.setSelected(getWrapStyle() == WRAP_STYLE_WORD);
wrapMenu.add(rbMenuItem);
wrapGroup.add(rbMenuItem);
popup.add(wrapMenu);
// Bind pop-up to objects
MouseListener popupListener = new PopupListener();
console.addMouseListener(popupListener);
frame.addMouseListener(popupListener);
// Add document listener to scroll to end when modified if required
console.getDocument().addDocumentListener(new DocumentListener() {
// References to the JTextArea and JCheckBox
// of this instantiation
JTextArea ta = console;
JCheckBox chk = autoScroll;
@Override
public void insertUpdate(DocumentEvent e) {
doAutoScroll(ta, chk.isSelected());
}
@Override
public void removeUpdate(DocumentEvent e) {
doAutoScroll(ta, chk.isSelected());
}
@Override
public void changedUpdate(DocumentEvent e) {
doAutoScroll(ta, chk.isSelected());
}
});
// Add the button panel to the frame & then arrange everything
frame.add(p, BorderLayout.SOUTH);
frame.pack();
}
use of java.awt.datatransfer.Clipboard in project JMRI by JMRI.
the class BeanTableDataModel method copyName.
public void copyName(int row, int column) {
NamedBean nBean = getBySystemName(sysNameList.get(row));
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
StringSelection name = new StringSelection(nBean.getUserName());
clipboard.setContents(name, null);
}
Aggregations