List of usage examples for javax.swing TransferHandler MOVE
int MOVE
To view the source code for javax.swing TransferHandler MOVE.
Click Source Link
int
representing a "move" transfer action. From source file:Main.java
@Override protected void exportDone(JComponent source, Transferable data, int action) { @SuppressWarnings("unchecked") JList<String> sourceList = (JList<String>) source; String movedItem = sourceList.getSelectedValue(); if (action == TransferHandler.MOVE) { DefaultListModel<String> listModel = (DefaultListModel<String>) sourceList.getModel(); listModel.removeElement(movedItem); }//from ww w. j a v a2s . com }
From source file:dnd.ChooseDropActionDemo.java
public ChooseDropActionDemo() { super("ChooseDropActionDemo"); for (int i = 15; i >= 0; i--) { from.add(0, "Source item " + i); }//from w ww . j a va2s. co m for (int i = 2; i >= 0; i--) { copy.add(0, "Target item " + i); move.add(0, "Target item " + i); } JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); dragFrom = new JList(from); dragFrom.setTransferHandler(new FromTransferHandler()); dragFrom.setPrototypeCellValue("List Item WWWWWW"); dragFrom.setDragEnabled(true); dragFrom.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JLabel label = new JLabel("Drag from here:"); label.setAlignmentX(0f); p.add(label); JScrollPane sp = new JScrollPane(dragFrom); sp.setAlignmentX(0f); p.add(sp); add(p, BorderLayout.WEST); JList moveTo = new JList(move); moveTo.setTransferHandler(new ToTransferHandler(TransferHandler.COPY)); moveTo.setDropMode(DropMode.INSERT); JList copyTo = new JList(copy); copyTo.setTransferHandler(new ToTransferHandler(TransferHandler.MOVE)); copyTo.setDropMode(DropMode.INSERT); p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); label = new JLabel("Drop to COPY to here:"); label.setAlignmentX(0f); p.add(label); sp = new JScrollPane(moveTo); sp.setAlignmentX(0f); p.add(sp); label = new JLabel("Drop to MOVE to here:"); label.setAlignmentX(0f); p.add(label); sp = new JScrollPane(copyTo); sp.setAlignmentX(0f); p.add(sp); p.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 0)); add(p, BorderLayout.CENTER); ((JPanel) getContentPane()).setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); getContentPane().setPreferredSize(new Dimension(320, 315)); }
From source file:ChooseDropActionDemo.java
public ChooseDropActionDemo() { super("ChooseDropActionDemo"); for (int i = 15; i >= 0; i--) { from.add(0, "Source item " + i); }/*w ww. j ava 2 s . c o m*/ for (int i = 2; i >= 0; i--) { copy.add(0, "Target item " + i); move.add(0, "Target item " + i); } JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); dragFrom = new JList(from); dragFrom.setTransferHandler(new FromTransferHandler()); dragFrom.setPrototypeCellValue("List Item WWWWWW"); dragFrom.setDragEnabled(true); dragFrom.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JLabel label = new JLabel("Drag from here:"); label.setAlignmentX(0f); p.add(label); JScrollPane sp = new JScrollPane(dragFrom); sp.setAlignmentX(0f); p.add(sp); add(p, BorderLayout.WEST); JList moveTo = new JList(move); moveTo.setTransferHandler(new ToTransferHandler(TransferHandler.COPY)); moveTo.setDropMode(DropMode.INSERT); JList copyTo = new JList(copy); copyTo.setTransferHandler(new ToTransferHandler(TransferHandler.MOVE)); copyTo.setDropMode(DropMode.INSERT); p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); label = new JLabel("Drop to COPY to here:"); ; label.setAlignmentX(0f); p.add(label); sp = new JScrollPane(moveTo); sp.setAlignmentX(0f); p.add(sp); label = new JLabel("Drop to MOVE to here:"); label.setAlignmentX(0f); p.add(label); sp = new JScrollPane(copyTo); sp.setAlignmentX(0f); p.add(sp); p.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 0)); add(p, BorderLayout.CENTER); ((JPanel) getContentPane()).setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); getContentPane().setPreferredSize(new Dimension(320, 315)); }
From source file:io.neocdtv.simpleplayer.ui.PlaylistTransferHandler.java
@Override protected void exportDone(JComponent c, Transferable data, int action) { cleanup(c, action == TransferHandler.MOVE); }
From source file:com.projity.pm.graphic.spreadsheet.common.transfer.NodeListTransferHandler.java
protected Transferable createTransferable(JComponent c, int action) { SpreadSheet spreadSheet = getSpreadSheet(c); if (spreadSheet == null) return null; ArrayList nodes = (ArrayList) spreadSheet.getSelectedNodes().clone(); ArrayList fields = spreadSheet.getSelectedFields(); boolean nodeSelection = (fields == null); if (fields == null) fields = spreadSheet.getSelectableFields(); if (action == TransferHandler.COPY) { if (nodeSelection) { SpreadSheet.SpreadSheetAction a = getNodeListCopyAction().getSpreadSheetAction(); a.execute(nodes);/*from w w w . jav a 2 s . com*/ } return new NodeListTransferable(nodes, fields, spreadSheet, spreadSheet.getSelectedRows(), spreadSheet.getSelectedColumns(), nodeSelection); } else if (action == TransferHandler.MOVE) {//cut if (nodeSelection) { SpreadSheet.SpreadSheetAction a = ((nodeSelection) ? getNodeListCutAction() : getNodeListCopyAction()).getSpreadSheetAction(); for (Iterator i = nodes.iterator(); i.hasNext();) { Node node = (Node) i.next(); final boolean[] okForAll = new boolean[] { false }; if (!transformSubprojectBranches(node, spreadSheet.getCache().getModel().getDataFactory(), new Predicate() { public boolean evaluate(Object arg0) { if (okForAll[0]) return true; Node parent = (Node) arg0; boolean r = Alert.okCancel(Messages.getString("Message.subprojectCut")); if (r) okForAll[0] = true; return r; } })) return null; } a.execute(nodes); } return new NodeListTransferable(nodes, fields, spreadSheet, spreadSheet.getSelectedRows(), spreadSheet.getSelectedColumns(), nodeSelection); } else return null; }
From source file:DropDemo.java
protected void exportDone(JComponent c, Transferable data, int action) { cleanup(c, action == TransferHandler.MOVE); }
From source file:DragPictureDemo2.java
public void mouseDragged(MouseEvent e) { //Don't bother to drag if the component displays no image. if (image == null) return;//w w w . j a va 2 s .c o m if (firstMouseEvent != null) { e.consume(); //If they are holding down the control key, COPY rather than MOVE int ctrlMask = InputEvent.CTRL_DOWN_MASK; int action = ((e.getModifiersEx() & ctrlMask) == ctrlMask) ? TransferHandler.COPY : TransferHandler.MOVE; int dx = Math.abs(e.getX() - firstMouseEvent.getX()); int dy = Math.abs(e.getY() - firstMouseEvent.getY()); //Arbitrarily define a 5-pixel shift as the //official beginning of a drag. if (dx > 5 || dy > 5) { //This is a drag, not a click. JComponent c = (JComponent) e.getSource(); TransferHandler handler = c.getTransferHandler(); //Tell the transfer handler to initiate the drag. handler.exportAsDrag(c, firstMouseEvent, action); firstMouseEvent = null; } } }
From source file:org.photovault.swingui.PhotoCollectionThumbView.java
protected void handleDnDDragEvent(MouseEvent e) { //Don't bother to drag if no photo is selected if (selection.isEmpty()) { return;// w ww.j av a2s. com } if (firstMouseEvent != null) { log.debug("considering drag"); e.consume(); //If they are holding down the control key, COPY rather than MOVE int ctrlMask = InputEvent.CTRL_DOWN_MASK; int action = e.isControlDown() ? TransferHandler.COPY : TransferHandler.MOVE; int dx = Math.abs(e.getX() - firstMouseEvent.getX()); int dy = Math.abs(e.getY() - firstMouseEvent.getY()); //Arbitrarily define a 5-pixel shift as the //official beginning of a drag. if (dx > 5 || dy > 5) { log.debug("Start a drag"); //This is a drag, not a click. JComponent c = (JComponent) e.getSource(); //Tell the transfer handler to initiate the drag. TransferHandler handler = c.getTransferHandler(); handler.exportAsDrag(c, firstMouseEvent, action); firstMouseEvent = null; } } }