use of org.freeplane.features.map.MapModel in project freeplane by freeplane.
the class OpenMapsNodeHook method createUndoActor.
private IActor createUndoActor(final OpenMapsExtension extension, final ICoordinate newlyChoosenLocation, final ICoordinate currentlyStoredLocation, final int newlyChoosenZoom, final int currentlyStoredZoom) {
return new IActor() {
private final ICoordinate oldLocation = currentlyStoredLocation;
private final int oldZoom = currentlyStoredZoom;
public void act() {
extension.updateLocation(newlyChoosenLocation);
extension.updateZoom(newlyChoosenZoom);
final MapModel map = Controller.getCurrentModeController().getController().getMap();
Controller.getCurrentModeController().getMapController().setSaved(map, false);
}
public String getDescription() {
return "setOpenMapsLocationChoiceUndoable";
}
public void undo() {
if (oldLocation.getLat() == 500 && oldLocation.getLon() == 500) {
removeLocationFromCurrentlySelectedNode();
} else {
extension.updateLocation(oldLocation);
extension.updateZoom(oldZoom);
}
refreshNode(getCurrentlySelectedNode());
}
};
}
use of org.freeplane.features.map.MapModel in project freeplane by freeplane.
the class OpenMapsNodeHook method removeLocationFromCurrentlySelectedNode.
public void removeLocationFromCurrentlySelectedNode() {
final NodeModel node = getCurrentlySelectedNode();
OpenMapsExtension openMapsExtension = (OpenMapsExtension) node.getExtension(OpenMapsExtension.class);
if (openMapsExtension != null) {
super.undoableToggleHook(node, openMapsExtension);
refreshNode(node);
}
final MapModel map = Controller.getCurrentModeController().getController().getMap();
Controller.getCurrentModeController().getMapController().setSaved(map, false);
}
use of org.freeplane.features.map.MapModel in project freeplane by freeplane.
the class MapStyle method setProperty.
public void setProperty(final MapModel model, final String key, final String newValue) {
final MapStyleModel styleModel = MapStyleModel.getExtension(model);
final String oldValue = styleModel.getProperty(key);
if (oldValue == newValue || oldValue != null && oldValue.equals(newValue)) {
return;
}
IActor actor = new IActor() {
public void undo() {
setPropertyWithoutUndo(model, key, oldValue);
}
public String getDescription() {
return "set map style property";
}
public void act() {
setPropertyWithoutUndo(model, key, newValue);
}
private void setPropertyWithoutUndo(final MapModel model, final String key, final String newValue) {
styleModel.setProperty(key, newValue);
Controller.getCurrentModeController().getMapController().fireMapChanged(new MapChangeEvent(MapStyle.this, model, key, oldValue, newValue));
}
};
Controller.getCurrentModeController().execute(actor, model);
}
use of org.freeplane.features.map.MapModel in project freeplane by freeplane.
the class MapStyleModel method createStyleMap.
void createStyleMap(final MapModel parentMap, MapStyleModel mapStyleModel, final String styleMapStr) {
final ModeController modeController = Controller.getCurrentModeController();
MapModel styleMap = new StyleMapModel(parentMap.getIconRegistry(), AttributeRegistry.getRegistry(parentMap));
styleMap.createNewRoot();
final MapReader mapReader = modeController.getMapController().getMapReader();
final Reader styleReader = new StringReader(styleMapStr);
NodeModel root;
try {
Map<Object, Object> hints = new HashMap<Object, Object>();
hints.put(Hint.MODE, Mode.FILE);
hints.put(NodeBuilder.FOLDING_LOADED, Boolean.TRUE);
root = mapReader.createNodeTreeFromXml(styleMap, styleReader, hints);
NodeStyleModel.setShapeConfiguration(root, ShapeConfigurationModel.NULL_SHAPE.withShape(NodeStyleModel.Shape.oval).withUniform(true));
NodeStyleModel.createNodeStyleModel(root).setFontSize(24);
styleMap.setRoot(root);
final Quantity<LengthUnits> styleBlockGap = ResourceController.getResourceController().getLengthQuantityProperty("style_block_gap");
LocationModel.createLocationModel(root).setVGap(styleBlockGap);
insertStyleMap(parentMap, styleMap);
NodeModel predefinedStyleParentNode = createStyleGroupNode(styleMap, STYLES_PREDEFINED);
createStyleGroupNode(styleMap, STYLES_USER_DEFINED);
createStyleGroupNode(styleMap, STYLES_AUTOMATIC_LAYOUT);
if (styleNodes.get(DEFAULT_STYLE) == null) {
final NodeModel newNode = new NodeModel(DEFAULT_STYLE, styleMap);
predefinedStyleParentNode.insert(newNode, 0);
addStyleNode(newNode);
}
NodeModel defaultStyleModel = styleNodes.get(DEFAULT_STYLE);
if (maxNodeWidth != null && null == NodeSizeModel.getMaxNodeWidth(defaultStyleModel))
NodeSizeModel.setMaxNodeWidth(defaultStyleModel, maxNodeWidth);
if (minNodeWidth != null && null == NodeSizeModel.getMinNodeWidth(defaultStyleModel))
NodeSizeModel.setNodeMinWidth(defaultStyleModel, minNodeWidth);
if (styleNodes.get(DETAILS_STYLE) == null) {
final NodeModel newNode = new NodeModel(DETAILS_STYLE, styleMap);
predefinedStyleParentNode.insert(newNode, 1);
addStyleNode(newNode);
}
if (styleNodes.get(ATTRIBUTE_STYLE) == null) {
final NodeModel newNode = new NodeModel(ATTRIBUTE_STYLE, styleMap);
final int defaultFontSize = 9;
NodeStyleModel.createNodeStyleModel(newNode).setFontSize(defaultFontSize);
predefinedStyleParentNode.insert(newNode, 2);
addStyleNode(newNode);
}
FontSizeExtension fontSizeExtension = parentMap.getExtension(FontSizeExtension.class);
if (fontSizeExtension != null) {
NodeStyleModel.createNodeStyleModel(styleNodes.get(ATTRIBUTE_STYLE)).setFontSize(fontSizeExtension.fontSize);
}
if (styleNodes.get(NOTE_STYLE) == null) {
final NodeModel newNode = new NodeModel(NOTE_STYLE, styleMap);
NodeStyleModel.createNodeStyleModel(newNode).setBackgroundColor(Color.WHITE);
predefinedStyleParentNode.insert(newNode, 3);
addStyleNode(newNode);
}
if (styleNodes.get(FLOATING_STYLE) == null) {
final NodeModel newNode = new NodeModel(FLOATING_STYLE, styleMap);
EdgeModel.createEdgeModel(newNode).setStyle(EdgeStyle.EDGESTYLE_HIDDEN);
CloudModel.createModel(newNode).setShape(CloudModel.Shape.ROUND_RECT);
predefinedStyleParentNode.insert(newNode, 4);
addStyleNode(newNode);
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.freeplane.features.map.MapModel in project freeplane by freeplane.
the class PresentationWriter method register.
void register(MapController mapController, final PresentationController presentationController) {
mapController.getReadManager().addElementHandler("hook", new IElementDOMHandler() {
private final ConditionFactory conditionFactory = FilterController.getCurrentFilterController().getConditionFactory();
@Override
public Object createElement(Object parent, String tag, XMLElement attributes) {
if (attributes == null) {
return null;
}
if (!PRESENTATIONS.equals(attributes.getAttribute("NAME", null))) {
return null;
}
return parent;
}
@Override
public void endElement(Object parent, String tag, Object element, XMLElement dom) {
final NodeModel node = (NodeModel) parent;
final MapModel map = node.getMap();
final NamedElementFactory<Slide> slideFactory = presentationController.getSlideFactory(map);
MapPresentations mapPresentationExtension = presentationController.getPresentations(map);
NamedElementCollection<Presentation> presentations = mapPresentationExtension.presentations;
Enumeration<XMLElement> xmlPresentations = dom.enumerateChildren();
while (xmlPresentations.hasMoreElements()) {
XMLElement xmlPresentation = xmlPresentations.nextElement();
presentations.add(xmlPresentation.getAttribute(NAME, "noname"));
Enumeration<XMLElement> xmlSlides = xmlPresentation.enumerateChildren();
NamedElementCollection<Slide> slides = presentations.getCurrentElement().slides;
while (xmlSlides.hasMoreElements()) {
XMLElement xmlSlide = xmlSlides.nextElement();
final String name = xmlSlide.getAttribute(NAME, "noname");
Slide s = slideFactory.create(name);
Slide slide = applySlideAttributes(xmlSlide, s);
slides.add(slide);
}
if (slides.getSize() > 1)
slides.selectCurrentElement(0);
}
if (presentations.getSize() > 1)
presentations.selectCurrentElement(0);
node.addExtension(mapPresentationExtension);
}
Slide applySlideAttributes(XMLElement xmlSlide, Slide s) {
s.setShowsAncestors(toBoolean(xmlSlide, SHOWS_ANCESTORS));
s.setShowsDescendants(toBoolean(xmlSlide, SHOWS_DESCENDANTS));
s.setShowsOnlySpecificNodes(toBoolean(xmlSlide, SHOWS_ONLY_SPECIFIC_NODES));
s.setChangesZoom(toBoolean(xmlSlide, CHANGES_ZOOM));
final String centeredNodeId = toString(xmlSlide, CENTERED_NODE_ID);
if (centeredNodeId != null) {
s.setPlacedNodeId(centeredNodeId);
}
final String placedNodeId = toString(xmlSlide, PLACED_NODE_ID);
if (placedNodeId != null) {
s.setPlacedNodeId(placedNodeId);
}
final String nodePosition = xmlSlide.getAttribute(PLACED_NODE_POSITION, NodePosition.CENTER.name());
s.setPlacedNodePosition(NodePosition.valueOf(nodePosition));
s.setZoom(toFloat(xmlSlide, ZOOM));
Enumeration<XMLElement> childAttributes = xmlSlide.enumerateChildren();
while (childAttributes.hasMoreElements()) {
XMLElement xmlElement = childAttributes.nextElement();
if (xmlElement.getName().equals(NODES_ON_SLIDE)) {
Set<String> ids = loadSpecificNodeIds(xmlElement);
s.setSelectedNodeIds(ids);
} else if (xmlElement.getName().equals(FOLDED_NODES)) {
Set<String> ids = loadSpecificNodeIds(xmlElement);
s.setFoldedNodeIDs(ids);
} else if (xmlElement.getName().equals(SLIDE_CONDITION)) {
ASelectableCondition condition = loadFilterCondition(xmlElement);
s.setFilterCondition(condition);
}
}
return s;
}
private Set<String> loadSpecificNodeIds(XMLElement xmlNodeIds) {
LinkedHashSet<String> nodeIds = new LinkedHashSet<>();
Enumeration<XMLElement> nodesEnumeration = xmlNodeIds.enumerateChildren();
while (nodesEnumeration.hasMoreElements()) {
XMLElement nodeIdXml = nodesEnumeration.nextElement();
if (nodeIdXml.getName().equals(NODE_ON_SLIDE)) {
String id = nodeIdXml.getAttribute(NODE_ID, null);
if (id != null)
nodeIds.add(id);
}
}
return nodeIds;
}
private ASelectableCondition loadFilterCondition(XMLElement xmlElement) {
return conditionFactory.loadCondition(xmlElement.getChildAtIndex(0));
}
private float toFloat(XMLElement element, String attribute) {
return Float.parseFloat(element.getAttribute(attribute, "1f"));
}
private boolean toBoolean(XMLElement element, String attribute) {
return Boolean.parseBoolean(element.getAttribute(attribute, ""));
}
private String toString(XMLElement element, String attribute) {
return element.getAttribute(attribute, null);
}
});
mapController.getWriteManager().addExtensionElementWriter(MapPresentations.class, new IExtensionElementWriter() {
@Override
public void writeContent(ITreeWriter writer, Object element, IExtension extension) throws IOException {
new PresentationWriter(((NodeModel) element).getMap()).writeContent(writer, extension);
}
});
}
Aggregations