KickJava   Java API By Example, From Geeks To Geeks.

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


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  * MacrosEditor is editor for Map of macroiations.
32  * Each macroiation is pair of Strings.
33  * @author David Konecny
34  */

35
36 public class MacrosEditor extends PropertyEditorSupport {
37
38     private MacrosEditorPanel editorPanel;
39
40     private static final String JavaDoc HELP_ID = "editing.macros.editing"; // !!! NOI18N
41

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

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

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

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

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

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

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