use of org.freeplane.features.map.IMapSelection in project freeplane by freeplane.
the class NewSummaryAction method check.
private boolean check() {
start = -1;
end = -1;
summaryLevel = -1;
final ModeController modeController = Controller.getCurrentModeController();
final IMapSelection selection = modeController.getController().getSelection();
final List<NodeModel> sortedSelection = selection.getSortedSelection(false);
final NodeModel firstNode = sortedSelection.get(0);
final NodeModel parentNode = firstNode.getParentNode();
// root node selected
if (parentNode == null)
return false;
final NodeModel lastNode = sortedSelection.get(sortedSelection.size() - 1);
// different parents
if (!parentNode.equals(lastNode.getParentNode())) {
return false;
}
final boolean isLeft = firstNode.isLeft();
// different sides
if (isLeft != lastNode.isLeft()) {
return false;
}
start = parentNode.getIndex(firstNode);
end = parentNode.getIndex(lastNode);
// last node is a group node
if (firstNode != lastNode && SummaryNode.isFirstGroupNode(lastNode))
return false;
summaryLevel = SummaryNode.getSummaryLevel(firstNode);
// selected nodes have different summary levels
if (summaryLevel != SummaryNode.getSummaryLevel(lastNode))
return false;
int level = summaryLevel;
for (int i = start + 1; i < end; i++) {
NodeModel node = (NodeModel) parentNode.getChildAt(i);
if (isLeft != node.isLeft())
continue;
if (SummaryNode.isSummaryNode(node))
level++;
else
level = 0;
// There is a higher summary node between the selected nodes
if (level > summaryLevel)
return false;
}
return true;
}
use of org.freeplane.features.map.IMapSelection in project freeplane by freeplane.
the class ExecuteScriptAction method actionPerformed.
@Override
public void actionPerformed(final ActionEvent e) {
Controller.getCurrentController().getViewController().setWaitingCursor(true);
try {
final List<NodeModel> nodes = new ArrayList<NodeModel>();
final IMapSelection selection = Controller.getCurrentController().getSelection();
if (mode == ExecutionMode.ON_SINGLE_NODE) {
nodes.add(selection.getSelected());
} else {
nodes.addAll(selection.getSelection());
}
final MModeController modeController = (MModeController) Controller.getCurrentModeController();
modeController.startTransaction();
for (final NodeModel node : nodes) {
try {
if (mode == ExecutionMode.ON_SELECTED_NODE_RECURSIVELY) {
// TODO: ensure that a script is invoked only once on every node?
// (might be a problem with recursive actions if parent and child
// are selected.)
executeScriptRecursive(node);
} else {
script.execute(node);
}
} catch (ExecuteScriptException ex) {
final String cause;
// that, it is what we want to know.
if (ex.getCause() != null) {
if (ex.getCause().getCause() != null) {
LogUtils.warn("ExecuteScriptAction failed:", ex.getCause().getCause());
cause = ex.getCause().getCause().toString();
} else {
LogUtils.warn("ExecuteScriptAction failed:", ex.getCause());
cause = ex.getCause().toString();
}
} else {
LogUtils.warn("ExecuteScriptAction failed:", ex);
cause = ex.toString();
}
LogUtils.warn("error executing script " + scriptFile + " - giving up\n" + cause);
modeController.delayedRollback();
ScriptingEngine.showScriptExceptionErrorMessage(ex);
return;
}
}
modeController.delayedCommit();
} finally {
Controller.getCurrentController().getViewController().setWaitingCursor(false);
}
}
use of org.freeplane.features.map.IMapSelection in project freeplane by freeplane.
the class MLinkController method createArrowLinkPopup.
@Override
protected void createArrowLinkPopup(final ConnectorModel link, final JComponent arrowLinkPopup) {
super.createArrowLinkPopup(link, arrowLinkPopup);
addClosingAction(arrowLinkPopup, new RemoveConnectorAction(this, link));
addSeparator(arrowLinkPopup);
addAction(arrowLinkPopup, new ConnectorColorAction(this, link));
final JSlider transparencySlider = new JSlider(20, 255, link.getAlpha());
transparencySlider.setMinorTickSpacing(20);
transparencySlider.setPaintTicks(true);
transparencySlider.setSnapToTicks(true);
transparencySlider.setPaintTrack(true);
addPopupComponent(arrowLinkPopup, TextUtils.getText("edit_transparency_label"), transparencySlider);
addSeparator(arrowLinkPopup);
AFreeplaneAction[] arrowActions = new AFreeplaneAction[] { new ChangeConnectorArrowsAction(this, "none", link, ArrowType.NONE, ArrowType.NONE), new ChangeConnectorArrowsAction(this, "forward", link, ArrowType.NONE, ArrowType.DEFAULT), new ChangeConnectorArrowsAction(this, "backward", link, ArrowType.DEFAULT, ArrowType.NONE), new ChangeConnectorArrowsAction(this, "both", link, ArrowType.DEFAULT, ArrowType.DEFAULT) };
final JComboBox connectorArrows = createActionBox(arrowActions);
addPopupComponent(arrowLinkPopup, TextUtils.getText("connector_arrows"), connectorArrows);
final boolean twoNodesConnector = !link.getSource().equals(link.getTarget());
AFreeplaneAction[] shapeActions;
if (twoNodesConnector) {
shapeActions = new AFreeplaneAction[] { new ChangeConnectorShapeAction(this, link, Shape.CUBIC_CURVE), new ChangeConnectorShapeAction(this, link, Shape.LINE), new ChangeConnectorShapeAction(this, link, Shape.LINEAR_PATH), new ChangeConnectorShapeAction(this, link, Shape.EDGE_LIKE) };
} else {
shapeActions = new AFreeplaneAction[] { new ChangeConnectorShapeAction(this, link, Shape.CUBIC_CURVE), new ChangeConnectorShapeAction(this, link, Shape.LINE), new ChangeConnectorShapeAction(this, link, Shape.LINEAR_PATH) };
}
final JComboBox connectorShapes = createActionBox(shapeActions);
addPopupComponent(arrowLinkPopup, TextUtils.getText("connector_shapes"), connectorShapes);
AFreeplaneAction[] dashActions = new AFreeplaneAction[] { new ChangeConnectorDashAction(this, link, null), new ChangeConnectorDashAction(this, link, new int[] { 3, 3 }), new ChangeConnectorDashAction(this, link, new int[] { 7, 7 }), new ChangeConnectorDashAction(this, link, new int[] { 2, 7 }), new ChangeConnectorDashAction(this, link, new int[] { 2, 7, 7, 7 }) };
final JComboBox connectorDashes = createActionBox(dashActions);
addPopupComponent(arrowLinkPopup, TextUtils.getText("connector_lines"), connectorDashes);
final SpinnerNumberModel widthModel = new SpinnerNumberModel(link.getWidth(), 1, 32, 1);
final JSpinner widthSpinner = new JSpinner(widthModel);
addPopupComponent(arrowLinkPopup, TextUtils.getText("edit_width_label"), widthSpinner);
addSeparator(arrowLinkPopup);
{
final GraphicsEnvironment gEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
final String[] envFonts = gEnv.getAvailableFontFamilyNames();
DefaultComboBoxModel fonts = new DefaultComboBoxModel(envFonts);
fonts.setSelectedItem(link.getLabelFontFamily());
JComboBox fontBox = new JComboBox(fonts);
fontBox.setEditable(false);
addPopupComponent(arrowLinkPopup, TextUtils.getText("edit_label_font_family"), fontBox);
fontBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
final Object item = e.getItem();
if (item != null)
setLabelFontFamily(link, item.toString());
}
});
}
{
final Integer[] sizes = { 4, 6, 8, 10, 12, 14, 16, 18, 24, 36 };
DefaultComboBoxModel sizesModel = new DefaultComboBoxModel(sizes);
sizesModel.setSelectedItem(link.getLabelFontSize());
JComboBox sizesBox = new JComboBox(sizesModel);
sizesBox.setEditable(true);
addPopupComponent(arrowLinkPopup, TextUtils.getText("edit_label_font_size"), sizesBox);
sizesBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
final Object item = e.getItem();
if (item != null) {
final int size;
if (item instanceof Integer)
size = (Integer) item;
else {
try {
size = Integer.valueOf(item.toString());
if (size <= 0)
return;
} catch (NumberFormatException ex) {
return;
}
}
setLabelFontSize(link, size);
}
}
});
}
final JTextArea sourceLabelEditor;
sourceLabelEditor = new JTextArea(link.getSourceLabel());
addTextEditor(arrowLinkPopup, "edit_source_label", sourceLabelEditor);
final JTextArea middleLabelEditor = new JTextArea(link.getMiddleLabel());
addTextEditor(arrowLinkPopup, "edit_middle_label", middleLabelEditor);
final JTextArea targetLabelEditor;
targetLabelEditor = new JTextArea(link.getTargetLabel());
addTextEditor(arrowLinkPopup, "edit_target_label", targetLabelEditor);
arrowLinkPopup.addHierarchyListener(new HierarchyListener() {
private Component focusOwner;
private Window dialog;
public void hierarchyChanged(HierarchyEvent e) {
final JComponent component = (JComponent) e.getComponent();
if (component.isShowing()) {
if (dialog == null) {
dialog = SwingUtilities.getWindowAncestor(component);
dialog.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
component.putClientProperty(CANCEL, Boolean.TRUE);
}
});
}
if (focusOwner == null)
focusOwner = FocusManager.getCurrentManager().getFocusOwner();
return;
}
if (focusOwner == null || !focusOwner.isShowing())
return;
focusOwner.requestFocus();
if (Boolean.TRUE.equals(component.getClientProperty(CANCEL))) {
return;
}
final IMapSelection selection = Controller.getCurrentController().getSelection();
if (selection == null || selection.getSelected() == null)
return;
setSourceLabel(link, sourceLabelEditor.getText());
setTargetLabel(link, targetLabelEditor.getText());
setMiddleLabel(link, middleLabelEditor.getText());
setAlpha(link, transparencySlider.getValue());
setWidth(link, widthModel.getNumber().intValue());
}
});
}
use of org.freeplane.features.map.IMapSelection in project freeplane by freeplane.
the class AddConnectorAction method actionPerformed.
public void actionPerformed(final ActionEvent e) {
final IMapSelection selection = Controller.getCurrentController().getSelection();
final List<NodeModel> selecteds = selection.getOrderedSelection();
final int size = selecteds.size();
final MLinkController linkController = (MLinkController) LinkController.getController();
final NodeModel target = selecteds.get(size - 1);
if (selecteds.size() < 2) {
linkController.addConnector(target, target);
return;
}
for (NodeModel node : selecteds) {
if (node != target)
linkController.addConnector(node, target);
}
}
use of org.freeplane.features.map.IMapSelection in project freeplane by freeplane.
the class MapViewController method afterViewChange.
public void afterViewChange(final Component oldMap, final Component pNewMap) {
Controller controller = Controller.getCurrentController();
final ModeController oldModeController = controller.getModeController();
ModeController newModeController = oldModeController;
if (pNewMap != null) {
final IMapSelection mapSelection = getMapSelection();
final NodeModel selected = mapSelection.getSelected();
mapSelection.scrollNodeToVisible(selected);
setZoomComboBox(getZoom());
obtainFocusForSelected();
newModeController = getModeController(pNewMap);
if (newModeController != oldModeController) {
controller.selectMode(newModeController);
}
}
setTitle();
controller.getViewController().viewNumberChanged(getViewNumber());
newModeController.getUserInputListenerFactory().updateMapList();
if (pNewMap != null) {
newModeController.setVisible(true);
}
}
Aggregations