use of org.freeplane.core.resources.NamedObject in project freeplane by freeplane.
the class NodeStyleProxy method setName.
public void setName(String styleName) {
if (styleName == null) {
setStyle(null);
} else {
final MapStyleModel mapStyleModel = MapStyleModel.getExtension(getDelegate().getMap());
// actually styles is a HashSet so lookup is fast
final Set<IStyle> styles = mapStyleModel.getStyles();
// search for user defined styles
final IStyle styleString = StyleFactory.create(styleName);
if (styles.contains(styleString)) {
setStyle(styleString);
return;
}
// search for predefined styles by key
final IStyle styleNamedObject = StyleFactory.create(new NamedObject(styleName));
if (styles.contains(styleNamedObject)) {
setStyle(styleNamedObject);
return;
}
// search for predefined styles by their translated name (style.toString())
for (IStyle style : styles) {
if (style.toString().equals(styleName)) {
setStyle(style);
return;
}
}
throw new IllegalArgumentException("style '" + styleName + "' not found");
}
}
use of org.freeplane.core.resources.NamedObject in project freeplane by freeplane.
the class ContainerComboBoxEditor method setItem.
public void setItem(Object anObject) {
if (anObject == null) {
setItem("");
return;
}
for (Entry<NamedObject, ComboBoxEditor> editorEntry : editors.entrySet()) {
final ComboBoxEditor editor = editorEntry.getValue();
editor.setItem(anObject);
final Object item = editor.getItem();
NamedObject key = editorEntry.getKey();
if (anObject.equals(item) && !key.equals(editorSelector.getSelectedItem())) {
editorSelector.setSelectedItem(key);
return;
}
}
}
use of org.freeplane.core.resources.NamedObject in project freeplane by freeplane.
the class FilterConditionEditor method getCondition.
public ASelectableCondition getCondition() {
ASelectableCondition newCond;
Object value;
if (values.isEditable()) {
value = values.getEditor().getItem();
} else {
value = values.getSelectedItem();
}
if (value == null) {
value = "";
}
final NamedObject simpleCond = (NamedObject) elementaryConditions.getSelectedItem();
final boolean matchCase = caseSensitive.isSelected();
final boolean matchApproximately = approximateMatching.isSelected();
ResourceController.getResourceController().setProperty(PROPERTY_FILTER_MATCH_CASE, matchCase);
final Object selectedItem = filteredPropertiesComponent.getSelectedItem();
newCond = filterController.getConditionFactory().createCondition(selectedItem, simpleCond, value, matchCase, matchApproximately);
if (values.isEditable()) {
if (!value.equals("")) {
DefaultComboBoxModel list = (DefaultComboBoxModel) values.getModel();
int indexOfValue = list.getIndexOf(value);
if (indexOfValue > 0)
list.removeElementAt(indexOfValue);
if (indexOfValue == -1 || list.getIndexOf(value) != indexOfValue) {
values.insertItemAt(value, 0);
values.setSelectedIndex(0);
} else if (indexOfValue != -1) {
values.setSelectedIndex(indexOfValue);
}
if (values.getItemCount() >= 10) {
values.removeItemAt(9);
}
}
}
return newCond;
}
use of org.freeplane.core.resources.NamedObject in project freeplane by freeplane.
the class StyleEditorPanel method addAutomaticLayout.
private void addAutomaticLayout(final DefaultFormBuilder rightBuilder) {
{
if (mAutomaticLayoutComboBox == null) {
NamedObject[] automaticLayoutTypes = NamedObject.fromEnum(AutomaticLayout.class);
mAutomaticLayoutComboBox = new JComboBox(automaticLayoutTypes);
DefaultComboBoxModel automaticLayoutComboBoxModel = (DefaultComboBoxModel) mAutomaticLayoutComboBox.getModel();
automaticLayoutComboBoxModel.addElement(AUTOMATIC_LAYOUT_DISABLED);
automaticLayoutComboBoxModel.setSelectedItem(AUTOMATIC_LAYOUT_DISABLED);
mAutomaticLayoutComboBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (internalChange)
return;
final ModeController modeController = Controller.getCurrentModeController();
AutomaticLayoutController al = modeController.getExtension(AutomaticLayoutController.class);
NamedObject selectedItem = (NamedObject) mAutomaticLayoutComboBox.getSelectedItem();
al.undoableDeactivateHook(Controller.getCurrentController().getMap().getRootNode());
if (!selectedItem.equals(AUTOMATIC_LAYOUT_DISABLED)) {
al.undoableActivateHook(Controller.getCurrentController().getMap().getRootNode(), (AutomaticLayout) selectedItem.getObject());
}
}
});
}
final String label = TextUtils.getText("AutomaticLayoutAction.text");
rightBuilder.append(new JLabel(label), 5);
rightBuilder.append(mAutomaticLayoutComboBox);
rightBuilder.nextLine();
}
{
if (mAutomaticEdgeColorCheckBox == null) {
mAutomaticEdgeColorCheckBox = new JCheckBox();
mAutomaticEdgeColorCheckBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
final ModeController modeController = Controller.getCurrentModeController();
AutomaticEdgeColorHook al = (AutomaticEdgeColorHook) modeController.getExtension(AutomaticEdgeColorHook.class);
al.undoableToggleHook(Controller.getCurrentController().getMap().getRootNode());
}
});
}
final String label = TextUtils.getText("AutomaticEdgeColorHookAction.text");
rightBuilder.append(new JLabel(label), 5);
rightBuilder.append(mAutomaticEdgeColorCheckBox);
rightBuilder.nextLine();
}
}
use of org.freeplane.core.resources.NamedObject in project freeplane by freeplane.
the class NodeTextBuilder method writeAttributes.
public void writeAttributes(final ITreeWriter writer, final Object userObject, final String tag) {
if (!NodeWriter.shouldWriteSharedContent(writer))
return;
final NodeModel node = (NodeModel) userObject;
final Object data = node.getUserObject();
if (data == null)
return;
final Class<? extends Object> dataClass = data.getClass();
if (dataClass.equals(StyleNamedObject.class)) {
writer.addAttribute(NodeTextBuilder.XML_NODE_LOCALIZED_TEXT, ((StyleNamedObject) data).getObject().toString());
return;
}
if (dataClass.equals(NamedObject.class)) {
writer.addAttribute(NodeTextBuilder.XML_NODE_LOCALIZED_TEXT, ((NamedObject) data).getObject().toString());
return;
}
final boolean forceFormatting = Boolean.TRUE.equals(writer.getHint(MapWriter.WriterHint.FORCE_FORMATTING));
if (forceFormatting) {
final String text = TextController.getController().getTransformedTextNoThrow(data, node, data);
if (!HtmlUtils.isHtmlNode(text)) {
writer.addAttribute(NodeTextBuilder.XML_NODE_TEXT, text.replace('\0', ' '));
} else {
node.addExtension(new TransformedXMLExtension(text));
}
} else {
final String text = data.toString();
if (node.getXmlText() == null) {
writer.addAttribute(NodeTextBuilder.XML_NODE_TEXT, text.replace('\0', ' '));
}
if (!(data instanceof String || data instanceof StyleString)) {
writer.addAttribute(XML_NODE_OBJECT, TypeReference.toSpec(data));
}
}
}
Aggregations