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:com.ibm.issw.odc.gui.BPMArgumentsPanel.java
/** * Add values from the clipboard/*from w w w. jav a 2 s . co m*/ */ protected void addFromClipboard() { GuiUtils.stopTableEditing(table); int rowCount = table.getRowCount(); try { String clipboardContent = GuiUtils.getPastedText(); if (clipboardContent == null) { return; } String[] clipboardLines = clipboardContent.split("\n"); for (String clipboardLine : clipboardLines) { String[] clipboardCols = clipboardLine.split("\t"); if (clipboardCols.length > 0) { Argument argument = makeNewArgument(); argument.setName(clipboardCols[0]); if (clipboardCols.length > 1) { argument.setValue(clipboardCols[1]); if (clipboardCols.length > 2) { argument.setDescription(clipboardCols[2]); } } tableModel.addRow(argument); } } if (table.getRowCount() > rowCount) { // Enable DELETE (which may already be enabled, but it won't hurt) delete.setEnabled(true); // Highlight (select) the appropriate rows. int rowToSelect = tableModel.getRowCount() - 1; table.setRowSelectionInterval(rowCount, rowToSelect); } } catch (IOException ioe) { JOptionPane.showMessageDialog(this, "Could not add read arguments from clipboard:\n" + ioe.getLocalizedMessage(), "Error", JOptionPane.ERROR_MESSAGE); } catch (UnsupportedFlavorException ufe) { JOptionPane .showMessageDialog(this, "Could not add retrieve " + DataFlavor.stringFlavor.getHumanPresentableName() + " from clipboard" + ufe.getLocalizedMessage(), "Error", JOptionPane.ERROR_MESSAGE); } }
From source file:org.apache.jmeter.config.gui.ArgumentsPanel.java
/** * Add values from the clipboard/*from ww w . j a va 2 s .c o m*/ */ protected void addFromClipboard() { GuiUtils.stopTableEditing(table); int rowCount = table.getRowCount(); try { String clipboardContent = GuiUtils.getPastedText(); if (clipboardContent == null) { return; } String[] clipboardLines = clipboardContent.split("\n"); for (String clipboardLine : clipboardLines) { String[] clipboardCols = clipboardLine.split("\t"); if (clipboardCols.length > 0) { Argument argument = createArgumentFromClipboard(clipboardCols); tableModel.addRow(argument); } } if (table.getRowCount() > rowCount) { checkButtonsStatus(); // Highlight (select) and scroll to the appropriate rows. int rowToSelect = tableModel.getRowCount() - 1; table.setRowSelectionInterval(rowCount, rowToSelect); table.scrollRectToVisible(table.getCellRect(rowCount, 0, true)); } } catch (IOException ioe) { JOptionPane.showMessageDialog(this, "Could not add read arguments from clipboard:\n" + ioe.getLocalizedMessage(), "Error", JOptionPane.ERROR_MESSAGE); } catch (UnsupportedFlavorException ufe) { JOptionPane .showMessageDialog(this, "Could not add retrieve " + DataFlavor.stringFlavor.getHumanPresentableName() + " from clipboard" + ufe.getLocalizedMessage(), "Error", JOptionPane.ERROR_MESSAGE); } }
From source file:de.tor.tribes.ui.views.DSWorkbenchSelectionFrame.java
private void pasteFromInternalClipboard() { List<Village> villages = null; try {/* w w w .j av a2 s.c o m*/ Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null); villages = PluginManager.getSingleton() .executeVillageParser((String) t.getTransferData(DataFlavor.stringFlavor)); } catch (Exception e) { logger.error("Failed to read village data from clipboard", e); showError("Fehler beim Lesen aus der Zwischenablage"); } if (villages == null || villages.isEmpty()) { showInfo("Keine Drfer in der Zwischenablage gefunden"); } else { addVillages(villages); showSuccess(((villages.size() == 1) ? "Dorf" : villages.size() + " Drfer") + " eingefgt"); } }
From source file:de.tor.tribes.ui.views.DSWorkbenchTagFrame.java
private void pasteVillagesFromClipboard() { List<Village> villages = null; try {//w w w. j a va 2s .co m Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null); villages = PluginManager.getSingleton() .executeVillageParser((String) t.getTransferData(DataFlavor.stringFlavor)); if (villages == null || villages.isEmpty()) { showInfo("Keine Drfer in der Zwischenablage gefunden"); return; } } catch (Exception e) { logger.error("Failed to read data from clipboard", e); showError("Fehler beim Lesen aus der Zwischenablage"); } fireVillagesDraggedEvent(villages, null); }
From source file:org.isatools.isacreator.spreadsheet.SpreadsheetFunctions.java
/** * Performs a clipboard function of pasting * * @param startRow - Where pasting is to start. If from selected row, supply -1 as a parameter * @param startCol - Where pasting is to start. If from selected column, supply -1 as a parameter * @param storeInHistory - variable to determine whether or not to store the paste action in the history *///from w w w .j a va 2 s. c o m public void paste(int startRow, int startCol, boolean storeInHistory) { CellEditor editor = spreadsheet.getTable().getCellEditor(); if (editor != null) { editor.cancelCellEditing(); } startRow = (startRow == -1) ? spreadsheet.getTable().getSelectedRow() : startRow; startCol = (startCol == -1) ? spreadsheet.getTable().getSelectedColumn() : startCol; //checks if anything is selected if (startRow != -1) { try { String trstring = (String) (spreadsheet.system.getContents(this) .getTransferData(DataFlavor.stringFlavor)); SpreadsheetCellPoint size = SpreadsheetModel.getSize(trstring, '\t'); int rowSpaceToFill = (size.getRow()); int endRow = Math.min(spreadsheet.getTable().getRowCount() - 1, (startRow + size.getRow()) - 1); int endCol = Math.min(spreadsheet.getTable().getColumnCount() - 1, (startCol + size.getCol()) - 1); int colSpaceToFill = (endCol - startCol) + 1; int[] colRange = new int[colSpaceToFill]; int[] rowRange = new int[rowSpaceToFill]; if (colSpaceToFill > 0) { colRange = new int[colSpaceToFill]; int startVal = 0; for (int val = startCol; val <= endCol; val++) { colRange[startVal] = val; startVal++; } } if (rowSpaceToFill > 0) { rowRange = new int[rowSpaceToFill]; int startVal = 0; for (int val = startRow; val <= endRow; val++) { rowRange[startVal] = val; startVal++; } } if (colRange.length == 0) { colRange = new int[1]; colRange[0] = startCol; } if (rowRange.length == 0) { rowRange = new int[1]; rowRange[0] = startRow; } SpreadsheetCellRange affectedRange = new SpreadsheetCellRange(rowRange, Utils.convertSelectedColumnsToModelIndices(spreadsheet.getTable(), colRange)); // add to history if (storeInHistory) { spreadsheet.spreadsheetHistory.add(affectedRange); } spreadsheet.spreadsheetModel.extendedFromString(trstring, '\t', affectedRange); spreadsheet.spreadsheetModel.extendedSetSelection(affectedRange); spreadsheet.getTable().repaint(); spreadsheet.notifyObservers(SpreadsheetEvent.PASTE); } catch (Exception e) { e.printStackTrace(); } } }
From source file:org.sikuli.script.App.java
/** * evaluates the current textual content of the system clipboard * * @return the textual content or empty string if not possible *//*from w ww . j a v a 2 s. co m*/ public static String getClipboard() { Transferable content = null; try { content = Clipboard.getSystemClipboard().getContents(null); } catch (Exception ex) { Debug.error("Env.getClipboard: clipboard not available:\n%s", ex.getMessage()); } if (content != null) { try { if (content.isDataFlavorSupported(DataFlavor.stringFlavor)) { return (String) content.getTransferData(DataFlavor.stringFlavor); } } catch (UnsupportedFlavorException ex) { Debug.error("Env.getClipboard: UnsupportedFlavorException: " + content); } catch (IOException ex) { Debug.error("Env.getClipboard: IOException:\n%s", ex.getMessage()); } } return ""; }
From source file:ScribbleDragAndDrop.java
/** Check whether we support a given flavor */ public boolean isDataFlavorSupported(DataFlavor flavor) { return (flavor.equals(scribbleDataFlavor) || flavor.equals(DataFlavor.stringFlavor)); }
From source file:org.freeplane.features.clipboard.mindmapmode.MClipboardController.java
private IDataFlavorHandler getFlavorHandler(final Transferable t) { if (t.isDataFlavorSupported(MindMapNodesSelection.mindMapNodesFlavor)) { try {//from w ww . jav a2 s . c o m final String textFromClipboard = t.getTransferData(MindMapNodesSelection.mindMapNodesFlavor) .toString(); return new MindMapNodesFlavorHandler(textFromClipboard); } catch (final UnsupportedFlavorException e) { } catch (final IOException e) { } } if (t.isDataFlavorSupported(MindMapNodesSelection.fileListFlavor)) { try { final List<File> fileList = castToFileList(t.getTransferData(MindMapNodesSelection.fileListFlavor)); if (!shouldIgnoreFileListFlavor(fileList)) return new FileListFlavorHandler(fileList); } catch (final UnsupportedFlavorException e) { } catch (final IOException e) { } } final ResourceController resourceController = ResourceController.getResourceController(); if (t.isDataFlavorSupported(MindMapNodesSelection.htmlFlavor)) { try { final String textFromClipboard = t.getTransferData(MindMapNodesSelection.htmlFlavor).toString(); if (textFromClipboard.charAt(0) != 65533) { if (t.isDataFlavorSupported(DataFlavor.stringFlavor)) { final MTextController textController = (MTextController) TextController.getController(); final boolean richText = textController .useRichTextInEditor(RESOURCES_REMIND_USE_RICH_TEXT_IN_NEW_NODES); if (richText) { final boolean structuredHtmlImport = resourceController .getBooleanProperty("structured_html_import"); final IDataFlavorHandler htmlFlavorHandler; if (structuredHtmlImport) { htmlFlavorHandler = new StructuredHtmlFlavorHandler(textFromClipboard); } else { htmlFlavorHandler = new DirectHtmlFlavorHandler(textFromClipboard); } return htmlFlavorHandler; } } } } catch (final UnsupportedFlavorException e) { } catch (final IOException e) { } } if (t.isDataFlavorSupported(DataFlavor.stringFlavor)) { try { final String plainTextFromClipboard = t.getTransferData(DataFlavor.stringFlavor).toString(); return new StringFlavorHandler(plainTextFromClipboard); } catch (final UnsupportedFlavorException e) { } catch (final IOException e) { } } if (t.isDataFlavorSupported(DataFlavor.imageFlavor)) { try { BufferedImage image = (BufferedImage) t.getTransferData(DataFlavor.imageFlavor); return new ImageFlavorHandler(image); } catch (final UnsupportedFlavorException e) { } catch (final IOException e) { } } return null; }
From source file:xtrememp.PlaylistManager.java
@Override @SuppressWarnings("unchecked") public void drop(DropTargetDropEvent ev) { DropTargetContext targetContext = ev.getDropTargetContext(); Transferable t = ev.getTransferable(); try {// w w w. j av a 2s. c om // Windows if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { ev.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); addFiles((List<File>) t.getTransferData(DataFlavor.javaFileListFlavor), false); targetContext.dropComplete(true); // Linux } else if (t.isDataFlavorSupported(DataFlavor.stringFlavor)) { ev.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); String urls = (String) t.getTransferData(DataFlavor.stringFlavor); List<File> fileList = new ArrayList<>(); StringTokenizer st = new StringTokenizer(urls); while (st.hasMoreTokens()) { URI uri = new URI(st.nextToken()); fileList.add(new File(uri)); } addFiles(fileList, false); targetContext.dropComplete(true); } } catch (UnsupportedFlavorException | InvalidDnDOperationException | IOException | URISyntaxException ex) { logger.error(ex.getMessage(), ex); } }
From source file:ScribbleDragAndDrop.java
/** * Return the scribble data in the requested format, or throw an exception * if we don't support the requested format *///from www .ja v a 2 s . c o m public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException { if (flavor.equals(scribbleDataFlavor)) { return this; } else if (flavor.equals(DataFlavor.stringFlavor)) { return toString(); } else throw new UnsupportedFlavorException(flavor); }