use of org.freeplane.features.map.MapModel in project freeplane by freeplane.
the class ManageMapConditionalStylesAction method actionPerformed.
public void actionPerformed(ActionEvent e) {
final Controller controller = Controller.getCurrentController();
final MapModel map = controller.getMap();
final ConditionalStyleModel conditionalStyleModel = getConditionalStyleModel();
Component pane = createConditionalStylePane(map, conditionalStyleModel);
Controller.getCurrentModeController().startTransaction();
try {
final int confirmed = JOptionPane.showConfirmDialog(controller.getMapViewManager().getMapViewComponent(), pane, TextUtils.getText(TextUtils.removeMnemonic("ManageConditionalStylesAction.text")), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
if (JOptionPane.OK_OPTION == confirmed) {
LogicalStyleController.getController().refreshMap(map);
Controller.getCurrentModeController().commit();
} else {
Controller.getCurrentModeController().rollback();
}
} catch (RuntimeException ex) {
ex.printStackTrace();
Controller.getCurrentModeController().rollback();
}
}
use of org.freeplane.features.map.MapModel in project freeplane by freeplane.
the class NewUserStyleAction method actionPerformed.
public void actionPerformed(final ActionEvent e) {
final String styleName = JOptionPane.showInputDialog(TextUtils.getText("enter_new_style_name"));
if (styleName == null) {
return;
}
final Controller controller = Controller.getCurrentController();
final NodeModel selectedNode = controller.getSelection().getSelected();
final MapModel map = controller.getMap();
final MapStyleModel styleModel = MapStyleModel.getExtension(map);
final MapModel styleMap = styleModel.getStyleMap();
final IStyle newStyle = StyleFactory.create(styleName);
if (null != styleModel.getStyleNode(newStyle)) {
UITools.errorMessage(TextUtils.getText("style_already_exists"));
return;
}
final MMapController mapController = (MMapController) Controller.getCurrentModeController().getMapController();
final NodeModel newNode = new NodeModel(styleMap);
newNode.setUserObject(newStyle);
final LogicalStyleController styleController = LogicalStyleController.getController();
final ArrayList<IStyle> styles = new ArrayList<IStyle>(styleController.getStyles(selectedNode));
for (int i = styles.size() - 1; i >= 0; i--) {
IStyle style = styles.get(i);
if (MapStyleModel.DEFAULT_STYLE.equals(style)) {
continue;
}
final NodeModel styleNode = styleModel.getStyleNode(style);
if (styleNode == null) {
continue;
}
Controller.getCurrentModeController().copyExtensions(LogicalStyleKeys.NODE_STYLE, styleNode, newNode);
}
Controller.getCurrentModeController().copyExtensions(LogicalStyleKeys.NODE_STYLE, selectedNode, newNode);
Controller.getCurrentModeController().copyExtensions(Keys.ICONS, selectedNode, newNode);
NodeModel userStyleParentNode = styleModel.getStyleNodeGroup(styleMap, MapStyleModel.STYLES_USER_DEFINED);
if (userStyleParentNode == null) {
userStyleParentNode = new NodeModel(styleMap);
userStyleParentNode.setUserObject(new StyleTranslatedObject(MapStyleModel.STYLES_USER_DEFINED));
mapController.insertNode(userStyleParentNode, styleMap.getRootNode(), false, false, true);
}
mapController.insertNode(newNode, userStyleParentNode, false, false, true);
mapController.select(newNode);
final IActor actor = new IActor() {
public void undo() {
styleModel.removeStyleNode(newNode);
styleController.refreshMap(map);
}
public String getDescription() {
return "NewStyle";
}
public void act() {
styleModel.addStyleNode(newNode);
styleController.refreshMap(map);
}
};
Controller.getCurrentModeController().execute(actor, styleMap);
}
use of org.freeplane.features.map.MapModel in project freeplane by freeplane.
the class MTextController method setImageByFileChooser.
public void setImageByFileChooser() {
boolean picturesAmongSelecteds = false;
final ModeController modeController = Controller.getCurrentModeController();
for (final NodeModel node : modeController.getMapController().getSelectedNodes()) {
final URI link = NodeLinks.getLink(node);
if (link != null) {
final String linkString = link.toString();
final String lowerCase = linkString.toLowerCase();
if (lowerCase.endsWith(".png") || lowerCase.endsWith(".jpg") || lowerCase.endsWith(".jpeg") || lowerCase.endsWith(".gif")) {
picturesAmongSelecteds = true;
final String encodedLinkString = HtmlUtils.unicodeToHTMLUnicodeEntity(linkString);
final String strText = "<html><img src=\"" + encodedLinkString + "\">";
((MLinkController) LinkController.getController()).setLink(node, (URI) null, LinkController.LINK_ABSOLUTE);
setNodeText(node, strText);
}
}
}
if (picturesAmongSelecteds) {
return;
}
final Controller controller = modeController.getController();
final ViewController viewController = controller.getViewController();
final NodeModel selectedNode = modeController.getMapController().getSelectedNode();
final MapModel map = selectedNode.getMap();
final File file = map.getFile();
if (file == null && LinkController.getLinkType() == LinkController.LINK_RELATIVE_TO_MINDMAP) {
JOptionPane.showMessageDialog(viewController.getCurrentRootComponent(), TextUtils.getText("not_saved_for_image_error"), "Freeplane", JOptionPane.WARNING_MESSAGE);
return;
}
final ExampleFileFilter filter = new ExampleFileFilter();
filter.addExtension("jpg");
filter.addExtension("jpeg");
filter.addExtension("png");
filter.addExtension("gif");
filter.setDescription(TextUtils.getText("bitmaps"));
final UrlManager urlManager = modeController.getExtension(UrlManager.class);
final JFileChooser chooser = urlManager.getFileChooser(null, false);
chooser.setFileFilter(filter);
chooser.setAcceptAllFileFilterUsed(false);
chooser.setAccessory(new BitmapImagePreview(chooser));
final int returnVal = chooser.showOpenDialog(viewController.getCurrentRootComponent());
if (returnVal != JFileChooser.APPROVE_OPTION) {
return;
}
final File input = chooser.getSelectedFile();
URI uri = input.toURI();
if (uri == null) {
return;
}
// bad hack: try to interpret file as http link
if (!input.exists()) {
uri = LinkController.toRelativeURI(map.getFile(), input, LinkController.LINK_RELATIVE_TO_MINDMAP);
if (uri == null || !"http".equals(uri.getScheme())) {
UITools.errorMessage(TextUtils.format("file_not_found", input.toString()));
return;
}
} else if (LinkController.getLinkType() != LinkController.LINK_ABSOLUTE) {
uri = LinkController.toLinkTypeDependantURI(map.getFile(), input);
}
String uriString = uri.toString();
if (uriString.startsWith("http:/")) {
uriString = "http://" + uriString.substring("http:/".length());
}
final String strText = "<html><img src=\"" + uriString + "\">";
setNodeText(selectedNode, strText);
}
use of org.freeplane.features.map.MapModel in project freeplane by freeplane.
the class StyleControlGroup method addEdgeColoringControls.
private void addEdgeColoringControls(final DefaultFormBuilder formBuilder) {
TranslatedObject[] automaticLayoutTypes = TranslatedObject.fromEnum(AutomaticEdgeColor.class.getSimpleName() + ".", AutomaticEdgeColor.Rule.class);
mAutomaticEdgeColorComboBox = new JComboBoxWithBorder(automaticLayoutTypes);
DefaultComboBoxModel automaticEdgeColorComboBoxModel = (DefaultComboBoxModel) mAutomaticEdgeColorComboBox.getModel();
automaticEdgeColorComboBoxModel.addElement(AUTOMATIC_LAYOUT_DISABLED);
automaticEdgeColorComboBoxModel.setSelectedItem(AUTOMATIC_LAYOUT_DISABLED);
mAutomaticEdgeColorComboBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (internalChange)
return;
final ModeController modeController = Controller.getCurrentModeController();
AutomaticEdgeColorHook hook = modeController.getExtension(AutomaticEdgeColorHook.class);
TranslatedObject selectedItem = (TranslatedObject) mAutomaticEdgeColorComboBox.getSelectedItem();
final MapModel map = Controller.getCurrentController().getMap();
final AutomaticEdgeColor oldExtension = (AutomaticEdgeColor) hook.getMapHook(map);
final int colorCount = oldExtension == null ? 0 : oldExtension.getColorCounter();
final NodeModel rootNode = map.getRootNode();
hook.undoableDeactivateHook(rootNode);
if (!selectedItem.equals(AUTOMATIC_LAYOUT_DISABLED)) {
final AutomaticEdgeColor newExtension = new AutomaticEdgeColor((AutomaticEdgeColor.Rule) selectedItem.getObject(), colorCount);
hook.undoableActivateHook(rootNode, newExtension);
}
}
});
appendLabeledComponent(formBuilder, "AutomaticEdgeColorHookAction.text", mAutomaticEdgeColorComboBox);
mEditEdgeColorsBtn = TranslatedElementFactory.createButton("editEdgeColors");
mEditEdgeColorsBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final MEdgeController edgeController = (MEdgeController) modeController.getExtension(EdgeController.class);
edgeController.editEdgeColorConfiguration(Controller.getCurrentController().getMap());
}
});
formBuilder.appendLineGapRow();
formBuilder.nextLine();
formBuilder.appendRow(FormSpecs.PREF_ROWSPEC);
formBuilder.setColumn(1);
formBuilder.append(mEditEdgeColorsBtn, 7);
formBuilder.nextLine();
}
use of org.freeplane.features.map.MapModel in project freeplane by freeplane.
the class XmlImporter method newMap.
private void newMap(final InputStream in, final File outputFile) throws IOException, XMLException, MalformedURLException {
final Reader reader = new XsltPipeReaderFactory(xsltResource).getReader(in);
final ModeController modeController = Controller.getCurrentModeController();
final MapController mapController = modeController.getMapController();
final MapModel map = new MMapModel();
modeController.getMapController().getMapReader().createNodeTreeFromXml(map, reader, Mode.FILE);
final URL mapUrl = Compat.fileToUrl(outputFile);
map.setURL(mapUrl);
map.setSaved(false);
mapController.fireMapCreated(map);
mapController.newMapView(map);
}
Aggregations