Search in sources :

Example 11 with MainView

use of org.freeplane.view.swing.map.MainView in project freeplane by freeplane.

the class EditNodeTextField method hideMe.

private void hideMe() {
    if (textfield == null) {
        return;
    }
    textfield.getDocument().removeDocumentListener(documentListener);
    final IMapViewManager mapViewManager = Controller.getCurrentController().getMapViewManager();
    mapViewManager.removeMapViewChangeListener(mapViewChangeListener);
    mapViewChangeListener = null;
    parent.setPreferredSize(null);
    if (SwingUtilities.getAncestorOfClass(MapView.class, nodeView) != null)
        nodeView.update();
    if (nodeView.isRoot() && parent instanceof MainView)
        parent.setHorizontalAlignment(JLabel.CENTER);
    final Dimension textFieldSize = textfield.getSize();
    final Point textFieldCoordinate = new Point();
    final MapView mapView = nodeView.getMap();
    UITools.convertPointToAncestor(textfield, textFieldCoordinate, mapView);
    textfield.getParent().remove(textfield);
    parent.revalidate();
    parent.repaint();
    mapView.repaint(textFieldCoordinate.x, textFieldCoordinate.y, textFieldSize.width, textFieldSize.height);
    textfield = null;
}
Also used : IMapViewManager(org.freeplane.features.ui.IMapViewManager) MainView(org.freeplane.view.swing.map.MainView) MapView(org.freeplane.view.swing.map.MapView) Dimension(java.awt.Dimension) Point(java.awt.Point)

Example 12 with MainView

use of org.freeplane.view.swing.map.MainView in project freeplane by freeplane.

the class EdgeView method createStart.

protected void createStart() {
    final MainView mainView = source.getMainView();
    final MainView targetMainView = target.getMainView();
    final Point relativeLocation = source.getRelativeLocation(target);
    relativeLocation.x += targetMainView.getWidth() / 2;
    relativeLocation.y += targetMainView.getHeight() / 2;
    start = mainView.getConnectorPoint(relativeLocation);
    startConnectorLocation = mainView.getConnectorLocation(relativeLocation);
    relativeLocation.x -= targetMainView.getWidth() / 2;
    relativeLocation.y -= targetMainView.getHeight() / 2;
    relativeLocation.x = -relativeLocation.x + mainView.getWidth() / 2;
    relativeLocation.y = -relativeLocation.y + mainView.getHeight() / 2;
    end = target.getMainView().getConnectorPoint(relativeLocation);
    endConnectorLocation = targetMainView.getConnectorLocation(relativeLocation);
}
Also used : MainView(org.freeplane.view.swing.map.MainView) Point(java.awt.Point)

Example 13 with MainView

use of org.freeplane.view.swing.map.MainView in project freeplane by freeplane.

the class EditNodeTextField method show.

/* (non-Javadoc)
	 * @see org.freeplane.view.swing.map.INodeTextField#show()
	 */
@SuppressWarnings("serial")
@Override
public void show(final RootPaneContainer frame) {
    final ModeController modeController = Controller.getCurrentModeController();
    final IMapViewManager viewController = modeController.getController().getMapViewManager();
    final MTextController textController = (MTextController) TextController.getController(modeController);
    nodeView = (NodeView) SwingUtilities.getAncestorOfClass(NodeView.class, parent);
    font = parent.getFont();
    zoom = viewController.getZoom();
    if (zoom != 1F) {
        final float fontSize = (int) (Math.rint(font.getSize() * zoom));
        font = font.deriveFont(fontSize);
    }
    final HTMLEditorKit kit = new ScaledEditorKit() {

        @Override
        public void write(Writer out, Document doc, int pos, int len) throws IOException, BadLocationException {
            if (doc instanceof HTMLDocument) {
                HTMLWriter w = new SHTMLWriter(out, (HTMLDocument) doc, pos, len);
                w.write();
            } else {
                super.write(out, doc, pos, len);
            }
        }
    };
    textfield.setEditorKit(kit);
    final InputMap inputMap = textfield.getInputMap();
    final ActionMap actionMap = textfield.getActionMap();
    actionMap.put(DefaultEditorKit.pasteAction, pasteAction);
    inputMap.put((KeyStroke) boldAction.getValue(Action.ACCELERATOR_KEY), "boldAction");
    actionMap.put("boldAction", boldAction);
    inputMap.put((KeyStroke) italicAction.getValue(Action.ACCELERATOR_KEY), "italicAction");
    actionMap.put("italicAction", italicAction);
    inputMap.put((KeyStroke) underlineAction.getValue(Action.ACCELERATOR_KEY), "underlineAction");
    actionMap.put("underlineAction", underlineAction);
    inputMap.put((KeyStroke) redAction.getValue(Action.ACCELERATOR_KEY), "redAction");
    actionMap.put("redAction", redAction);
    inputMap.put((KeyStroke) greenAction.getValue(Action.ACCELERATOR_KEY), "greenAction");
    actionMap.put("greenAction", greenAction);
    inputMap.put((KeyStroke) blueAction.getValue(Action.ACCELERATOR_KEY), "blueAction");
    actionMap.put("blueAction", blueAction);
    inputMap.put((KeyStroke) blackAction.getValue(Action.ACCELERATOR_KEY), "blackAction");
    actionMap.put("blackAction", blackAction);
    inputMap.put((KeyStroke) defaultColorAction.getValue(Action.ACCELERATOR_KEY), "defaultColorAction");
    actionMap.put("defaultColorAction", defaultColorAction);
    inputMap.put((KeyStroke) removeFormattingAction.getValue(Action.ACCELERATOR_KEY), "removeFormattingAction");
    actionMap.put("removeFormattingAction", removeFormattingAction);
    final Color nodeTextColor = parent.getForeground();
    textfield.setCaretColor(nodeTextColor);
    final StringBuilder ruleBuilder = new StringBuilder(100);
    ruleBuilder.append("body {");
    ruleBuilder.append("font-family: ").append(font.getFamily()).append(";");
    final int fontSize = Math.round(font.getSize() / UITools.FONT_SCALE_FACTOR);
    ruleBuilder.append("font-size: ").append(fontSize).append("pt;");
    if (font.isItalic()) {
        ruleBuilder.append("font-style: italic; ");
    }
    if (font.isBold()) {
        ruleBuilder.append("font-weight: bold; ");
    }
    ruleBuilder.append("color: ").append(ColorUtils.colorToString(nodeTextColor)).append(";");
    final Color bgColor = getBackground();
    ruleBuilder.append("background-color: ").append(ColorUtils.colorToString(bgColor)).append(";");
    ruleBuilder.append("}\n");
    final HTMLDocument document = (HTMLDocument) textfield.getDocument();
    final StyleSheet styleSheet = document.getStyleSheet();
    styleSheet.addRule(ruleBuilder.toString());
    textfield.setText(text);
    final MapView mapView = (MapView) viewController.getMapViewComponent();
    if (!mapView.isValid())
        mapView.validate();
    final NodeStyleController nsc = NodeStyleController.getController(modeController);
    maxWidth = nsc.getMaxWidth(node);
    final Icon icon = parent.getIcon();
    if (icon != null) {
        maxWidth -= icon.getIconWidth();
        maxWidth -= parent.getIconTextGap();
    }
    maxWidth = mapView.getZoomed(maxWidth);
    extraWidth = ResourceController.getResourceController().getIntProperty("editor_extra_width", 80);
    extraWidth = mapView.getZoomed(extraWidth);
    final TextFieldListener textFieldListener = new TextFieldListener();
    this.textFieldListener = textFieldListener;
    textfield.addFocusListener(textFieldListener);
    textfield.addKeyListener(textFieldListener);
    textfield.addMouseListener(textFieldListener);
    mapViewChangeListener = new MapViewChangeListener();
    Controller.getCurrentController().getMapViewManager().addMapViewChangeListener(mapViewChangeListener);
    SpellCheckerController.getController().enableAutoSpell(textfield, true);
    mapView.scrollNodeToVisible(nodeView);
    assert (parent.isValid());
    final int nodeWidth = parent.getWidth();
    final int nodeHeight = parent.getHeight();
    final Dimension textFieldSize;
    textfield.setBorder(new MatteBorder(2, 2, 2, 2, nodeView.getSelectedColor()));
    textFieldSize = textfield.getPreferredSize();
    textFieldSize.width += 1;
    if (textFieldSize.width < extraWidth)
        textFieldSize.width = extraWidth;
    if (textFieldSize.width < 10)
        textFieldSize.width = 10;
    if (textFieldSize.width > maxWidth) {
        textFieldSize.width = maxWidth;
        setLineWrap();
        textFieldSize.height = textfield.getPreferredSize().height;
    }
    final Rectangle textR = ((ZoomableLabelUI) parent.getUI()).getTextR(parent);
    textFieldSize.width = Math.max(textFieldSize.width, textR.width);
    textFieldSize.height = Math.max(textFieldSize.height, textR.height);
    textfield.setSize(textFieldSize.width, textFieldSize.height);
    horizontalSpace = Math.max(nodeWidth - textFieldSize.width, textR.x);
    verticalSpace = Math.max(nodeHeight - textFieldSize.height, textR.y);
    final Dimension newParentSize = new Dimension(horizontalSpace + textFieldSize.width, verticalSpace + textFieldSize.height);
    parent.setPreferredSize(newParentSize);
    final Point location = new Point(textR.x - 2, textR.y);
    if (!layoutMapOnTextChange)
        UITools.convertPointToAncestor(parent, location, mapView);
    textfield.setBounds(location.x, location.y, textFieldSize.width, textFieldSize.height);
    parent.setText("");
    if (nodeView.isRoot() && parent instanceof MainView)
        parent.setHorizontalAlignment(JLabel.LEFT);
    if (layoutMapOnTextChange)
        parent.add(textfield, 0);
    else
        mapView.add(textfield, 0);
    final EventBuffer eventQueue = MTextController.getController().getEventQueue();
    KeyEvent firstEvent = eventQueue.getFirstEvent();
    redispatchKeyEvents(textfield, firstEvent);
    if (firstEvent == null) {
        MouseEvent currentEvent = eventQueue.getMouseEvent();
        int pos = document.getLength();
        if (currentEvent != null) {
            MouseEvent mouseEvent = (MouseEvent) currentEvent;
            if (mouseEvent.getComponent().equals(parent)) {
                final Point point = mouseEvent.getPoint();
                point.x -= textR.x;
                point.y -= textR.y;
                pos = textfield.viewToModel(point);
            }
        }
        textfield.setCaretPosition(pos);
    }
    document.addDocumentListener(documentListener);
    if (textController.isMinimized(node)) {
        layout();
    }
    textfield.repaint();
    textfield.requestFocusInWindow();
}
Also used : MainView(org.freeplane.view.swing.map.MainView) HTMLDocument(javax.swing.text.html.HTMLDocument) Rectangle(java.awt.Rectangle) EventBuffer(org.freeplane.features.text.mindmapmode.EventBuffer) ModeController(org.freeplane.features.mode.ModeController) ScaledEditorKit(org.freeplane.core.ui.components.html.ScaledEditorKit) HTMLDocument(javax.swing.text.html.HTMLDocument) Document(javax.swing.text.Document) KeyEvent(java.awt.event.KeyEvent) SHTMLWriter(com.lightdev.app.shtm.SHTMLWriter) MatteBorder(javax.swing.border.MatteBorder) ZoomableLabelUI(org.freeplane.view.swing.map.ZoomableLabelUI) MapView(org.freeplane.view.swing.map.MapView) HTMLWriter(javax.swing.text.html.HTMLWriter) SHTMLWriter(com.lightdev.app.shtm.SHTMLWriter) MouseEvent(java.awt.event.MouseEvent) ActionMap(javax.swing.ActionMap) Color(java.awt.Color) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) Dimension(java.awt.Dimension) Point(java.awt.Point) Point(java.awt.Point) IMapViewManager(org.freeplane.features.ui.IMapViewManager) StyleSheet(javax.swing.text.html.StyleSheet) IMapViewChangeListener(org.freeplane.features.ui.IMapViewChangeListener) NodeStyleController(org.freeplane.features.nodestyle.NodeStyleController) InputMap(javax.swing.InputMap) MTextController(org.freeplane.features.text.mindmapmode.MTextController) Icon(javax.swing.Icon) HTMLWriter(javax.swing.text.html.HTMLWriter) Writer(java.io.Writer) SHTMLWriter(com.lightdev.app.shtm.SHTMLWriter)

Example 14 with MainView

use of org.freeplane.view.swing.map.MainView in project freeplane by freeplane.

the class MNodeDropListener method dragOver.

public void dragOver(final DropTargetDragEvent dtde) {
    supportFolding(dtde);
    final MainView draggedNode = (MainView) dtde.getDropTargetContext().getComponent();
    final int oldDraggedOver = draggedNode.getDraggedOver();
    draggedNode.setDraggedOver(dtde.getLocation());
    final int newDraggedOver = draggedNode.getDraggedOver();
    final boolean repaint = newDraggedOver != oldDraggedOver;
    if (repaint) {
        draggedNode.repaint();
    }
}
Also used : MainView(org.freeplane.view.swing.map.MainView)

Example 15 with MainView

use of org.freeplane.view.swing.map.MainView in project freeplane by freeplane.

the class MNodeDropListener method drop.

public void drop(final DropTargetDropEvent dtde) {
    try {
        int dropAction = dtde.getDropAction();
        final Transferable t = dtde.getTransferable();
        final MainView mainView = (MainView) dtde.getDropTargetContext().getComponent();
        final NodeView targetNodeView = mainView.getNodeView();
        final MapView mapView = targetNodeView.getMap();
        mapView.select();
        final NodeModel targetNode = targetNodeView.getModel();
        final Controller controller = Controller.getCurrentController();
        if (dtde.isLocalTransfer() && t.isDataFlavorSupported(MindMapNodesSelection.dropActionFlavor)) {
            final String sourceAction = (String) t.getTransferData(MindMapNodesSelection.dropActionFlavor);
            if (sourceAction.equals("LINK")) {
                dropAction = DnDConstants.ACTION_LINK;
            }
            if (sourceAction.equals("COPY")) {
                dropAction = DnDConstants.ACTION_COPY;
            }
        }
        mainView.setDraggedOver(NodeView.DRAGGED_OVER_NO);
        mainView.repaint();
        if (dtde.isLocalTransfer() && (dropAction == DnDConstants.ACTION_MOVE) && !isDropAcceptable(dtde)) {
            dtde.rejectDrop();
            return;
        }
        final boolean dropAsSibling = mainView.dropAsSibling(dtde.getLocation().getX());
        ModeController modeController = controller.getModeController();
        final MMapController mapController = (MMapController) modeController.getMapController();
        if ((dropAction == DnDConstants.ACTION_MOVE || dropAction == DnDConstants.ACTION_COPY)) {
            final NodeModel parent = dropAsSibling ? targetNode.getParentNode() : targetNode;
            if (!mapController.isWriteable(parent)) {
                dtde.rejectDrop();
                final String message = TextUtils.getText("node_is_write_protected");
                UITools.errorMessage(message);
                return;
            }
        }
        final boolean isLeft = mainView.dropLeft(dtde.getLocation().getX());
        if (!dtde.isLocalTransfer()) {
            dtde.acceptDrop(DnDConstants.ACTION_COPY);
            ((MClipboardController) ClipboardController.getController()).paste(t, targetNode, dropAsSibling, isLeft, dropAction);
            dtde.dropComplete(true);
            return;
        }
        dtde.acceptDrop(dropAction);
        if (dropAction == DnDConstants.ACTION_LINK) {
            int yesorno = JOptionPane.YES_OPTION;
            if (controller.getSelection().size() >= 5) {
                yesorno = JOptionPane.showConfirmDialog(controller.getViewController().getContentPane(), TextUtils.getText("lots_of_links_warning"), Integer.toString(controller.getSelection().size()) + " links to the same node", JOptionPane.YES_NO_OPTION);
            }
            if (yesorno == JOptionPane.YES_OPTION) {
                for (final Iterator<NodeModel> it = controller.getSelection().getSelection().iterator(); it.hasNext(); ) {
                    final NodeModel selectedNodeModel = (it.next());
                    ((MLinkController) LinkController.getController(modeController)).addConnector(selectedNodeModel, targetNode);
                }
            }
        } else {
            Transferable trans = null;
            final Collection<NodeModel> selecteds = mapController.getSelectedNodes();
            if (DnDConstants.ACTION_MOVE == dropAction) {
                NodeModel actualNode = targetNode;
                do {
                    if (selecteds.contains(actualNode)) {
                        final String message = TextUtils.getText("cannot_move_to_child");
                        JOptionPane.showMessageDialog(controller.getViewController().getContentPane(), message, "Freeplane", JOptionPane.WARNING_MESSAGE);
                        dtde.dropComplete(true);
                        return;
                    }
                    actualNode = (actualNode.isRoot()) ? null : actualNode.getParentNode();
                } while (actualNode != null);
                final NodeModel[] array = selecteds.toArray(new NodeModel[selecteds.size()]);
                final List<NodeModel> sortedSelection = controller.getSelection().getSortedSelection(true);
                for (final NodeModel node : sortedSelection) {
                    boolean changeSide = isLeft != node.isLeft();
                    if (dropAsSibling) {
                        mapController.moveNodeBefore(node, targetNode, isLeft, changeSide);
                    } else {
                        mapController.moveNodeAsChild(node, targetNode, isLeft, changeSide);
                    }
                }
                if (dropAsSibling || !targetNode.isFolded())
                    controller.getSelection().replaceSelection(array);
                else
                    controller.getSelection().selectAsTheOnlyOneSelected(targetNode);
            } else {
                trans = ClipboardController.getController().copy(controller.getSelection());
                ((MClipboardController) ClipboardController.getController()).paste(trans, targetNode, dropAsSibling, isLeft);
                controller.getSelection().selectAsTheOnlyOneSelected(targetNode);
            }
        }
    } catch (final Exception e) {
        LogUtils.severe("Drop exception:", e);
        dtde.dropComplete(false);
        return;
    }
    dtde.dropComplete(true);
}
Also used : MainView(org.freeplane.view.swing.map.MainView) MMapController(org.freeplane.features.map.mindmapmode.MMapController) Transferable(java.awt.datatransfer.Transferable) ModeController(org.freeplane.features.mode.ModeController) NodeView(org.freeplane.view.swing.map.NodeView) ClipboardController(org.freeplane.features.clipboard.ClipboardController) MMapController(org.freeplane.features.map.mindmapmode.MMapController) LinkController(org.freeplane.features.link.LinkController) Controller(org.freeplane.features.mode.Controller) ModeController(org.freeplane.features.mode.ModeController) MLinkController(org.freeplane.features.link.mindmapmode.MLinkController) MClipboardController(org.freeplane.features.clipboard.mindmapmode.MClipboardController) NodeModel(org.freeplane.features.map.NodeModel) MLinkController(org.freeplane.features.link.mindmapmode.MLinkController) MClipboardController(org.freeplane.features.clipboard.mindmapmode.MClipboardController) MapView(org.freeplane.view.swing.map.MapView)

Aggregations

MainView (org.freeplane.view.swing.map.MainView)26 NodeView (org.freeplane.view.swing.map.NodeView)11 NodeModel (org.freeplane.features.map.NodeModel)10 ModeController (org.freeplane.features.mode.ModeController)9 MapView (org.freeplane.view.swing.map.MapView)9 Point (java.awt.Point)7 MapController (org.freeplane.features.map.MapController)6 Controller (org.freeplane.features.mode.Controller)5 Component (java.awt.Component)4 ResourceController (org.freeplane.core.resources.ResourceController)4 MMapController (org.freeplane.features.map.mindmapmode.MMapController)4 Dimension (java.awt.Dimension)3 Rectangle (java.awt.Rectangle)3 MTextController (org.freeplane.features.text.mindmapmode.MTextController)3 Color (java.awt.Color)2 Cursor (java.awt.Cursor)2 Transferable (java.awt.datatransfer.Transferable)2 JPopupMenu (javax.swing.JPopupMenu)2 LinkController (org.freeplane.features.link.LinkController)2 LocationController (org.freeplane.features.nodelocation.LocationController)2