javax.swing.TransferHandler.TransferSupport Java Examples
The following examples show how to use
javax.swing.TransferHandler.TransferSupport.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FileDropHandler.java From audiveris with GNU Affero General Public License v3.0 | 6 votes |
@Override public boolean canImport (TransferSupport support) { /* For the time being, only support drops (not clipboard paste) */ if (!support.isDrop()) { return false; } /* Check that the drop contains a list of files */ if (!support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { return false; } /* Check to see if the source actions contains the COPY action */ boolean copySupported = (COPY & support.getSourceDropActions()) == COPY; /* If COPY is supported, choose COPY and accept the transfer */ if (copySupported) { support.setDropAction(COPY); return true; } /* COPY isn't supported, so reject the transfer */ return false; }
Example #2
Source File: AttributeDropTextField.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
@Override public void dragStarted(Transferable t) { TransferSupport support = new TransferSupport(this, t); boolean doesSupportFlavor = ((DataTableColumnDropTextFieldTransferHandler) getTransferHandler()) .doesSupportFlavor(support); if (doesSupportFlavor) { switch (RapidMinerGUI.getDragHighlighteMode()) { case FULL: setBackground(ProcessDrawer.INNER_DRAG_COLOR); case BORDER: setBorder(ongoingDropBorder); break; default: break; } } }
Example #3
Source File: ObjectDnD.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 5 votes |
@Override public boolean canImport(TransferSupport ts) { return ts.getComponent().equals(tree) && ts.isDataFlavorSupported(OBJECT_FLAVOR) && getDestinationObject(ts) != null && !(getDestinationObject(ts) instanceof ORRootInf); }
Example #4
Source File: ObjectDnD.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 5 votes |
@Override public boolean importData(TransferSupport ts) { if (canImport(ts)) { ObjectRepDnD oDnd; try { oDnd = (ObjectRepDnD) ts.getTransferable().getTransferData(OBJECT_FLAVOR); } catch (UnsupportedFlavorException | IOException ex) { Logger.getLogger(ObjectDnD.class.getName()).log(Level.SEVERE, null, ex); return false; } Object object = getDestinationObject(ts); Boolean shouldCut = ts.isDrop() ? ts.getDropAction() == MOVE : isCut; if (object instanceof ORPageInf) { if (oDnd.isGroup()) { copyObjectGroups((ORPageInf) object, oDnd, shouldCut); return true; } else if (oDnd.isObject()) { copyObjects((ORPageInf) object, oDnd, shouldCut); return true; } } else if (object instanceof ObjectGroup) { if (oDnd.isObject()) { copyObjects((ObjectGroup) object, oDnd, shouldCut); return true; } } else if (object instanceof ORObjectInf) { if (oDnd.isObject()) { if (copyObjects(((ORObjectInf) object).getParent(), oDnd, shouldCut)) { if (((ORObjectInf) object).getParent().getChildCount() == 2) { reload(((ORObjectInf) object).getParent().getParent()); } } return true; } } } return false; }
Example #5
Source File: ObjectDnD.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 5 votes |
private Object getDestinationObject(TransferSupport ts) { TreePath path; if (ts.isDrop()) { path = ((JTree.DropLocation) ts.getDropLocation()).getPath(); } else { path = ((JTree) ts.getComponent()).getSelectionPath(); } if (path != null) { return path.getLastPathComponent(); } return null; }
Example #6
Source File: ChartConfigurationPanel.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
@Override public void dragStarted(Transferable t) { TransferSupport support = new TransferSupport(this, t); boolean doesSupportFlavor = ((PlotConfigurationTreeTransferHandler) plotConfigurationTree.getTransferHandler()) .doesSupportFlavor(support); if (doesSupportFlavor) { if (SwingUtilities.isEventDispatchThread()) { switch (RapidMinerGUI.getDragHighlighteMode()) { case FULL: plotConfigurationTree.setBackground(ProcessDrawer.INNER_DRAG_COLOR); case BORDER: plotConfigurationTreeScrollPane.setBorder(ONGOING_DROP_BORDER); break; default: break; } } else { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { switch (RapidMinerGUI.getDragHighlighteMode()) { case FULL: plotConfigurationTree.setBackground(ProcessDrawer.INNER_DRAG_COLOR); case BORDER: plotConfigurationTreeScrollPane.setBorder(ONGOING_DROP_BORDER); break; default: break; } } }); } } }
Example #7
Source File: ShowToolSettingsPanel.java From jeveassets with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public boolean importData(TransferSupport info) { TransferHandler.DropLocation tdl = info.getDropLocation(); if (!canImport(info) || !(tdl instanceof JList.DropLocation)) { return false; } JList.DropLocation dl = (JList.DropLocation) tdl; JList<?> target = (JList) info.getComponent(); DefaultListModel<Object> listModel = (DefaultListModel) target.getModel(); int max = listModel.getSize(); int index = dl.getIndex(); index = index < 0 ? max : index; // If it is out of range, it is appended to the end index = Math.min(index, max); addIndex = index; try { Object[] values = (Object[]) info.getTransferable().getTransferData(localObjectFlavor); for (Object value : values) { int idx = index++; listModel.add(idx, value); target.addSelectionInterval(idx, idx); } addCount = values.length; return true; } catch (UnsupportedFlavorException | IOException ex) { LOG.error(ex.getMessage(), ex); return false; } }
Example #8
Source File: FileDropHandler.java From libreveris with GNU Lesser General Public License v3.0 | 5 votes |
/** * {@inheritDoc} */ @Override public boolean canImport (TransferSupport support) { /* For the time being, only support drops (not clipboard paste) */ if (!support.isDrop()) { return false; } /* Check that the drop contains a list of files */ if (!support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { return false; } /* Check to see if the source actions contains the COPY action */ boolean copySupported = (COPY & support.getSourceDropActions()) == COPY; /* If COPY is supported, choose COPY and accept the transfer */ if (copySupported) { support.setDropAction(COPY); return true; } /* COPY isn't supported, so reject the transfer */ return false; }
Example #9
Source File: ClipboardHandler.java From netbeans with Apache License 2.0 | 4 votes |
@Override public boolean canImport(TransferSupport support) { return delegate.canImport(support); }
Example #10
Source File: TreeTransferHandler.java From RobotBuilder with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public boolean canImport(TransferSupport support) { if (!support.isDrop()) { return false; } support.setShowDropLocation(true); JTree.DropLocation dl = (JTree.DropLocation) support.getDropLocation(); TreePath path = dl.getPath(); if (path == null) { return false; } RobotComponent target = (RobotComponent) path.getLastPathComponent(); if (support.getTransferable().isDataFlavorSupported(DataFlavor.stringFlavor)) { String data; try { data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor); } catch (UnsupportedFlavorException | IOException e) { return false; } PaletteComponent base = Palette.getInstance().getItem(data); assert base != null; // TODO: Handle more gracefully return target.supports(base); } else if (support.getTransferable().isDataFlavorSupported(RobotTree.ROBOT_COMPONENT_FLAVOR)) { RobotComponent data; try { data = (RobotComponent) support.getTransferable().getTransferData(RobotTree.ROBOT_COMPONENT_FLAVOR); } catch (UnsupportedFlavorException e) { System.out.println("UnsupportedFlavor"); return false; } catch (IOException e) { e.printStackTrace(); System.out.println("IOException"); return false; } if (dl.getChildIndex() == -1 && target.getChildren().contains(data)) { // Cannot drag something into its own parent // (This allows for reordering) return false; } Set<String> invalid = new HashSet(); invalid.add("Robot"); invalid.add("Subsystems"); invalid.add("OI"); invalid.add("Commands"); if (data == null) { return false; } if (invalid.contains(data.getBase().getType())) { return false; } return target.supports(data); } else { System.out.println("Unsupported flavor. The flavor you have chosen is not sufficiently delicious."); return false; } }
Example #11
Source File: ShowToolSettingsPanel.java From jeveassets with GNU General Public License v2.0 | 4 votes |
@Override public boolean canImport(TransferSupport info) { return info.isDrop() && info.isDataFlavorSupported(localObjectFlavor); }
Example #12
Source File: DragAndDropSupportWrapper.java From binnavi with Apache License 2.0 | 2 votes |
/** * Sets the transfer support instance which contains all relevant information to handle the drag * and drop operation. * * @param support The transfer support for the drag and drop operation. */ public void setSupport(final TransferSupport support) { this.support = support; }