Search in sources :

Example 31 with DropTarget

use of java.awt.dnd.DropTarget in project openchemlib by Actelion.

the class JDrawArea method initializeDragAndDrop.

private void initializeDragAndDrop(int dropAction) {
    if (dropAction != DnDConstants.ACTION_NONE) {
        MoleculeDropAdapter d = new MoleculeDropAdapter() {

            public void onDropMolecule(StereoMolecule m, Point pt) {
                if (m != null && m.getAllAtoms() != 0) {
                    for (int atom = 0; atom < mMol.getAllAtoms(); atom++) {
                        // deselect all current atoms
                        mMol.setAtomSelection(atom, false);
                    }
                    double avbl = mMol.getAverageBondLength();
                    double dropAVBL = m.getAverageBondLength();
                    m.scaleCoords(avbl / dropAVBL);
                    Point cog = new Point();
                    for (int atom = 0; atom < m.getAllAtoms(); atom++) {
                        // select all new atoms
                        m.setAtomSelection(atom, true);
                        cog.x += m.getAtomX(atom);
                        cog.y += m.getAtomY(atom);
                    }
                    cog.x /= m.getAllAtoms();
                    cog.y /= m.getAllAtoms();
                    m.translateCoords(pt.x - cog.x, pt.y - cog.y);
                    m.removeAtomColors();
                    m.removeBondHiliting();
                    mMol.addMolecule(m);
                    fireMoleculeChanged();
                    update(UPDATE_CHECK_COORDS);
                }
            }
        };
        new DropTarget(this, dropAction, d, true, new OurFlavorMap());
    }
}
Also used : MoleculeDropAdapter(com.actelion.research.gui.dnd.MoleculeDropAdapter) DropTarget(java.awt.dnd.DropTarget)

Example 32 with DropTarget

use of java.awt.dnd.DropTarget in project GCViewer by chewiebug.

the class TestGCModelLoaderController method dropOnDesktopPane.

/**
 * Test drag and drop action on GCViewerGui.
 */
@Test
public void dropOnDesktopPane() throws Exception {
    // TODO SWINGWORKER: test drag and drop on GCDocument
    assertThat("number of gcdocuments before", controller.getGCViewerGui().getDesktopPane().getAllFrames().length, is(0));
    List<File> fileList = new ArrayList<File>();
    fileList.add(new File(UnittestHelper.getResource(FOLDER.OPENJDK, "SampleSun1_6_0G1_MarkStackFull.txt").getPath()));
    Transferable tr = Mockito.mock(Transferable.class);
    Mockito.when(tr.getTransferData(DataFlavor.javaFileListFlavor)).thenReturn(fileList);
    DropTargetDropEvent dte = Mockito.mock(DropTargetDropEvent.class);
    Mockito.when(dte.isDataFlavorSupported(DataFlavor.javaFileListFlavor)).thenReturn(true);
    Mockito.when(dte.getTransferable()).thenReturn(tr);
    DropTarget target = controller.getGCViewerGui().getDesktopPane().getDropTarget();
    target.drop(dte);
    assertThat("number of gcdocuments after drop", controller.getGCViewerGui().getDesktopPane().getAllFrames().length, is(1));
}
Also used : ArrayList(java.util.ArrayList) Transferable(java.awt.datatransfer.Transferable) DropTarget(java.awt.dnd.DropTarget) File(java.io.File) GcResourceFile(com.tagtraum.perf.gcviewer.model.GcResourceFile) DropTargetDropEvent(java.awt.dnd.DropTargetDropEvent) Test(org.junit.Test)

Example 33 with DropTarget

use of java.awt.dnd.DropTarget in project bytecode-viewer by Konloch.

the class FileDrop method makeDropTarget.

// END 2007-09-12 Nathan Blomquist -- Linux (KDE/Gnome) support added.
private void makeDropTarget(final PrintStream out, final Component c, final boolean recursive) {
    // Make drop target
    final DropTarget dt = new DropTarget();
    try {
        dt.addDropTargetListener(dropListener);
    }// end try
     catch (final java.util.TooManyListenersException e) {
        BytecodeViewer.handleException(e);
        log(out, "FileDrop: Drop will not work due to previous error. Do you have another listener attached?");
    }
    // end catch
    // Listen for hierarchy changes and remove the drop target when the
    // parent gets cleared out.
    // end hierarchyChanged
    c.addHierarchyListener(evt -> {
        log(out, "FileDrop: Hierarchy changed.");
        final Component parent = c.getParent();
        if (parent == null) {
            c.setDropTarget(null);
            log(out, "FileDrop: Drop target cleared from component.");
        } else // end if: null parent
        {
            new DropTarget(c, dropListener);
            log(out, "FileDrop: Drop target added to component.");
        }
    // end else: parent not null
    });
    // end hierarchy listener
    if (c.getParent() != null) {
        new DropTarget(c, dropListener);
    }
    if (recursive && (c instanceof Container)) {
        // Get the container
        final Container cont = (Container) c;
        // Get its components
        final Component[] comps = cont.getComponents();
        // Set its components as listeners also
        for (Component comp : comps) {
            makeDropTarget(out, comp, true);
        }
    }
// end if: recursively set components as listener
}
Also used : Container(java.awt.Container) DropTarget(java.awt.dnd.DropTarget) JComponent(javax.swing.JComponent) Component(java.awt.Component)

Example 34 with DropTarget

use of java.awt.dnd.DropTarget in project GCViewer by chewiebug.

the class GCModelLoaderControllerImpl method openGCResource.

private void openGCResource(GCResource gcResource, GCModelLoader loader) {
    GCDocument document = new GCDocument(gcViewerGui.getPreferences(), gcResource.getResourceName());
    document.setDropTarget(new DropTarget(document, DnDConstants.ACTION_COPY, new FileDropTargetListener(this, DropFlavor.ADD)));
    document.addInternalFrameListener(new GCViewerGuiInternalFrameController());
    gcViewerGui.addDocument(document);
    GCDocumentController docController = new GCDocumentController(document);
    docController.addGCResource(loader, getViewMenuController());
    loader.execute();
}
Also used : GCDocument(com.tagtraum.perf.gcviewer.view.GCDocument) DropTarget(java.awt.dnd.DropTarget)

Example 35 with DropTarget

use of java.awt.dnd.DropTarget in project airavata by apache.

the class GraphCanvas method initGUI.

/**
 * Initializes the GUI.
 */
private void initGUI() {
    this.panel = new JPanel() {

        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            GraphCanvas.this.paintComponent((Graphics2D) g);
        }
    };
    this.panel.setLayout(null);
    // To make the background color visible.
    this.panel.setOpaque(true);
    this.panel.setBackground(new Color(255, 255, 255));
    this.panel.setDoubleBuffered(true);
    this.panel.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent event) {
            GraphCanvas.this.mouseClicked(event);
        }

        @Override
        public void mousePressed(MouseEvent event) {
            GraphCanvas.this.mousePressed(event);
        }

        @Override
        public void mouseReleased(MouseEvent event) {
            GraphCanvas.this.mouseReleased(event);
            notifyListeners(new GraphCanvasEvent(GraphCanvasEvent.GraphCanvasEventType.WORKFLOW_CHANGED, GraphCanvas.this, GraphCanvas.this.workflow));
        }
    });
    this.panel.addMouseMotionListener(new MouseMotionListener() {

        public void mouseDragged(MouseEvent event) {
            GraphCanvas.this.mouseDragged(event);
        }

        public void mouseMoved(MouseEvent event) {
            GraphCanvas.this.mouseMoved(event);
        }
    });
    this.panel.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent event) {
            GraphCanvas.this.keyPressed(event);
        }

        @Override
        public void keyReleased(KeyEvent event) {
            GraphCanvas.this.keyReleased(event);
        }
    });
    this.scrollPane = new JScrollPane(this.panel);
    // Set up drag and drop
    DropTargetListener dropTargetListener = new DropTargetAdapter() {

        public void drop(DropTargetDropEvent event) {
            GraphCanvas.this.drop(event);
        }
    };
    new DropTarget(this.panel, DnDConstants.ACTION_COPY_OR_MOVE, dropTargetListener);
    createPopupMenu();
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) MouseEvent(java.awt.event.MouseEvent) Color(java.awt.Color) KeyAdapter(java.awt.event.KeyAdapter) MouseAdapter(java.awt.event.MouseAdapter) MouseMotionListener(java.awt.event.MouseMotionListener) Graphics2D(java.awt.Graphics2D) Graphics(java.awt.Graphics) KeyEvent(java.awt.event.KeyEvent) DropTargetAdapter(java.awt.dnd.DropTargetAdapter) DropTargetListener(java.awt.dnd.DropTargetListener) DropTarget(java.awt.dnd.DropTarget) DropTargetDropEvent(java.awt.dnd.DropTargetDropEvent)

Aggregations

DropTarget (java.awt.dnd.DropTarget)39 DropTargetDropEvent (java.awt.dnd.DropTargetDropEvent)12 Component (java.awt.Component)9 DropTargetAdapter (java.awt.dnd.DropTargetAdapter)9 DropTargetDragEvent (java.awt.dnd.DropTargetDragEvent)9 Point (java.awt.Point)5 Container (java.awt.Container)4 DropTargetListener (java.awt.dnd.DropTargetListener)4 MouseEvent (java.awt.event.MouseEvent)4 IOException (java.io.IOException)4 JPanel (javax.swing.JPanel)4 JScrollPane (javax.swing.JScrollPane)4 EditorFragmentComponent (com.intellij.codeInsight.hint.EditorFragmentComponent)3 JBLayeredPane (com.intellij.ui.components.JBLayeredPane)3 Activatable (com.intellij.util.ui.update.Activatable)3 UiNotifyConnector (com.intellij.util.ui.update.UiNotifyConnector)3 Dimension (java.awt.Dimension)3 DropTargetContext (java.awt.dnd.DropTargetContext)3 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)2 DropTargetEvent (java.awt.dnd.DropTargetEvent)2