use of org.freeplane.core.extension.IExtension in project freeplane by freeplane.
the class StyleControlGroup method setStyle.
@Override
public void setStyle(NodeModel node) {
internalChange = true;
try {
final LogicalStyleController logicalStyleController = LogicalStyleController.getController();
if (addStyleBox) {
final boolean isStyleSet = LogicalStyleModel.getStyle(node) != null;
mSetStyle.setValue(isStyleSet);
setStyleList(mMapStyleButton, logicalStyleController.getMapStyleNames(node, "\n"));
}
setStyleList(mNodeStyleButton, logicalStyleController.getNodeStyleNames(node, "\n"));
if (mAutomaticLayoutComboBox != null) {
final ModeController modeController = Controller.getCurrentModeController();
AutomaticLayoutController al = modeController.getExtension(AutomaticLayoutController.class);
IExtension extension = al.getExtension(node);
if (extension == null)
mAutomaticLayoutComboBox.setSelectedItem(AUTOMATIC_LAYOUT_DISABLED);
else
mAutomaticLayoutComboBox.setSelectedIndex(((AutomaticLayout) extension).ordinal());
}
if (mAutomaticEdgeColorComboBox != null) {
final ModeController modeController = Controller.getCurrentModeController();
AutomaticEdgeColorHook al = (AutomaticEdgeColorHook) modeController.getExtension(AutomaticEdgeColorHook.class);
final AutomaticEdgeColor extension = (AutomaticEdgeColor) al.getExtension(node);
if (extension == null) {
mAutomaticEdgeColorComboBox.setSelectedItem(AUTOMATIC_LAYOUT_DISABLED);
mEditEdgeColorsBtn.setEnabled(false);
} else {
mAutomaticEdgeColorComboBox.setSelectedIndex(extension.rule.ordinal());
mEditEdgeColorsBtn.setEnabled(true);
}
}
} finally {
internalChange = false;
}
}
use of org.freeplane.core.extension.IExtension in project freeplane by freeplane.
the class MMapController method moveNodesAsChildren.
public void moveNodesAsChildren(final List<NodeModel> children, final NodeModel target, final boolean isLeft, final boolean changeSide) {
FreeNode r = Controller.getCurrentModeController().getExtension(FreeNode.class);
for (NodeModel node : children) {
final IExtension extension = node.getExtension(FreeNode.class);
if (extension != null) {
r.undoableToggleHook(node, extension);
if (MapStyleModel.FLOATING_STYLE.equals(LogicalStyleModel.getStyle(node)))
((MLogicalStyleController) MLogicalStyleController.getController(getMModeController())).setStyle(node, null);
}
}
int position = target.getChildCount();
moveNodes(children, target, position, isLeft, changeSide);
}
use of org.freeplane.core.extension.IExtension in project freeplane by freeplane.
the class TreeXmlWriter method addElement.
@SuppressWarnings("unchecked")
public void addElement(final Object userObject, final XMLElement element) throws IOException {
final boolean isString = userObject instanceof String;
if (elementStarted == false && xmlElement != null) {
xmlwriter.write(xmlElement, !isString, 0, true, false);
}
final String name = element.getName();
xmlElement = element;
elementStarted = false;
{
final Iterator<IAttributeWriter> iterator = getAttributeWriters().iterator(name);
while (iterator.hasNext()) {
final IAttributeWriter as = iterator.next();
as.writeAttributes(this, userObject, name);
}
if (userObject instanceof List<?>) {
addExtensionAttributes(userObject, (List<IExtension>) userObject);
}
}
if (isString) {
addElementContent((String) userObject);
} else {
final Iterator<IElementWriter> iterator = getNodeWriters().iterator(name);
while (iterator.hasNext()) {
final IElementWriter nw = iterator.next();
nw.writeContent(this, userObject, name);
}
if (userObject instanceof List<?>) {
addExtensionNodes(userObject, (List<IExtension>) userObject);
}
}
if (elementStarted == false) {
xmlwriter.write(xmlElement, true, 0, true, true);
elementStarted = true;
} else {
xmlwriter.endElement(name, true);
}
}
use of org.freeplane.core.extension.IExtension in project freeplane by freeplane.
the class ExportBranchAction method actionPerformed.
public void actionPerformed(final ActionEvent e) {
final NodeModel existingNode = Controller.getCurrentModeController().getMapController().getSelectedNode();
final Controller controller = Controller.getCurrentController();
final MapModel parentMap = controller.getMap();
if (parentMap == null || existingNode == null || existingNode.isRoot()) {
controller.getViewController().err("Could not export branch.");
return;
}
if (parentMap.getFile() == null) {
controller.getViewController().out("You must save the current map first!");
((MModeController) Controller.getCurrentModeController()).save();
}
JFileChooser chooser;
final File file = parentMap.getFile();
if (file == null) {
return;
}
chooser = new JFileChooser(file.getParentFile());
chooser.setSelectedFile(new File(createFileName(TextController.getController().getShortText(existingNode))));
if (((MFileManager) UrlManager.getController()).getFileFilter() != null) {
chooser.addChoosableFileFilter(((MFileManager) UrlManager.getController()).getFileFilter());
}
final int returnVal = chooser.showSaveDialog(controller.getViewController().getContentPane());
if (returnVal == JFileChooser.APPROVE_OPTION) {
File chosenFile = chooser.getSelectedFile();
final String ext = FileUtils.getExtension(chosenFile.getName());
if (!ext.equals(org.freeplane.features.url.UrlManager.FREEPLANE_FILE_EXTENSION_WITHOUT_DOT)) {
chosenFile = new File(chosenFile.getParent(), chosenFile.getName() + org.freeplane.features.url.UrlManager.FREEPLANE_FILE_EXTENSION);
}
try {
Compat.fileToUrl(chosenFile);
} catch (final MalformedURLException ex) {
UITools.errorMessage(TextUtils.getText("invalid_url"));
return;
}
if (chosenFile.exists()) {
final int overwriteMap = JOptionPane.showConfirmDialog(controller.getMapViewManager().getMapViewComponent(), TextUtils.getText("map_already_exists"), "Freeplane", JOptionPane.YES_NO_OPTION);
if (overwriteMap != JOptionPane.YES_OPTION) {
return;
}
}
/*
* Now make a copy from the node, remove the node from the map and
* create a new Map with the node as root, store the new Map, add
* the copy of the node to the parent, and set a link from the copy
* to the new Map.
*/
final NodeModel parent = existingNode.getParentNode();
final File oldFile = parentMap.getFile();
final URI newUri = LinkController.toLinkTypeDependantURI(oldFile, chosenFile);
final URI oldUri = LinkController.toLinkTypeDependantURI(chosenFile, file);
((MLinkController) LinkController.getController()).setLink(existingNode, oldUri, LinkController.LINK_ABSOLUTE);
final int nodePosition = parent.getChildPosition(existingNode);
final ModeController modeController = Controller.getCurrentModeController();
modeController.undoableResolveParentExtensions(LogicalStyleKeys.NODE_STYLE, existingNode);
final MMapController mMapController = (MMapController) modeController.getMapController();
mMapController.deleteNode(existingNode);
{
final IActor actor = new IActor() {
private final boolean wasFolded = existingNode.isFolded();
public void undo() {
PersistentNodeHook.removeMapExtensions(existingNode);
existingNode.setMap(parentMap);
existingNode.setFolded(wasFolded);
}
public String getDescription() {
return "ExportBranchAction";
}
public void act() {
existingNode.setParent(null);
existingNode.setFolded(false);
mMapController.newModel(existingNode);
}
};
Controller.getCurrentModeController().execute(actor, parentMap);
}
final MapModel map = existingNode.getMap();
IExtension[] oldExtensions = map.getRootNode().getSharedExtensions().values().toArray(new IExtension[] {});
for (final IExtension extension : oldExtensions) {
final Class<? extends IExtension> clazz = extension.getClass();
if (PersistentNodeHook.isMapExtension(clazz)) {
existingNode.removeExtension(clazz);
}
}
final Collection<IExtension> newExtensions = parentMap.getRootNode().getSharedExtensions().values();
for (final IExtension extension : newExtensions) {
final Class<? extends IExtension> clazz = extension.getClass();
if (PersistentNodeHook.isMapExtension(clazz)) {
existingNode.addExtension(extension);
}
}
((MFileManager) UrlManager.getController()).save(map, chosenFile);
final NodeModel newNode = mMapController.addNewNode(parent, nodePosition, existingNode.isLeft());
((MTextController) TextController.getController()).setNodeText(newNode, existingNode.getText());
modeController.undoableCopyExtensions(LogicalStyleKeys.NODE_STYLE, existingNode, newNode);
map.getFile();
((MLinkController) LinkController.getController()).setLink(newNode, newUri, LinkController.LINK_ABSOLUTE);
map.destroy();
}
}
use of org.freeplane.core.extension.IExtension in project freeplane by freeplane.
the class StyleEditorPanel method setStyle.
public void setStyle(final NodeModel node) {
if (internalChange) {
return;
}
internalChange = true;
try {
final LogicalStyleController logicalStyleController = LogicalStyleController.getController();
if (addStyleBox) {
final boolean isStyleSet = LogicalStyleModel.getStyle(node) != null;
mSetStyle.setValue(isStyleSet);
setStyleList(mMapStyleButton, logicalStyleController.getMapStyleNames(node, "\n"));
}
setStyleList(mNodeStyleButton, logicalStyleController.getNodeStyleNames(node, "\n"));
final NodeStyleController styleController = NodeStyleController.getController();
{
final Color nodeColor = NodeStyleModel.getColor(node);
final Color viewNodeColor = styleController.getColor(node);
mSetNodeColor.setValue(nodeColor != null);
mNodeColor.setColorValue(viewNodeColor);
}
{
final Color color = NodeStyleModel.getBackgroundColor(node);
final Color viewColor = styleController.getBackgroundColor(node);
mSetNodeBackgroundColor.setValue(color != null);
mNodeBackgroundColor.setColorValue(viewColor != null ? viewColor : Controller.getCurrentController().getMapViewManager().getBackgroundColor(node));
}
{
final String shape = NodeStyleModel.getShape(node);
final String viewShape = styleController.getShape(node);
mSetNodeShape.setValue(shape != null);
mNodeShape.setValue(viewShape);
}
final NodeSizeModel nodeSizeModel = NodeSizeModel.getModel(node);
{
final int width = nodeSizeModel != null ? nodeSizeModel.getMaxNodeWidth() : NodeSizeModel.NOT_SET;
final int viewWidth = styleController.getMaxWidth(node);
mSetMaxNodeWidth.setValue(width != NodeSizeModel.NOT_SET);
mMaxNodeWidth.setValue(Integer.toString(viewWidth));
}
{
final int width = nodeSizeModel != null ? nodeSizeModel.getMinNodeWidth() : NodeSizeModel.NOT_SET;
final int viewWidth = styleController.getMinWidth(node);
mSetMinNodeWidth.setValue(width != NodeSizeModel.NOT_SET);
mMinNodeWidth.setValue(Integer.toString(viewWidth));
}
final EdgeController edgeController = EdgeController.getController();
final EdgeModel edgeModel = EdgeModel.getModel(node);
{
final Color edgeColor = edgeModel != null ? edgeModel.getColor() : null;
final Color viewColor = edgeController.getColor(node);
mSetEdgeColor.setValue(edgeColor != null);
mEdgeColor.setColorValue(viewColor);
}
{
final EdgeStyle style = edgeModel != null ? edgeModel.getStyle() : null;
final EdgeStyle viewStyle = edgeController.getStyle(node);
mSetEdgeStyle.setValue(style != null);
mEdgeStyle.setValue(viewStyle.toString());
}
{
final int width = edgeModel != null ? edgeModel.getWidth() : EdgeModel.DEFAULT_WIDTH;
final int viewWidth = edgeController.getWidth(node);
mSetEdgeWidth.setValue(width != EdgeModel.DEFAULT_WIDTH);
mEdgeWidth.setValue(Integer.toString(viewWidth));
}
{
final CloudController cloudController = CloudController.getController();
final CloudModel cloudModel = CloudModel.getModel(node);
final Color viewCloudColor = cloudController.getColor(node);
mSetCloud.setValue(cloudModel != null);
mCloudColor.setColorValue(viewCloudColor);
final CloudModel.Shape viewCloudShape = cloudController.getShape(node);
mCloudShape.setValue(viewCloudShape != null ? viewCloudShape.toString() : CloudModel.Shape.ARC.toString());
}
{
final String fontFamilyName = NodeStyleModel.getFontFamilyName(node);
final String viewFontFamilyName = styleController.getFontFamilyName(node);
mSetNodeFontName.setValue(fontFamilyName != null);
mNodeFontName.setValue(viewFontFamilyName);
}
{
final Integer fontSize = NodeStyleModel.getFontSize(node);
final Integer viewfontSize = styleController.getFontSize(node);
mSetNodeFontSize.setValue(fontSize != null);
mNodeFontSize.setValue(viewfontSize.toString());
}
{
final Boolean bold = NodeStyleModel.isBold(node);
final Boolean viewbold = styleController.isBold(node);
mSetNodeFontBold.setValue(bold != null);
mNodeFontBold.setValue(viewbold);
}
{
final Boolean italic = NodeStyleModel.isItalic(node);
final Boolean viewitalic = styleController.isItalic(node);
mSetNodeFontItalic.setValue(italic != null);
mNodeFontItalic.setValue(viewitalic);
}
{
final Boolean hyperlink = NodeLinks.formatNodeAsHyperlink(node);
final Boolean viewhyperlink = LinkController.getController().formatNodeAsHyperlink(node);
mSetNodeFontHyperlink.setValue(hyperlink != null);
mNodeFontHyperlink.setValue(viewhyperlink);
}
{
final Boolean nodeNumbering = NodeStyleModel.getNodeNumbering(node);
final Boolean viewNodeNumbering = styleController.getNodeNumbering(node);
mSetNodeNumbering.setValue(nodeNumbering != null);
mNodeNumbering.setValue(viewNodeNumbering);
}
{
String nodeFormat = NodeStyleModel.getNodeFormat(node);
String viewNodeFormat = TextController.getController().getNodeFormat(node);
mSetNodeFormat.setValue(nodeFormat != null);
if (viewNodeFormat == null && node.getUserObject() instanceof IFormattedObject)
viewNodeFormat = ((IFormattedObject) node.getUserObject()).getPattern();
mNodeFormat.setValue(viewNodeFormat);
}
if (mAutomaticLayoutComboBox != null) {
final ModeController modeController = Controller.getCurrentModeController();
AutomaticLayoutController al = modeController.getExtension(AutomaticLayoutController.class);
IExtension extension = al.getExtension(node);
if (extension == null)
mAutomaticLayoutComboBox.setSelectedItem(AUTOMATIC_LAYOUT_DISABLED);
else
mAutomaticLayoutComboBox.setSelectedIndex(((AutomaticLayout) extension).ordinal());
}
if (mAutomaticEdgeColorCheckBox != null) {
final ModeController modeController = Controller.getCurrentModeController();
AutomaticEdgeColorHook al = (AutomaticEdgeColorHook) modeController.getExtension(AutomaticEdgeColorHook.class);
mAutomaticEdgeColorCheckBox.setSelected(al.isActive(node));
}
} finally {
internalChange = false;
}
}
Aggregations