Search in sources :

Example 31 with MapView

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

the class MapViewSerializer method writeView.

public void writeView(View view, ObjectOutputStream out) throws IOException {
    if (view.isDisplayable()) {
        Component component = MapViewDockingWindows.getContainedMapView(view);
        if (component instanceof MapView) {
            MapView mapView = (MapView) component;
            if (mapView.getModeController().getModeName().equals(MModeController.MODENAME) && !mapView.getModel().containsExtension(DocuMapAttribute.class)) {
                out.writeBoolean(true);
                out.writeUTF(mapView.getModeController().getModeName());
                out.writeObject(mapView.getModel().getURL());
                return;
            }
        }
    }
    out.writeBoolean(false);
}
Also used : MapView(org.freeplane.view.swing.map.MapView) Component(java.awt.Component)

Example 32 with MapView

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

the class FreeplaneGUIStarter method createFrame.

public void createFrame(final String[] args) {
    Controller controller = Controller.getCurrentController();
    ModeController modeController = controller.getModeController(MModeController.MODENAME);
    controller.selectModeForBuild(modeController);
    Compat.macMenuChanges();
    new UserPropertiesUpdater().importOldDefaultStyle();
    EventQueue.invokeLater(new Runnable() {

        public void run() {
            final Options options = CommandLineParser.parse(args);
            viewController.init(Controller.getCurrentController());
            splash.toBack();
            final Frame frame = viewController.getFrame();
            final int extendedState = frame.getExtendedState();
            Container contentPane = viewController.getContentPane();
            contentPane.setVisible(false);
            splash.dispose();
            splash = null;
            frame.setVisible(true);
            if (extendedState != frame.getExtendedState()) {
                frame.setExtendedState(extendedState);
            }
            loadMaps(options.getFilesToOpenAsArray());
            focusCurrentView();
            viewController.getContentPane().setVisible(true);
            frame.toFront();
            startupFinished = true;
            System.setProperty("nonInteractive", Boolean.toString(options.isNonInteractive()));
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            MenuUtils.executeMenuItems(options.getMenuItemsToExecute());
        }

        private void focusCurrentView() {
            final MapView currentMapView = (MapView) Controller.getCurrentController().getMapViewManager().getMapViewComponent();
            if (currentMapView != null) {
                viewController.focusTo(currentMapView);
            }
        }
    });
}
Also used : Options(org.freeplane.main.application.CommandLineParser.Options) JFrame(javax.swing.JFrame) Frame(java.awt.Frame) JRibbonFrame(org.pushingpixels.flamingo.api.ribbon.JRibbonFrame) Container(java.awt.Container) MapView(org.freeplane.view.swing.map.MapView) FModeController(org.freeplane.features.mode.filemode.FModeController) BModeController(org.freeplane.features.mode.browsemode.BModeController) ModeController(org.freeplane.features.mode.ModeController) MModeController(org.freeplane.features.mode.mindmapmode.MModeController) FModeController(org.freeplane.features.mode.filemode.FModeController) TimeController(org.freeplane.features.time.TimeController) FilterController(org.freeplane.features.filter.FilterController) HelpController(org.freeplane.features.help.HelpController) MapController(org.freeplane.features.map.MapController) LogicalStyleFilterController(org.freeplane.features.styles.LogicalStyleFilterController) IconController(org.freeplane.features.icon.IconController) Controller(org.freeplane.features.mode.Controller) MMapViewController(org.freeplane.view.swing.map.mindmapmode.MMapViewController) TextController(org.freeplane.features.text.TextController) ModelessAttributeController(org.freeplane.features.attribute.ModelessAttributeController) PrintController(org.freeplane.features.print.PrintController) BModeController(org.freeplane.features.mode.browsemode.BModeController) FormatController(org.freeplane.features.format.FormatController) AddOnsController(org.freeplane.main.addons.AddOnsController) ResourceController(org.freeplane.core.resources.ResourceController) LinkController(org.freeplane.features.link.LinkController) FrameController(org.freeplane.features.ui.FrameController) ModeController(org.freeplane.features.mode.ModeController) MModeController(org.freeplane.features.mode.mindmapmode.MModeController) ScannerController(org.freeplane.features.format.ScannerController)

Example 33 with MapView

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

the class ExportPdf method export.

public void export(MapModel map, File chosenFile) {
    if (!ExportController.getContoller().checkCurrentMap(map)) {
        return;
    }
    try {
        final MapView view = (MapView) Controller.getCurrentController().getMapViewManager().getMapViewComponent();
        if (view == null) {
            return;
        }
        Controller.getCurrentController().getViewController().setWaitingCursor(true);
        final SVGGraphics2D g2d = fillSVGGraphics2D(view);
        final PDFTranscoder pdfTranscoder = new PDFTranscoder();
        /*
			 * according to https: &aid=1921334&group_id=7118 Submitted By:
			 * Frank Spangenberg (f_spangenberg) Summary: Large mind maps
			 * produce invalid PDF
			 */
        pdfTranscoder.addTranscodingHint(SVGAbstractTranscoder.KEY_MAX_HEIGHT, new Float(19200));
        pdfTranscoder.addTranscodingHint(SVGAbstractTranscoder.KEY_MAX_WIDTH, new Float(19200));
        pdfTranscoder.addTranscodingHint(ImageTranscoder.KEY_PIXEL_UNIT_TO_MILLIMETER, 25.4f / 72f / UITools.FONT_SCALE_FACTOR);
        /* end patch */
        final Document doc = g2d.getDOMFactory();
        final Element rootE = doc.getDocumentElement();
        g2d.getRoot(rootE);
        final TranscoderInput input = new TranscoderInput(doc);
        final FileOutputStream ostream = new FileOutputStream(chosenFile);
        final BufferedOutputStream bufStream = new BufferedOutputStream(ostream);
        final TranscoderOutput output = new TranscoderOutput(bufStream);
        pdfTranscoder.transcode(input, output);
        ostream.flush();
        ostream.close();
    } catch (final Exception ex) {
        org.freeplane.core.util.LogUtils.warn(ex);
        UITools.errorMessage(ex.getLocalizedMessage());
    } finally {
        Controller.getCurrentController().getViewController().setWaitingCursor(false);
    }
}
Also used : TranscoderOutput(org.apache.batik.transcoder.TranscoderOutput) TranscoderInput(org.apache.batik.transcoder.TranscoderInput) Element(org.w3c.dom.Element) FileOutputStream(java.io.FileOutputStream) MapView(org.freeplane.view.swing.map.MapView) SVGGraphics2D(org.apache.batik.svggen.SVGGraphics2D) Document(org.w3c.dom.Document) BufferedOutputStream(java.io.BufferedOutputStream) PDFTranscoder(org.apache.fop.svg.PDFTranscoder)

Example 34 with MapView

use of org.freeplane.view.swing.map.MapView 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 35 with MapView

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

the class MMapMouseListener method mouseReleased.

public void mouseReleased(final MouseEvent e) {
    super.mouseReleased(e);
    if (draggedLink != null) {
        draggedLink.setShowControlPoints(false);
        final Point draggedLinkNewStartPoint = draggedLink.getStartInclination();
        final Point draggedLinkNewEndPoint = draggedLink.getEndInclination();
        draggedLink.setStartInclination(draggedLinkOldStartPoint);
        draggedLink.setEndInclination(draggedLinkOldEndPoint);
        ((MLinkController) LinkController.getController(Controller.getCurrentController().getModeController())).setArrowLinkEndPoints(draggedLink, draggedLinkNewStartPoint, draggedLinkNewEndPoint);
        final MapView mapView = (MapView) e.getComponent();
        mapView.repaintVisible();
        draggedLink = null;
    }
}
Also used : MLinkController(org.freeplane.features.link.mindmapmode.MLinkController) MapView(org.freeplane.view.swing.map.MapView) Point(java.awt.Point)

Aggregations

MapView (org.freeplane.view.swing.map.MapView)55 NodeView (org.freeplane.view.swing.map.NodeView)20 ModeController (org.freeplane.features.mode.ModeController)19 Point (java.awt.Point)15 NodeModel (org.freeplane.features.map.NodeModel)13 Controller (org.freeplane.features.mode.Controller)11 Component (java.awt.Component)9 MainView (org.freeplane.view.swing.map.MainView)9 Dimension (java.awt.Dimension)8 JComponent (javax.swing.JComponent)8 MMapController (org.freeplane.features.map.mindmapmode.MMapController)7 ResourceController (org.freeplane.core.resources.ResourceController)6 MapController (org.freeplane.features.map.MapController)6 MTextController (org.freeplane.features.text.mindmapmode.MTextController)5 IMapViewManager (org.freeplane.features.ui.IMapViewManager)5 Color (java.awt.Color)4 Rectangle (java.awt.Rectangle)4 LocationController (org.freeplane.features.nodelocation.LocationController)4 MLocationController (org.freeplane.features.nodelocation.mindmapmode.MLocationController)4 NodeStyleController (org.freeplane.features.nodestyle.NodeStyleController)4