alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 * 
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 * 
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.modules.java.ui.nodes.elements;

import java.util.List;

import org.openide.options.SystemOption;
import org.openide.util.HelpCtx;
import org.openide.util.NbBundle;
import org.openide.ErrorManager;
import org.netbeans.jmi.javamodel.*;
import org.netbeans.modules.javacore.internalapi.JavaMetamodel;

import javax.jmi.reflect.JmiException;

/*
* TODO:
* 
    *
  • weak listeners for listening on format changes - all element nodes should react on it. *
*/ /** Display options for the hierarchy of source elements. * These options determine the display name format * of each kind of element. *

Also included are read-only properties for the "long formats", * which are in practice used for {@link ElementNode#getHintElementFormat}. *

Changes to settings will fire property change events. * * @author Petr Hamernik */ public final class SourceOptions extends SystemOption { private static final int lastCompatibleVersionTag = 1; private static final int currentVersionTag = 1; /** Kinds of the format. */ private static final byte T_INITIALIZER = 0; private static final byte T_FIELD = 1; private static final byte T_CONSTRUCTOR = 2; private static final byte T_METHOD = 3; private static final byte T_CLASS = 4; private static final byte T_INTERFACE = 5; private static final byte T_ENUM = 6; private static final byte T_CONSTANT = 7; private static final byte T_ANNOTATION_TYPE = 8; private static final byte T_ANNOTATION_TYPE_METHOD = 9; /** Names of all properties. */ static final String[] PROP_NAMES = { "initializerElementFormat", "fieldElementFormat", // NOI18N "constructorElementFormat", "methodElementFormat", // NOI18N "classElementFormat", "interfaceElementFormat", // NOI18N "enumElementFormat", "constantElementFormat", // NOI18N "annTypeElementFormat", "annTypeMethodElementFormat", // NOI18N }; static Element[] TEST_ELEMENTS; /** default values for the formats - short form. */ private static final ElementFormat[] DEFAULT_FORMATS_SHORT = new ElementFormat[PROP_NAMES.length]; /** default values for the formats - long form. */ private static final ElementFormat[] DEFAULT_FORMATS_LONG = new ElementFormat[PROP_NAMES.length]; /** * Current format for individual element types, or null if the format is * not yet specified by the user. */ private ElementFormat[] formats = new ElementFormat[PROP_NAMES.length]; /** * Version tag to use; */ private int version = 1; private static void loadDefaultFormats() { synchronized (SourceOptions.class) { if (DEFAULT_FORMATS_SHORT[0] != null) return; for (int i = 0; i < PROP_NAMES.length; i++) { DEFAULT_FORMATS_SHORT[i] = new ElementFormat(getString("SHORT_" + PROP_NAMES[i])); // NOI18N DEFAULT_FORMATS_LONG[i] = new ElementFormat(getString("LONG_" + PROP_NAMES[i])); // NOI18N } } } /** * Resets all element formats to their default values. */ private void clearElementFormats() { formats = new ElementFormat[PROP_NAMES.length]; } /** Property name of the initializer display format. */ public static final String PROP_INITIALIZER_FORMAT = PROP_NAMES[T_INITIALIZER]; /** Property name of the field display format. */ public static final String PROP_FIELD_FORMAT = PROP_NAMES[T_FIELD]; /** Property name of the constructor display format. */ public static final String PROP_CONSTRUCTOR_FORMAT = PROP_NAMES[T_CONSTRUCTOR]; /** Property name of the method display format. */ public static final String PROP_METHOD_FORMAT = PROP_NAMES[T_METHOD]; /** Property name of the class display format. */ public static final String PROP_CLASS_FORMAT = PROP_NAMES[T_CLASS]; /** Property name of the interface display format. */ public static final String PROP_INTERFACE_FORMAT = PROP_NAMES[T_INTERFACE]; /** Property name of the enum display format. */ public static final String PROP_ENUM_FORMAT = PROP_NAMES[T_ENUM]; /** Property name of the enum constant display format. */ public static final String PROP_CONSTANT_FORMAT = PROP_NAMES[T_CONSTANT]; /** Property name of the annotation type display format. */ public static final String PROP_ANNOTATION_TYPE_FORMAT = PROP_NAMES[T_ANNOTATION_TYPE]; /** Property name of the annotation type display format. */ public static final String PROP_ANNOTATION_TYPE_METHOD_FORMAT = PROP_NAMES[T_ANNOTATION_TYPE_METHOD]; /** Property name of the 'categories usage' property. */ public static final String PROP_CATEGORIES_USAGE = "categoriesUsage"; // NOI18N /** CategoriesUsage property current value */ private static boolean categories = true; static final long serialVersionUID = 1; /** @return display name */ public String displayName() { return getString("MSG_sourceOptions"); // NOI18N } public HelpCtx getHelpCtx() { return new HelpCtx(SourceOptions.class); } // ============= public methods =================== /** Set the initializer format. * @param format the new format */ public void setInitializerElementFormat(ElementFormat format) { setElementFormat(T_INITIALIZER, format); } /** Get the initializer format. * @return the current format */ public ElementFormat getInitializerElementFormat() { return getElementFormat(T_INITIALIZER); } /** Set the field format. * @param format the new format */ public void setFieldElementFormat(ElementFormat format) { setElementFormat(T_FIELD, format); } private ElementFormat getElementFormat(int type) { synchronized (this) { if (formats[type] != null) return formats[type]; // if writing the option to the disk, return a default == null value. if (isWriteExternal()) return null; } loadDefaultFormats(); return DEFAULT_FORMATS_SHORT[type]; } /** Get the field format. * @return the current format */ public ElementFormat getFieldElementFormat() { return getElementFormat(T_FIELD); } /** Set the constructor format. * @param format the new format */ public void setConstructorElementFormat(ElementFormat format) { setElementFormat(T_CONSTRUCTOR, format); } /** Get the constructor format. * @return the current format */ public ElementFormat getConstructorElementFormat() { return getElementFormat(T_CONSTRUCTOR); } /** Set the method format. * @param format the new format */ public void setMethodElementFormat(ElementFormat format) { setElementFormat(T_METHOD, format); } /** Get the method format. * @return the current format */ public ElementFormat getMethodElementFormat() { return getElementFormat(T_METHOD); } /** Set the class format. * @param format the new format */ public void setClassElementFormat(ElementFormat format) { setElementFormat(T_CLASS, format); } /** Get the class format. * @return the current format */ public ElementFormat getClassElementFormat() { return getElementFormat(T_CLASS); } /** Set the interface format. * @param format the new format */ public void setInterfaceElementFormat(ElementFormat format) { setElementFormat(T_INTERFACE, format); } /** Get the interface format. * @return the current format */ public ElementFormat getInterfaceElementFormat() { return getElementFormat(T_INTERFACE); } /** Set the enum format. * @param format the new format */ public void setEnumElementFormat(ElementFormat format) { setElementFormat(T_ENUM, format); } /** Get the enum format. * @return the current format */ public ElementFormat getEnumElementFormat() { return getElementFormat(T_ENUM); } /** Get the enum constant format. * @return the current format */ public ElementFormat getConstantElementFormat() { return getElementFormat(T_CONSTANT); } /** Set the annotation type format. * @param format the new format */ public void setAnnTypeElementFormat(ElementFormat format) { setElementFormat(T_ANNOTATION_TYPE, format); } /** Get the annotation type format. * @return the current format */ public ElementFormat getAnnTypeElementFormat() { return getElementFormat(T_ANNOTATION_TYPE); } /** Set the annotation type method format. * @param format the new format */ public void setAnnTypeMethodElementFormat(ElementFormat format) { setElementFormat(T_ANNOTATION_TYPE_METHOD, format); } /** Get the annotation type method format. * @return the current format */ public ElementFormat getAnnTypeMethodElementFormat() { return getElementFormat(T_ANNOTATION_TYPE_METHOD); } // ============= getters for long form of formats ================= /** Get the initializer format for longer hints. * @return the current format */ public ElementFormat getInitializerElementLongFormat() { loadDefaultFormats(); return DEFAULT_FORMATS_LONG[T_INITIALIZER]; } /** Get the field format for longer hints. * @return the current format */ public ElementFormat getFieldElementLongFormat() { loadDefaultFormats(); return DEFAULT_FORMATS_LONG[T_FIELD]; } /** Get the constructor format for longer hints. * @return the current format */ public ElementFormat getConstructorElementLongFormat() { loadDefaultFormats(); return DEFAULT_FORMATS_LONG[T_CONSTRUCTOR]; } /** Get the method format for longer hints. * @return the current format */ public ElementFormat getMethodElementLongFormat() { loadDefaultFormats(); return DEFAULT_FORMATS_LONG[T_METHOD]; } /** Get the class format for longer hints. * @return the current format */ public ElementFormat getClassElementLongFormat() { loadDefaultFormats(); return DEFAULT_FORMATS_LONG[T_CLASS]; } /** Get the interface format for longer hints. * @return the current format */ public ElementFormat getInterfaceElementLongFormat() { loadDefaultFormats(); return DEFAULT_FORMATS_LONG[T_INTERFACE]; } /** Get the enum format for longer hints. * @return the current format */ public ElementFormat getEnumElementLongFormat() { loadDefaultFormats(); return DEFAULT_FORMATS_LONG[T_ENUM]; } /** Get the enum constant format for longer hints. * @return the current format */ public ElementFormat getConstantElementLongFormat() { loadDefaultFormats(); return DEFAULT_FORMATS_LONG[T_CONSTANT]; } /** Get the annotation type format for longer hints. * @return the current format */ public ElementFormat getAnnTypeElementLongFormat() { loadDefaultFormats(); return DEFAULT_FORMATS_LONG[T_ANNOTATION_TYPE]; } /** Get the annotation type method format for longer hints. * @return the current format */ public ElementFormat getAnnTypeMethodElementLongFormat() { loadDefaultFormats(); return DEFAULT_FORMATS_LONG[T_ANNOTATION_TYPE_METHOD]; } // ============= categories of elements usage =================== /** Set the property whether categories under class elements should be used or not. * @param cat if true the elements under class elements are divided into * categories: fields, constructors, methods. Otherwise (false) all elements * are placed directly under class element. */ public void setCategoriesUsage(boolean cat) { categories = cat; } /** Test whether categiries under class elements are used or not. * @return true if the elements under class elements are divided into * categories: fields, constructors, methods. Otherwise false (all elements * are placed directly under class element). */ public boolean getCategoriesUsage() { return categories; } // ============= private methods =================== /** Sets the format for the given index. * @param index One of the constants T_XXX * @param format the new format for the specific type. */ private void setElementFormat(byte index, ElementFormat format) { ElementFormat old = formats[index]; formats[index] = format; firePropertyChange (PROP_NAMES[index], old, formats[index]); } public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException { super.writeExternal(out); out.writeInt(version); } public void readExternal (java.io.ObjectInput in) throws java.io.IOException, ClassNotFoundException { super.readExternal(in); if (in.available() > 0) { version = in.readInt(); } if (version < lastCompatibleVersionTag) { clearElementFormats(); version = currentVersionTag; } } private static String getString(String key) { return NbBundle.getMessage(SourceOptions.class, key); } }

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.