List of usage examples for java.awt.datatransfer UnsupportedFlavorException getLocalizedMessage
public String getLocalizedMessage()
From source file:com.ibm.issw.odc.gui.BPMArgumentsPanel.java
/** * Add values from the clipboard//from ww w .jav a2s . com */ 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// w w w . j a v a 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:org.orbisgis.sif.components.fstree.TreeNodeFolder.java
/** * Create a file from a Reader instance in this folder * @param tf Transferable instance//from ww w . j a va 2s . co m * @param flavor DataFlavor * @return If the file has been created */ private boolean importReader(Transferable tf, DataFlavor flavor) { try { // From this transferable, a file can be created Object transferData = tf.getTransferData(flavor); if (!(transferData instanceof Reader)) { return false; } BufferedReader br = new BufferedReader((Reader) transferData); File fileName; if (transferData instanceof TransferableFileContent) { // The filename is given by the drag source fileName = new File(getFilePath(), ((TransferableFileContent) transferData).getFileNameHint()); } else { // The filename must be given by the user String contentFileName = JOptionPane.showInputDialog(UIFactory.getMainFrame(), I18N.tr("Enter the folder name"), I18N.tr("Folder")); if (contentFileName != null) { fileName = new File(getFilePath(), contentFileName); } else { return false; } } // If the file exists found a new one fileName = getUniqueFileName(fileName); FileWriter writer = new FileWriter(fileName); String res = br.readLine(); while (res != null) { writer.write(res + "\n"); res = br.readLine(); } writer.close(); return true; } catch (UnsupportedFlavorException ex) { LOGGER.error(ex.getLocalizedMessage(), ex); return false; } catch (IOException ex) { LOGGER.error(ex.getLocalizedMessage(), ex); return false; } }