KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > css > visual > ui > StyleEditor


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * StyleEditor.java
22  *
23  * Created on October 13, 2004, 12:26 PM
24  */

25
26 package org.netbeans.modules.css.visual.ui;
27
28 import org.netbeans.modules.css.visual.model.CssStyleData;
29 import java.beans.PropertyChangeEvent JavaDoc;
30 import java.beans.PropertyChangeListener JavaDoc;
31 import java.beans.PropertyChangeSupport JavaDoc;
32 import javax.swing.Icon JavaDoc;
33 import javax.swing.JPanel JavaDoc;
34
35 /**
36  * Super class for all Style editors
37  * @author Winston Prakash
38  * @version 1.0
39  */

40 abstract public class StyleEditor extends JPanel JavaDoc {
41
42     PropertyChangeSupport JavaDoc cssPropertyChangeSupport = new PropertyChangeSupport JavaDoc(this);
43
44     CssPropertyChangeListener cssPropertyChangeListener = new CssPropertyChangeListener();
45
46     boolean listenerAdded = false;
47
48     /**
49      * Overriden by the subclasses
50      * - Remove the property change listener
51      * - Set the values from CSS data to GUI elements
52      * - Set back the CSS property change listener
53      */

54     abstract protected void setCssPropertyValues(CssStyleData styleData);
55
56     /**
57      * Set the CSS property change listener
58      */

59     public void setCssPropertyChangeListener(CssStyleData styleData){
60         // We don't want the property change listener added more than
61
// once accidently
62
synchronized(StyleEditor.class){
63             if (!listenerAdded){
64                 listenerAdded = true;
65                 cssPropertyChangeListener.setCssStyleData(styleData);
66                 cssPropertyChangeSupport.addPropertyChangeListener(cssPropertyChangeListener);
67             }
68         }
69     }
70
71     /**
72      * Remove the CSS property change listener
73      */

74     public void removeCssPropertyChangeListener(){
75         synchronized(StyleEditor.class){
76             if (listenerAdded){
77                 listenerAdded = false;
78                 cssPropertyChangeSupport.removePropertyChangeListener(cssPropertyChangeListener);
79             }
80         }
81     }
82
83
84     /**
85      * Holds value of property displayName.
86      */

87     private String JavaDoc displayName;
88
89     /**
90      * Holds value of property icon.
91      */

92     private Icon JavaDoc icon;
93
94     /**
95      * Getter for property displayName.
96      * @return Value of property displayName.
97      */

98     public String JavaDoc getDisplayName() {
99         return this.displayName;
100     }
101
102     /**
103      * Setter for property displayName.
104      * @param displayName New value of property displayName.
105      */

106     public void setDisplayName(String JavaDoc displayName) {
107         this.displayName = displayName;
108     }
109
110     /**
111      * Getter for property icon.
112      * @return Value of property icon.
113      */

114     public Icon JavaDoc getIcon() {
115         return this.icon;
116     }
117
118     /**
119      * Setter for property icon.
120      * @param icon New value of property icon.
121      */

122     public void setIcon(Icon JavaDoc icon) {
123         this.icon = icon;
124     }
125
126     static class CssPropertyChangeListener implements PropertyChangeListener JavaDoc{
127         CssStyleData cssStyleData;
128
129         public CssPropertyChangeListener(){
130         }
131
132         public CssPropertyChangeListener(CssStyleData styleData){
133             cssStyleData = styleData;
134         }
135
136         public void setCssStyleData(CssStyleData styleData){
137             cssStyleData = styleData;
138         }
139
140         public void propertyChange(PropertyChangeEvent JavaDoc evt) {
141             cssStyleData.modifyProperty(evt.getPropertyName(), (String JavaDoc)evt.getNewValue());
142         }
143     }
144 }
145
Popular Tags