KickJava   Java API By Example, From Geeks To Geeks.

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


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.beans.*;
23 import java.util.*;
24 import javax.swing.event.*;
25
26 import org.openide.util.HelpCtx;
27 import org.openide.util.NbBundle;
28
29 /**
30  * AbbrevsEditor is editor for Map of abbreviations.
31  * Each abbreviation is pair of Strings.
32  * @author Petr Nejedly
33  */

34
35 public class AbbrevsEditor extends PropertyEditorSupport {
36
37     private AbbrevsEditorPanel editorPanel;
38
39     private static final String JavaDoc HELP_ID = "editing.abbreviations"; // !!! NOI18N
40

41     protected HelpCtx getHelpCtx () {
42         return new HelpCtx (HELP_ID);
43     }
44
45     /**
46      * Tell the world that we have nice editor Component
47      */

48     public boolean supportsCustomEditor() {
49         return true;
50     }
51
52     /**
53      * Create custom editor tightly coupled with this editor
54      */

55     public java.awt.Component JavaDoc getCustomEditor() {
56         if( editorPanel == null ) {
57             editorPanel = new AbbrevsEditorPanel( this );
58             HelpCtx.setHelpIDString( editorPanel, getHelpCtx().getHelpID() );
59             refreshEditorPanel();
60         }
61         return editorPanel;
62     }
63
64     private void refreshEditorPanel() {
65         if( editorPanel != null ) {
66             editorPanel.setValue( (Map)getValue() );
67         }
68     }
69
70     /**
71      * Sets the value for editor / customEditor
72      */

73     public void setValue( Object JavaDoc obj ) {
74         Object JavaDoc oldValue = getValue();
75         if( (obj != null) && (! obj.equals( oldValue ) ) ) {
76             super.setValue( obj );
77             if( ( editorPanel != null ) && (! editorPanel.getValue().equals( getValue() ) ) ) {
78                 refreshEditorPanel();
79             }
80         }
81     }
82
83     /**
84      * The way our customEditor notifies us when user changes something.
85      */

86     protected void customEditorChange() {
87         // forward it to parent, which will fire propertyChange
88
super.setValue( new HashMap( editorPanel.getValue() ) );
89     }
90
91     /**
92      * Return the label to be shown in the PropertySheet
93      */

94     public String JavaDoc getAsText() {
95         return NbBundle.getBundle( KeyBindingsEditor.class ).getString( "PROP_Abbreviations" ); // NOI18N
96
}
97
98     /**
99      * Don't bother if the user tried to edit our label in the PropertySheet
100      */

101     public void setAsText( String JavaDoc s ) {
102     }
103
104 }
105
Popular Tags