Search in sources :

Example 16 with DropTargetDropEvent

use of java.awt.dnd.DropTargetDropEvent 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 17 with DropTargetDropEvent

use of java.awt.dnd.DropTargetDropEvent 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)

Example 18 with DropTargetDropEvent

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

the class MModeWorkspaceController method setupController.

private void setupController(ModeController modeController) {
    modeController.removeExtension(UrlManager.class);
    UrlManager.install(new MModeWorkspaceUrlManager());
    modeController.removeExtension(LinkController.class);
    LinkController.install(MModeWorkspaceLinkController.getController());
    // add link type entry to the chooser
    MModeWorkspaceLinkController.getController().prepareOptionPanelBuilder(((MModeController) modeController).getOptionPanelBuilder());
    modeController.addINodeViewLifeCycleListener(new INodeViewLifeCycleListener() {

        public void onViewCreated(Container nodeView) {
            NodeView node = (NodeView) nodeView;
            final DropTarget dropTarget = new DropTarget(node.getMainView(), new MNodeDropListener() {

                public void drop(final DropTargetDropEvent dtde) {
                    DropTargetDropEvent evt = dtde;
                    if (dtde.getTransferable().isDataFlavorSupported(WorkspaceTransferable.WORKSPACE_NODE_FLAVOR)) {
                        evt = new DropTargetDropEvent(dtde.getDropTargetContext(), dtde.getLocation(), dtde.getDropAction(), dtde.getSourceActions(), false);
                    }
                    super.drop(evt);
                }
            });
            dropTarget.setActive(true);
        }

        public void onViewRemoved(Container nodeView) {
        }
    });
    modeController.addMenuContributor(new IMenuContributor() {

        public void updateMenus(ModeController modeController, MenuBuilder builder) {
            final String MENU_PROJECT_KEY = "/menu_bar/project";
            // insert project menu into main menu
            JMenu projectMenu = new JMenu(TextUtils.getText("menu.project.entry.label"));
            projectMenu.setMnemonic('o');
            builder.addMenuItem("/menu_bar/format", projectMenu, MENU_PROJECT_KEY, MenuBuilder.AFTER);
            builder.addAction(MENU_PROJECT_KEY, WorkspaceController.getAction(WorkspaceNewProjectAction.KEY), MenuBuilder.AS_CHILD);
            builder.addAction(MENU_PROJECT_KEY, WorkspaceController.getAction(WorkspaceImportProjectAction.KEY), MenuBuilder.AS_CHILD);
            builder.addSeparator(MENU_PROJECT_KEY, MenuBuilder.AS_CHILD);
            final String MENU_PROJECT_ADD_KEY = builder.getMenuKey(MENU_PROJECT_KEY, "new");
            final JMenu addMenu = new JMenu(TextUtils.getText("workspace.action.new.label"));
            builder.addMenuItem(MENU_PROJECT_KEY, addMenu, MENU_PROJECT_ADD_KEY, MenuBuilder.AS_CHILD);
            builder.addAction(MENU_PROJECT_ADD_KEY, new NodeNewFolderAction(), MenuBuilder.AS_CHILD);
            builder.addAction(MENU_PROJECT_ADD_KEY, new NodeNewLinkAction(), MenuBuilder.AS_CHILD);
            final WorkspaceRemoveProjectAction rmProjectAction = new WorkspaceRemoveProjectAction();
            builder.addAction(MENU_PROJECT_KEY, rmProjectAction, MenuBuilder.AS_CHILD);
            builder.addSeparator(MENU_PROJECT_KEY, MenuBuilder.AS_CHILD);
            setDefaultAccelerator(builder.getShortcutKey(builder.getMenuKey(MENU_PROJECT_KEY, WorkspaceProjectOpenLocationAction.KEY)), "control alt L");
            final WorkspaceProjectOpenLocationAction openLocAction = new WorkspaceProjectOpenLocationAction();
            builder.addAction(MENU_PROJECT_KEY, openLocAction, MenuBuilder.AS_CHILD);
            projectMenu.getPopupMenu().addPopupMenuListener(new PopupMenuListener() {

                public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
                    rmProjectAction.setEnabled();
                    openLocAction.setEnabled();
                    if (WorkspaceController.getCurrentProject() == null) {
                        addMenu.setEnabled(false);
                    } else {
                        addMenu.setEnabled(true);
                    }
                }

                public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
                }

                public void popupMenuCanceled(PopupMenuEvent e) {
                }
            });
        }

        private void setDefaultAccelerator(final String shortcutKey, String accelerator) {
            if (accelerator != null) {
                if (null == ResourceController.getResourceController().getProperty(shortcutKey, null)) {
                    if (Compat.isMacOsX()) {
                        accelerator = accelerator.replaceFirst("CONTROL", "META").replaceFirst("control", "meta");
                    }
                    ResourceController.getResourceController().setDefaultProperty(shortcutKey, accelerator);
                }
            }
        }
    });
}
Also used : PopupMenuListener(javax.swing.event.PopupMenuListener) ModeController(org.freeplane.features.mode.ModeController) MModeController(org.freeplane.features.mode.mindmapmode.MModeController) NodeView(org.freeplane.view.swing.map.NodeView) MenuBuilder(org.freeplane.core.ui.MenuBuilder) PopupMenuEvent(javax.swing.event.PopupMenuEvent) INodeViewLifeCycleListener(org.freeplane.features.ui.INodeViewLifeCycleListener) Container(java.awt.Container) IMenuContributor(org.freeplane.core.ui.IMenuContributor) NodeNewFolderAction(org.freeplane.plugin.workspace.actions.NodeNewFolderAction) NodeNewLinkAction(org.freeplane.plugin.workspace.actions.NodeNewLinkAction) MNodeDropListener(org.freeplane.view.swing.ui.mindmapmode.MNodeDropListener) WorkspaceRemoveProjectAction(org.freeplane.plugin.workspace.actions.WorkspaceRemoveProjectAction) DropTarget(java.awt.dnd.DropTarget) WorkspaceProjectOpenLocationAction(org.freeplane.plugin.workspace.actions.WorkspaceProjectOpenLocationAction) DropTargetDropEvent(java.awt.dnd.DropTargetDropEvent) JMenu(javax.swing.JMenu)

Aggregations

DropTargetDropEvent (java.awt.dnd.DropTargetDropEvent)18 DropTarget (java.awt.dnd.DropTarget)12 DropTargetAdapter (java.awt.dnd.DropTargetAdapter)10 DropTargetDragEvent (java.awt.dnd.DropTargetDragEvent)10 DropTargetListener (java.awt.dnd.DropTargetListener)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 DropTargetContext (java.awt.dnd.DropTargetContext)3 JPanel (javax.swing.JPanel)3 Color (java.awt.Color)2 Component (java.awt.Component)2 Point (java.awt.Point)2 DataFlavor (java.awt.datatransfer.DataFlavor)2 Transferable (java.awt.datatransfer.Transferable)2 DropTargetEvent (java.awt.dnd.DropTargetEvent)2 MouseAdapter (java.awt.event.MouseAdapter)2 MouseEvent (java.awt.event.MouseEvent)2 DropTargetDragEventBuilder (com.android.tools.idea.uibuilder.fixtures.DropTargetDragEventBuilder)1