Search in sources :

Example 41 with IMapSelection

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

the class NewSummaryAction method check.

private boolean check() {
    start = -1;
    end = -1;
    summaryLevel = -1;
    final ModeController modeController = Controller.getCurrentModeController();
    final IMapSelection selection = modeController.getController().getSelection();
    final List<NodeModel> sortedSelection = selection.getSortedSelection(false);
    final NodeModel firstNode = sortedSelection.get(0);
    final NodeModel parentNode = firstNode.getParentNode();
    // root node selected
    if (parentNode == null)
        return false;
    final NodeModel lastNode = sortedSelection.get(sortedSelection.size() - 1);
    // different parents
    if (!parentNode.equals(lastNode.getParentNode())) {
        return false;
    }
    final boolean isLeft = firstNode.isLeft();
    // different sides
    if (isLeft != lastNode.isLeft()) {
        return false;
    }
    start = parentNode.getIndex(firstNode);
    end = parentNode.getIndex(lastNode);
    // last node is a group node
    if (firstNode != lastNode && SummaryNode.isFirstGroupNode(lastNode))
        return false;
    summaryLevel = SummaryNode.getSummaryLevel(firstNode);
    // selected nodes have different summary levels
    if (summaryLevel != SummaryNode.getSummaryLevel(lastNode))
        return false;
    int level = summaryLevel;
    for (int i = start + 1; i < end; i++) {
        NodeModel node = (NodeModel) parentNode.getChildAt(i);
        if (isLeft != node.isLeft())
            continue;
        if (SummaryNode.isSummaryNode(node))
            level++;
        else
            level = 0;
        // There is a higher summary node between the selected nodes
        if (level > summaryLevel)
            return false;
    }
    return true;
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) IMapSelection(org.freeplane.features.map.IMapSelection) ModeController(org.freeplane.features.mode.ModeController)

Example 42 with IMapSelection

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

the class ExecuteScriptAction method actionPerformed.

@Override
public void actionPerformed(final ActionEvent e) {
    Controller.getCurrentController().getViewController().setWaitingCursor(true);
    try {
        final List<NodeModel> nodes = new ArrayList<NodeModel>();
        final IMapSelection selection = Controller.getCurrentController().getSelection();
        if (mode == ExecutionMode.ON_SINGLE_NODE) {
            nodes.add(selection.getSelected());
        } else {
            nodes.addAll(selection.getSelection());
        }
        final MModeController modeController = (MModeController) Controller.getCurrentModeController();
        modeController.startTransaction();
        for (final NodeModel node : nodes) {
            try {
                if (mode == ExecutionMode.ON_SELECTED_NODE_RECURSIVELY) {
                    // TODO: ensure that a script is invoked only once on every node?
                    // (might be a problem with recursive actions if parent and child
                    // are selected.)
                    executeScriptRecursive(node);
                } else {
                    script.execute(node);
                }
            } catch (ExecuteScriptException ex) {
                final String cause;
                // that, it is what we want to know.
                if (ex.getCause() != null) {
                    if (ex.getCause().getCause() != null) {
                        LogUtils.warn("ExecuteScriptAction failed:", ex.getCause().getCause());
                        cause = ex.getCause().getCause().toString();
                    } else {
                        LogUtils.warn("ExecuteScriptAction failed:", ex.getCause());
                        cause = ex.getCause().toString();
                    }
                } else {
                    LogUtils.warn("ExecuteScriptAction failed:", ex);
                    cause = ex.toString();
                }
                LogUtils.warn("error executing script " + scriptFile + " - giving up\n" + cause);
                modeController.delayedRollback();
                ScriptingEngine.showScriptExceptionErrorMessage(ex);
                return;
            }
        }
        modeController.delayedCommit();
    } finally {
        Controller.getCurrentController().getViewController().setWaitingCursor(false);
    }
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) IMapSelection(org.freeplane.features.map.IMapSelection) ArrayList(java.util.ArrayList) MModeController(org.freeplane.features.mode.mindmapmode.MModeController)

Example 43 with IMapSelection

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

the class MLinkController method createArrowLinkPopup.

@Override
protected void createArrowLinkPopup(final ConnectorModel link, final JComponent arrowLinkPopup) {
    super.createArrowLinkPopup(link, arrowLinkPopup);
    addClosingAction(arrowLinkPopup, new RemoveConnectorAction(this, link));
    addSeparator(arrowLinkPopup);
    addAction(arrowLinkPopup, new ConnectorColorAction(this, link));
    final JSlider transparencySlider = new JSlider(20, 255, link.getAlpha());
    transparencySlider.setMinorTickSpacing(20);
    transparencySlider.setPaintTicks(true);
    transparencySlider.setSnapToTicks(true);
    transparencySlider.setPaintTrack(true);
    addPopupComponent(arrowLinkPopup, TextUtils.getText("edit_transparency_label"), transparencySlider);
    addSeparator(arrowLinkPopup);
    AFreeplaneAction[] arrowActions = new AFreeplaneAction[] { new ChangeConnectorArrowsAction(this, "none", link, ArrowType.NONE, ArrowType.NONE), new ChangeConnectorArrowsAction(this, "forward", link, ArrowType.NONE, ArrowType.DEFAULT), new ChangeConnectorArrowsAction(this, "backward", link, ArrowType.DEFAULT, ArrowType.NONE), new ChangeConnectorArrowsAction(this, "both", link, ArrowType.DEFAULT, ArrowType.DEFAULT) };
    final JComboBox connectorArrows = createActionBox(arrowActions);
    addPopupComponent(arrowLinkPopup, TextUtils.getText("connector_arrows"), connectorArrows);
    final boolean twoNodesConnector = !link.getSource().equals(link.getTarget());
    AFreeplaneAction[] shapeActions;
    if (twoNodesConnector) {
        shapeActions = new AFreeplaneAction[] { new ChangeConnectorShapeAction(this, link, Shape.CUBIC_CURVE), new ChangeConnectorShapeAction(this, link, Shape.LINE), new ChangeConnectorShapeAction(this, link, Shape.LINEAR_PATH), new ChangeConnectorShapeAction(this, link, Shape.EDGE_LIKE) };
    } else {
        shapeActions = new AFreeplaneAction[] { new ChangeConnectorShapeAction(this, link, Shape.CUBIC_CURVE), new ChangeConnectorShapeAction(this, link, Shape.LINE), new ChangeConnectorShapeAction(this, link, Shape.LINEAR_PATH) };
    }
    final JComboBox connectorShapes = createActionBox(shapeActions);
    addPopupComponent(arrowLinkPopup, TextUtils.getText("connector_shapes"), connectorShapes);
    AFreeplaneAction[] dashActions = new AFreeplaneAction[] { new ChangeConnectorDashAction(this, link, null), new ChangeConnectorDashAction(this, link, new int[] { 3, 3 }), new ChangeConnectorDashAction(this, link, new int[] { 7, 7 }), new ChangeConnectorDashAction(this, link, new int[] { 2, 7 }), new ChangeConnectorDashAction(this, link, new int[] { 2, 7, 7, 7 }) };
    final JComboBox connectorDashes = createActionBox(dashActions);
    addPopupComponent(arrowLinkPopup, TextUtils.getText("connector_lines"), connectorDashes);
    final SpinnerNumberModel widthModel = new SpinnerNumberModel(link.getWidth(), 1, 32, 1);
    final JSpinner widthSpinner = new JSpinner(widthModel);
    addPopupComponent(arrowLinkPopup, TextUtils.getText("edit_width_label"), widthSpinner);
    addSeparator(arrowLinkPopup);
    {
        final GraphicsEnvironment gEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
        final String[] envFonts = gEnv.getAvailableFontFamilyNames();
        DefaultComboBoxModel fonts = new DefaultComboBoxModel(envFonts);
        fonts.setSelectedItem(link.getLabelFontFamily());
        JComboBox fontBox = new JComboBox(fonts);
        fontBox.setEditable(false);
        addPopupComponent(arrowLinkPopup, TextUtils.getText("edit_label_font_family"), fontBox);
        fontBox.addItemListener(new ItemListener() {

            public void itemStateChanged(ItemEvent e) {
                final Object item = e.getItem();
                if (item != null)
                    setLabelFontFamily(link, item.toString());
            }
        });
    }
    {
        final Integer[] sizes = { 4, 6, 8, 10, 12, 14, 16, 18, 24, 36 };
        DefaultComboBoxModel sizesModel = new DefaultComboBoxModel(sizes);
        sizesModel.setSelectedItem(link.getLabelFontSize());
        JComboBox sizesBox = new JComboBox(sizesModel);
        sizesBox.setEditable(true);
        addPopupComponent(arrowLinkPopup, TextUtils.getText("edit_label_font_size"), sizesBox);
        sizesBox.addItemListener(new ItemListener() {

            public void itemStateChanged(ItemEvent e) {
                final Object item = e.getItem();
                if (item != null) {
                    final int size;
                    if (item instanceof Integer)
                        size = (Integer) item;
                    else {
                        try {
                            size = Integer.valueOf(item.toString());
                            if (size <= 0)
                                return;
                        } catch (NumberFormatException ex) {
                            return;
                        }
                    }
                    setLabelFontSize(link, size);
                }
            }
        });
    }
    final JTextArea sourceLabelEditor;
    sourceLabelEditor = new JTextArea(link.getSourceLabel());
    addTextEditor(arrowLinkPopup, "edit_source_label", sourceLabelEditor);
    final JTextArea middleLabelEditor = new JTextArea(link.getMiddleLabel());
    addTextEditor(arrowLinkPopup, "edit_middle_label", middleLabelEditor);
    final JTextArea targetLabelEditor;
    targetLabelEditor = new JTextArea(link.getTargetLabel());
    addTextEditor(arrowLinkPopup, "edit_target_label", targetLabelEditor);
    arrowLinkPopup.addHierarchyListener(new HierarchyListener() {

        private Component focusOwner;

        private Window dialog;

        public void hierarchyChanged(HierarchyEvent e) {
            final JComponent component = (JComponent) e.getComponent();
            if (component.isShowing()) {
                if (dialog == null) {
                    dialog = SwingUtilities.getWindowAncestor(component);
                    dialog.addWindowListener(new WindowAdapter() {

                        @Override
                        public void windowClosing(WindowEvent e) {
                            component.putClientProperty(CANCEL, Boolean.TRUE);
                        }
                    });
                }
                if (focusOwner == null)
                    focusOwner = FocusManager.getCurrentManager().getFocusOwner();
                return;
            }
            if (focusOwner == null || !focusOwner.isShowing())
                return;
            focusOwner.requestFocus();
            if (Boolean.TRUE.equals(component.getClientProperty(CANCEL))) {
                return;
            }
            final IMapSelection selection = Controller.getCurrentController().getSelection();
            if (selection == null || selection.getSelected() == null)
                return;
            setSourceLabel(link, sourceLabelEditor.getText());
            setTargetLabel(link, targetLabelEditor.getText());
            setMiddleLabel(link, middleLabelEditor.getText());
            setAlpha(link, transparencySlider.getValue());
            setWidth(link, widthModel.getNumber().intValue());
        }
    });
}
Also used : ItemEvent(java.awt.event.ItemEvent) JTextArea(javax.swing.JTextArea) IMapSelection(org.freeplane.features.map.IMapSelection) WindowAdapter(java.awt.event.WindowAdapter) HierarchyListener(java.awt.event.HierarchyListener) SpinnerNumberModel(javax.swing.SpinnerNumberModel) JSlider(javax.swing.JSlider) Component(java.awt.Component) JComponent(javax.swing.JComponent) Window(java.awt.Window) JComboBox(javax.swing.JComboBox) JComponent(javax.swing.JComponent) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) GraphicsEnvironment(java.awt.GraphicsEnvironment) Point(java.awt.Point) AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) HierarchyEvent(java.awt.event.HierarchyEvent) WindowEvent(java.awt.event.WindowEvent) JSpinner(javax.swing.JSpinner) ItemListener(java.awt.event.ItemListener)

Example 44 with IMapSelection

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

the class AddConnectorAction method actionPerformed.

public void actionPerformed(final ActionEvent e) {
    final IMapSelection selection = Controller.getCurrentController().getSelection();
    final List<NodeModel> selecteds = selection.getOrderedSelection();
    final int size = selecteds.size();
    final MLinkController linkController = (MLinkController) LinkController.getController();
    final NodeModel target = selecteds.get(size - 1);
    if (selecteds.size() < 2) {
        linkController.addConnector(target, target);
        return;
    }
    for (NodeModel node : selecteds) {
        if (node != target)
            linkController.addConnector(node, target);
    }
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) IMapSelection(org.freeplane.features.map.IMapSelection)

Example 45 with IMapSelection

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

the class MapViewController method afterViewChange.

public void afterViewChange(final Component oldMap, final Component pNewMap) {
    Controller controller = Controller.getCurrentController();
    final ModeController oldModeController = controller.getModeController();
    ModeController newModeController = oldModeController;
    if (pNewMap != null) {
        final IMapSelection mapSelection = getMapSelection();
        final NodeModel selected = mapSelection.getSelected();
        mapSelection.scrollNodeToVisible(selected);
        setZoomComboBox(getZoom());
        obtainFocusForSelected();
        newModeController = getModeController(pNewMap);
        if (newModeController != oldModeController) {
            controller.selectMode(newModeController);
        }
    }
    setTitle();
    controller.getViewController().viewNumberChanged(getViewNumber());
    newModeController.getUserInputListenerFactory().updateMapList();
    if (pNewMap != null) {
        newModeController.setVisible(true);
    }
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) IMapSelection(org.freeplane.features.map.IMapSelection) ModeController(org.freeplane.features.mode.ModeController) ResourceController(org.freeplane.core.resources.ResourceController) ViewController(org.freeplane.features.ui.ViewController) MapController(org.freeplane.features.map.MapController) Controller(org.freeplane.features.mode.Controller) ModeController(org.freeplane.features.mode.ModeController)

Aggregations

IMapSelection (org.freeplane.features.map.IMapSelection)47 NodeModel (org.freeplane.features.map.NodeModel)33 Controller (org.freeplane.features.mode.Controller)12 ModeController (org.freeplane.features.mode.ModeController)12 ResourceController (org.freeplane.core.resources.ResourceController)7 MapController (org.freeplane.features.map.MapController)7 Component (java.awt.Component)6 MapModel (org.freeplane.features.map.MapModel)4 Container (java.awt.Container)3 ASelectableCondition (org.freeplane.features.filter.condition.ASelectableCondition)3 NodeStyleController (org.freeplane.features.nodestyle.NodeStyleController)3 MTextController (org.freeplane.features.text.mindmapmode.MTextController)3 NodeView (org.freeplane.view.swing.map.NodeView)3 Point (java.awt.Point)2 Window (java.awt.Window)2 WindowEvent (java.awt.event.WindowEvent)2 ArrayList (java.util.ArrayList)2 JComponent (javax.swing.JComponent)2 JPopupMenu (javax.swing.JPopupMenu)2 JRootPane (javax.swing.JRootPane)2