Search in sources :

Example 1 with ReturnsOriginal

use of com.igormaznitsa.meta.annotation.ReturnsOriginal in project netbeans-mmd-plugin by raydac.

the class MindMapPanelConfig method saveTo.

@Nullable
@ReturnsOriginal
public Preferences saveTo(@Nullable final Preferences prefs) {
    if (prefs != null) {
        final String prefix = MindMapPanelConfig.class.getSimpleName();
        for (final Field f : MindMapPanelConfig.class.getDeclaredFields()) {
            if ((f.getModifiers() & (Modifier.STATIC | Modifier.TRANSIENT | Modifier.FINAL)) != 0) {
                continue;
            }
            final Class<?> fieldClass = f.getType();
            final String fieldName = prefix + '.' + f.getName();
            try {
                if (fieldClass == boolean.class) {
                    prefs.putBoolean(fieldName, f.getBoolean(this));
                } else if (fieldClass == int.class) {
                    prefs.putInt(fieldName, f.getInt(this));
                } else if (fieldClass == float.class) {
                    prefs.putFloat(fieldName, f.getFloat(this));
                } else if (fieldClass == double.class) {
                    prefs.putDouble(fieldName, f.getDouble(this));
                } else if (fieldClass == Font.class) {
                    final Font theFont = (Font) f.get(this);
                    prefs.put(fieldName + ".name", theFont.getName());
                    prefs.putInt(fieldName + ".size", theFont.getSize());
                    prefs.putInt(fieldName + ".style", theFont.getStyle());
                } else if (fieldClass == Color.class) {
                    prefs.putInt(fieldName, ((Color) f.get(this)).getRGB());
                } else if (fieldClass == String.class) {
                    prefs.put(fieldName, (String) f.get(this));
                } else if (fieldClass == RenderQuality.class) {
                    prefs.put(fieldName, ((RenderQuality) f.get(this)).name());
                } else {
                    throw new Error("Unexpected field type " + fieldClass.getName());
                }
            } catch (IllegalAccessException ex) {
                throw new Error("IllegalAccessException [" + fieldClass.getName() + ']', ex);
            } catch (IllegalArgumentException ex) {
                throw new Error("IllegalArgumentException [" + fieldClass.getName() + ']', ex);
            }
        }
        for (final Map.Entry<String, KeyShortcut> e : this.mapShortCut.entrySet()) {
            prefs.put("mapShortCut." + e.getValue().getID(), e.getValue().packToString());
        }
    }
    return prefs;
}
Also used : Field(java.lang.reflect.Field) Color(java.awt.Color) KeyShortcut(com.igormaznitsa.mindmap.swing.panel.utils.KeyShortcut) RenderQuality(com.igormaznitsa.mindmap.swing.panel.utils.RenderQuality) HashMap(java.util.HashMap) Map(java.util.Map) Font(java.awt.Font) ReturnsOriginal(com.igormaznitsa.meta.annotation.ReturnsOriginal) Nullable(javax.annotation.Nullable)

Example 2 with ReturnsOriginal

use of com.igormaznitsa.meta.annotation.ReturnsOriginal in project netbeans-mmd-plugin by raydac.

the class SwingUtils method addTextActions.

@Nonnull
@ReturnsOriginal
public static JPopupMenu addTextActions(@Nonnull final JPopupMenu menu) {
    final Action cut = new DefaultEditorKit.CutAction();
    cut.putValue(Action.NAME, "Cut");
    menu.add(cut);
    final Action copy = new DefaultEditorKit.CopyAction();
    copy.putValue(Action.NAME, "Copy");
    menu.add(copy);
    final Action paste = new DefaultEditorKit.PasteAction();
    paste.putValue(Action.NAME, "Paste");
    menu.add(paste);
    menu.add(new SelectAllTextAction());
    return menu;
}
Also used : Action(javax.swing.Action) TextAction(javax.swing.text.TextAction) Nonnull(javax.annotation.Nonnull) ReturnsOriginal(com.igormaznitsa.meta.annotation.ReturnsOriginal)

Aggregations

ReturnsOriginal (com.igormaznitsa.meta.annotation.ReturnsOriginal)2 KeyShortcut (com.igormaznitsa.mindmap.swing.panel.utils.KeyShortcut)1 RenderQuality (com.igormaznitsa.mindmap.swing.panel.utils.RenderQuality)1 Color (java.awt.Color)1 Font (java.awt.Font)1 Field (java.lang.reflect.Field)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 Action (javax.swing.Action)1 TextAction (javax.swing.text.TextAction)1