List of usage examples for java.awt.datatransfer DataFlavor stringFlavor
DataFlavor stringFlavor
To view the source code for java.awt.datatransfer DataFlavor stringFlavor.
Click Source Link
representationClass = java.lang.String mimeType = "application/x-java-serialized-object"
From source file:DragFileDemo.java
FileAndTextTransferHandler(TabbedPaneController t) {
tpc = t;
fileFlavor = DataFlavor.javaFileListFlavor;
stringFlavor = DataFlavor.stringFlavor;
}
From source file:ExtendedDnDDemo.java
public boolean importData(JComponent c, Transferable t) { if (canImport(c, t.getTransferDataFlavors())) { try {/*from w ww . j ava2 s .c o m*/ String str = (String) t.getTransferData(DataFlavor.stringFlavor); importString(c, str); return true; } catch (UnsupportedFlavorException ufe) { } catch (IOException ioe) { } } return false; }
From source file:de.tor.tribes.util.parser.SOSParser.java
public static void main(String[] args) throws Exception { try {/*from w ww. ja v a 2s .c o m*/ Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null); String data = (String) t.getTransferData(DataFlavor.stringFlavor); new SOSParser().parse(data); } catch (Exception e) { e.printStackTrace(); } }
From source file:ExtendedDnDDemo.java
public boolean canImport(JComponent c, DataFlavor[] flavors) { for (int i = 0; i < flavors.length; i++) { if (DataFlavor.stringFlavor.equals(flavors[i])) { return true; }//from ww w. java 2s.co m } return false; }
From source file:ListCutPaste.java
/** * Perform the actual data import.// w ww . j a v a 2 s .co m */ public boolean importData(TransferHandler.TransferSupport info) { String data = null; // If we can't handle the import, bail now. if (!canImport(info)) { return false; } JList list = (JList) info.getComponent(); DefaultListModel model = (DefaultListModel) list.getModel(); // Fetch the data -- bail if this fails try { data = (String) info.getTransferable().getTransferData(DataFlavor.stringFlavor); } catch (UnsupportedFlavorException ufe) { System.out.println("importData: unsupported data flavor"); return false; } catch (IOException ioe) { System.out.println("importData: I/O exception"); return false; } if (info.isDrop()) { // This is a drop JList.DropLocation dl = (JList.DropLocation) info.getDropLocation(); int index = dl.getIndex(); if (dl.isInsert()) { model.add(index, data); return true; } else { model.set(index, data); return true; } } else { // This is a paste int index = list.getSelectedIndex(); // if there is a valid selection, // insert data after the selection if (index >= 0) { model.add(list.getSelectedIndex() + 1, data); // else append to the end of the list } else { model.addElement(data); } return true; } }
From source file:ScribbleDragAndDrop.java
/** * This method is invoked when the user first drags something over us. If we * understand the data type being dragged, then call acceptDrag() to tell * the system that we're receptive. Also, we change our border as a "drag * under" effect to signal that we can accept the drop. *///ww w . j a va2 s . com public void dragEnter(DropTargetDragEvent e) { if (e.isDataFlavorSupported(Scribble.scribbleDataFlavor) || e.isDataFlavorSupported(DataFlavor.stringFlavor)) { e.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE); this.setBorder(dropBorder); } }
From source file:de.mycrobase.jcloudapp.Main.java
@SuppressWarnings("unchecked") public boolean doUploadClipboard() { Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard(); Transferable t = cb.getContents(null); if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { try {/*from ww w . j a va 2 s.c o m*/ List<File> data = (List<File>) t.getTransferData(DataFlavor.javaFileListFlavor); uploadFilesFromClipboard(data); } catch (UnsupportedFlavorException ex) { } catch (IOException ex) { } return true; } else if (t.isDataFlavorSupported(DataFlavor.imageFlavor)) { try { Image data = (Image) t.getTransferData(DataFlavor.imageFlavor); BufferedImage bi = (BufferedImage) data; uploadImageFromClipboard(bi); } catch (UnsupportedFlavorException ex) { } catch (IOException ex) { } return true; } else if (t.isDataFlavorSupported(DataFlavor.stringFlavor)) { try { String data = (String) t.getTransferData(DataFlavor.stringFlavor); if (isValidURL(data)) { createBookmarkFromClipboard(data); } else { uploadStringFromClipboard(data); } } catch (UnsupportedFlavorException ex) { } catch (IOException ex) { } return true; } return false; }
From source file:ScribbleDragAndDrop.java
/** * This is the key method of DropTargetListener. It is invoked when the user * drops something on us./* w w w.j a va 2 s .co m*/ */ public void drop(DropTargetDropEvent e) { this.setBorder(normalBorder); // Restore the default border // First, check whether we understand the data that was dropped. // If we supports our data flavors, accept the drop, otherwise reject. if (e.isDataFlavorSupported(Scribble.scribbleDataFlavor) || e.isDataFlavorSupported(DataFlavor.stringFlavor)) { e.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); } else { e.rejectDrop(); return; } // We've accepted the drop, so now we attempt to get the dropped data // from the Transferable object. Transferable t = e.getTransferable(); // Holds the dropped data Scribble droppedScribble; // This will hold the Scribble object // First, try to get the data directly as a scribble object try { droppedScribble = (Scribble) t.getTransferData(Scribble.scribbleDataFlavor); } catch (Exception ex) { // unsupported flavor, IO exception, etc. // If that doesn't work, try to get it as a String and parse it try { String s = (String) t.getTransferData(DataFlavor.stringFlavor); droppedScribble = Scribble.parse(s); } catch (Exception ex2) { // If we still couldn't get the data, tell the system we failed e.dropComplete(false); return; } } // If we get here, we've got the Scribble object Point p = e.getLocation(); // Where did the drop happen? droppedScribble.translate(p.getX(), p.getY()); // Move it there scribbles.add(droppedScribble); // add to display list repaint(); // ask for redraw e.dropComplete(true); // signal success! }
From source file:simplesqlformatter.formatter.SQLFormatterEditor.java
private void paste() { final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); final Transferable transferable = clipboard.getContents(null); try {// www . j a v a2 s . c o m textArea.setText((String) transferable.getTransferData(DataFlavor.stringFlavor)); } catch (final IOException e) { LOGGER.log(Level.FINE, e.getMessage(), e); } catch (final UnsupportedFlavorException e) { LOGGER.log(Level.FINE, e.getMessage(), e); } statusBar.setText("Pasted new SQL statement over the old"); }
From source file:org.rimudb.editor.DescriptorEditor.java
/** * Build the panel/*www. j av a 2s .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; }