use of org.freeplane.view.swing.map.NodeView in project freeplane by freeplane.
the class MNodeDragListener method dragGestureRecognized.
public void dragGestureRecognized(final DragGestureEvent e) {
final MainView mainView = (MainView) e.getComponent();
final NodeView nodeView = mainView.getNodeView();
final MapView mapView = nodeView.getMap();
mapView.select();
if (!nodeView.isSelected()) {
nodeView.getMap().getModeController().getController().getSelection().selectAsTheOnlyOneSelected(nodeView.getModel());
}
Rectangle bounds = new Rectangle(0, 0, mainView.getWidth(), mainView.getHeight());
if (!bounds.contains(e.getDragOrigin()))
return;
final int dragActionType = e.getDragAction();
if (dragActionType == DnDConstants.ACTION_MOVE) {
final NodeModel node = nodeView.getModel();
if (node.isRoot()) {
if (!isLinkDragEvent(e))
return;
}
}
final String dragActionName;
Cursor cursor = getCursorByAction(dragActionType);
if (isLinkDragEvent(e)) {
cursor = DragSource.DefaultLinkDrop;
dragActionName = "LINK";
} else if ((e.getTriggerEvent().getModifiersEx() & InputEvent.BUTTON2_DOWN_MASK) != 0) {
cursor = DragSource.DefaultCopyDrop;
dragActionName = "COPY";
} else {
dragActionName = "MOVE";
}
final Transferable t = ClipboardController.getController().copy(Controller.getCurrentController().getSelection());
((MindMapNodesSelection) t).setDropAction(dragActionName);
try {
e.startDrag(cursor, t, new DragSourceListener() {
public void dragDropEnd(final DragSourceDropEvent dsde) {
}
public void dragEnter(final DragSourceDragEvent e) {
}
public void dragExit(final DragSourceEvent dse) {
}
public void dragOver(final DragSourceDragEvent dsde) {
}
public void dropActionChanged(final DragSourceDragEvent dsde) {
dsde.getDragSourceContext().setCursor(getCursorByAction(dsde.getUserAction()));
}
});
} catch (final InvalidDnDOperationException ex) {
}
}
use of org.freeplane.view.swing.map.NodeView in project freeplane by freeplane.
the class MNodeMotionListener method adjustNodeIndices.
private void adjustNodeIndices(final NodeView nodeV) {
NodeModel[] selectedsBackup = null;
final NodeModel node = nodeV.getModel();
if (FreeNode.isFreeNode(node)) {
selectedsBackup = adjustNodeIndexBackupSelection(nodeV, selectedsBackup);
} else {
final MapView map = nodeV.getMap();
final NodeModel[] siblingNodes = node.getParentNode().getChildren().toArray(new NodeModel[] {});
for (NodeModel sibling : siblingNodes) {
if (FreeNode.isFreeNode(sibling)) {
final NodeView siblingV = map.getNodeView(sibling);
selectedsBackup = adjustNodeIndexBackupSelection(siblingV, selectedsBackup);
}
}
}
if (selectedsBackup != null) {
final ModeController modeController = nodeV.getMap().getModeController();
final Controller controller = modeController.getController();
controller.getSelection().replaceSelection(selectedsBackup);
}
}
use of org.freeplane.view.swing.map.NodeView 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.NodeView 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.NodeView in project freeplane by freeplane.
the class DetailsViewMouseListener method mouseClicked.
@Override
public void mouseClicked(MouseEvent e) {
final ModeController mc = Controller.getCurrentController().getModeController();
if (Compat.isMacOsX()) {
final JPopupMenu popupmenu = mc.getUserInputListenerFactory().getNodePopupMenu();
if (popupmenu.isShowing()) {
return;
}
}
final NodeView nodeView = nodeSelector.getRelatedNodeView(e);
if (nodeView == null)
return;
final NodeModel model = nodeView.getModel();
TextController controller = TextController.getController();
if (eventFromHideDisplayArea(e)) {
final IMapSelection selection = Controller.getCurrentController().getSelection();
selection.keepNodePosition(model, 0.0f, 0.0f);
controller.setDetailsHidden(model, !DetailTextModel.getDetailText(model).isHidden());
} else {
nodeSelector.extendSelection(e);
if (canEdit(controller) && isEditingStartEvent(e)) {
((MTextController) controller).editDetails(model, e, e.isAltDown());
} else
super.mouseClicked(e);
}
}
Aggregations