Search in sources :

Example 1 with ControllerPopupMenuListener

use of org.freeplane.core.ui.ControllerPopupMenuListener in project freeplane by freeplane.

the class DefaultMapMouseListener method handlePopup.

protected void handlePopup(final MouseEvent e) {
    if (e.isPopupTrigger()) {
        Component popup = null;
        final Component popupForModel;
        final MapView mapView = (MapView) Controller.getCurrentController().getMapViewManager().getMapViewComponent();
        final ModeController modeController = Controller.getCurrentController().getModeController();
        if (mapView != null) {
            final java.lang.Object obj = mapView.detectCollision(e.getPoint());
            popupForModel = LinkController.getController(modeController).getPopupForModel(obj);
        } else {
            popupForModel = null;
        }
        if (popupForModel != null) {
            final ControllerPopupMenuListener popupListener = new ControllerPopupMenuListener();
            popupForModel.addHierarchyListener(popupListener);
            popup = popupForModel;
        } else {
            popup = modeController.getUserInputListenerFactory().getMapPopup();
        }
        Component component = e.getComponent();
        if (popup instanceof JPopupMenu) {
            ((JPopupMenu) popup).show(component, e.getX(), e.getY());
        } else {
            Point locationOnScreen = component.getLocationOnScreen();
            final Component window;
            if (popup instanceof Window) {
                window = popup;
            } else {
                final Frame frame = UITools.getFrame();
                final JDialog d = new JDialog(frame, popup.getName());
                d.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
                d.setModal(false);
                d.add(popup);
                d.pack();
                d.addWindowFocusListener(new WindowFocusListener() {

                    public void windowLostFocus(WindowEvent e) {
                    }

                    public void windowGainedFocus(WindowEvent e) {
                        frame.addWindowFocusListener(new WindowFocusListener() {

                            public void windowLostFocus(WindowEvent e) {
                            }

                            public void windowGainedFocus(WindowEvent e) {
                                d.setVisible(false);
                                frame.removeWindowFocusListener(this);
                            }
                        });
                        d.removeWindowFocusListener(this);
                    }
                });
                window = d;
            }
            window.setLocation(locationOnScreen.x + e.getX(), locationOnScreen.y + e.getY());
            window.setVisible(true);
        }
    }
}
Also used : Window(java.awt.Window) Frame(java.awt.Frame) ModeController(org.freeplane.features.mode.ModeController) Point(java.awt.Point) JPopupMenu(javax.swing.JPopupMenu) ControllerPopupMenuListener(org.freeplane.core.ui.ControllerPopupMenuListener) WindowEvent(java.awt.event.WindowEvent) MapView(org.freeplane.view.swing.map.MapView) JComponent(javax.swing.JComponent) Component(java.awt.Component) JDialog(javax.swing.JDialog) WindowFocusListener(java.awt.event.WindowFocusListener)

Example 2 with ControllerPopupMenuListener

use of org.freeplane.core.ui.ControllerPopupMenuListener in project freeplane by freeplane.

the class DefaultNodeKeyListener method keyPressed.

public void keyPressed(final KeyEvent e) {
    final boolean checkForScrollMap = e.isShiftDown() && e.isControlDown() && e.isAltDown();
    final MapView mapView = (MapView) Controller.getCurrentController().getMapViewManager().getMapViewComponent();
    if (mapView == null || SwingUtilities.isDescendingFrom(mapView, e.getComponent()))
        return;
    if (checkForScrollMap) {
        switch(e.getKeyCode()) {
            case KeyEvent.VK_UP:
                mapView.scrollBy(0, -10);
                e.consume();
                return;
            case KeyEvent.VK_DOWN:
                mapView.scrollBy(0, 10);
                e.consume();
                return;
            case KeyEvent.VK_LEFT:
                mapView.scrollBy(-10, 0);
                e.consume();
                return;
            case KeyEvent.VK_RIGHT:
                mapView.scrollBy(10, 0);
                e.consume();
        }
        return;
    }
    if ((e.isAltDown() || e.isControlDown() || e.isMetaDown())) {
        return;
    }
    switch(e.getKeyCode()) {
        case KeyEvent.VK_ENTER:
        case KeyEvent.VK_ESCAPE:
        case KeyEvent.VK_SHIFT:
        case KeyEvent.VK_DELETE:
        case KeyEvent.VK_SPACE:
        case KeyEvent.VK_INSERT:
        case KeyEvent.VK_TAB:
            return;
    }
    final boolean continious = e.isShiftDown();
    switch(e.getKeyCode()) {
        case KeyEvent.VK_UP:
            if (mapView.selectUp(continious))
                e.consume();
            return;
        case KeyEvent.VK_DOWN:
            if (mapView.selectDown(continious))
                e.consume();
            return;
        case KeyEvent.VK_LEFT:
            if (mapView.selectLeft(continious))
                e.consume();
            return;
        case KeyEvent.VK_RIGHT:
            if (mapView.selectRight(continious))
                e.consume();
            return;
        case KeyEvent.VK_PAGE_UP:
            if (mapView.selectPageUp(continious))
                e.consume();
            return;
        case KeyEvent.VK_PAGE_DOWN:
            if (mapView.selectPageDown(continious))
                e.consume();
            return;
        case KeyEvent.VK_HOME:
        case KeyEvent.VK_END:
        case KeyEvent.VK_BACK_SPACE:
            if (editHandler != null) {
                editHandler.edit(e, FirstAction.EDIT_CURRENT, false);
            }
            return;
        case KeyEvent.VK_CONTEXT_MENU:
            final ModeController modeController = Controller.getCurrentModeController();
            final NodeModel node = Controller.getCurrentModeController().getMapController().getSelectedNode();
            final NodeView nodeView = mapView.getNodeView(node);
            final JPopupMenu popupmenu = modeController.getUserInputListenerFactory().getNodePopupMenu();
            if (popupmenu != null) {
                popupmenu.addHierarchyListener(new ControllerPopupMenuListener());
                final MainView mainView = nodeView.getMainView();
                popupmenu.show(mainView, mainView.getX(), mainView.getY());
            }
    }
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) ControllerPopupMenuListener(org.freeplane.core.ui.ControllerPopupMenuListener) MainView(org.freeplane.view.swing.map.MainView) MapView(org.freeplane.view.swing.map.MapView) ModeController(org.freeplane.features.mode.ModeController) NodeView(org.freeplane.view.swing.map.NodeView) JPopupMenu(javax.swing.JPopupMenu)

Aggregations

JPopupMenu (javax.swing.JPopupMenu)2 ControllerPopupMenuListener (org.freeplane.core.ui.ControllerPopupMenuListener)2 ModeController (org.freeplane.features.mode.ModeController)2 MapView (org.freeplane.view.swing.map.MapView)2 Component (java.awt.Component)1 Frame (java.awt.Frame)1 Point (java.awt.Point)1 Window (java.awt.Window)1 WindowEvent (java.awt.event.WindowEvent)1 WindowFocusListener (java.awt.event.WindowFocusListener)1 JComponent (javax.swing.JComponent)1 JDialog (javax.swing.JDialog)1 NodeModel (org.freeplane.features.map.NodeModel)1 MainView (org.freeplane.view.swing.map.MainView)1 NodeView (org.freeplane.view.swing.map.NodeView)1