List of usage examples for java.awt.datatransfer Clipboard isDataFlavorAvailable
public boolean isDataFlavorAvailable(DataFlavor flavor)
From source file:TextTransferTest.java
/** * Pastes the text from the system clipboard into the text area. *///from www.ja v a 2 s . c o m private void paste() { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); DataFlavor flavor = DataFlavor.stringFlavor; if (clipboard.isDataFlavorAvailable(flavor)) { try { String text = (String) clipboard.getData(flavor); textArea.replaceSelection(text); } catch (UnsupportedFlavorException e) { JOptionPane.showMessageDialog(this, e); } catch (IOException e) { JOptionPane.showMessageDialog(this, e); } } }
From source file:ImageTransferTest.java
/** * Pastes the image from the system clipboard into the image label. *///from w w w. j ava 2 s. co m private void paste() { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); DataFlavor flavor = DataFlavor.imageFlavor; if (clipboard.isDataFlavorAvailable(flavor)) { try { image = (Image) clipboard.getData(flavor); label.setIcon(new ImageIcon(image)); } catch (UnsupportedFlavorException exception) { JOptionPane.showMessageDialog(this, exception); } catch (IOException exception) { JOptionPane.showMessageDialog(this, exception); } } }
From source file:SerialTransferTest.java
/** * Pastes the color from the system clipboard into the chooser. *//* w w w . j a va 2 s . com*/ private void paste() { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); try { DataFlavor flavor = new DataFlavor("application/x-java-serialized-object;class=java.awt.Color"); if (clipboard.isDataFlavorAvailable(flavor)) { Color color = (Color) clipboard.getData(flavor); chooser.setColor(color); } } catch (ClassNotFoundException e) { JOptionPane.showMessageDialog(this, e); } catch (UnsupportedFlavorException e) { JOptionPane.showMessageDialog(this, e); } catch (IOException e) { JOptionPane.showMessageDialog(this, e); } }
From source file:cn.lambdalib.cgui.gui.component.TextBox.java
private String getClipboardContent() { Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard(); if (cb.isDataFlavorAvailable(DataFlavor.stringFlavor)) { try {/*from www. j a v a2s . c o m*/ return (String) cb.getData(DataFlavor.stringFlavor); } catch (UnsupportedFlavorException | IOException e) { e.printStackTrace(); } } return ""; }
From source file:edu.ku.brc.ui.tmanfe.SpreadSheet.java
/** * @return true if pastable data is present in the clipboard *//* w w w . j a va 2 s .co m*/ protected boolean canPasteFromClipboard() { Clipboard sysClipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); return sysClipboard.isDataFlavorAvailable(DataFlavor.stringFlavor); }
From source file:edu.ku.brc.ui.tmanfe.SpreadSheet.java
/** * Paste data from clipboard into spreadsheet. * Currently only implemented for string data. *//*from ww w . j ava 2 s . c om*/ public void paste() { //System.out.println("Trying to Paste"); int[] rows = getSelectedRows(); int[] cols = getSelectedColumns(); pastedRows[0] = -1; pastedRows[1] = -1; if (rows != null && cols != null && rows.length > 0 && cols.length > 0) { int startRow = rows[0]; pastedRows[0] = startRow; int startCol = cols[0]; try { Clipboard sysClipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); if (sysClipboard.isDataFlavorAvailable(DataFlavor.stringFlavor)) { String trstring = (String) sysClipboard.getData(DataFlavor.stringFlavor); StringTokenizer st1 = new StringTokenizer(trstring, "\n\r"); for (int i = 0; st1.hasMoreTokens(); i++) { String rowstring = st1.nextToken(); //System.out.println("Row [" + rowstring+"]"); String[] tokens = StringUtils.splitPreserveAllTokens(rowstring, '\t'); for (int j = 0; j < tokens.length; j++) { if (startRow + i < getRowCount() && startCol + j < getColumnCount()) { int colInx = startCol + j; if (tokens[j].length() <= model.getColDataLen(colInx)) { String token = tokens[j]; if ("\b".equals(token)) //is placeholder for empty cell { token = ""; } setValueAt(token, startRow + i, colInx); } else { String msg = String.format(getResourceString("UI_NEWDATA_TOO_LONG"), new Object[] { model.getColumnName(startCol + j), model.getColDataLen(colInx) }); UIRegistry.getStatusBar().setErrorMessage(msg); Toolkit.getDefaultToolkit().beep(); } } //System.out.println("Putting [" + tokens[j] + "] at row=" + startRow + i + "column=" + startCol + j); } pastedRows[1] = pastedRows[1] + 1; } } } catch (IllegalStateException ex) { UIRegistry.displayStatusBarErrMsg(getResourceString("Spreadsheet.ClipboardUnavailable")); } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(SpreadSheet.class, ex); ex.printStackTrace(); } } }
From source file:org.docx4all.ui.main.WordMLEditor.java
void preStartup(JApplet applet) { _applet = applet;// ww w . java 2s. c o m _viewManager = new ViewManager(); _iframeMap = new HashMap<String, JInternalFrame>(); log.info("setting up InternalFrameListener"); _internalFrameListener = new InternalFrameListener(); log.info("setting up TitleBarMouseListener"); _titleBarMouseListener = new TitleBarMouseListener(); log.info("setting up ToolBarStates"); _toolbarStates = new ToolBarStates(); Clipboard clipboard = getContext().getClipboard(); clipboard.addFlavorListener(_toolbarStates); //As a FlavorListener, _toolbarStates will ONLY be notified //when there is a DataFlavor change in Clipboard. //Therefore, make sure that toolbarStates' _isPasteEnable property //is initialised correctly. boolean available = clipboard.isDataFlavorAvailable(WordMLTransferable.STRING_FLAVOR) || clipboard.isDataFlavorAvailable(WordMLTransferable.WORDML_FRAGMENT_FLAVOR); _toolbarStates.setPasteEnabled(available); log.info("setting up VFSJFileChooser"); initVFSJFileChooser(); log.info("setting up WmlExitListener"); addExitListener(new WmlExitListener()); }