Java 类javax.swing.TransferHandler 实例源码

项目:incubator-netbeans    文件:QuietEditorPane.java   
@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 );
        }
    }
}
项目:incubator-netbeans    文件:FolderList.java   
@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;
}
项目:JuggleMasterPro    文件:ExtendedTransferHandler.java   
/**
 * Method description
 * 
 * @see
 * @param objPtransferSupport
 * @return
 */
@Override final public boolean canImport(TransferHandler.TransferSupport objPtransferSupport) {

    if (this.objGcontrolJFrame.getJuggleMasterPro().bolGprogramTrusted
        || this.objGcontrolJFrame.getJuggleMasterPro().bytGprogramType == Constants.bytS_STATE_PROGRAM_LOCAL_APPLET) {
        final DataFlavor[] objLdataFlavorA = objPtransferSupport.getDataFlavors();
        if (objLdataFlavorA.length > 0) {
            if (objLdataFlavorA.length == 1) {
                return this.objGtextTransferHandler != null && objLdataFlavorA[0].equals(DataFlavor.stringFlavor)
                        || objLdataFlavorA[0].equals(DataFlavor.javaFileListFlavor);
            }
            for (final DataFlavor objLdataFlavor : objLdataFlavorA) {
                if (!objLdataFlavor.equals(DataFlavor.javaFileListFlavor)) {
                    return false;
                }
            }
            return true;
        }
    }
    return false;
}
项目:scorekeeperfrontend    文件:DriverTable.java   
/**
 * Called for drop and paste operations
 */
@Override
public boolean importData(TransferHandler.TransferSupport support)
{
    try
    {
        JTable target = (JTable)support.getComponent();
        EntryModel model = (EntryModel)target.getModel();

        if (support.isDrop())
        {
            JTable.DropLocation dl = (JTable.DropLocation)support.getDropLocation();
            model.moveRow(rowsidx[0], rowsidx[rowsidx.length-1], dl.getRow());
            target.clearSelection();
        }

        return true;
    }
    catch (Exception e) { log.warning("\bGeneral error during driver drag:" + e); }

    return false;
}
项目:Tarski    文件:mxGraphTransferHandler.java   
/**
 * 
 */
public void exportDone(JComponent c, Transferable data, int action) {
  initialImportCount = 1;

  if (c instanceof mxGraphComponent && data instanceof mxGraphTransferable) {
    // Requires that the graph handler resets the location to null if the drag leaves the
    // component. This is the condition to identify a cross-component move.
    boolean isLocalDrop = location != null;

    if (action == TransferHandler.MOVE && !isLocalDrop) {
      removeCells((mxGraphComponent) c, originalCells);
      initialImportCount = 0;
    }
  }

  originalCells = null;
  location = null;
  offset = null;
}
项目:Cognizant-Intelligent-Test-Scripter    文件:InjectScript.java   
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;
}
项目:Cognizant-Intelligent-Test-Scripter    文件:ProjectTree.java   
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);
}
项目:Cognizant-Intelligent-Test-Scripter    文件:ProjectDnD.java   
@Override
public boolean importData(TransferHandler.TransferSupport ts) {
    if (ts.isDataFlavorSupported(TESTCASE_FLAVOR)) {
        try {
            TestCaseDnD testCaseDnD
                    = (TestCaseDnD) ts.getTransferable()
                    .getTransferData(TESTCASE_FLAVOR);
            sourceTreeModel = testCaseDnD.model;
            if (testCaseDnD.isTestCases()) {
                return importTestCases(testCaseDnD.getTestCaseList(), ts);
            } else {
                return importScenarios(testCaseDnD.getScenarioList(), ts);
            }

        } catch (UnsupportedFlavorException | IOException ex) {
            Logger.getLogger(ProjectDnD.class
                    .getName()).log(Level.SEVERE, null, ex);
            return false;
        }

    }
    return false;
}
项目:Cognizant-Intelligent-Test-Scripter    文件:ProjectDnD.java   
private Boolean importTestCases(List<TestCaseNode> testCaseNodes,
        TransferHandler.TransferSupport ts) {
    Boolean shouldCut = ts.isDrop() ? ts.getDropAction() == MOVE : isCut;
    Object destObject = getDestinationObject(ts);
    ScenarioNode scNode = getScenarioNode(destObject);
    if (scNode != null) {
        copySelectedTestCases(testCaseNodes, scNode, shouldCut);
        return true;
    }
    if (!(destObject instanceof TestPlanNode)
            && destObject instanceof GroupNode) {
        copySelectedTestCases(testCaseNodes, (GroupNode) destObject, shouldCut);
        return true;
    }
    return false;
}
项目:Cognizant-Intelligent-Test-Scripter    文件:ObjectPopupMenu.java   
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);
}
项目:Cognizant-Intelligent-Test-Scripter    文件:ScenarioDnD.java   
@Override
public boolean canImport(TransferHandler.TransferSupport support) {
    if (!support.isDrop()) {
        return false;
    }
    JTable.DropLocation dl = (JTable.DropLocation) support.getDropLocation();
    if (dl.getColumn() < 1) {
        return false;
    }
    try {
        if (support.isDataFlavorSupported(ProjectDnD.TESTCASE_FLAVOR)) {
            dropObject = support.getTransferable().getTransferData(ProjectDnD.TESTCASE_FLAVOR);
            return true;
        } else {
            return false;
        }
    } catch (UnsupportedFlavorException | IOException ex) {
        Logger.getLogger(ScenarioDnD.class.getName()).log(Level.SEVERE, null, ex);
        return false;
    }
}
项目:Cognizant-Intelligent-Test-Scripter    文件:ScenarioDnD.java   
@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);
}
项目:pdfjumbler    文件:JDragDropList.java   
@Override
public boolean canImport(TransferHandler.TransferSupport info) {
    if (JDragDropList.this.dropListener != null) {
        return JDragDropList.this.dropListener.acceptDrop(JDragDropList.this, info);
    } else {
        return canImportHere(info);
    }
}
项目:pdfjumbler    文件:JDragDropList.java   
@Override
public boolean importData(TransferHandler.TransferSupport info) {
    if (!info.isDrop()) {
        return false;
    }
    if (!canImportHere(info)) {
        if (
            (JDragDropList.this.dropListener != null) &&
            JDragDropList.this.dropListener.acceptDrop(JDragDropList.this, info)
        ) {
            return JDragDropList.this.dropListener.handleDrop(JDragDropList.this, info);
        } else {
            return false;
        }
    }

    JDDLTransferData<T> data = getData(info);
    int destIndex = JDragDropList.this.getDropLocation().getIndex();        

    /*
    System.err.print("[ ");
    for (int index : data.getIndices()) {
        System.err.print(index + " ");
    }
    System.err.print("] -> ");
    System.err.println(destIndex);
    */

    if ((info.getDropAction() & DnDConstants.ACTION_COPY) != 0) {
        copyItems(data.getSourceList(), JDragDropList.this, data.getValuesList(), destIndex);
    } else if ((info.getDropAction() & DnDConstants.ACTION_MOVE) != 0) {
        moveItems(data.getSourceList(), JDragDropList.this, data.getIndices(), destIndex);  
    } else {
        return false;
    }

    return true;
}
项目:incubator-netbeans    文件:NbClipboardIsUsedByAlreadyInitializedComponentsTest.java   
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();
}
项目:incubator-netbeans    文件:BaseCaret.java   
protected int mapDragOperationFromModifiers(MouseEvent e) {
    int mods = e.getModifiersEx();

    if ((mods & InputEvent.BUTTON1_DOWN_MASK) == 0) {
        return TransferHandler.NONE;
    }

    return TransferHandler.COPY_OR_MOVE;
}
项目:scorekeeperfrontend    文件:EntrantTree.java   
@Override
public boolean canImport(TransferHandler.TransferSupport support)
{
    try 
    {
        BracketEntry e = (BracketEntry) support.getTransferable().getTransferData(BracketEntry.Transfer.myFlavor);
        if (e.source == null) return false;
        support.setDropAction(MOVE);
        return true;
    } 
    catch (Exception ex) { return false; }
}
项目:incubator-netbeans    文件:EditorCaret.java   
private int mapDragOperationFromModifiers(MouseEvent e) {
    int mods = e.getModifiersEx();

    if ((mods & InputEvent.BUTTON1_DOWN_MASK) == 0) {
        return TransferHandler.NONE;
    }

    return TransferHandler.COPY_OR_MOVE;
}
项目:scorekeeperfrontend    文件:BracketPane.java   
@Override
public boolean importData(TransferHandler.TransferSupport support)
{
    try
    {
        if (support.isDrop())
        {
            BracketEntry transfer = (BracketEntry)support.getTransferable().getTransferData(BracketEntry.Transfer.myFlavor);
            EntrantLabel target = (EntrantLabel)support.getComponent();
            BracketEntry old = target.getEntry();                   
            boolean swap = ((transfer.source != null) && (transfer.source.getDepth() == target.entryId.getDepth()));

            // swap operation in the same level of the challenge
            if (swap)
            {
                if (!target.isEmpty() && (JOptionPane.showConfirmDialog(BracketPane.this,
                                        String.format("This will swap %s and %s.  Is that what you would like to do?", old.entrant.getName(), transfer.entrant.getName()),
                                            "Entrant Swap", JOptionPane.OK_CANCEL_OPTION) != JOptionPane.OK_OPTION))
                    return false;
                model.setEntrant(transfer.source, old.entrant, old.dialin);
                rounds.get(transfer.source.round).updateEntrants();
            }

            // copy from tree or previous round
            if (!swap)
            {
                if (!target.isEmpty() && (JOptionPane.showConfirmDialog(null, 
                                        String.format("This will overwrite %s with %s.  Is that what you would like to do?", old.entrant.getName(), transfer.entrant.getName()), 
                                            "Overwrite Warning", JOptionPane.OK_CANCEL_OPTION) != JOptionPane.OK_OPTION))
                    return false;
            }

            target.setEntry(transfer);
            Messenger.sendEvent(MT.ENTRANT_CHANGED, old);
            return true;
        }
    }
    catch (Exception ioe) { log.warning("\bError during drop:" + ioe); }
    return false;
}
项目:scorekeeperfrontend    文件:RunsTable.java   
@Override
public boolean importData(TransferHandler.TransferSupport support)
{
    try
    {
        Run newdata[][] = (Run[][])support.getTransferable().getTransferData(flavor);
        JTable target = (JTable)support.getComponent();
        int dr,dc;

        if (!support.isDrop())
        {
            /* Set the data */
            dr = target.getSelectedRow();
            dc = target.getSelectedColumn();

            for (int ii = 0; ii < newdata.length; ii++)
                for (int jj = 0; jj < newdata[0].length; jj++)
                    target.setValueAt((newdata[ii][jj]).clone(), dr+ii, dc+jj);
        }

        return true;
    }
    catch (UnsupportedFlavorException ufe) { log.warning("Sorry, you pasted data I don't work with"); }
    catch (IOException ioe) { log.log(Level.WARNING, "I/O Error during paste:{0}", ioe.getMessage()); }
    catch (Exception e) { log.log(Level.WARNING, "General error during paste:{0}", e.getMessage()); }

    return false;
}
项目:incubator-netbeans    文件:DashboardTransferHandler.java   
@Override
public boolean canImport(TransferHandler.TransferSupport info) {
    if (!info.isDataFlavorSupported(taskFlavor)) {
        return false;
    }
    Category category = getTargetCategory(info);
    return category != null;
}
项目:rapidminer    文件:ProcessRendererDropTarget.java   
public ProcessRendererDropTarget(final ProcessRendererView view, final DropTargetListener dropTargetListener) {
    super(view, TransferHandler.COPY_OR_MOVE | TransferHandler.LINK, null);
    this.view = view;
    try {
        super.addDropTargetListener(dropTargetListener);
    } catch (TooManyListenersException tmle) {
    }
}
项目:rapidminer    文件:OperatorTransferHandler.java   
public static void addToActionMap(JComponent component) {
    ActionMap actionMap = component.getActionMap();
    actionMap.put(TransferHandler.getCutAction().getValue(Action.NAME), TransferHandler.getCutAction());
    actionMap.put(TransferHandler.getCopyAction().getValue(Action.NAME), TransferHandler.getCopyAction());
    actionMap.put(TransferHandler.getPasteAction().getValue(Action.NAME), TransferHandler.getPasteAction());
    actionMap.put(DeleteOperatorAction.getActionName(), new DeleteOperatorAction());

    // only required if you have not set the menu accelerators
    InputMap inputMap = component.getInputMap();
    inputMap.put(KeyStroke.getKeyStroke("ctrl X"), TransferHandler.getCutAction().getValue(Action.NAME));
    inputMap.put(KeyStroke.getKeyStroke("ctrl C"), TransferHandler.getCopyAction().getValue(Action.NAME));
    inputMap.put(KeyStroke.getKeyStroke("ctrl V"), TransferHandler.getPasteAction().getValue(Action.NAME));
    inputMap.put(KeyStroke.getKeyStroke("del"), DeleteOperatorAction.getActionName());
}
项目:rapidminer    文件:AbstractPatchedTransferHandler.java   
/**
 * 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
}
项目:rapidminer    文件:PlotConfigurationTree.java   
@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);
}
项目:jmt    文件:JmtGraphUI.java   
@Override
protected void installKeyboardActions() {
    super.installKeyboardActions();
    ActionMap am = SwingUtilities.getUIActionMap(graph);
    am.remove(TransferHandler.getCutAction().getValue(Action.NAME));
    am.remove(TransferHandler.getCopyAction().getValue(Action.NAME));
    am.remove(TransferHandler.getPasteAction().getValue(Action.NAME));
    SwingUtilities.replaceUIActionMap(graph, am);
}
项目:marathonv5    文件:DnDHandler.java   
public Boolean performInEQ() {
    if (!(source instanceof JComponent) || !(dest instanceof JComponent)) {
        return false;
    }
    try {
        Method m;
        TransferHandler th = ((JComponent) source).getTransferHandler();
        if (th == null) {
            return false;
        }
        m = getDeclaredMethod(th, "createTransferable", JComponent.class);
        transferable = (Transferable) m.invoke(th, source);
        if (transferable == null) {
            return false;
        }
        m = getDeclaredMethod(dest, "dropLocationForPoint", Point.class);
        Object dropLocation = m.invoke(dest, location);
        m = getDeclaredMethod(dest, "setDropLocation", TransferHandler.DropLocation.class, Object.class, Boolean.TYPE);
        m.invoke(dest, dropLocation, null, true);
        dest.getDropTarget().dragEnter(createDropTargetDragEvent());
        dest.getDropTarget().drop(createDropTargetDropEvent());
        m = getDeclaredMethod(th, "exportDone", JComponent.class, Transferable.class, Integer.TYPE);
        m.invoke(th, source, transferable, dropAction);
    } catch (Throwable t) {
        return false;
    }
    return true;
}
项目:marathonv5    文件:ListTransferHandler.java   
@Override public boolean canImport(TransferHandler.TransferSupport info) {
    // Check for String flavor
    if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) {
        return false;
    }
    return true;
}
项目:scorekeeperfrontend    文件:BracketPane.java   
@Override
public void mouseDragged(MouseEvent e) 
{
    JComponent c = (JComponent)e.getSource();
    TransferHandler th = c.getTransferHandler();
    th.exportAsDrag(c, e, TransferHandler.MOVE);
}
项目:marathonv5    文件:ListTransferHandler.java   
@Override public boolean importData(TransferHandler.TransferSupport info) {
    if (!info.isDrop()) {
        return false;
    }

    JList list = (JList) info.getComponent();
    DefaultListModel listModel = (DefaultListModel) list.getModel();
    JList.DropLocation dl = (JList.DropLocation) info.getDropLocation();
    int index = dl.getIndex();
    boolean insert = dl.isInsert();

    // Get the string that is being dropped.
    Transferable t = info.getTransferable();
    String data;
    try {
        data = (String) t.getTransferData(DataFlavor.stringFlavor);
    } catch (Exception e) {
        return false;
    }

    // Perform the actual import.
    if (insert) {
        listModel.add(index, data);
    } else {
        listModel.set(index, data);
    }
    return true;
}
项目:JAddOn    文件:TreeTransferHandler.java   
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;
}
项目:scorekeeperfrontend    文件:BracketPane.java   
/**
 * Returns true if data flavor is good and entrant isn't the same as the one dropping.
 * @param support DND support object
 * @return true if okay to drop
 */
@Override
public boolean canImport(TransferHandler.TransferSupport support)
{
    try 
    {
        EntrantLabel l = (EntrantLabel)support.getComponent();
        BracketEntry e = (BracketEntry) support.getTransferable().getTransferData(BracketEntry.Transfer.myFlavor);
        if (e.source == null)
            return true;
        if (l.entryId.round == e.source.round) // can't drag to same round
            return false;
        if (e.source.getDepth() < l.entryId.getDepth())  // can't drag backwards
            return false;
        if ((e.source.getDepth() - l.entryId.getDepth()) > 1) // can't go more than one forward
            return false;
        if (e.source.getDepth() == l.entryId.getDepth())
            support.setDropAction(LINK);
        else
            support.setDropAction(COPY);
        return true;
    } 
    catch (Exception ex) 
    { 
        return false; 
    }
}
项目:dead-code-detector    文件:ParametersPanel.java   
private void initTransferHandler() {
    setTransferHandler(controller.createFileTransferHandler());
    filesTable.setTransferHandler(getTransferHandler());
    final Action pasteAction = TransferHandler.getPasteAction();
    getInputMap().put(KeyStroke.getKeyStroke("ctrl V"), pasteAction.getValue(Action.NAME));
    getActionMap().put(pasteAction.getValue(Action.NAME), pasteAction);
}
项目:QN-ACTR-Release    文件:JmtGraphUI.java   
@Override
protected void installKeyboardActions() {
    super.installKeyboardActions();
    ActionMap am = SwingUtilities.getUIActionMap(graph);

    am.remove(TransferHandler.getCutAction().getValue(Action.NAME));
    am.remove(TransferHandler.getCopyAction().getValue(Action.NAME));
    am.remove(TransferHandler.getPasteAction().getValue(Action.NAME));

    SwingUtilities.replaceUIActionMap(graph, am);

}
项目:JavaGraph    文件:GraphEditorTab.java   
/**
 * Lazily creates and returns the action to cut graph elements in the
 * editor.
 */
private Action getCutAction() {
    if (this.cutAction == null) {
        Action action = TransferHandler.getCutAction();
        action.putValue(Action.ACCELERATOR_KEY, Options.CUT_KEY);
        this.cutAction = new TransferAction(action, Options.CUT_KEY, Options.CUT_ACTION_NAME);
        this.cutAction.putValue(Action.SMALL_ICON, Icons.CUT_ICON);
    }
    return this.cutAction;
}
项目:JavaGraph    文件:GraphEditorTab.java   
/**
 * Lazily creates and returns the action to copy graph elements in the
 * editor.
 */
private Action getCopyAction() {
    if (this.copyAction == null) {
        Action action = TransferHandler.getCopyAction();
        this.copyAction =
            new TransferAction(action, Options.COPY_KEY, Options.COPY_ACTION_NAME);
        this.copyAction.putValue(Action.SMALL_ICON, Icons.COPY_ICON);
    }
    return this.copyAction;
}
项目:JavaGraph    文件:GraphEditorTab.java   
/**
 * Lazily creates and returns the action to paste graph elements into the
 * editor.
 */
private Action getPasteAction() {
    if (this.pasteAction == null) {
        Action action = TransferHandler.getPasteAction();
        this.pasteAction =
            new TransferAction(action, Options.PASTE_KEY, Options.PASTE_ACTION_NAME);
        this.pasteAction.putValue(Action.SMALL_ICON, Icons.PASTE_ICON);
        this.pasteAction.setEnabled(true);
    }
    return this.pasteAction;
}
项目:Shellcode-IDE    文件:DragAndDrop.java   
@Override
public boolean canImport(TransferHandler.TransferSupport info) {
    if (!info.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
        return false;
    }
    return true;
}
项目:Shellcode-IDE    文件:DragAndDrop.java   
@SuppressWarnings("unchecked")
@Override
   public boolean importData(TransferHandler.TransferSupport info) {
       if (!info.isDrop()) {
           return false;
       }

       // Check for FileList flavor
       if (!info.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
           System.out.println("List doesn't accept a drop of this type.");
           return false;
       }

       // Get the fileList that is being dropped.
       Transferable t = info.getTransferable();
       List<File> data;
       try {
           data = (List<File>)t.getTransferData(DataFlavor.javaFileListFlavor);
       } 
       catch (Exception e) { return false; }

       if(data.size() > 1) {    // More than one file!
        main.ready = false;
        return false;
       }

       main.receiveFile(data.get(0));

       return true;
   }
项目:freecol    文件:DropListener.java   
/**
 * Gets called when the mouse was released on a Swing component
 * that has this object as a MouseListener.
 *
 * @param e The event that holds the information about the mouse click.
 */
@Override
public void mouseReleased(MouseEvent e) {
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    Transferable clipData = clipboard.getContents(clipboard);
    if (clipData != null) {
        if (clipData.isDataFlavorSupported(DefaultTransferHandler.flavor)) {
            JComponent comp = (JComponent)e.getSource();
            TransferHandler handler = comp.getTransferHandler();
            handler.importData(comp, clipData);
        }
    }
}