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;
}
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;
}
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;
}
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);
}
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);
}
Aggregations