KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > editor > options > BasePrintOptions


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
20 package org.netbeans.modules.editor.options;
21
22 import java.util.Map JavaDoc;
23 import org.netbeans.editor.Settings;
24 import org.netbeans.editor.SettingsNames;
25 import org.netbeans.editor.SettingsUtil;
26 import org.netbeans.editor.BaseKit;
27 import org.netbeans.modules.editor.NbEditorSettingsInitializer;
28 import org.openide.text.PrintSettings;
29 import org.openide.util.HelpCtx;
30
31 /**
32 * Options for the plain editor kit
33 *
34 * @author Miloslav Metelka
35 */

36 public class BasePrintOptions extends OptionSupport {
37
38     public static final String JavaDoc BASE = "base"; // NOI18N
39

40     public static final String JavaDoc PRINT_PREFIX = "print_"; // NOI18N
41

42     public static final String JavaDoc PRINT_COLORING_MAP_PROP = "printColoringMap"; // NOI18N
43

44     private static final String JavaDoc HELP_ID = "editing.fontsandcolors"; // !!! NOI18N
45

46     static final String JavaDoc[] BASE_PROP_NAMES = {
47         PRINT_COLORING_MAP_PROP,
48     };
49
50     static final long serialVersionUID =7740651671176408299L;
51     public BasePrintOptions() {
52         this(BaseKit.class, BASE);
53     }
54
55     private transient Settings.Initializer printColoringMapInitializer;
56     
57     public BasePrintOptions(Class JavaDoc kitClass, String JavaDoc typeName) {
58         super(kitClass, typeName);
59     }
60
61     public String JavaDoc displayName() {
62
63         String JavaDoc name;
64         try {
65             name = getString(OPTIONS_PREFIX + PRINT_PREFIX + getTypeName());
66         } catch (Throwable JavaDoc t) {
67             name = super.displayName();
68         }
69         return name;
70     }
71
72     public void init(){
73         refreshContextListeners();
74     }
75     
76     private void refreshContextListeners() {
77         PrintSettings ps = (PrintSettings) PrintSettings.findObject(PrintSettings.class, true);
78         // Start listening on AllOptions and PrintSettings
79
ContextOptionsListener.processExistingAndListen(ps);
80     }
81
82     public HelpCtx getHelpCtx () {
83         return new HelpCtx (HELP_ID);
84     }
85
86     /** Get the name of the <code>Settings.Initializer</code> related
87      * to these options.
88      */

89     protected String JavaDoc getSettingsInitializerName() {
90         return getTypeName() + "-print-options-initalizer"; // NOI18N
91
}
92
93     protected void updateSettingsMap(Class JavaDoc kitClass, Map JavaDoc settingsMap) {
94         super.updateSettingsMap(kitClass, settingsMap);
95
96         if (printColoringMapInitializer != null) {
97             printColoringMapInitializer.updateSettingsMap(kitClass, settingsMap);
98         }
99     }
100     
101
102     public boolean getPrintLineNumberVisible() {
103         return ((Boolean JavaDoc)getSettingValue(SettingsNames.LINE_NUMBER_VISIBLE)).booleanValue();
104     }
105     public void setPrintLineNumberVisible(boolean b) {
106     }
107
108     public Map JavaDoc getPrintColoringMap() {
109         NbEditorSettingsInitializer.init();
110         Map JavaDoc cm = SettingsUtil.getColoringMap(getKitClass(), true, true);
111         cm.put(null, getKitClass().getName() ); // add kit class
112
return cm;
113     }
114     public void setPrintColoringMap(Map JavaDoc coloringMap) {
115         NbEditorSettingsInitializer.init();
116         if (coloringMap != null) {
117             coloringMap.remove(null); // remove kit class
118
SettingsUtil.setColoringMap( getKitClass(), coloringMap, true );
119
120             printColoringMapInitializer = SettingsUtil.getColoringMapInitializer(
121                 getKitClass(), coloringMap, true,
122                 getTypeName() + "-print-coloring-map-initializer" // NOI18N
123
);
124
125
126             firePropertyChange(PRINT_COLORING_MAP_PROP, null, null);
127         }
128     }
129
130 }
131
Popular Tags