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:net.sf.jabref.exporter.RtfSelection.java
public RtfSelection(String s) { content = s;/*from w w w. j av a 2 s .c o m*/ try { rtfFlavor = new DataFlavor("text/rtf; class=java.io.InputStream"); supportedFlavors = new DataFlavor[] { rtfFlavor, DataFlavor.stringFlavor }; } catch (ClassNotFoundException ex) { LOGGER.warn("Cannot find class", ex); } }
From source file:ja.lingo.application.gui.actions.PasteAndTranslateAction.java
public PasteAndTranslateAction(Model model) { this.model = model; Toolkit.getDefaultToolkit().getSystemClipboard().addFlavorListener(new FlavorListener() { public void flavorsChanged(FlavorEvent e) { setEnabled(((Clipboard) e.getSource()).isDataFlavorAvailable(DataFlavor.stringFlavor)); }//from w w w.jav a2 s . c o m }); }
From source file:corelyzer.util.StringUtility.java
public static String getClipboard() { Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null); try {// www . j a va2s . c o m if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) { String text = (String) t.getTransferData(DataFlavor.stringFlavor); return text; } } catch (UnsupportedFlavorException e) { } catch (IOException e) { } return ""; }
From source file:com.burakgon.gcmsender.GCMSenderUI.java
private String getFromClipboad() { try {/* w w w.j av a 2 s . c om*/ String data = (String) Toolkit.getDefaultToolkit().getSystemClipboard() .getData(DataFlavor.stringFlavor); return data; } catch (UnsupportedFlavorException | IOException ex) { Logger.getLogger(GCMSenderUI.class.getName()).log(Level.SEVERE, null, ex); return null; } }
From source file:de.tor.tribes.util.parser.TroopsParser70.java
public static void main(String[] args) { Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null); try {//from w w w . j a va 2 s . co m /* * String data = "Rattennest (0|0) (486|833) K84 eigene 14 8 6490 0 181 2550 300 0 300 30 0 +3 + Befehle\n" + "im Dorf 15000 * 15000 5493 15000 950 2449 257 5000 300 30 0 1 Truppen\n" + "auswrts 0 0 0 0 0 0 0 0 0 0 0 0\n" + "unterwegs 0 0 0 0 0 0 0 0 * 0 0 0 0 Befehle\n"; * */ String data = (String) t.getTransferData(DataFlavor.stringFlavor); new TroopsParser70().parse(data); } catch (Exception e) { e.printStackTrace(); } // TroopsParser.parse(pTroopsString); }
From source file:net.sf.jabref.exporter.RtfSelection.java
@Override public boolean isDataFlavorSupported(DataFlavor flavor) { return flavor.equals(rtfFlavor) || flavor.equals(DataFlavor.stringFlavor); }
From source file:ja.lingo.application.gui.actions.PasteAndTranslateAction.java
public void actionPerformed(ActionEvent e) { try {/*from w w w. j av a 2s. co m*/ String data = (String) Toolkit.getDefaultToolkit().getSystemClipboard() .getData(DataFlavor.stringFlavor); data = data.trim(); model.navigateAndTranslate(data); model.main_showAtTop(); } catch (UnsupportedFlavorException e1) { LOG.error("Could not paste from system clipboard", e1); } catch (IOException e1) { LOG.error("Could not paste from system clipboard", e1); } }
From source file:ClipMe.java
public boolean action(Event e, Object o) { if (clipboard == null) clipboard = getToolkit().getSystemClipboard(); if ((e.target == tf) || (e.target == copy)) { StringSelection data;/*from w ww.j a v a 2 s.c o m*/ data = new StringSelection(tf.getText()); clipboard.setContents(data, data); } else if (e.target == paste) { Transferable clipData = clipboard.getContents(this); String s; try { s = (String) (clipData.getTransferData(DataFlavor.stringFlavor)); } catch (Exception ee) { s = ee.toString(); } ta.setText(s); } return true; }
From source file:ja.lingo.application.gui.drophandler.DropHandler.java
public boolean canImport(JComponent c, DataFlavor[] flavors) { if (engine.getFinder().isEmpty()) { return false; }/*from w w w .j av a2 s. c o m*/ boolean canImport = Arrays.asList(flavors).contains(DataFlavor.stringFlavor); if (!canImport) { LOG.warn("Can't import from flavors " + Arrays.asList(flavors)); } return canImport; }
From source file:Main.java
public Main() { setLayout(new GridLayout(1, 3)); tree = new JTree(getTreeModel()); tree.setDragEnabled(true);/*from w ww .j a va2s. co m*/ tree.setPreferredSize(new Dimension(200, 400)); JScrollPane scroll = new JScrollPane(); scroll.setViewportView(tree); treeModel = getTreeModel(); JTree secondTree = new JTree(treeModel); secondTree.setPreferredSize(new Dimension(200, 400)); secondTree.setTransferHandler(new TransferHandler() { @Override public boolean importData(TransferSupport support) { if (!canImport(support)) { return false; } JTree.DropLocation dl = (JTree.DropLocation) support.getDropLocation(); TreePath path = dl.getPath(); int childIndex = dl.getChildIndex(); String data; try { data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor); } catch (Exception e) { return false; } if (childIndex == -1) { childIndex = tree.getModel().getChildCount(path.getLastPathComponent()); } DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(data); DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) path.getLastPathComponent(); treeModel.insertNodeInto(newNode, parentNode, childIndex); tree.makeVisible(path.pathByAddingChild(newNode)); tree.scrollRectToVisible(tree.getPathBounds(path.pathByAddingChild(newNode))); return true; } public boolean canImport(TransferSupport support) { if (!support.isDrop()) { return false; } support.setShowDropLocation(true); if (!support.isDataFlavorSupported(DataFlavor.stringFlavor)) { System.out.println("only string is supported"); return false; } JTree.DropLocation dl = (JTree.DropLocation) support.getDropLocation(); TreePath path = dl.getPath(); if (path == null) { return false; } return true; } }); JScrollPane secondScroll = new JScrollPane(); secondScroll.setViewportView(secondTree); JPanel topPanel = new JPanel(new BorderLayout()); topPanel.add(scroll, BorderLayout.CENTER); JPanel btmPanel = new JPanel(new BorderLayout()); btmPanel.add(secondScroll, BorderLayout.CENTER); add(topPanel); add(btmPanel); }