use of org.freeplane.core.resources.ResourceController in project freeplane by freeplane.
the class NodeBuilder method registerAttributeHandlers.
private void registerAttributeHandlers(final ReadManager reader) {
reader.addAttributeHandler(NodeBuilder.XML_NODE, NodeBuilder.XML_NODE_ENCRYPTED_CONTENT, new IAttributeHandler() {
private void createEncryptedNode(final NodeModel node, final String additionalInfo) {
final EncryptionModel encryptionModel = new EncryptionModel(node, additionalInfo);
node.addExtension(encryptionModel);
}
public void setAttribute(final Object userObject, final String value) {
final NodeModel node = (NodeModel) userObject;
createEncryptedNode(node, value);
node.setFolded(true);
}
});
reader.addAttributeHandler(NodeBuilder.XML_NODE, NodeBuilder.XML_NODE_HISTORY_CREATED_AT, new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
final NodeModel node = (NodeModel) userObject;
if (node.getHistoryInformation() == null) {
node.setHistoryInformation(new HistoryInformationModel());
}
node.getHistoryInformation().setCreatedAt(TreeXmlReader.xmlToDate(value));
}
});
reader.addAttributeHandler(NodeBuilder.XML_NODE, NodeBuilder.XML_NODE_HISTORY_LAST_MODIFIED_AT, new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
final NodeModel node = (NodeModel) userObject;
if (node.getHistoryInformation() == null) {
node.setHistoryInformation(new HistoryInformationModel());
}
node.getHistoryInformation().setLastModifiedAt(TreeXmlReader.xmlToDate(value));
}
});
reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "FOLDED", new IAttributeHandler() {
public void setAttribute(Object userObject, String value) {
}
});
reader.addAttributeHandler(NodeBuilder.XML_NODE, "FOLDED", new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
final NodeModel node = (NodeModel) userObject;
final Object mode = mapReader.getCurrentNodeTreeCreator().getHint(Hint.MODE);
if (mode.equals(Mode.FILE)) {
final String loadFolding = ResourceController.getResourceController().getProperty(NodeBuilder.RESOURCES_LOAD_FOLDING);
if (loadFolding.equals(NodeBuilder.RESOURCES_ALWAYS_FOLD_ALL_AFTER_LOAD) || loadFolding.equals(NodeBuilder.RESOURCES_ALWAYS_UNFOLD_ALL_AFTER_LOAD) || loadFolding.equals(NodeBuilder.RESOURCES_ALWAYS_SHOW_LESS_THAN_N_NODES_AFTER_LOAD)) {
return;
}
mapReader.getCurrentNodeTreeCreator().setHint(FOLDING_LOADED, Boolean.TRUE);
}
if (value.equals("true")) {
node.setFolded(true);
}
}
});
reader.addReadCompletionListener(new IReadCompletionListener() {
private int foldAll(final NodeModel node, int nodeCount) {
if (node.getChildCount() == 0) {
return nodeCount;
}
if (nodeCount <= 0) {
node.setFolded(true);
} else {
nodeCount -= node.getChildCount();
}
for (final NodeModel child : node.getChildren()) {
nodeCount = foldAll(child, nodeCount);
}
return nodeCount;
}
public void readingCompleted(final NodeModel topNode, final Map<String, String> newIds) {
if (!Mode.FILE.equals(mapReader.getCurrentNodeTreeCreator().getHint(Hint.MODE))) {
return;
}
if (Boolean.TRUE.equals(mapReader.getCurrentNodeTreeCreator().getHint(NodeBuilder.FOLDING_LOADED))) {
return;
}
final ResourceController resourceController = ResourceController.getResourceController();
final String loadFolding = resourceController.getProperty(NodeBuilder.RESOURCES_LOAD_FOLDING);
if (loadFolding.equals(NodeBuilder.RESOURCES_ALWAYS_FOLD_ALL_AFTER_LOAD) || loadFolding.equals(NodeBuilder.RESOURCES_LOAD_FOLDING_FROM_MAP_DEFAULT_FOLD_ALL) || loadFolding.equals(NodeBuilder.RESOURCES_ALWAYS_SHOW_LESS_THAN_N_NODES_AFTER_LOAD) || loadFolding.equals(NodeBuilder.RESOURCES_SHOW_LESS_THAN_N_NODES_BY_DEFAULT_AFTER_LOAD)) {
int nodeCount = 1;
if (loadFolding.equals(NodeBuilder.RESOURCES_ALWAYS_SHOW_LESS_THAN_N_NODES_AFTER_LOAD) || loadFolding.equals(NodeBuilder.RESOURCES_SHOW_LESS_THAN_N_NODES_BY_DEFAULT_AFTER_LOAD))
nodeCount = resourceController.getIntProperty(NodeBuilder.MAX_DISPLAYED_NODE_COUNT, 20);
final List<NodeModel> children = topNode.getChildren();
nodeCount = nodeCount - 1 - children.size();
for (final NodeModel child : children) {
nodeCount = foldAll(child, nodeCount);
}
}
}
});
final IAttributeHandler positionHandler = new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
final NodeModel node = (NodeModel) userObject;
node.setLeft(value.equals("left"));
}
};
reader.addAttributeHandler(NodeBuilder.XML_NODE, "POSITION", positionHandler);
reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "POSITION", positionHandler);
reader.addAttributeHandler(NodeBuilder.XML_NODE, "ID", new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
final NodeModel node = (NodeModel) userObject;
final String realId = getMap().generateNodeID(value);
node.setID(realId);
if (!realId.equals(value)) {
mapReader.getCurrentNodeTreeCreator().substituteNodeID(value, realId);
}
}
});
final IAttributeHandler subtreeReferenceHandler = new CloneHandler(CloneType.TREE);
reader.addAttributeHandler(NodeBuilder.XML_NODE, "REFERENCE_ID", subtreeReferenceHandler);
reader.addAttributeHandler(NodeBuilder.XML_NODE, "TREE_ID", subtreeReferenceHandler);
final IAttributeHandler contentReferenceHandler = new CloneHandler(CloneType.CONTENT);
reader.addAttributeHandler(NodeBuilder.XML_NODE, "CONTENT_ID", contentReferenceHandler);
}
use of org.freeplane.core.resources.ResourceController in project freeplane by freeplane.
the class ScriptingConfiguration method getScriptDirs.
private TreeSet<File> getScriptDirs() {
final ResourceController resourceController = ResourceController.getResourceController();
final String dirsString = resourceController.getProperty(ScriptResources.RESOURCES_SCRIPT_DIRECTORIES);
// remove duplicates -> Set
final TreeSet<File> dirs = new TreeSet<File>();
if (dirsString != null) {
for (String dir : ConfigurationUtils.decodeListValue(dirsString, false)) {
dirs.add(createFile(dir));
}
}
dirs.add(ScriptResources.getBuiltinScriptsDir());
dirs.add(ScriptResources.getUserScriptsDir());
return dirs;
}
use of org.freeplane.core.resources.ResourceController in project freeplane by freeplane.
the class SetNoteWindowPosition method setSelected.
@Override
public void setSelected() {
final ResourceController resourceController = ResourceController.getResourceController();
final boolean isSelected = resourceController.getProperty("note_location").equals(position);
setSelected(isSelected);
}
use of org.freeplane.core.resources.ResourceController in project freeplane by freeplane.
the class SetNoteWindowPosition method actionPerformed.
public void actionPerformed(final ActionEvent e) {
final ResourceController resourceController = ResourceController.getResourceController();
resourceController.setProperty("note_location", position);
final ViewController viewController = Controller.getCurrentModeController().getController().getViewController();
viewController.changeNoteWindowLocation();
}
use of org.freeplane.core.resources.ResourceController in project freeplane by freeplane.
the class SpellCheckerController method init.
private void init() {
if (spellCheckerInitialized == true) {
return;
}
spellCheckerInitialized = true;
final ResourceController resourceController = ResourceController.getResourceController();
final File orthoDir = new File(resourceController.getResourceBaseDir(), "ortho");
registerDictionaries(orthoDir);
final File userOrthoDir = new File(resourceController.getFreeplaneUserDirectory(), "ortho");
registerDictionaries(userOrthoDir);
if (!spellCheckerEnabled) {
return;
}
setSpellCheckOptions(resourceController);
resourceController.addPropertyChangeListener(new IFreeplanePropertyListener() {
public void propertyChanged(final String propertyName, final String newValue, final String oldValue) {
if (propertyName.startsWith("spelling_opt")) {
setSpellCheckOptions(resourceController);
}
}
});
String spellingLanguage = resourceController.getProperty(SPELLING_LANGUAGE, null);
if (spellingLanguage == null) {
spellingLanguage = resourceController.getLanguageCode();
}
if (!spellingLanguage.equals("disabled")) {
SpellChecker.setLanguage(spellingLanguage);
}
languageChangeListener = new LanguageChangeListener() {
public void languageChanged(final LanguageChangeEvent ev) {
EventQueue.invokeLater(new Runnable() {
public void run() {
final Locale currentLocale = ev.getCurrentLocale();
if (currentLocale == null) {
resourceController.setProperty(SPELLING_LANGUAGE, "disabled");
return;
}
resourceController.setProperty(SPELLING_LANGUAGE, currentLocale.getLanguage());
}
});
}
};
SpellChecker.addLanguageChangeLister(languageChangeListener);
}
Aggregations