use of java.awt.datatransfer.UnsupportedFlavorException in project JMRI by JMRI.
the class DnDTableImportExportHandler method importData.
@Override
public boolean importData(TransferHandler.TransferSupport support) {
if (!canImport(support)) {
return false;
}
if (log.isDebugEnabled()) {
JTable.DropLocation loc = (JTable.DropLocation) support.getDropLocation();
log.debug("importData: isDrop= {} location= {} row= {} col= {}", support.isDrop(), loc.getDropPoint(), loc.getRow(), loc.getColumn());
}
if (!support.isDrop()) {
return false;
}
TransferHandler.DropLocation loc = support.getDropLocation();
if (!(loc instanceof JTable.DropLocation)) {
return false;
}
Component comp = support.getComponent();
if (!(comp instanceof JTable)) {
return false;
}
JTable.DropLocation location = (JTable.DropLocation) loc;
JTable table = (JTable) comp;
int row = location.getRow();
int col = location.getColumn();
row = table.convertRowIndexToModel(row);
col = table.convertColumnIndexToModel(col);
for (int i = 0; i < _skipColumns.length; i++) {
if (_skipColumns[i] == col) {
return false;
}
}
try {
Transferable trans = support.getTransferable();
Object obj = trans.getTransferData(DataFlavor.stringFlavor);
table.getModel().setValueAt(obj, row, col);
return true;
} catch (UnsupportedFlavorException ufe) {
log.warn("DnDStringImportHandler.importData: " + ufe.getMessage());
} catch (IOException ioe) {
log.warn("DnDStringImportHandler.importData: " + ioe.getMessage());
}
return false;
}
use of java.awt.datatransfer.UnsupportedFlavorException in project android by JetBrains.
the class PTable method performPaste.
@Override
public void performPaste(@NotNull DataContext dataContext) {
PTableItem item = getSelectedNonGroupItem();
if (item == null) {
return;
}
Transferable transferable = myCopyPasteManager.getContents();
if (transferable == null || !transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
return;
}
try {
item.setValue(transferable.getTransferData(DataFlavor.stringFlavor));
} catch (IOException | UnsupportedFlavorException exception) {
Logger.getInstance(PTable.class).warn(exception);
}
}
use of java.awt.datatransfer.UnsupportedFlavorException in project knime-core by knime.
the class SelectionPanel method drop.
/**
* {@inheritDoc}
*/
@Override
public void drop(final DropTargetDropEvent dtde) {
if (dtde.getDropAction() == DnDConstants.ACTION_MOVE) {
dtde.acceptDrop(dtde.getDropAction());
Transferable t = dtde.getTransferable();
String s = "default";
try {
s = (String) t.getTransferData(DataFlavor.stringFlavor);
} catch (UnsupportedFlavorException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
int i = m_config.drop(s);
Pane dp = getNewPane(m_includePanel, m_config, i);
m_includePanel.add(dp.getComponentPanel(), m_gbc);
m_gbc.gridy++;
m_includePanel.setBackground(UIManager.getColor("Panel.background"));
m_scrollPane.revalidate();
dtde.dropComplete(true);
}
}
use of java.awt.datatransfer.UnsupportedFlavorException in project Terasology by MovingBlocks.
the class AbstractEditorScreen method pasteJson.
/**
* Attempts to serialize the system clipboard's contents - if successful,
* sets the current state of the editor to the serialized {@link JsonTree}.
*/
protected void pasteJson() {
// Get the clipboard contents.
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable t = clipboard.getContents(null);
// Attempt to convert them to a string.
String clipboardContents = null;
try {
if (t != null) {
clipboardContents = (String) t.getTransferData(DataFlavor.stringFlavor);
}
} catch (UnsupportedFlavorException | IOException e) {
logger.warn("Could not fetch clipboard contents.", e);
}
if (clipboardContents != null) {
try {
// Attempt to serialize them to a JsonTree and reset the editor state.
JsonElement json = new JsonParser().parse(clipboardContents);
JsonTree node = JsonTreeConverter.serialize(json);
resetState(node);
} catch (JsonSyntaxException | NullPointerException e) {
logger.warn("Could not construct a valid tree from clipboard contents.", e);
}
}
}
use of java.awt.datatransfer.UnsupportedFlavorException in project pdfbox by apache.
the class PDFDebugger method initComponents.
/**
* This method is called from within the constructor to initialize the form.
*/
private void initComponents() {
jSplitPane1 = new javax.swing.JSplitPane();
jScrollPane1 = new JScrollPane();
tree = new Tree(this);
jScrollPane2 = new JScrollPane();
jTextPane1 = new javax.swing.JTextPane();
tree.setCellRenderer(new PDFTreeCellRenderer());
tree.setModel(null);
setTitle("Apache PDFBox Debugger");
addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowOpened(WindowEvent windowEvent) {
tree.requestFocusInWindow();
super.windowOpened(windowEvent);
}
@Override
public void windowClosing(WindowEvent evt) {
exitForm(evt);
}
});
jScrollPane1.setBorder(new BevelBorder(BevelBorder.RAISED));
jScrollPane1.setPreferredSize(new Dimension(350, 500));
tree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent evt) {
jTree1ValueChanged(evt);
}
});
jScrollPane1.setViewportView(tree);
jSplitPane1.setRightComponent(jScrollPane2);
jSplitPane1.setDividerSize(3);
jScrollPane2.setPreferredSize(new Dimension(300, 500));
jScrollPane2.setViewportView(jTextPane1);
jSplitPane1.setLeftComponent(jScrollPane1);
JScrollPane documentScroller = new JScrollPane();
documentScroller.setViewportView(documentPanel);
statusPane = new TreeStatusPane(tree);
statusPane.getPanel().setBorder(new BevelBorder(BevelBorder.RAISED));
statusPane.getPanel().setPreferredSize(new Dimension(300, 25));
getContentPane().add(statusPane.getPanel(), BorderLayout.PAGE_START);
getContentPane().add(jSplitPane1, BorderLayout.CENTER);
statusBar = new ReaderBottomPanel();
getContentPane().add(statusBar, BorderLayout.SOUTH);
// create menus
JMenuBar menuBar = new JMenuBar();
menuBar.add(createFileMenu());
menuBar.add(createEditMenu());
ViewMenu viewMenu = ViewMenu.getInstance(this);
menuBar.add(viewMenu.getMenu());
setJMenuBar(menuBar);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int width = 1000;
int height = 970;
setBounds((screenSize.width - width) / 2, (screenSize.height - height) / 2, width, height);
// drag and drop to open files
setTransferHandler(new TransferHandler() {
@Override
public boolean canImport(TransferSupport transferSupport) {
return transferSupport.isDataFlavorSupported(DataFlavor.javaFileListFlavor);
}
@Override
@SuppressWarnings("unchecked")
public boolean importData(TransferSupport transferSupport) {
try {
Transferable transferable = transferSupport.getTransferable();
List<File> files = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
readPDFFile(files.get(0), "");
return true;
} catch (IOException e) {
new ErrorDialog(e).setVisible(true);
return true;
} catch (UnsupportedFlavorException e) {
throw new RuntimeException(e);
}
}
});
// Mac OS X file open/quit handler
if (IS_MAC_OS && !isMinJdk9()) {
// TODO this needs to be rewritten for JDK9, see PDFBOX-4013
try {
Method osxOpenFiles = getClass().getDeclaredMethod("osxOpenFiles", String.class);
osxOpenFiles.setAccessible(true);
OSXAdapter.setFileHandler(this, osxOpenFiles);
Method osxQuit = getClass().getDeclaredMethod("osxQuit");
osxQuit.setAccessible(true);
OSXAdapter.setQuitHandler(this, osxQuit);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}
}
}
Aggregations