KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > core > settings > CoreSettings


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.xml.core.settings;
20
21
22
23 import java.util.prefs.Preferences JavaDoc;
24 import org.openide.nodes.BeanNode;
25 import org.openide.util.HelpCtx;
26 import org.openide.util.NbPreferences;
27 import org.openide.util.actions.SystemAction;
28
29 /** Settings for xml module
30  *
31  * @author Libor Kramolis
32  * @version 0.2
33  */

34 public class CoreSettings {
35     private static final CoreSettings INSTANCE = new CoreSettings();
36     public static final String JavaDoc PROP_AUTO_PARSING_DELAY = "autoParsingDelay"; // NOI18N
37
public static final String JavaDoc PROP_DEFAULT_ACTION = "defaultAction"; // NOI18N
38
public static final String JavaDoc PROP_PREFERED_SHORT_EMPTY_ELEMENT = "preferedShortEmptyElement"; // NOI18N
39

40     private static Preferences JavaDoc getPreferences() {
41         return NbPreferences.forModule(CoreSettings.class);
42     }
43
44     public static CoreSettings getDefault () {
45         return INSTANCE;
46     }
47     /** Create new CoreSettings. */
48     private CoreSettings () {}
49     //
50
// itself
51
//
52

53     /** If true then external execution is used */
54     public String JavaDoc displayName () {
55         String JavaDoc displayName = Util.THIS.getString ("CTL_XML_option");
56
57         if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("CoreSettings::displayName = " + displayName); // NOI18N
58

59         return displayName;
60     }
61     
62
63     public HelpCtx getHelpCtx() {
64         //return new HelpCtx( CoreSettings.class);
65
return HelpCtx.DEFAULT_HELP;
66     }
67     
68     //
69
// Auto parsing delay
70
//
71

72     /** Gets the delay time for the start of the parsing.
73      * @return The time in milis
74      */

75     public int getAutoParsingDelay () {
76         int autoParsingDelay = getPreferences().getInt(PROP_AUTO_PARSING_DELAY, 3000);
77         if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("CoreSettings::getAutoParsingDelay: " + autoParsingDelay); // NOI18N
78

79         return autoParsingDelay;
80     }
81
82     /** Sets the delay time for the start of the parsing.
83      * @param delay The time in milis
84      */

85     public void setAutoParsingDelay (int delay) {
86         if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("CoreSettings::setAutoParsingDelay: " + delay); // NOI18N
87

88         if (delay < 0)
89             throw new IllegalArgumentException JavaDoc();
90
91         getPreferences().putInt(PROP_AUTO_PARSING_DELAY, delay);
92     }
93     
94     
95     /**
96      * Getter for prefered default action class name.
97      * It should be used at all places tackling with default action for all XML
98      * flavours (XSLT, DTD, ...). Note: some more specifics mechanism can defined
99      * for particular XML flavour.
100      * @return Value of property default action class or <code>null</code>.
101      */

102     public String JavaDoc getDefaultAction() {
103         return getPreferences().get(PROP_DEFAULT_ACTION, null);
104     }
105     
106     /** Setter for property defaultAction.
107      * @param defaultAction New value of property defaultAction.
108      */

109     public void setDefaultAction(String JavaDoc defaultAction) {
110         getPreferences().put(PROP_DEFAULT_ACTION, defaultAction);
111     }
112
113     /**
114      * Utility method for determinig default action.
115      * @param actions an array of actons that are available at client
116      * @param systemDefault a fallback system defaul action
117      */

118     public SystemAction getDefaultAction(SystemAction actions[], SystemAction systemDefault) {
119         String JavaDoc defaultAction = getDefaultAction();
120         if (defaultAction == null) return systemDefault;
121         if (actions == null) return systemDefault;
122         
123         // does it exist at client's action pool?
124
for (int i=0; i<actions.length; i++) {
125             SystemAction next = (SystemAction) actions[i];
126             if (next == null) continue;
127             Class JavaDoc klass = next.getClass();
128             String JavaDoc name = klass.getName();
129             if (name.equals(defaultAction)) {
130                 return next;
131             }
132         }
133
134         return systemDefault;
135     }
136     
137     /**
138      * @return true if "&lt;empty/&gt;" is preffered over "&lt;empty&gt;&lt;/empty&gt;"
139      */

140     public boolean isPreferedShortEmptyElement() {
141         return getPreferences().getBoolean(PROP_PREFERED_SHORT_EMPTY_ELEMENT, false);
142     }
143     
144     /**
145      * @param true if "&lt;empty/&gt;" is preffered over "&lt;empty&gt;&lt;/empty&gt;"
146      */

147     public void setPreferedShortEmptyElement(boolean pref) {
148         getPreferences().putBoolean(PROP_PREFERED_SHORT_EMPTY_ELEMENT, pref);
149     }
150     
151     private static BeanNode createViewNode() throws java.beans.IntrospectionException JavaDoc {
152         return new BeanNode(CoreSettings.getDefault());
153     }
154 }
155
Popular Tags