Search in sources :

Example 91 with Clipboard

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) {
        }
    });
}
Also used : Transferable(java.awt.datatransfer.Transferable) ClipboardOwner(java.awt.datatransfer.ClipboardOwner) PsiFile(com.intellij.psi.PsiFile) Clipboard(java.awt.datatransfer.Clipboard) Editor(com.intellij.openapi.editor.Editor) BindingContext(org.jetbrains.kotlin.resolve.BindingContext) StringSelection(java.awt.datatransfer.StringSelection)

Example 92 with Clipboard

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;
}
Also used : MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) URI(java.net.URI) StringSelection(java.awt.datatransfer.StringSelection) Clipboard(java.awt.datatransfer.Clipboard)

Example 93 with Clipboard

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);
}
Also used : Clipboard(java.awt.datatransfer.Clipboard) StringSelection(java.awt.datatransfer.StringSelection)

Example 94 with Clipboard

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();
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) DocumentListener(javax.swing.event.DocumentListener) JTextArea(javax.swing.JTextArea) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) DocumentEvent(javax.swing.event.DocumentEvent) UserPreferencesManager(jmri.UserPreferencesManager) JSeparator(javax.swing.JSeparator) StringSelection(java.awt.datatransfer.StringSelection) JCheckBox(javax.swing.JCheckBox) MouseListener(java.awt.event.MouseListener) JmriJFrame(jmri.util.JmriJFrame) ButtonGroup(javax.swing.ButtonGroup) Clipboard(java.awt.datatransfer.Clipboard) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu)

Example 95 with Clipboard

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);
}
Also used : NamedBean(jmri.NamedBean) Clipboard(java.awt.datatransfer.Clipboard) StringSelection(java.awt.datatransfer.StringSelection)

Aggregations

Clipboard (java.awt.datatransfer.Clipboard)181 StringSelection (java.awt.datatransfer.StringSelection)117 Transferable (java.awt.datatransfer.Transferable)44 IOException (java.io.IOException)30 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)16 JDialog (javax.swing.JDialog)12 JOptionPane (javax.swing.JOptionPane)12 ActionEvent (java.awt.event.ActionEvent)11 Flame (org.jwildfire.create.tina.base.Flame)10 ActionListener (java.awt.event.ActionListener)8 JButton (javax.swing.JButton)8 JScrollPane (javax.swing.JScrollPane)8 JMenuItem (javax.swing.JMenuItem)7 JPanel (javax.swing.JPanel)7 JTextArea (javax.swing.JTextArea)7 Foundation (org.concord.energy3d.model.Foundation)7 HousePart (org.concord.energy3d.model.HousePart)7 FlameReader (org.jwildfire.create.tina.io.FlameReader)7 RenderedFlame (org.jwildfire.create.tina.render.RenderedFlame)7 Point (java.awt.Point)6