Search in sources :

Example 11 with MapView

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

the class MNodeMotionListener method mouseDragged.

@Override
public void mouseDragged(final MouseEvent e) {
    if (!isDragActive())
        return;
    if ((e.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) == (InputEvent.BUTTON1_DOWN_MASK)) {
        final MainView mainView = (MainView) e.getSource();
        final NodeView nodeV = getNodeView(e);
        final MapView mapView = nodeV.getMap();
        final Point point = e.getPoint();
        findGridPoint(point);
        UITools.convertPointToAncestor(nodeV, point, JScrollPane.class);
        ModeController c = Controller.getCurrentController().getModeController();
        final Point dragNextPoint = point;
        if (!Compat.isCtrlEvent(e)) {
            final NodeModel node = nodeV.getModel();
            final LocationModel locationModel = LocationModel.createLocationModel(node);
            final int hGapChange = getHGapChange(dragNextPoint, node);
            if (hGapChange != 0) {
                locationModel.setHGap(originalHGap + hGapChange);
            }
            final int shiftYChange = getNodeShiftYChange(dragNextPoint, node);
            if (shiftYChange != 0) {
                locationModel.setShiftY(originalShiftY + shiftYChange);
            }
            if (hGapChange != 0 || shiftYChange != 0)
                c.getMapController().nodeRefresh(node);
            else
                return;
        } else {
            final NodeModel parentNode = nodeV.getVisibleParentView().getModel();
            final int vGapChange = getVGapChange(dragNextPoint, parentNode);
            if (vGapChange != 0) {
                LocationModel.createLocationModel(parentNode).setVGap(Math.max(0, originalParentVGap - vGapChange));
                final MapController mapController = c.getMapController();
                mapController.nodeRefresh(parentNode);
                mapController.nodeRefresh(nodeV.getModel());
            } else
                return;
        }
        EventQueue.invokeLater(new Runnable() {

            public void run() {
                final Rectangle r = mainView.getBounds();
                UITools.convertRectangleToAncestor(mainView.getParent(), r, mapView);
                final boolean isEventPointVisible = mapView.getVisibleRect().contains(r);
                if (!isEventPointVisible) {
                    mapView.scrollRectToVisible(r);
                }
            }
        });
    }
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) MainView(org.freeplane.view.swing.map.MainView) Rectangle(java.awt.Rectangle) MapView(org.freeplane.view.swing.map.MapView) Point(java.awt.Point) ModeController(org.freeplane.features.mode.ModeController) NodeView(org.freeplane.view.swing.map.NodeView) LocationModel(org.freeplane.features.nodelocation.LocationModel) Point(java.awt.Point) MMapController(org.freeplane.features.map.mindmapmode.MMapController) MapController(org.freeplane.features.map.MapController)

Example 12 with MapView

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

the class MNodeMotionListener method getNodeShiftYChange.

/**
 */
private int getNodeShiftYChange(final Point dragNextPoint, final NodeModel node) {
    final Controller controller = Controller.getCurrentController();
    final MapView mapView = ((MapView) controller.getMapViewManager().getMapViewComponent());
    final int shiftYChange = (int) ((dragNextPoint.y - dragStartingPoint.y) / mapView.getZoom());
    return shiftYChange;
}
Also used : MapView(org.freeplane.view.swing.map.MapView) MTextController(org.freeplane.features.text.mindmapmode.MTextController) ResourceController(org.freeplane.core.resources.ResourceController) MMapController(org.freeplane.features.map.mindmapmode.MMapController) MapController(org.freeplane.features.map.MapController) LocationController(org.freeplane.features.nodelocation.LocationController) Controller(org.freeplane.features.mode.Controller) ModeController(org.freeplane.features.mode.ModeController) MLocationController(org.freeplane.features.nodelocation.mindmapmode.MLocationController) Point(java.awt.Point)

Example 13 with MapView

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

the class EditNodeTextField method layout.

private void layout() {
    if (textfield == null) {
        return;
    }
    final int lastWidth = textfield.getWidth();
    final int lastHeight = textfield.getHeight();
    final boolean lineWrap = lastWidth == maxWidth;
    Dimension preferredSize = textfield.getPreferredSize();
    if (!lineWrap) {
        preferredSize.width++;
        if (preferredSize.width > maxWidth) {
            setLineWrap();
            preferredSize = textfield.getPreferredSize();
        } else {
            if (preferredSize.width < lastWidth) {
                preferredSize.width = lastWidth;
            } else {
                preferredSize.width = Math.min(preferredSize.width + extraWidth, maxWidth);
                if (preferredSize.width == maxWidth) {
                    setLineWrap();
                }
            }
        }
    } else {
        preferredSize.width = Math.max(maxWidth, preferredSize.width);
    }
    if (preferredSize.width != lastWidth) {
        preferredSize.height = lastHeight;
        SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                layout();
            }
        });
    } else {
        preferredSize.height = Math.max(preferredSize.height, lastHeight);
    }
    if (preferredSize.width == lastWidth && preferredSize.height == lastHeight) {
        textfield.repaint();
        return;
    }
    textfield.setSize(preferredSize);
    if (layoutMapOnTextChange)
        parent.setPreferredSize(new Dimension(preferredSize.width + horizontalSpace, preferredSize.height + verticalSpace));
    textfield.revalidate();
    final NodeView nodeView = (NodeView) SwingUtilities.getAncestorOfClass(NodeView.class, parent);
    final MapView mapView = (MapView) SwingUtilities.getAncestorOfClass(MapView.class, nodeView);
    if (mapView == null)
        return;
    if (layoutMapOnTextChange)
        mapView.scrollNodeToVisible(nodeView);
    else
        mapView.scrollRectToVisible(textfield.getBounds());
}
Also used : MapView(org.freeplane.view.swing.map.MapView) Dimension(java.awt.Dimension) NodeView(org.freeplane.view.swing.map.NodeView) Point(java.awt.Point)

Example 14 with MapView

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

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

the class AttributeTable method prepareRenderer.

@Override
public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
    Object value = getValueAt(row, column);
    boolean isSelected = false;
    boolean hasFocus = false;
    // Only indicate the selection and focused cell if not printing
    MapView map = (MapView) SwingUtilities.getAncestorOfClass(MapView.class, this);
    if (map == null || !map.isPrinting()) {
        isSelected = isCellSelected(row, column);
        boolean rowIsLead = (selectionModel.getLeadSelectionIndex() == row);
        boolean colIsLead = (columnModel.getSelectionModel().getLeadSelectionIndex() == column);
        final Window windowAncestor = SwingUtilities.getWindowAncestor(this);
        hasFocus = (rowIsLead && colIsLead) && windowAncestor != null && equals(windowAncestor.getMostRecentFocusOwner());
    }
    return renderer.getTableCellRendererComponent(this, value, isSelected, hasFocus, row, column);
}
Also used : Window(java.awt.Window) MapView(org.freeplane.view.swing.map.MapView) EventObject(java.util.EventObject) IFormattedObject(org.freeplane.features.format.IFormattedObject)

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