use of java.awt.datatransfer.UnsupportedFlavorException in project jmeter by apache.
the class MainFrame method drop.
/**
* Handler of Top level Dnd
*/
@Override
public void drop(DropTargetDropEvent dtde) {
Transferable tr = dtde.getTransferable();
boolean anyFlavourIsJavaFileList = Arrays.stream(tr.getTransferDataFlavors()).anyMatch(DataFlavor::isFlavorJavaFileListType);
if (anyFlavourIsJavaFileList) {
dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
try {
openJmxFilesFromDragAndDrop(tr);
} catch (UnsupportedFlavorException | IOException e) {
log.warn("Dnd failed", e);
} finally {
dtde.dropComplete(true);
}
}
}
use of java.awt.datatransfer.UnsupportedFlavorException in project jmeter by apache.
the class JMeterTreeNodeTransferable method getTransferData.
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
if (!isDataFlavorSupported(flavor)) {
throw new UnsupportedFlavorException(flavor);
}
if (data != null) {
ObjectInput ois = null;
try {
ois = new ObjectInputStream(new ByteArrayInputStream(data));
JMeterTreeNode[] nodes = (JMeterTreeNode[]) ois.readObject();
return nodes;
} catch (ClassNotFoundException cnfe) {
throw new IOException("Failed to read object stream.", cnfe);
} finally {
if (ois != null) {
try {
ois.close();
} catch (Exception e) {
// NOOP
}
}
}
}
return null;
}
use of java.awt.datatransfer.UnsupportedFlavorException in project jmeter by apache.
the class ArgumentsPanel method addFromClipboard.
/**
* Add values from the clipboard
* @param lineDelimiter Delimiter string to split clipboard into lines
* @param argDelimiter Delimiter string to split line into key-value pair
*/
protected void addFromClipboard(String lineDelimiter, String argDelimiter) {
GuiUtils.stopTableEditing(table);
int rowCount = table.getRowCount();
try {
String clipboardContent = GuiUtils.getPastedText();
if (clipboardContent == null) {
return;
}
String[] clipboardLines = clipboardContent.split(lineDelimiter);
for (String clipboardLine : clipboardLines) {
String[] clipboardCols = clipboardLine.split(argDelimiter);
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);
}
}
use of java.awt.datatransfer.UnsupportedFlavorException in project Openfire by igniterealtime.
the class DroppableFrame method drop.
@Override
public void drop(DropTargetDropEvent dropTargetDropEvent) {
try {
Transferable transferable = dropTargetDropEvent.getTransferable();
if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
dropTargetDropEvent.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
List fileList = (List) transferable.getTransferData(DataFlavor.javaFileListFlavor);
Iterator iterator = fileList.iterator();
while (iterator.hasNext()) {
File file = (File) iterator.next();
if (file.isFile()) {
fileDropped(file);
}
if (file.isDirectory()) {
directoryDropped(file);
}
}
dropTargetDropEvent.getDropTargetContext().dropComplete(true);
} else {
dropTargetDropEvent.rejectDrop();
}
} catch (IOException | UnsupportedFlavorException io) {
io.printStackTrace();
dropTargetDropEvent.rejectDrop();
}
}
use of java.awt.datatransfer.UnsupportedFlavorException in project java-swing-tips by aterai.
the class TablePopupMenu method importData.
@Override
public boolean importData(TransferHandler.TransferSupport support) {
List<?> list;
try {
list = (List<?>) support.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
} catch (UnsupportedFlavorException | IOException ex) {
return false;
}
DefaultTableModel model = (DefaultTableModel) ((JTable) support.getComponent()).getModel();
list.stream().filter(File.class::isInstance).map(File.class::cast).map(f -> Collections.nCopies(3, f).toArray()).forEach(model::addRow);
return true;
}
Aggregations