use of org.freeplane.view.swing.map.NodeView in project freeplane by freeplane.
the class MNodeMouseWheelListener method mouseWheelMoved.
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
if (!e.isAltDown()) {
super.mouseWheelMoved(e);
return;
}
final MainView view = (MainView) e.getComponent();
final MapView map = (MapView) SwingUtilities.getAncestorOfClass(MapView.class, view);
if (map.usesLayoutSpecificMaxNodeWidth())
return;
final int wheelRotation = e.getWheelRotation();
final NodeView nodeView = view.getNodeView();
if (!nodeView.isSelected())
map.selectAsTheOnlyOneSelected(nodeView);
final double factor = e.isControlDown() ? 1 : 6 * LengthUnits.pt.factor();
double newZoomedWidth = Math.max((view.getWidth() - wheelRotation * factor) / map.getZoom(), 0);
final IMapSelection selection = Controller.getCurrentController().getSelection();
Quantity<LengthUnits> newZoomedWidthQuantity = LengthUnits.pixelsInPt(newZoomedWidth);
final ModeController modeController = map.getModeController();
final MNodeStyleController styleController = (MNodeStyleController) modeController.getExtension(NodeStyleController.class);
selection.keepNodePosition(nodeView.getModel(), 0f, 0f);
for (final NodeModel node : selection.getSelection()) {
styleController.setMinNodeWidth(node, newZoomedWidthQuantity);
styleController.setMaxNodeWidth(node, newZoomedWidthQuantity);
}
}
use of org.freeplane.view.swing.map.NodeView in project freeplane by freeplane.
the class ViewerController method onViewCreated.
public void onViewCreated(final Container container) {
final NodeView nodeView = (NodeView) container;
final ExternalResource previewUri = nodeView.getModel().getExtension(ExternalResource.class);
if (previewUri == null) {
return;
}
createViewer(previewUri, nodeView);
}
use of org.freeplane.view.swing.map.NodeView in project freeplane by freeplane.
the class MExternalImageDropListener method drop.
public void drop(final DropTargetDropEvent ev) {
try {
int dropAction = ev.getDropAction();
if (dropAction == DnDConstants.ACTION_MOVE && ev.isDataFlavorSupported(MindMapNodesSelection.fileListFlavor)) {
try {
ev.acceptDrop(ev.getDropAction());
@SuppressWarnings("unchecked") final List<File> transferData = (List<File>) ev.getTransferable().getTransferData(MindMapNodesSelection.fileListFlavor);
if (transferData.size() != 1)
return;
final Component target = ev.getDropTargetContext().getComponent();
NodeView nodeView = (NodeView) SwingUtilities.getAncestorOfClass(NodeView.class, target);
final File file = transferData.get(0);
final ViewerController vc = (Controller.getCurrentController().getModeController().getExtension(ViewerController.class));
final NodeModel node = nodeView.getModel();
vc.paste(file.toURI(), node, node.isLeft());
} catch (Exception e) {
LogUtils.warn(e);
}
}
} catch (final Exception e) {
LogUtils.severe("Drop exception:", e);
ev.dropComplete(false);
return;
}
ev.dropComplete(true);
}
use of org.freeplane.view.swing.map.NodeView in project freeplane by freeplane.
the class MMapViewController method createEditor.
private EditNodeBase createEditor(final NodeModel node, final EditedComponent parent, final String text, final IEditControl editControl) {
final ZoomableLabel parentComponent;
final MainView mainView = (MainView) getComponent(node);
final NodeView nodeView = mainView.getNodeView();
if (EditedComponent.TEXT.equals(parent))
parentComponent = mainView;
else if (EditedComponent.DETAIL.equals(parent)) {
final JComponent component = nodeView.getContent(NodeView.DETAIL_VIEWER_POSITION);
if (component instanceof ZoomableLabel)
parentComponent = (ZoomableLabel) component;
else
parentComponent = null;
} else
parentComponent = null;
if (parentComponent == null || !parentComponent.isVisible()) {
return null;
}
final EditNodeTextField textField = new EditNodeTextField(node, (ZoomableLabel) parentComponent, text, editControl);
if (EditedComponent.TEXT.equals(parent))
textField.setBackground(nodeView.getTextBackground());
else if (EditedComponent.DETAIL.equals(parent))
textField.setBackground(nodeView.getDetailBackground());
return textField;
}
use of org.freeplane.view.swing.map.NodeView in project freeplane by freeplane.
the class MMapMouseListener method mouseDragged.
public void mouseDragged(final MouseEvent e) {
final MapView mapView = (MapView) e.getComponent();
if (draggedLink != null && mapView.getLayoutType().equals(MapViewLayout.MAP)) {
final int deltaX = (int) ((e.getX() - originX) / mapView.getZoom());
final int deltaY = (int) ((e.getY() - originY) / mapView.getZoom());
double distSqToTarget = 0;
double distSqToSource = 0;
final NodeModel target = draggedLink.getTarget();
final NodeView targetView = mapView.getNodeView(target);
final NodeView sourceView = mapView.getNodeView(draggedLink.getSource());
if (targetView != null && sourceView != null) {
final Point targetLinkPoint = targetView.getLinkPoint(draggedLink.getEndInclination());
final Point sourceLinkPoint = sourceView.getLinkPoint(draggedLink.getStartInclination());
distSqToTarget = targetLinkPoint.distanceSq(originX, originY);
distSqToSource = sourceLinkPoint.distanceSq(originX, originY);
}
if ((targetView == null || sourceView != null) && distSqToSource <= distSqToTarget * 2.25) {
final Point changedInclination = draggedLink.getStartInclination();
draggedLink.changeInclination(deltaX, deltaY, draggedLink.getSource(), changedInclination);
draggedLink.setStartInclination(changedInclination);
}
if ((sourceView == null || targetView != null) && distSqToTarget <= distSqToSource * 2.25) {
final Point changedInclination = draggedLink.getEndInclination();
draggedLink.changeInclination(deltaX, deltaY, target, changedInclination);
draggedLink.setEndInclination(changedInclination);
}
originX = e.getX();
originY = e.getY();
mapView.repaintVisible();
} else {
super.mouseDragged(e);
}
}
Aggregations