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);
}
}
});
}
}
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;
}
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());
}
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;
}
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);
}
Aggregations