Search in sources :

Example 6 with NamedObject

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");
    }
}
Also used : IStyle(org.freeplane.features.styles.IStyle) MapStyleModel(org.freeplane.features.styles.MapStyleModel) NamedObject(org.freeplane.core.resources.NamedObject) StyleNamedObject(org.freeplane.features.styles.StyleNamedObject)

Example 7 with NamedObject

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;
        }
    }
}
Also used : NamedObject(org.freeplane.core.resources.NamedObject) NamedObject(org.freeplane.core.resources.NamedObject) ComboBoxEditor(javax.swing.ComboBoxEditor)

Example 8 with NamedObject

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;
}
Also used : NamedObject(org.freeplane.core.resources.NamedObject) NamedObject(org.freeplane.core.resources.NamedObject) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) ASelectableCondition(org.freeplane.features.filter.condition.ASelectableCondition)

Example 9 with NamedObject

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();
    }
}
Also used : JCheckBox(javax.swing.JCheckBox) AutomaticLayoutController(org.freeplane.features.styles.AutomaticLayoutController) JComboBox(javax.swing.JComboBox) ActionListener(java.awt.event.ActionListener) AutomaticEdgeColorHook(org.freeplane.features.edge.mindmapmode.AutomaticEdgeColorHook) AutomaticLayout(org.freeplane.features.styles.AutomaticLayout) ActionEvent(java.awt.event.ActionEvent) NamedObject(org.freeplane.core.resources.NamedObject) JLabel(javax.swing.JLabel) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) ModeController(org.freeplane.features.mode.ModeController)

Example 10 with NamedObject

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));
        }
    }
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) StyleString(org.freeplane.features.styles.StyleString) NamedObject(org.freeplane.core.resources.NamedObject) StyleNamedObject(org.freeplane.features.styles.StyleNamedObject) NamedObject(org.freeplane.core.resources.NamedObject) StyleNamedObject(org.freeplane.features.styles.StyleNamedObject) IFormattedObject(org.freeplane.features.format.IFormattedObject) StyleString(org.freeplane.features.styles.StyleString) StyleNamedObject(org.freeplane.features.styles.StyleNamedObject)

Aggregations

NamedObject (org.freeplane.core.resources.NamedObject)14 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)4 MapModel (org.freeplane.features.map.MapModel)3 StyleNamedObject (org.freeplane.features.styles.StyleNamedObject)3 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 File (java.io.File)2 ComboBoxEditor (javax.swing.ComboBoxEditor)2 JComboBox (javax.swing.JComboBox)2 FixedBasicComboBoxEditor (org.freeplane.core.ui.FixedBasicComboBoxEditor)2 ModeController (org.freeplane.features.mode.ModeController)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 NoSuchElementException (java.util.NoSuchElementException)1 ComboBoxModel (javax.swing.ComboBoxModel)1 JCheckBox (javax.swing.JCheckBox)1 JFileChooser (javax.swing.JFileChooser)1 JLabel (javax.swing.JLabel)1