KickJava   Java API By Example, From Geeks To Geeks.

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


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.Component JavaDoc;
23 import java.beans.*;
24 import java.util.*;
25 import javax.swing.event.*;
26
27 import org.openide.util.HelpCtx;
28 import org.openide.util.NbBundle;
29
30 /**
31  * KeyBindingsEditor is editor for MultiKeyBindings settings of Editor,
32  * operates over java.util.List, where single MultiKeyBindings are stored.
33  * First item in List (with index 0) is used for transferring kitClass.
34  *
35  * @author Petr Nejedly
36  */

37
38 public class KeyBindingsEditor extends PropertyEditorSupport {
39
40     private KeyBindingsEditorPanel editorPanel;
41
42     private static final String JavaDoc HELP_ID = "editing.keybindings"; // !!! NOI18N
43

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

51     public boolean supportsCustomEditor() {
52         return true;
53     }
54
55     /**
56      * Create custom editor tightly coupled with this editor
57      */

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

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

90     protected void customEditorChange() {
91         // forward it to parent, which will fire propertyChange
92
super.setValue( editorPanel.getValue() );
93     }
94
95     /**
96      * Return the label to be shown in the PropertySheet
97      */

98     public String JavaDoc getAsText() {
99         // return "KeyBindings";
100
return NbBundle.getBundle( KeyBindingsEditor.class ).getString( "PROP_KeyBindings" ); // NOI18N
101
}
102
103     /**
104      * Don't bother if the user tried to edit our label in the PropertySheet
105      */

106     public void setAsText( String JavaDoc s ) {
107     }
108
109 }
110
Popular Tags