001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.visualweb.propertyeditors.css.model;
042:
043: import com.sun.rave.designtime.DesignProperty;
044: import com.sun.rave.designtime.markup.MarkupDesignBean;
045: import com.sun.rave.designtime.markup.MarkupDesignContext;
046: import java.awt.Font;
047: import java.awt.GraphicsEnvironment;
048: import java.beans.PropertyChangeListener;
049: import java.beans.PropertyChangeSupport;
050: import java.io.StringWriter;
051: import java.util.ArrayList;
052: import java.util.HashMap;
053: import java.util.HashSet;
054: import java.util.Iterator;
055: import java.util.List;
056: import java.util.Map;
057: import java.util.Properties;
058: import java.util.Set;
059: import java.util.StringTokenizer;
060: import javax.swing.JTextArea;
061: import org.openide.util.NbBundle;
062:
063: /**
064: * The Style Properties Data
065: * @author Winston Prakash
066: */
067: public class CssStyleData {
068:
069: public final static String PREVIEW_NOT_SUPPORTED = NbBundle
070: .getMessage(CssStyleData.class, "PREVIEW_NOT_SUPPORTED_MSG");
071: public final static String NOT_SET = NbBundle.getMessage(
072: CssStyleData.class, "NOT_SET");
073: public final static String VALUE = NbBundle.getMessage(
074: CssStyleData.class, "VALUE");
075:
076: public final static String FONT_FAMILY = "font-family"; //NOI18N
077: public final static String FONT_SIZE = "font-size"; //NOI18N
078: public final static String FONT_STYLE = "font-style"; //NOI18N
079: public final static String FONT_WEIGHT = "font-weight"; //NOI18N
080: public final static String FONT_VARIANT = "font-variant"; //NOI18N
081:
082: public final static String TEXT_DECORATION = "text-decoration"; //NOI18N
083: public final static String TEXT_ALIGN = "text-align"; //NOI18N
084: public final static String TEXT_INDENT = "text-indent"; //NOI18N
085:
086: public final static String COLOR = "color"; //NOI18N
087:
088: public final static String BACKGROUND_COLOR = "background-color"; //NOI18N
089: public final static String BACKGROUND_IMAGE = "background-image"; //NOI18N
090: public final static String BACKGROUND_REPEAT = "background-repeat"; //NOI18N
091: public final static String BACKGROUND_ATTACHMENT = "background-attachment"; //NOI18N
092: public final static String BACKGROUND_POSITION = "background-position"; //NOI18N
093:
094: public final static String DIRECTION = "direction"; //NOI18N
095: public final static String LINE_HEIGHT = "line-height"; //NOI18N
096: public final static String VERTICAL_ALIGN = "vertical-align"; //NOI18N
097:
098: public final static String WORD_SPACING = "word-spacing"; //NOI18N
099: public final static String LETTER_SPACING = "letter-spacing"; //NOI18N
100:
101: public final static String BORDER = "border"; //NOI18N
102: public final static String BORDER_TOP = "border-top"; //NOI18N
103: public final static String BORDER_BOTTOM = "border-bottom"; //NOI18N
104: public final static String BORDER_LEFT = "border-left"; //NOI18N
105: public final static String BORDER_RIGHT = "border-right"; //NOI18N
106:
107: public final static String BORDER_COLOR = "border-color"; //NOI18N
108: public final static String BORDER_STYLE = "border-style"; //NOI18N
109: public final static String BORDER_WIDTH = "border-width"; //NOI18N
110:
111: public final static String BORDER_TOP_COLOR = "border-top-color"; //NOI18N
112: public final static String BORDER_TOP_STYLE = "border-top-style"; //NOI18N
113: public final static String BORDER_TOP_WIDTH = "border-top-width"; //NOI18N
114:
115: public final static String BORDER_BOTTOM_COLOR = "border-bottom-color"; //NOI18N
116: public final static String BORDER_BOTTOM_STYLE = "border-bottom-style"; //NOI18N
117: public final static String BORDER_BOTTOM_WIDTH = "border-bottom-width"; //NOI18N
118:
119: public final static String BORDER_LEFT_COLOR = "border-left-color"; //NOI18N
120: public final static String BORDER_LEFT_STYLE = "border-left-style"; //NOI18N
121: public final static String BORDER_LEFT_WIDTH = "border-left-width"; //NOI18N
122:
123: public final static String BORDER_RIGHT_COLOR = "border-right-color"; //NOI18N
124: public final static String BORDER_RIGHT_STYLE = "border-right-style"; //NOI18N
125: public final static String BORDER_RIGHT_WIDTH = "border-right-width"; //NOI18N
126:
127: public final static String MARGIN = "margin"; //NOI18N
128: public final static String MARGIN_TOP = "margin-top"; //NOI18N
129: public final static String MARGIN_BOTTOM = "margin-bottom"; //NOI18N
130: public final static String MARGIN_LEFT = "margin-left"; //NOI18N
131: public final static String MARGIN_RIGHT = "margin-right"; //NOI18N
132:
133: public final static String PADDING = "padding"; //NOI18N
134: public final static String PADDING_TOP = "padding-top"; //NOI18N
135: public final static String PADDING_BOTTOM = "padding-bottom"; //NOI18N
136: public final static String PADDING_LEFT = "padding-left"; //NOI18N
137: public final static String PADDING_RIGHT = "padding-right"; //NOI18N
138:
139: public final static String POSITION = "position"; //NOI18N
140: public final static String TOP = "top"; //NOI18N
141: public final static String BOTTOM = "bottom"; //NOI18N
142: public final static String LEFT = "left"; //NOI18N
143: public final static String RIGHT = "right"; //NOI18N
144:
145: public final static String WIDTH = "width"; //NOI18N
146: public final static String HEIGHT = "height"; //NOI18N
147: public final static String MIN_WIDTH = "min-width"; //NOI18N
148: public final static String MAX_WIDTH = "max-width"; //NOI18N
149: public final static String MIN_HEIGHT = "min-height"; //NOI18N
150: public final static String MAX_HEIGHT = "max-height"; //NOI18N
151:
152: public final static String Z_INDEX = "z-index"; //NOI18N
153: public final static String VISIBILITY = "visibility"; //NOI18N
154:
155: public final static String CLIP = "clip"; //NOI18N
156:
157: public final static String STYLE = "style"; //NOI18N
158:
159: Properties styleProperties = new Properties();
160:
161: Set propertyNames = new HashSet();
162:
163: Map fontFaceFamilyMap = new HashMap();
164: Set fontNames = new HashSet();
165:
166: Font defaultFont = new JTextArea().getFont();
167: String defaultFontName = defaultFont.getFontName();
168: int defaultFontSize = defaultFont.getSize();
169: int defaultFontStyle = defaultFont.getStyle();
170:
171: DesignProperty designProperty;
172:
173: /**
174: * Holds value of property test.
175: */
176: private String test;
177:
178: /**
179: * Utility field used by bound properties.
180: */
181: private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(
182: this );
183:
184: public CssStyleData() {
185: propertyNames.add(FONT_FAMILY);
186: }
187:
188: public void setDesignProperty(DesignProperty designProperty) {
189: this .designProperty = designProperty;
190: }
191:
192: /**
193: * Get the names of the supported properties
194: * @return Set of property names.
195: */
196: public Set getPropertyNames() {
197: return propertyNames;
198: }
199:
200: /**
201: * Get the value of specified property from the set.
202: * @return Value of the specified property.
203: */
204: public String getProperty(String property) {
205: return (String) styleProperties.get(property);
206: }
207:
208: /**
209: * Add the specified property to the property set.
210: * @param property name & value of the property.
211: */
212: public void addProperty(String property, String value) {
213: if (value != null) {
214: if (styleProperties.containsKey(property)) {
215: styleProperties.remove(property);
216: }
217: styleProperties.put(property, value.trim());
218: }
219: }
220:
221: /**
222: * Modify the specified property in the property set.
223: * @param property name & value of the property.
224: */
225: public void modifyProperty(String property, String newValue) {
226: Object oldValue = null;
227: newValue = newValue.trim();
228: if (styleProperties.containsKey(property)) {
229: oldValue = styleProperties.remove(property);
230: }
231: if ((newValue != null) && (!newValue.equals(""))
232: && (!newValue.equals(NOT_SET))
233: && (!newValue.equals(VALUE))) {
234: styleProperties.put(property, newValue);
235: }
236: propertyChangeSupport.firePropertyChange("property", oldValue,
237: newValue);
238: }
239:
240: public String getStyleValue() {
241: return toString();
242: }
243:
244: /**
245: * Reove the specified property from the property set.
246: * @param property name & value of the property.
247: */
248: public void removeProperty(String property) {
249: if (styleProperties.containsKey(property)) {
250: String oldValue = getProperty(property);
251: styleProperties.remove(property);
252: propertyChangeSupport.firePropertyChange("property",
253: oldValue, null); //NOI18N
254: }
255: }
256:
257: public String toString() {
258: // If the design property is not null, then construct the Style
259: // String from the style properties using DesignContext.convertMapToCssStyle
260:
261: if (designProperty != null) {
262: MarkupDesignBean liveBean = (MarkupDesignBean) designProperty
263: .getDesignBean();
264: MarkupDesignContext liveContext = (MarkupDesignContext) liveBean
265: .getDesignContext();
266: String styleString = liveContext
267: .convertMapToCssStyle(styleProperties);
268: return styleString;
269: } else {
270: StringWriter strWriter = new StringWriter();
271: for (Iterator iter = styleProperties.keySet().iterator(); iter
272: .hasNext();) {
273: String property = (String) iter.next();
274: strWriter.write(property);
275: strWriter.write(":");
276: strWriter.write(getProperty(property));
277: if (iter.hasNext())
278: strWriter.write("; ");
279: }
280: return strWriter.toString().replaceAll("\"", """); //NOI18N
281: }
282: }
283:
284: /**
285: * Adds a PropertyChangeListener to the listener list.
286: * @param listener The listener to add.
287: */
288: public void addCssPropertyChangeListener(
289: PropertyChangeListener listener) {
290: propertyChangeSupport.addPropertyChangeListener(listener);
291: }
292:
293: /**
294: * Removes a PropertyChangeListener from the listener list.
295: * @param listener The listener to remove.
296: */
297: public void removeCssPropertyChangeListener(
298: PropertyChangeListener listener) {
299: propertyChangeSupport.removePropertyChangeListener(listener);
300: }
301: }
|