Search in sources :

Example 1 with DragSource

use of java.awt.dnd.DragSource in project jna by java-native-access.

the class DragHandler method dragDropEnd.

public void dragDropEnd(DragSourceDropEvent e) {
    describe("end", e);
    setModifiers(UNKNOWN_MODIFIERS);
    transferable = UNKNOWN_TRANSFERABLE;
    if (ghost != null) {
        if (e.getDropSuccess()) {
            ghost.dispose();
        } else {
            ghost.returnToOrigin();
        }
        ghost = null;
    }
    DragSource src = e.getDragSourceContext().getDragSource();
    src.removeDragSourceMotionListener(this);
    moved = false;
}
Also used : DragSource(java.awt.dnd.DragSource)

Example 2 with DragSource

use of java.awt.dnd.DragSource in project JMRI by JMRI.

the class DragJLabel method init.

private void init(DataFlavor flavor) {
    DragSource dragSource = DragSource.getDefaultDragSource();
    dragSource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY, this);
    _dataFlavor = flavor;
}
Also used : DragSource(java.awt.dnd.DragSource)

Example 3 with DragSource

use of java.awt.dnd.DragSource in project keystore-explorer by kaikramer.

the class KseFrame method createEmptyKeyStoreTable.

private JTable createEmptyKeyStoreTable() {
    KeyStoreTableModel ksModel = new KeyStoreTableModel();
    final JTable jtKeyStore = new JKseTable(ksModel);
    RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(ksModel);
    jtKeyStore.setRowSorter(sorter);
    jtKeyStore.setShowGrid(false);
    jtKeyStore.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    jtKeyStore.getTableHeader().setReorderingAllowed(false);
    jtKeyStore.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    // min. height of 18 because of 16x16 icons
    jtKeyStore.setRowHeight(Math.max(18, jtKeyStore.getRowHeight()));
    // Register cut, copy and paste actions with the relevant keystrokes
    jtKeyStore.getInputMap().put((KeyStroke) cutAction.getValue(Action.ACCELERATOR_KEY), CUT_KEY);
    jtKeyStore.getActionMap().put(CUT_KEY, cutAction);
    jtKeyStore.getInputMap().put((KeyStroke) copyAction.getValue(Action.ACCELERATOR_KEY), COPY_KEY);
    jtKeyStore.getActionMap().put(COPY_KEY, copyAction);
    jtKeyStore.getInputMap().put((KeyStroke) pasteAction.getValue(Action.ACCELERATOR_KEY), PASTE_KEY);
    jtKeyStore.getActionMap().put(PASTE_KEY, pasteAction);
    // open keystore entry details when user presses enter key
    KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
    jtKeyStore.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(enter, "Enter");
    jtKeyStore.getActionMap().put("Enter", new AbstractAction() {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent ae) {
            try {
                int selectedRow = jtKeyStore.getSelectedRow();
                if (selectedRow != -1) {
                    CursorUtil.setCursorBusy(frame);
                    showSelectedEntryDetails(jtKeyStore, selectedRow);
                }
            } finally {
                CursorUtil.setCursorFree(frame);
            }
        }
    });
    // Add DnD source support to KeyStore
    DragSource ds = DragSource.getDefaultDragSource();
    ds.createDefaultDragGestureRecognizer(jtKeyStore, DnDConstants.ACTION_MOVE, new KeyStoreEntryDragGestureListener(this));
    // Add custom renderers for headers and cells
    for (int i = 0; i < jtKeyStore.getColumnCount(); i++) {
        TableColumn column = jtKeyStore.getColumnModel().getColumn(i);
        column.setHeaderRenderer(new KeyStoreTableHeadRend(jtKeyStore.getTableHeader().getDefaultRenderer()));
        column.setCellRenderer(new KeyStoreTableCellRend());
    }
    // Make the first three columns small and not resizable as they hold icons
    TableColumn typeCol = jtKeyStore.getColumnModel().getColumn(0);
    typeCol.setResizable(false);
    typeCol.setMinWidth(28);
    typeCol.setMaxWidth(28);
    typeCol.setPreferredWidth(28);
    TableColumn statusCol = jtKeyStore.getColumnModel().getColumn(1);
    statusCol.setResizable(false);
    statusCol.setMinWidth(28);
    statusCol.setMaxWidth(28);
    statusCol.setPreferredWidth(28);
    TableColumn certExpiredCol = jtKeyStore.getColumnModel().getColumn(2);
    certExpiredCol.setResizable(false);
    certExpiredCol.setMinWidth(28);
    certExpiredCol.setMaxWidth(28);
    certExpiredCol.setPreferredWidth(28);
    jtKeyStore.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent evt) {
            maybeShowSelectedEntryDetails(evt);
        }

        @Override
        public void mousePressed(MouseEvent evt) {
            maybeShowSelectedEntryPopupMenu(evt);
        }

        @Override
        public void mouseReleased(MouseEvent evt) {
            maybeShowSelectedEntryPopupMenu(evt);
        }
    });
    jtKeyStore.addKeyListener(new KeyAdapter() {

        boolean deleteLastPressed = false;

        @Override
        public void keyPressed(KeyEvent evt) {
            // Record delete pressed on non-Macs
            if (!OperatingSystem.isMacOs()) {
                deleteLastPressed = evt.getKeyCode() == KeyEvent.VK_DELETE;
            }
        }

        @Override
        public void keyReleased(KeyEvent evt) {
            // Delete on non-Mac if delete was pressed and is now released
            if (!OperatingSystem.isMacOs() && deleteLastPressed && evt.getKeyCode() == KeyEvent.VK_DELETE) {
                deleteLastPressed = false;
                handleDeleteSelectedEntry();
            }
        }

        @Override
        public void keyTyped(KeyEvent evt) {
            // Delete on Mac if back space typed
            if (OperatingSystem.isMacOs() && evt.getKeyChar() == 0x08) {
                handleDeleteSelectedEntry();
            }
        }
    });
    return jtKeyStore;
}
Also used : MouseEvent(java.awt.event.MouseEvent) ActionEvent(java.awt.event.ActionEvent) KeyAdapter(java.awt.event.KeyAdapter) MouseAdapter(java.awt.event.MouseAdapter) DragSource(java.awt.dnd.DragSource) TableColumn(javax.swing.table.TableColumn) Point(java.awt.Point) KeyEvent(java.awt.event.KeyEvent) KeyStoreEntryDragGestureListener(org.kse.gui.dnd.KeyStoreEntryDragGestureListener) JTable(javax.swing.JTable) KeyStroke(javax.swing.KeyStroke) AbstractAction(javax.swing.AbstractAction) TableModel(javax.swing.table.TableModel) TableRowSorter(javax.swing.table.TableRowSorter)

Example 4 with DragSource

use of java.awt.dnd.DragSource in project freeplane by freeplane.

the class NodeView method addDragListener.

void addDragListener(final DragGestureListener dgl) {
    if (dgl == null) {
        return;
    }
    final DragSource dragSource = DragSource.getDefaultDragSource();
    dragSource.createDefaultDragGestureRecognizer(getMainView(), DnDConstants.ACTION_COPY | DnDConstants.ACTION_MOVE | DnDConstants.ACTION_LINK, dgl);
}
Also used : DragSource(java.awt.dnd.DragSource)

Example 5 with DragSource

use of java.awt.dnd.DragSource in project WorldPainter by Captain-Chaos.

the class DnDToggleButton method init.

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);
}
Also used : JComponent(javax.swing.JComponent) Transferable(java.awt.datatransfer.Transferable) TransferHandler(javax.swing.TransferHandler) DragSource(java.awt.dnd.DragSource)

Aggregations

DragSource (java.awt.dnd.DragSource)10 MouseEvent (java.awt.event.MouseEvent)5 Point (java.awt.Point)4 DragGestureEvent (java.awt.dnd.DragGestureEvent)3 MouseAdapter (java.awt.event.MouseAdapter)3 DragGestureListener (java.awt.dnd.DragGestureListener)2 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)2 TreeSelectionListener (javax.swing.event.TreeSelectionListener)2 TreePath (javax.swing.tree.TreePath)2 com.mxgraph.model.mxGeometry (com.mxgraph.model.mxGeometry)1 com.mxgraph.swing.util.mxGraphTransferable (com.mxgraph.swing.util.mxGraphTransferable)1 com.mxgraph.util.mxPoint (com.mxgraph.util.mxPoint)1 com.mxgraph.util.mxRectangle (com.mxgraph.util.mxRectangle)1 ParameterSetList (gov.sandia.umf.platform.ensemble.params.ParameterSetList)1 FilterableParameterTreePanel (gov.sandia.umf.platform.ui.ensemble.tree.FilterableParameterTreePanel)1 NodeSubdomain (gov.sandia.umf.platform.ui.ensemble.tree.NodeSubdomain)1 ParameterTree (gov.sandia.umf.platform.ui.ensemble.tree.ParameterTree)1 Button (java.awt.Button)1 Component (java.awt.Component)1 Cursor (java.awt.Cursor)1