use of org.freeplane.features.mode.ModeController in project freeplane by freeplane.
the class DefaultMouseWheelListener method mouseWheelMoved.
/*
* (non-Javadoc)
* @see
* freeplane.modes.ModeController.MouseWheelEventHandler#handleMouseWheelEvent
* (java.awt.event.MouseWheelEvent)
*/
public void mouseWheelMoved(final MouseWheelEvent e) {
final MapView mapView = (MapView) e.getSource();
final ModeController mController = mapView.getModeController();
if (mController.isBlocked()) {
return;
}
final Set<IMouseWheelEventHandler> registeredMouseWheelEventHandler = mController.getUserInputListenerFactory().getMouseWheelEventHandlers();
for (final IMouseWheelEventHandler handler : registeredMouseWheelEventHandler) {
final boolean result = handler.handleMouseWheelEvent(e);
if (result) {
return;
}
}
if ((e.getModifiers() & DefaultMouseWheelListener.ZOOM_MASK) != 0) {
float newZoomFactor = 1f + Math.abs((float) e.getWheelRotation()) / 10f;
if (e.getWheelRotation() < 0) {
newZoomFactor = 1 / newZoomFactor;
}
final float oldZoom = ((MapView) e.getComponent()).getZoom();
float newZoom = oldZoom / newZoomFactor;
newZoom = (float) Math.rint(newZoom * 1000f) / 1000f;
newZoom = Math.max(1f / 32f, newZoom);
newZoom = Math.min(32f, newZoom);
if (newZoom != oldZoom) {
Controller.getCurrentController().getMapViewManager().setZoom(newZoom);
}
} else if ((e.getModifiers() & DefaultMouseWheelListener.HORIZONTAL_SCROLL_MASK) != 0) {
((MapView) e.getComponent()).scrollBy(DefaultMouseWheelListener.SCROLL_SKIPS * e.getWheelRotation(), 0);
} else {
((MapView) e.getComponent()).scrollBy(0, DefaultMouseWheelListener.SCROLL_SKIPS * e.getWheelRotation());
}
}
use of org.freeplane.features.mode.ModeController in project freeplane by freeplane.
the class UserInputListenerFactory method updateModeMenu.
private void updateModeMenu() {
if (!useRibbonMenu()) {
getMenuBuilder(MenuBuilder.class).removeChildElements(FreeplaneMenuBar.MODES_MENU);
Controller controller = Controller.getCurrentController();
for (final String key : new LinkedList<String>(controller.getModes())) {
final AFreeplaneAction modesMenuActionListener = new ModesMenuActionListener(key, controller);
final ModeController modeController = controller.getModeController();
final boolean isSelected;
if (modeController != null) {
isSelected = modeController.getModeName().equals(key);
} else {
isSelected = false;
}
getMenuBuilder(MenuBuilder.class).addRadioItem(FreeplaneMenuBar.MODES_MENU, modesMenuActionListener, isSelected);
ResourceController.getResourceController().getProperty(("keystroke_mode_" + key));
}
}
}
use of org.freeplane.features.mode.ModeController in project freeplane by freeplane.
the class MMapMouseListener method mouseClicked.
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2 && Compat.isCtrlEvent(e)) {
final MapView mapView = (MapView) e.getComponent();
final Object object = mapView.detectCollision(new Point(originX, originY));
if (object != null)
return;
final ModeController modeController = Controller.getCurrentModeController();
final IExtension freeNode = modeController.getExtension(FreeNode.class);
if (freeNode != null && modeController instanceof MModeController) {
final JComponent rootContent = mapView.getRoot().getMainView();
final Point contentPt = new Point();
UITools.convertPointToAncestor(rootContent, contentPt, mapView);
final float zoom = mapView.getZoom();
final Point eventPoint = e.getPoint();
int x = (int) ((eventPoint.x - contentPt.x) / zoom);
final int y = (int) ((eventPoint.y - contentPt.y) / zoom);
final int rootContentNormalWidth = (int) (rootContent.getWidth() / zoom);
final boolean newNodeIsLeft = x < rootContentNormalWidth / 2;
if (newNodeIsLeft) {
x = rootContentNormalWidth - x;
}
final Point pt = new Point(x, y);
((MMapController) modeController.getMapController()).addFreeNode(pt, newNodeIsLeft);
}
} else
super.mouseClicked(e);
}
use of org.freeplane.features.mode.ModeController in project freeplane by freeplane.
the class Activator method start.
/*
* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*/
@Override
public void start(final BundleContext context) throws Exception {
final Hashtable<String, String[]> props = new Hashtable<String, String[]>();
props.put("mode", new String[] { MModeController.MODENAME /*TODO: other modes too?*/
});
context.registerService(IModeControllerExtensionProvider.class.getName(), new IModeControllerExtensionProvider() {
@Override
public void installExtension(ModeController modeController) {
final MenuBuilder menuBuilder = modeController.getUserInputListenerFactory().getMenuBuilder(MenuBuilder.class);
final $$$$Action action = new $$$$Action();
modeController.addAction(action);
modeController.addMenuContributor(new IMenuContributor() {
@Override
public void updateMenus(ModeController modeController, MenuBuilder builder) {
menuBuilder.addAction("/menu_bar/file", action, MenuBuilder.AS_CHILD);
}
});
}
}, props);
}
use of org.freeplane.features.mode.ModeController 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);
}
}
Aggregations