|
What this is
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-2000 Sun * Microsystems, Inc. All Rights Reserved. */ package org.openide.src.nodes; import java.util.ResourceBundle; import org.openide.src.*; import org.openide.options.SystemOption; import org.openide.util.HelpCtx; import org.openide.util.NbBundle; /* * TODO: *
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;
/** Resource bundle. */
private static ResourceBundle bundle;
/** 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;
/** Names of all properties. */
static final String[] PROP_NAMES = {
"initializerElementFormat", "fieldElementFormat", // NOI18N
"constructorElementFormat", "methodElementFormat", // NOI18N
"classElementFormat", "interfaceElementFormat" // NOI18N
};
static Element[] TEST_ELEMENTS;
/** default values for the formats - short form. */
private static final ElementFormat[] DEFAULT_FORMATS_SHORT = new ElementFormat[6];
/** default values for the formats - long form. */
private static final ElementFormat[] DEFAULT_FORMATS_LONG = new ElementFormat[6];
/**
* Current format for individual element types, or null if the format is
* not yet specified by the user.
*/
private ElementFormat[] formats = new ElementFormat[6];
/**
* Version tag to use;
*/
private int version;
private static synchronized void loadBundle() {
if (bundle != null)
return;
bundle = NbBundle.getBundle(SourceOptions.class);
}
private static void loadDefaultFormats() {
if (DEFAULT_FORMATS_SHORT[0] != null)
return;
synchronized (SourceOptions.class) {
if (DEFAULT_FORMATS_SHORT[0] != null)
return;
loadBundle();
for (int i = 0; i < 6; i++) {
DEFAULT_FORMATS_SHORT[i] = new ElementFormat(bundle.getString("SHORT_"+PROP_NAMES[i]));
DEFAULT_FORMATS_LONG[i] = new ElementFormat(bundle.getString("LONG_"+PROP_NAMES[i]));
}
}
}
/**
* Resets all element formats to their default values.
*/
private void clearElementFormats() {
formats = new ElementFormat[6];
}
/** 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 '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 =-2120623049071035434L;
/** @return display name
*/
public String displayName () {
loadBundle();
return bundle.getString("MSG_sourceOptions");
}
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);
}
// ============= 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];
}
// ============= categories of elements usage ===================
/** Set the property whether categories under class elements should be used or not.
* @param cat if |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
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.