KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > editor > options > CodeFoldingEditor


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.java.editor.options;
21
22 import java.beans.PropertyEditorSupport JavaDoc;
23 import java.util.HashMap JavaDoc;
24 import java.util.Map JavaDoc;
25 import org.openide.util.HelpCtx;
26 import org.openide.util.NbBundle;
27
28 /**
29  *
30  * @author Martin Roskanin
31  */

32 public class CodeFoldingEditor extends PropertyEditorSupport JavaDoc{
33
34     protected HelpCtx getHelpCtx () {
35         return HelpCtx.DEFAULT_HELP;
36     }
37
38     /** Creates a new instance of CodeFoldingEditor */
39     public CodeFoldingEditor() {
40     }
41
42     public boolean supportsCustomEditor() {
43         return true;
44     }
45
46     
47     private CodeFoldingEditorPanel editorPanel;
48     
49     /**
50      * Create custom editor tightly coupled with this editor
51      */

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

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

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

91     public String JavaDoc getAsText() {
92         return NbBundle.getBundle( CodeFoldingEditor.class ).getString( "PROP_CodeFolding" ); // NOI18N
93
}
94
95     /**
96      * Don't bother if the user tried to edit our label in the PropertySheet
97      */

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