KickJava   Java API By Example, From Geeks To Geeks.

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


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.awt.*;
23 import java.beans.*;
24 import java.util.HashMap JavaDoc;
25 import javax.swing.event.*;
26
27 import org.netbeans.editor.Coloring;
28 //import org.netbeans.modules.editor.options.ColoringBean;
29
import org.openide.explorer.propertysheet.PropertyPanel;
30 import org.openide.util.HelpCtx;
31 import org.openide.util.NbBundle;
32
33 /**
34  * ColoringArrayEditor is editor for Editors colorings settings, operates over
35  * java.util.HashMap as it needs null key. Null key is used for transferring kitClass,
36  * default coloring is named Settings.DEFAULT, other colorings are mapped by their names.
37  *
38  * @author Petr Nejedly
39  * @version 1.0
40  */

41
42 public class ColoringArrayEditor extends PropertyEditorSupport {
43
44     private ColoringArrayEditorPanel editor;
45     
46     private static final String JavaDoc HELP_ID = "editing.fontsandcolors"; // !!! NOI18N
47

48     public boolean supportsCustomEditor() {
49         return true;
50     }
51
52     public String JavaDoc getAsText() {
53         return NbBundle.getMessage( ColoringArrayEditor.class, "PROP_Coloring" ); // NOI18N
54
}
55
56     public java.awt.Component JavaDoc getCustomEditor() {
57         if( editor == null ) {
58             editor = new ColoringArrayEditorPanel();
59             HelpCtx.setHelpIDString( editor, getHelpCtx().getHelpID() );
60             refreshEditor();
61             editor.addPropertyChangeListener( new PropertyChangeListener() {
62                                                   public void propertyChange( PropertyChangeEvent evt ) {
63                                                       if( "value".equals( evt.getPropertyName() ) ) setValue( editor.getValue() ); // NOI18N
64
}
65                                               });
66         }
67         return editor;
68     }
69
70     protected HelpCtx getHelpCtx () {
71         return new HelpCtx (HELP_ID);
72     }
73     
74     public void setAsText( String JavaDoc s ) {
75         return;
76     }
77
78     public void setValue( Object JavaDoc obj ) {
79         Object JavaDoc oldValue = getValue();
80         if( (obj != null) && (! obj.equals( oldValue ) ) ) {
81             super.setValue( obj );
82             if( ( editor != null ) && (! editor.getValue().equals( getValue() ) ) ) {
83                 refreshEditor();
84             }
85         }
86     }
87
88     private void refreshEditor() {
89         if( editor != null ) {
90             editor.setValue( (HashMap JavaDoc)getValue() );
91         }
92     }
93 }
94
Popular Tags