List of usage examples for java.awt.datatransfer StringSelection StringSelection
public StringSelection(String data)
From source file:com.mirth.connect.client.ui.components.MirthTreeTable.java
public void setMirthTransferHandlerEnabled(boolean enable) { setDragEnabled(enable);//w w w . j a v a2 s .co m if (transferHandler == null) { transferHandler = new TransferHandler() { @Override public int getSourceActions(JComponent c) { return COPY_OR_MOVE; } @Override protected Transferable createTransferable(JComponent c) { int row = getSelectedRow(); List columnValuesList = new ArrayList<Object>(); for (TableColumn column : getColumns()) { Object value = getValueAt(row, convertColumnIndexToView(column.getModelIndex())); if (value != null) { if (value instanceof Calendar) { Calendar calendar = (GregorianCalendar) value; SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT); dateFormat.setCalendar(calendar); value = (String) dateFormat.format(calendar.getTime()); } else if (value instanceof Long) { value = String.valueOf(value); } else if (value instanceof Status) { value = Status.fromChar(((Status) value).getStatusCode()); } else { value = String.valueOf(value); } } else { value = "-"; } columnValuesList.add(value); } return new StringSelection(StringUtils.join(columnValuesList, " ")); } }; setTransferHandler(transferHandler); } }
From source file:org.rimudb.editor.DescriptorEditor.java
/** * Build the panel/*from w w w . jav a 2 s . c o m*/ */ private JPanel createColumnTablePanel() { JPanel columnPanel = new JPanel(); columnPanel.setLayout(new BoxLayout(columnPanel, BoxLayout.Y_AXIS)); // Create the property table panel propertyModel = new PropertyTableModel(); // Add a listener to set the changed state propertyModel.addTableModelListener(new TableModelListener() { public void tableChanged(TableModelEvent e) { markChanged(); if (e instanceof PropertyTableModelEvent) { PropertyTableModelEvent ptme = (PropertyTableModelEvent) e; // If the columnName column was changed then check it isn't // a PK if (ptme.getColumn() == 1) { String beforeColumnName = (String) ptme.getBeforeValue(); String afterColumnName = (String) ptme.getAfterValue(); // Is the field entry in the list of primary keys? for (int i = 0; i < pkListModel.getSize(); i++) { String pkColumnName = (String) pkListModel.get(i); // If it's found then remove it if (beforeColumnName.equals(pkColumnName)) { pkListModel.set(i, afterColumnName); break; } } } } } }); table = new ATable(getPropertyModel()); table.setName("ColumnTable"); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { int selectedRowCount = table.getSelectedRowCount(); removeColumnBtn.setEnabled(selectedRowCount > 0); moveUpBtn.setEnabled(selectedRowCount > 0); moveDownBtn.setEnabled(selectedRowCount > 0); } }); table.setTransferHandler(new TransferHandler() { public int getSourceActions(JComponent c) { return COPY; } protected Transferable createTransferable(JComponent c) { ATable columnTable = (ATable) c; int row = columnTable.getSelectedRow(); String columnName = getPropertyModel().getRow(row).getColumnName(); return new StringSelection(columnName); } }); table.setDragEnabled(true); JScrollPane sp = new JScrollPane(table); sp.setMaximumSize(new Dimension(Short.MAX_VALUE, 325)); sp.setPreferredSize(new Dimension(Short.MAX_VALUE, 325)); sp.setMinimumSize(new Dimension(Short.MAX_VALUE, 325)); JComboBox typeCB = new JComboBox(DatabaseTypes.getAllTypes()); typeCB.setEditable(false); javax.swing.table.TableColumn typeColumn = table.getColumnModel().getColumn(2); typeColumn.setCellEditor(new DefaultCellEditor(typeCB)); // Create the popup menu and set it on the table propertyPopup = new TablePopupMenu(this, table); table.addMouseListener(propertyPopup); sp.addMouseListener(propertyPopup); sp.setAlignmentX(LEFT_ALIGNMENT); columnPanel.add(sp); columnPanel.add(Box.createVerticalStrut(10)); JLabel pkLabel = new JLabel("Primary Key Columns", SwingConstants.LEFT); pkLabel.setAlignmentX(LEFT_ALIGNMENT); columnPanel.add(pkLabel); pkListModel = new DefaultListModel(); pkListModel.addListDataListener(new ListDataListener() { public void intervalRemoved(ListDataEvent e) { markChanged(); } public void intervalAdded(ListDataEvent e) { markChanged(); } public void contentsChanged(ListDataEvent e) { markChanged(); } }); pkList = new JList(pkListModel); pkList.setName("pkList"); pkList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); pkList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { int selectedRowCount = pkList.getSelectedIndex(); removePkBtn.setEnabled(selectedRowCount > -1); } }); pkList.setTransferHandler(new TransferHandler() { public boolean canImport(TransferHandler.TransferSupport info) { // we only import Strings if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) { return false; } JList.DropLocation dl = (JList.DropLocation) info.getDropLocation(); if (dl.getIndex() == -1) { return false; } return true; } public boolean importData(TransferHandler.TransferSupport info) { if (!info.isDrop()) { return false; } // Check for String flavor if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) { displayDropLocation("List doesn't accept a drop of this type."); return false; } JList.DropLocation dl = (JList.DropLocation) info.getDropLocation(); DefaultListModel listModel = (DefaultListModel) pkList.getModel(); int index = dl.getIndex(); // Get the string that is being dropped. Transferable t = info.getTransferable(); String data; try { data = (String) t.getTransferData(DataFlavor.stringFlavor); } catch (Exception e) { return false; } // If this is a copy action then check we don't already have that String if (info.getDropAction() == COPY && listModel.indexOf(data) > -1) { displayDropLocation("The column " + data + " is already a primary key"); return false; } // Perform the actual import. if (dl.isInsert()) { int oldIndex = listModel.indexOf(data); if (oldIndex < index) { listModel.add(index, data); listModel.remove(oldIndex); } else { listModel.remove(oldIndex); listModel.add(index, data); } } else { // Don't handle replacements } return true; } public int getSourceActions(JComponent c) { return MOVE; } protected Transferable createTransferable(JComponent c) { JList list = (JList) c; Object[] values = list.getSelectedValues(); StringBuffer buff = new StringBuffer(); for (int i = 0; i < values.length; i++) { Object val = values[i]; buff.append(val == null ? "" : val.toString()); if (i != values.length - 1) { buff.append("\n"); } } return new StringSelection(buff.toString()); } }); pkList.setDropMode(DropMode.INSERT); pkList.setDragEnabled(true); JScrollPane pkScrollPanel = new JScrollPane(pkList); pkScrollPanel.setMaximumSize(new Dimension(Short.MAX_VALUE, 100)); pkScrollPanel.setAlignmentX(LEFT_ALIGNMENT); columnPanel.add(pkScrollPanel); return columnPanel; }
From source file:balony.summarizeJFrame.java
public void clipboardCopy(int col) { String clip = ""; if (!jTextField1.getText().isEmpty()) { clip = jTextField1.getText().concat("\n"); }/*from w ww. jav a 2s. co m*/ for (int i = 0; i < tableData.length; i++) { int j = jTable1.convertRowIndexToModel(i); clip = clip.concat(tableData[j][col].toString().concat("\n")); } Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(new StringSelection(clip), this); }
From source file:gdt.jgui.entity.webset.JWeblinkEditor.java
private void showLoginMenu(MouseEvent e) { try {/*from w ww . j av a 2 s . co m*/ JPopupMenu logonMenu = new JPopupMenu(); JMenuItem copyItem = new JMenuItem("Copy"); logonMenu.add(copyItem); copyItem.setHorizontalTextPosition(JMenuItem.RIGHT); copyItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { StringSelection stringSelection = new StringSelection(loginField.getText()); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(stringSelection, JWeblinkEditor.this); } catch (Exception ee) { Logger.getLogger(getClass().getName()).info(ee.toString()); } } }); logonMenu.show(e.getComponent(), e.getX(), e.getY()); } catch (Exception ee) { Logger.getLogger(getClass().getName()).severe(ee.toString()); } }
From source file:de.tor.tribes.ui.views.DSWorkbenchFormFrame.java
private void copySelectionToInternalClipboardAsBBCodes() { try {/* ww w .ja va 2 s . c o m*/ List<AbstractForm> forms = getSelectedForms(); if (forms.isEmpty()) { showInfo("Keine Zeichnungen ausgewhlt"); return; } int ignoredForms = 0; for (AbstractForm form : forms) { if (!form.allowsBBExport()) { ignoredForms++; } } boolean extended = (JOptionPaneHelper.showQuestionConfirmBox(this, "Erweiterte BB-Codes verwenden (nur fr Forum und Notizen geeignet)?", "Erweiterter BB-Code", "Nein", "Ja") == JOptionPane.YES_OPTION); StringBuilder buffer = new StringBuilder(); if (extended) { buffer.append("[u][size=12]Zeichnungen[/size][/u]\n\n"); } else { buffer.append("[u]Zeichnungen[/u]\n\n"); } buffer.append(new FormListFormatter().formatElements(forms, extended)); if (extended) { buffer.append("\n[size=8]Erstellt am "); buffer.append( new SimpleDateFormat("dd.MM.yy 'um' HH:mm:ss").format(Calendar.getInstance().getTime())); buffer.append(" mit DS Workbench "); buffer.append(Constants.VERSION).append(Constants.VERSION_ADDITION + "[/size]\n"); } else { buffer.append("\nErstellt am "); buffer.append( new SimpleDateFormat("dd.MM.yy 'um' HH:mm:ss").format(Calendar.getInstance().getTime())); buffer.append(" mit DS Workbench "); buffer.append(Constants.VERSION).append(Constants.VERSION_ADDITION + "\n"); } String b = buffer.toString(); StringTokenizer t = new StringTokenizer(b, "["); int cnt = t.countTokens(); if (cnt > 1000) { if (JOptionPaneHelper.showQuestionConfirmBox(this, "Die ausgewhlten Zeichnungen bentigen mehr als 1000 BB-Codes\n" + "und knnen daher im Spiel (Forum/IGM/Notizen) nicht auf einmal dargestellt werden.\nTrotzdem exportieren?", "Zu viele BB-Codes", "Nein", "Ja") == JOptionPane.NO_OPTION) { return; } } Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(b), null); String result = null; if (ignoredForms != forms.size()) { result = "<html>Daten in Zwischenablage kopiert."; if (ignoredForms > 0) { result += ((ignoredForms == 1) ? " Eine Zeichnung wurde" : " " + ignoredForms + " Zeichnungen wurden") + " ignoriert, da der BB-Export nur fr Rechtecke, Kreise und Freihandzeichnungen verfügbar ist."; } result += "</html>"; } else { showError( "<html>Keine Zeichnungen exportiert, da der BB-Export nur fr Rechtecke, Kreise und Freihandzeichnungen verfügbar ist.</html>"); return; } showSuccess(result); } catch (Exception e) { logger.error("Failed to copy data to clipboard", e); String result = "Fehler beim Kopieren in die Zwischenablage."; showError(result); } }
From source file:ListCutPaste.java
/** * Bundle up the data for export.// w w w .jav a2 s. c o m */ protected Transferable createTransferable(JComponent c) { JList list = (JList) c; int index = list.getSelectedIndex(); String value = (String) list.getSelectedValue(); return new StringSelection(value); }
From source file:net.java.sip.communicator.impl.gui.main.chat.ChatConversationPanel.java
/** * Creates an instance of <tt>ChatConversationPanel</tt>. * * @param chatContainer The parent <tt>ChatConversationContainer</tt>. *//*from www . j av a2s . co m*/ public ChatConversationPanel(ChatConversationContainer chatContainer) { editorKit = new ChatConversationEditorKit(this); this.chatContainer = chatContainer; isHistory = (chatContainer instanceof HistoryWindow); this.rightButtonMenu = new ChatRightButtonMenu(this); this.document = (HTMLDocument) editorKit.createDefaultDocument(); this.document.addDocumentListener(editorKit); this.chatTextPane.setEditorKitForContentType("text/html", editorKit); this.chatTextPane.setEditorKit(editorKit); this.chatTextPane.setEditable(false); this.chatTextPane.setDocument(document); this.chatTextPane.setDragEnabled(true); chatTextPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE); Constants.loadSimpleStyle(document.getStyleSheet(), chatTextPane.getFont()); this.chatTextPane.addHyperlinkListener(this); this.chatTextPane.addMouseListener(this); this.chatTextPane.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR)); this.addChatLinkClickedListener(showPreview); this.setWheelScrollingEnabled(true); this.setViewportView(chatTextPane); this.setBorder(null); this.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); ToolTipManager.sharedInstance().registerComponent(chatTextPane); String copyLinkString = GuiActivator.getResources().getI18NString("service.gui.COPY_LINK"); copyLinkItem = new JMenuItem(copyLinkString, new ImageIcon(ImageLoader.getImage(ImageLoader.COPY_ICON))); copyLinkItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { StringSelection stringSelection = new StringSelection(currentHref); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(stringSelection, ChatConversationPanel.this); } }); String openLinkString = GuiActivator.getResources().getI18NString("service.gui.OPEN_IN_BROWSER"); openLinkItem = new JMenuItem(openLinkString, new ImageIcon(ImageLoader.getImage(ImageLoader.BROWSER_ICON))); openLinkItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { GuiActivator.getBrowserLauncher().openURL(currentHref); // after opening the link remove the currentHref to avoid // clicking on the window to gain focus to open the link again ChatConversationPanel.this.currentHref = ""; } }); openLinkItem.setMnemonic(GuiActivator.getResources().getI18nMnemonic("service.gui.OPEN_IN_BROWSER")); copyLinkItem.setMnemonic(GuiActivator.getResources().getI18nMnemonic("service.gui.COPY_LINK")); configureReplacementItem = new JMenuItem( GuiActivator.getResources().getI18NString("plugin.chatconfig.replacement.CONFIGURE_REPLACEMENT"), GuiActivator.getResources().getImage("service.gui.icons.CONFIGURE_ICON")); configureReplacementItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { final ConfigurationContainer configContainer = GuiActivator.getUIService() .getConfigurationContainer(); ConfigurationForm chatConfigForm = getChatConfigForm(); if (chatConfigForm != null) { configContainer.setSelected(chatConfigForm); configContainer.setVisible(true); } } }); this.isSimpleTheme = ConfigurationUtils.isChatSimpleThemeEnabled(); /* * When we append a new message (regardless of whether it is a string or * an UI component), we want to make it visible in the viewport of this * JScrollPane so that the user can see it. */ ComponentListener componentListener = new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { synchronized (scrollToBottomRunnable) { if (!scrollToBottomIsPending) return; scrollToBottomIsPending = false; /* * Yana Stamcheva, pointed out that Java 5 (on Linux only?) * needs invokeLater for JScrollBar. */ SwingUtilities.invokeLater(scrollToBottomRunnable); } } }; chatTextPane.addComponentListener(componentListener); getViewport().addComponentListener(componentListener); }
From source file:de.tor.tribes.ui.views.DSWorkbenchReTimerFrame.java
private void copySelectionToInternalClipboard() { jideRetimeTabbedPane.setSelectedIndex(1); List<Attack> selection = getSelectedAttacks(); if (selection.isEmpty()) { showInfo("Keine Angriffe ausgewhlt"); return;//from w ww . j a va 2s .c o m } /* Herkunft: Rattennest (-42|35) (444|868) K84 Ziel: Rattennest (-43|38) (443|871) K84 Ankunft: 23.08.11 17:15:00:931 */ StringBuilder b = new StringBuilder(); int cnt = 0; for (Attack a : selection) { b.append(Attack.toInternalRepresentation(a)).append("\n"); cnt++; } try { Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(b.toString()), null); showSuccess(cnt + ((cnt == 1) ? " Angriff kopiert" : " Angriffe kopiert")); } catch (HeadlessException hex) { showError("Fehler beim Kopieren der Angriffe"); } }
From source file:org.monkeys.gui.matcher.MatcherPanel.java
private void copyToClipboard() { String delim = ClipboardAction.LINE.delim(); final Object selected = this.clipboardDropdown.getSelectedItem(); if (selected instanceof ClipboardAction) { final ClipboardAction action = (ClipboardAction) selected; delim = action.delim();//from w w w . j a v a 2s. c o m } else if (selected != null) { delim = " " + selected.toString().trim() + " "; } final StringBuilder buffer = new StringBuilder(); boolean first = true; for (final String match : this.matchingList.getSelectedText()) { if (!first) { buffer.append(delim); } buffer.append(match); first = false; } final String blob = buffer.toString().trim(); final StringSelection selection = new StringSelection(blob); final Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard(); clpbrd.setContents(selection, selection); }
From source file:DragFileDemo.java
protected Transferable createTransferable(JComponent c) { source = (JTextArea) c;//from w ww .j av a 2 s. c o m int start = source.getSelectionStart(); int end = source.getSelectionEnd(); Document doc = source.getDocument(); if (start == end) { return null; } try { p0 = doc.createPosition(start); p1 = doc.createPosition(end); } catch (BadLocationException e) { System.out.println("Can't create position - unable to remove text from source."); } shouldRemove = true; String data = source.getSelectedText(); return new StringSelection(data); }