List of usage examples for java.awt.dnd DnDConstants ACTION_COPY_OR_MOVE
int ACTION_COPY_OR_MOVE
To view the source code for java.awt.dnd DnDConstants ACTION_COPY_OR_MOVE.
Click Source Link
From source file:com.mirth.connect.client.ui.editors.JavaScriptEditorDialog.java
public void drop(DropTargetDropEvent dtde) { try {//ww w. j a v a2 s .c o m Transferable tr = dtde.getTransferable(); if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); java.util.List fileList = (java.util.List) tr.getTransferData(DataFlavor.javaFileListFlavor); Iterator iterator = fileList.iterator(); while (iterator.hasNext()) { File file = (File) iterator.next(); scriptContent.setText( scriptContent.getText() + FileUtils.readFileToString(file, UIConstants.CHARSET)); } } } catch (Exception e) { dtde.rejectDrop(); } }
From source file:it.unibas.spicygui.vista.ProjectTreeTopComponent.java
private void myInitComponents() { this.setLayout(new BorderLayout()); this.scrollPane = new JScrollPane(); scrollPane.setPreferredSize(new DimensionUIResource(100, this.getHeight())); this.setPreferredSize(new Dimension(100, this.getHeight())); this.jTree = new JTree(null, false); new TreeDragSource(jTree, DnDConstants.ACTION_COPY_OR_MOVE); this.jTree.setDragEnabled(true); // new TreeDropTarget(tree); this.scrollPane.setViewportView(jTree); this.add(this.scrollPane, BorderLayout.CENTER); }
From source file:EditorDropTarget2.java
protected boolean acceptOrRejectDrag(DropTargetDragEvent dtde) { int dropAction = dtde.getDropAction(); int sourceActions = dtde.getSourceActions(); boolean acceptedDrag = false; DnDUtils.debugPrintln("\tSource actions are " + DnDUtils.showActions(sourceActions) + ", drop action is " + DnDUtils.showActions(dropAction)); // Reject if the object being transferred // or the operations available are not acceptable if (!acceptableType || (sourceActions & DnDConstants.ACTION_COPY_OR_MOVE) == 0) { DnDUtils.debugPrintln("Drop target rejecting drag"); dtde.rejectDrag();/*from ww w. j a va 2s. c o m*/ } else if (!draggingFile && !pane.isEditable()) { // Can't drag text to a read-only JEditorPane DnDUtils.debugPrintln("Drop target rejecting drag"); dtde.rejectDrag(); } else if ((dropAction & DnDConstants.ACTION_COPY_OR_MOVE) == 0) { // Not offering copy or move - suggest a copy DnDUtils.debugPrintln("Drop target offering COPY"); dtde.acceptDrag(DnDConstants.ACTION_COPY); acceptedDrag = true; } else { // Offering an acceptable operation: accept DnDUtils.debugPrintln("Drop target accepting drag"); dtde.acceptDrag(dropAction); acceptedDrag = true; } return acceptedDrag; }
From source file:TransferableScribblePane.java
public TransferableScribblePane() { setPreferredSize(new Dimension(450, 200)); // We need a default size setBorder(normalBorder); // and a border. lines = new ArrayList(); // Start with an empty list of lines // Register interest in mouse button and mouse motion events. enableEvents(AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK); // Enable drag-and-drop by specifying a listener that will be // notified when a drag begins. dragGestureListener is defined later. DragSource dragSource = DragSource.getDefaultDragSource(); dragSource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY_OR_MOVE, dragGestureListener); // Enable drops on this component by registering a listener to // be notified when something is dragged or dropped over us. this.setDropTarget(new DropTarget(this, dropTargetListener)); // Check whether the system allows us to drag an image of the line canDragImage = dragSource.isDragImageSupported(); }
From source file:ScribbleDragAndDrop.java
/** The constructor: set up drag-and-drop stuff */ public ScribbleDragAndDrop() { // Give ourselves a nice default border. // We'll change this border during drag-and-drop. setBorder(normalBorder);//w w w . j av a 2 s. com // Register listeners to handle drawing addMouseListener(this); addMouseMotionListener(this); // Create a DragSource and DragGestureRecognizer to listen for drags // The DragGestureRecognizer will notify the DragGestureListener // when the user tries to drag an object dragSource = DragSource.getDefaultDragSource(); dragSource.createDefaultDragGestureRecognizer(this, // What component DnDConstants.ACTION_COPY_OR_MOVE, // What drag types? this);// the listener // Create and set up a DropTarget that will listen for drags and // drops over this component, and will notify the DropTargetListener DropTarget dropTarget = new DropTarget(this, // component to monitor this); // listener to notify this.setDropTarget(dropTarget); // Tell the component about it. }
From source file:com.mirth.connect.client.ui.TemplatePanel.java
public void dragEnter(DropTargetDragEvent dtde) { try {/*w w w.ja v a 2 s . c om*/ Transferable tr = dtde.getTransferable(); if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE); List<File> fileList = (List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor); Iterator<File> iterator = fileList.iterator(); while (iterator.hasNext()) { iterator.next(); } } else { dtde.rejectDrag(); } } catch (Exception e) { dtde.rejectDrag(); } }
From source file:ColorSink.java
/** This method is invoked when the user drops something on us */ public void drop(DropTargetDropEvent e) { this.setBorder(null); // Restore the default border Transferable t = e.getTransferable(); // Get the data that was dropped // Check for types of data that we support if (t.isDataFlavorSupported(TransferableColor.colorFlavor)) { // If it was a color, accept it, and use it as the background color e.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); try {// w w w .j a va2 s . c o m Color c = (Color) t.getTransferData(TransferableColor.colorFlavor); this.setBackground(c); e.dropComplete(true); } catch (Exception ex) { e.dropComplete(false); } } else if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { // If it was a file list, accept it, read the first file in the list // and display the file contents e.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); try { List files = (List) t.getTransferData(DataFlavor.javaFileListFlavor); File f = (File) files.get(0); BufferedReader in = new BufferedReader(new FileReader(f)); String s; this.setText(""); while ((s = in.readLine()) != null) this.append(s); e.dropComplete(true); } catch (Exception ex) { e.dropComplete(false); } } else { // If it wasn't a color or a file list, reject it. e.rejectDrop(); return; } }
From source file:com.mirth.connect.client.ui.TemplatePanel.java
public void drop(DropTargetDropEvent dtde) { try {//from ww w. j av a 2s . c o m Transferable tr = dtde.getTransferable(); if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); File file = ((List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor)).get(0); String dataType = PlatformUI.MIRTH_FRAME.displayNameToDataType.get(getDataType()); DataTypeClientPlugin dataTypePlugin = LoadedExtensions.getInstance().getDataTypePlugins() .get(dataType); if (dataTypePlugin.isBinary()) { byte[] content = FileUtils.readFileToByteArray(file); // The plugin should decide how to convert the byte array to string pasteBox.setText(dataTypePlugin.getTemplateString(content)); } else { pasteBox.setText(FileUtils.readFileToString(file, UIConstants.CHARSET)); } parent.modified = true; } } catch (Exception e) { dtde.rejectDrop(); } }
From source file:PanelDropTarget.java
public static String showActions(int action) { String actions = ""; if ((action & (DnDConstants.ACTION_LINK | DnDConstants.ACTION_COPY_OR_MOVE)) == 0) { return "None"; }//ww w. j av a2s . c om if ((action & DnDConstants.ACTION_COPY) != 0) { actions += "Copy "; } if ((action & DnDConstants.ACTION_MOVE) != 0) { actions += "Move "; } if ((action & DnDConstants.ACTION_LINK) != 0) { actions += "Link"; } return actions; }
From source file:com.eviware.soapui.impl.wsdl.panels.teststeps.support.PropertyHolderTable.java
public PropertyHolderTable(TestPropertyHolder holder) { super(new BorderLayout()); this.holder = holder; loadPropertiesAction = new LoadPropertiesAction(); JScrollPane scrollPane = new JScrollPane(buildPropertiesTable()); if (getHolder().getModelItem() != null) { DropTarget dropTarget = new DropTarget(scrollPane, new PropertyHolderTablePropertyExpansionDropTarget()); dropTarget.setDefaultActions(DnDConstants.ACTION_COPY_OR_MOVE); }//from w ww. jav a 2 s . c o m add(scrollPane, BorderLayout.CENTER); add(buildToolbar(), BorderLayout.NORTH); projectListener = new ProjectListenerAdapter() { public void environmentSwitched(Environment environment) { getPropertiesModel().fireTableDataChanged(); } }; }