javax.swing.TransferHandler Java Examples
The following examples show how to use
javax.swing.TransferHandler.
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: FolderList.java From netbeans with Apache License 2.0 | 6 votes |
@Override public boolean canImport(TransferHandler.TransferSupport support) { if (!support.isDrop()) { return false; } if (!support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { return false; } boolean actionSupported = (MOVE & support.getSourceDropActions()) == MOVE; if (!actionSupported) { return false; } support.setDropAction(MOVE); return true; }
Example #2
Source File: QuietEditorPane.java From netbeans with Apache License 2.0 | 6 votes |
@Override public void setDocument(Document doc) { super.setDocument(doc); // Setting DelegatingTransferHandler, where CallbackTransferable will // be handled in importData method. // For more details, please refer issue #53439 if (doc != null){ TransferHandler thn = getTransferHandler(); if( !(thn instanceof DelegatingTransferHandler) ) { DelegatingTransferHandler dth = new DelegatingTransferHandler(thn); setTransferHandler(dth); } DropTarget currDt = getDropTarget(); if( !(currDt instanceof DelegatingDropTarget ) ) { DropTarget dt = new DelegatingDropTarget( currDt ); setDropTarget( dt ); } } }
Example #3
Source File: TreeGuiView.java From niftyeditor with Apache License 2.0 | 6 votes |
/** * Creates new form TreeGuiView */ public TreeGuiView() { initComponents(); TreeTrasferHandling trasferHandling = new TreeTrasferHandling(); this.jTree2.setTransferHandler(trasferHandling); CommandProcessor.getInstance().getObservable().addObserver(this); ActionMap map = this.getActionMap(); map.put(TransferHandler.getCopyAction().getValue(javax.swing.Action.NAME), TransferHandler.getCopyAction()); map.put(TransferHandler.getPasteAction().getValue(javax.swing.Action.NAME), TransferHandler.getPasteAction()); map.put(TransferHandler.getCutAction().getValue(javax.swing.Action.NAME), TransferHandler.getCutAction()); }
Example #4
Source File: JarDropHandler.java From Cafebabe with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") @Override public boolean importData(TransferHandler.TransferSupport info) { if (!info.isDrop()) return false; Transferable t = info.getTransferable(); List<File> data = null; try { data = (List<File>) t.getTransferData(DataFlavor.javaFileListFlavor); } catch (Exception e) { return false; } user.preLoadJars(id); for (File jar : data) { if (jar.getName().toLowerCase().endsWith(".jar")) { user.onJarLoad(id, jar); break; } } return true; }
Example #5
Source File: DataObjectTransferHandler.java From nextreports-designer with Apache License 2.0 | 6 votes |
public void dragEnter(DropTargetDragEvent event) { DataFlavor[] dataFlavors = event.getCurrentDataFlavors(); JComponent c = (JComponent) event.getDropTargetContext().getComponent(); TransferHandler transferHandler = c.getTransferHandler(); if ((transferHandler != null) && transferHandler.canImport(c, dataFlavors)) { canImport = true; } else { canImport = false; } int dropAction = event.getDropAction(); if (canImport && actionSupported(dropAction)) { event.acceptDrag(dropAction); } else { event.rejectDrag(); } }
Example #6
Source File: InjectScript.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 6 votes |
private Boolean reorderProjects(TransferHandler.TransferSupport support) { JList list = (JList) support.getComponent(); try { int[] selectedIndices = (int[]) support.getTransferable().getTransferData(INDICES); DefaultListModel model = (DefaultListModel) list.getModel(); JList.DropLocation dl = (JList.DropLocation) support.getDropLocation(); if (dl.getIndex() != -1) { for (int selectedIndex : selectedIndices) { Object value = model.get(selectedIndex); model.removeElement(value); model.add(dl.getIndex(), value); } return true; } else { LOG.warning("Invalid Drop Location"); } } catch (UnsupportedFlavorException | IOException ex) { LOG.log(Level.SEVERE, ex.getMessage(), ex); } return false; }
Example #7
Source File: DragAction.java From constellation with Apache License 2.0 | 6 votes |
public DraggableButton(final Action action) { super(action); addMouseListener(new MouseAdapter() { @Override public void mousePressed(final MouseEvent event) { getTransferHandler().exportAsDrag(DraggableButton.this, event, TransferHandler.COPY); } }); t = new TransferHandler("graph") { @Override public Transferable createTransferable(final JComponent c) { return new StringSelection("graphSelection"); } }; setTransferHandler(t); source = new DragSource(); source.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY, this); }
Example #8
Source File: ProjectTree.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 6 votes |
private void setCCP() { TransferActionListener actionListener = new TransferActionListener(); cut = new JMenuItem("Cut"); cut.setActionCommand((String) TransferHandler.getCutAction().getValue(Action.NAME)); cut.addActionListener(actionListener); cut.setAccelerator(Keystroke.CUT); cut.setMnemonic(KeyEvent.VK_T); add(cut); copy = new JMenuItem("Copy"); copy.setActionCommand((String) TransferHandler.getCopyAction().getValue(Action.NAME)); copy.addActionListener(actionListener); copy.setAccelerator(Keystroke.COPY); copy.setMnemonic(KeyEvent.VK_C); add(copy); paste = new JMenuItem("Paste"); paste.setActionCommand((String) TransferHandler.getPasteAction().getValue(Action.NAME)); paste.addActionListener(actionListener); paste.setAccelerator(Keystroke.PASTE); paste.setMnemonic(KeyEvent.VK_P); add(paste); }
Example #9
Source File: ObjectPopupMenu.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 6 votes |
private void setCCP() { TransferActionListener actionListener = new TransferActionListener(); cut = new JMenuItem("Cut"); cut.setActionCommand((String) TransferHandler.getCutAction().getValue(Action.NAME)); cut.addActionListener(actionListener); cut.setAccelerator(Keystroke.CUT); cut.setMnemonic(KeyEvent.VK_T); add(cut); copy = new JMenuItem("Copy"); copy.setActionCommand((String) TransferHandler.getCopyAction().getValue(Action.NAME)); copy.addActionListener(actionListener); copy.setAccelerator(Keystroke.COPY); copy.setMnemonic(KeyEvent.VK_C); add(copy); paste = new JMenuItem("Paste"); paste.setActionCommand((String) TransferHandler.getPasteAction().getValue(Action.NAME)); paste.addActionListener(actionListener); paste.setAccelerator(Keystroke.PASTE); paste.setMnemonic(KeyEvent.VK_P); add(paste); }
Example #10
Source File: ScenarioDnD.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 6 votes |
@Override public boolean importData(TransferHandler.TransferSupport support) { if (!canImport(support)) { return false; } JTable.DropLocation dl = (JTable.DropLocation) support.getDropLocation(); JTable table = (JTable) support.getComponent(); int row = dl.getRow(); int tcRow = dl.getColumn() - 1; if (row == -1) { return false; } Scenario scenario = (Scenario) table.getModel(); TestCase testCase = scenario.getTestCaseByName( table.getValueAt(row, 0).toString()); if (dropObject instanceof TestCaseDnD) { putReusables(testCase, tcRow); } else { return false; } return super.importData(support); }
Example #11
Source File: SampleFractionListDisplayPane.java From ET_Redux with Apache License 2.0 | 5 votes |
@Override public boolean importData(TransferHandler.TransferSupport info) { // faking out the clipboard with our own clipboard to prevent copying of data objects if (!info.isDrop()) { return false; } DefaultListModel<TripoliFraction> listModel = (DefaultListModel<TripoliFraction>) list.getModel(); // // Get the DragAndDropListItemInterface that is being dropped. // Transferable t = info.getTransferable(); // DragAndDropListItemInterface[] data; // try { // data = (DragAndDropListItemInterface[])t.getTransferData( DataFlavor.stringFlavor );; // } catch (Exception e) { // return false; // } /** * Perform the actual import. Keep items in sort order * */ DragAndDropListItemInterface[] data = reduxDragAndDropClipboardInterface.getDndClipboardListItems(); for (int i = 0; i < data.length; i++) { // find where to insert element in backing list TripoliFraction tf = (TripoliFraction) data[i]; int index = Collections.binarySearch(dndListTripoliFractions, tf); dndListTripoliFractions.add(Math.abs(index + 1), tf); // insert into list as well listModel.add(Math.abs(index + 1), tf); tripoliSample.addTripoliFraction(tf); } closeButton.setEnabled(dndListTripoliFractions.isEmpty()); return true; }
Example #12
Source File: PlotConfigurationTree.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
@Override public void setTransferHandler(TransferHandler newHandler) { if (newHandler instanceof PlotConfigurationTreeTransferHandler) { DragListener cellRenderer = (DragListener) getCellRenderer(); PlotConfigurationTreeTransferHandler plotConfigurationTreeTransferHandler = (PlotConfigurationTreeTransferHandler) newHandler; if (cellRenderer != null) { plotConfigurationTreeTransferHandler.removeDragListener(cellRenderer); } plotConfigurationTreeTransferHandler.addDragListener(cellRenderer); } super.setTransferHandler(newHandler); }
Example #13
Source File: InjectScript.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 5 votes |
@Override public boolean importData(TransferHandler.TransferSupport support) { if (!canImport(support)) { return false; } if (support.getTransferable().isDataFlavorSupported(INDICES)) { return reorderProjects(support); } else { return dropProjects(support); } }
Example #14
Source File: LastNodeLowerHalfDrop.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override public boolean importData(TransferHandler.TransferSupport support) { if (!canImport(support)) { return false; } // Extract transfer data. DefaultMutableTreeNode[] nodes = null; try { Transferable t = support.getTransferable(); nodes = (DefaultMutableTreeNode[]) t.getTransferData(nodesFlavor); } catch (UnsupportedFlavorException ufe) { System.out.println("UnsupportedFlavor: " + ufe.getMessage()); } catch (java.io.IOException ioe) { System.out.println("I/O error: " + ioe.getMessage()); } // Get drop location info. JTree.DropLocation dl = (JTree.DropLocation) support.getDropLocation(); int childIndex = dl.getChildIndex(); TreePath dest = dl.getPath(); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) dest.getLastPathComponent(); JTree tree = (JTree) support.getComponent(); DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); // Configure for drop mode. int index = childIndex; // DropMode.INSERT if (childIndex == -1) { // DropMode.ON index = parent.getChildCount(); } // Add data to model. for (DefaultMutableTreeNode node : nodes) { model.insertNodeInto(node, parent, index++); } return true; }
Example #15
Source File: LastNodeLowerHalfDrop.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override public boolean canImport(TransferHandler.TransferSupport support) { if (!support.isDrop()) { return false; } support.setShowDropLocation(true); if (!support.isDataFlavorSupported(nodesFlavor)) { return false; } // Do not allow a drop on the drag source selections. JTree.DropLocation dl = (JTree.DropLocation) support.getDropLocation(); JTree tree = (JTree) support.getComponent(); int dropRow = tree.getRowForPath(dl.getPath()); int[] selRows = tree.getSelectionRows(); for (int i = 0; i < selRows.length; i++) { if (selRows[i] == dropRow) { return false; } } // Do not allow MOVE-action drops if a non-leaf node is // selected unless all of its children are also selected. int action = support.getDropAction(); if (action == MOVE) { return haveCompleteNode(tree); } // Do not allow a non-leaf node to be copied to a level // which is less than its source level. TreePath dest = dl.getPath(); DefaultMutableTreeNode target = (DefaultMutableTreeNode) dest.getLastPathComponent(); TreePath path = tree.getPathForRow(selRows[0]); DefaultMutableTreeNode firstNode = (DefaultMutableTreeNode) path.getLastPathComponent(); if (firstNode.getChildCount() > 0 && target.getLevel() < firstNode.getLevel()) { return false; } return true; }
Example #16
Source File: ScriptTreeTransferHandler.java From zap-extensions with Apache License 2.0 | 5 votes |
private TransferHandler getTransferHandlerForSelection(Component c) { if (!(c instanceof JTree)) { logger.debug( "getTransferHandlerForSelection not jtree " + c.getClass().getCanonicalName()); return null; } JTree tree = (JTree) c; TransferHandler th = null; if (tree.getSelectionPaths() == null) { return null; } for (TreePath tp : tree.getSelectionPaths()) { if (tp.getLastPathComponent() instanceof ScriptNode) { Object uo = ((ScriptNode) tp.getLastPathComponent()).getUserObject(); if (uo == null) { // One of the selection doesnt have a user object // logger.debug("getTransferHandlerForSelection no user object for " + tp); return null; } TransferHandler th2 = this.htMap.get(uo.getClass()); if (th2 == null) { // No transfer handler, no go return null; } if (th == null) { th = th2; } else if (!th.equals(th2)) { // Different transfer handlers, no go return null; } } } // logger.debug("getTransferHandlerForSelection no user objects found"); return th; }
Example #17
Source File: ProjectDnD.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 5 votes |
private Boolean importScenarios(List<ScenarioNode> scenarioNodes, TransferHandler.TransferSupport ts) { Boolean shouldCut = ts.isDrop() ? ts.getDropAction() == MOVE : isCut; if (shouldCut) { return false; } Object destObject = getDestinationObject(ts); if (destObject instanceof GroupNode) { for (ScenarioNode scenarioNode : scenarioNodes) { addScenario(scenarioNode.getScenario(), (GroupNode) destObject); } return true; } return false; }
Example #18
Source File: GuiSelectionListener.java From niftyeditor with Apache License 2.0 | 5 votes |
public final void startDrag(MouseEvent e) { if(enable){ if (!(this.getSelected() instanceof GScreen) && !(this.getSelected() instanceof GLayer)) { JPanel c = (JPanel) e.getComponent(); TransferHandler handler = c.getTransferHandler(); handler.exportAsDrag(c, e, TransferHandler.MOVE); this.niftyView.getDDManager().startDrag(this.getSelected()); } } }
Example #19
Source File: XTextFieldPeer.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
@Override public void setTransferHandler(TransferHandler newHandler) { TransferHandler oldHandler = (TransferHandler) getClientProperty(AWTAccessor.getClientPropertyKeyAccessor() .getJComponent_TRANSFER_HANDLER()); putClientProperty(AWTAccessor.getClientPropertyKeyAccessor() .getJComponent_TRANSFER_HANDLER(), newHandler); firePropertyChange("transferHandler", oldHandler, newHandler); }
Example #20
Source File: TableRowTransferHandler.java From RobotBuilder with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public boolean importData(TransferHandler.TransferSupport info) { JTable target = (JTable) info.getComponent(); JTable.DropLocation dl = (JTable.DropLocation) info.getDropLocation(); int index = dl.getRow(); int max = table.getModel().getRowCount(); if (index < 0 || index > max) { index = max; } target.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); try { Integer rowFrom = (Integer) info.getTransferable().getTransferData(localObjectFlavor); if (rowFrom != -1 && rowFrom != index) { Vector<Object> rowData = (Vector) getTableModel().getDataVector().get(rowFrom); getTableModel().removeRow(rowFrom); getTableModel().insertRow(index, rowData); if (index > rowFrom) { index--; } target.getSelectionModel().addSelectionInterval(index, index); return true; } } catch (UnsupportedFlavorException | IOException e) { e.printStackTrace(); } return false; }
Example #21
Source File: ScriptTreeTransferHandler.java From zap-extensions with Apache License 2.0 | 5 votes |
@Override public boolean canImport(TransferHandler.TransferSupport support) { logger.debug("canImport " + support.getComponent().getClass().getCanonicalName()); TransferHandler th = getTransferHandlerForSelection(support.getComponent()); if (th != null) { return th.canImport(support); } return false; }
Example #22
Source File: XTextAreaPeer.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
@Override public void setTransferHandler(TransferHandler newHandler) { TransferHandler oldHandler = (TransferHandler) getClientProperty(AWTAccessor.getClientPropertyKeyAccessor() .getJComponent_TRANSFER_HANDLER()); putClientProperty(AWTAccessor.getClientPropertyKeyAccessor() .getJComponent_TRANSFER_HANDLER(), newHandler); firePropertyChange("transferHandler", oldHandler, newHandler); }
Example #23
Source File: XTextFieldPeer.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
@Override public void setTransferHandler(TransferHandler newHandler) { TransferHandler oldHandler = (TransferHandler) getClientProperty(AWTAccessor.getClientPropertyKeyAccessor() .getJComponent_TRANSFER_HANDLER()); putClientProperty(AWTAccessor.getClientPropertyKeyAccessor() .getJComponent_TRANSFER_HANDLER(), newHandler); firePropertyChange("transferHandler", oldHandler, newHandler); }
Example #24
Source File: XTextFieldPeer.java From hottub with GNU General Public License v2.0 | 5 votes |
@Override public void setTransferHandler(TransferHandler newHandler) { TransferHandler oldHandler = (TransferHandler) getClientProperty(AWTAccessor.getClientPropertyKeyAccessor() .getJComponent_TRANSFER_HANDLER()); putClientProperty(AWTAccessor.getClientPropertyKeyAccessor() .getJComponent_TRANSFER_HANDLER(), newHandler); firePropertyChange("transferHandler", oldHandler, newHandler); }
Example #25
Source File: ListTransferHandler.java From dualsub with GNU General Public License v3.0 | 5 votes |
@Override public boolean canImport(TransferHandler.TransferSupport info) { if (!info.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { return false; } return true; }
Example #26
Source File: NbClipboardIsUsedByAlreadyInitializedComponentsTest.java From netbeans with Apache License 2.0 | 5 votes |
protected void inMiddleOfSettingUpTheManager() { assertNotNull("There is a manager already", System.getSecurityManager()); // do some strange tricks to initialize the system field = new javax.swing.JTextField (); TransferHandler.getCopyAction(); TransferHandler.getCutAction(); TransferHandler.getPasteAction(); }
Example #27
Source File: DnDToggleButton.java From WorldPainter with GNU General Public License v3.0 | 5 votes |
private void init() { transferHandler = new TransferHandler() { @Override protected Transferable createTransferable(JComponent c) { return new DnDToggleButton(getText(), getIcon()); } }; setTransferHandler(transferHandler); source = new DragSource(); source.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY, this); }
Example #28
Source File: DragDropList.java From constellation with Apache License 2.0 | 5 votes |
@Override public boolean canImport(final TransferHandler.TransferSupport support) { if (!support.isDataFlavorSupported(DataFlavor.stringFlavor)) { return false; } JList.DropLocation dl = (JList.DropLocation) support.getDropLocation(); return dl.getIndex() != -1; }
Example #29
Source File: AbstractPatchedTransferHandler.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
/** * Dirty hack to get the drop target listener defined in {@link TransferHandler} by method * invokation. */ public static DropTargetListener getDropTargetListener() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { Method m; m = TransferHandler.class.getDeclaredMethod("getDropTargetListener"); m.setAccessible(true); // if security settings allow this return (DropTargetListener) m.invoke(null); // use null if the method is static }
Example #30
Source File: XTextAreaPeer.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
@Override public void setTransferHandler(TransferHandler newHandler) { TransferHandler oldHandler = (TransferHandler) getClientProperty(AWTAccessor.getClientPropertyKeyAccessor() .getJComponent_TRANSFER_HANDLER()); putClientProperty(AWTAccessor.getClientPropertyKeyAccessor() .getJComponent_TRANSFER_HANDLER(), newHandler); firePropertyChange("transferHandler", oldHandler, newHandler); }