Search in sources :

Example 1 with AMapChangeListenerAdapter

use of org.freeplane.features.map.AMapChangeListenerAdapter in project freeplane by freeplane.

the class NodeTooltipManager method getSharedInstance.

public static NodeTooltipManager getSharedInstance(ModeController modeController) {
    {
        final NodeTooltipManager instance = modeController.getExtension(NodeTooltipManager.class);
        if (instance != null) {
            return instance;
        }
    }
    final NodeTooltipManager instance = new NodeTooltipManager();
    setTooltipDelays(instance);
    UIManager.put("PopupMenu.consumeEventOnClose", Boolean.FALSE);
    ResourceController.getResourceController().addPropertyChangeListener(new IFreeplanePropertyListener() {

        public void propertyChanged(final String propertyName, final String newValue, final String oldValue) {
            if (propertyName.startsWith(TOOL_TIP_MANAGER)) {
                setTooltipDelays(instance);
            }
        }
    });
    IMapChangeListener mapChangeListener = new AMapChangeListenerAdapter() {

        @Override
        public void onNodeDeleted(NodeDeletionEvent nodeDeletionEvent) {
            instance.hideTipWindow();
        }

        @Override
        public void onNodeInserted(NodeModel parent, NodeModel child, int newIndex) {
            instance.hideTipWindow();
        }

        @Override
        public void onNodeMoved(NodeMoveEvent nodeMoveEvent) {
            instance.hideTipWindow();
        }
    };
    MapController mapController = modeController.getMapController();
    mapController.addMapChangeListener(mapChangeListener);
    INodeSelectionListener nodeSelectionListener = new INodeSelectionListener() {

        public void onSelect(NodeModel node) {
            NodeView view = (NodeView) SwingUtilities.getAncestorOfClass(NodeView.class, instance.insideComponent);
            if (view != null && node.equals(view.getModel()))
                return;
            instance.hideTipWindow();
        }

        public void onDeselect(NodeModel node) {
        }
    };
    mapController.addNodeSelectionListener(nodeSelectionListener);
    modeController.addExtension(NodeTooltipManager.class, instance);
    return instance;
}
Also used : NodeMoveEvent(org.freeplane.features.map.NodeMoveEvent) INodeSelectionListener(org.freeplane.features.map.INodeSelectionListener) NodeModel(org.freeplane.features.map.NodeModel) NodeDeletionEvent(org.freeplane.features.map.NodeDeletionEvent) IFreeplanePropertyListener(org.freeplane.core.resources.IFreeplanePropertyListener) IMapChangeListener(org.freeplane.features.map.IMapChangeListener) AMapChangeListenerAdapter(org.freeplane.features.map.AMapChangeListenerAdapter) MapController(org.freeplane.features.map.MapController)

Example 2 with AMapChangeListenerAdapter

use of org.freeplane.features.map.AMapChangeListenerAdapter in project freeplane by freeplane.

the class StyleEditorPanel method addListeners.

private void addListeners() {
    final Controller controller = Controller.getCurrentController();
    final ModeController modeController = Controller.getCurrentModeController();
    final MapController mapController = modeController.getMapController();
    mapController.addNodeSelectionListener(new INodeSelectionListener() {

        public void onSelect(final NodeModel node) {
            final IMapSelection selection = controller.getSelection();
            if (selection == null) {
                return;
            }
            if (selection.size() == 1) {
                setComponentsEnabled(true);
                setStyle(node);
            }
        }

        public void setComponentsEnabled(boolean enabled) {
            final Container panel = (Container) getComponent(0);
            for (int i = 0; i < panel.getComponentCount(); i++) {
                panel.getComponent(i).setEnabled(enabled);
            }
        }

        public void onDeselect(final NodeModel node) {
            setComponentsEnabled(false);
        }
    });
    mapController.addNodeChangeListener(new INodeChangeListener() {

        public void nodeChanged(final NodeChangeEvent event) {
            final IMapSelection selection = controller.getSelection();
            if (selection == null) {
                return;
            }
            final NodeModel node = event.getNode();
            if (selection.getSelected().equals(node)) {
                setStyle(node);
            }
        }
    });
    mapController.addMapChangeListener(new AMapChangeListenerAdapter() {

        @Override
        public void mapChanged(MapChangeEvent event) {
            if (!MapStyle.MAP_STYLES.equals(event.getProperty()))
                return;
            final IMapSelection selection = controller.getSelection();
            if (selection == null) {
                return;
            }
            final NodeModel node = selection.getSelected();
            setStyle(node);
        }
    });
}
Also used : NodeChangeEvent(org.freeplane.features.map.NodeChangeEvent) IMapSelection(org.freeplane.features.map.IMapSelection) ModeController(org.freeplane.features.mode.ModeController) MapController(org.freeplane.features.map.MapController) Controller(org.freeplane.features.mode.Controller) ModeController(org.freeplane.features.mode.ModeController) AMapChangeListenerAdapter(org.freeplane.features.map.AMapChangeListenerAdapter) MapController(org.freeplane.features.map.MapController) INodeSelectionListener(org.freeplane.features.map.INodeSelectionListener) NodeModel(org.freeplane.features.map.NodeModel) Container(java.awt.Container) INodeChangeListener(org.freeplane.features.map.INodeChangeListener) MapChangeEvent(org.freeplane.features.map.MapChangeEvent)

Aggregations

AMapChangeListenerAdapter (org.freeplane.features.map.AMapChangeListenerAdapter)2 INodeSelectionListener (org.freeplane.features.map.INodeSelectionListener)2 MapController (org.freeplane.features.map.MapController)2 NodeModel (org.freeplane.features.map.NodeModel)2 Container (java.awt.Container)1 IFreeplanePropertyListener (org.freeplane.core.resources.IFreeplanePropertyListener)1 IMapChangeListener (org.freeplane.features.map.IMapChangeListener)1 IMapSelection (org.freeplane.features.map.IMapSelection)1 INodeChangeListener (org.freeplane.features.map.INodeChangeListener)1 MapChangeEvent (org.freeplane.features.map.MapChangeEvent)1 NodeChangeEvent (org.freeplane.features.map.NodeChangeEvent)1 NodeDeletionEvent (org.freeplane.features.map.NodeDeletionEvent)1 NodeMoveEvent (org.freeplane.features.map.NodeMoveEvent)1 Controller (org.freeplane.features.mode.Controller)1 ModeController (org.freeplane.features.mode.ModeController)1