1 19 20 25 26 package org.netbeans.modules.css.visual.model; 27 28 import java.awt.Font ; 29 import java.beans.PropertyChangeListener ; 30 import java.beans.PropertyChangeSupport ; 31 import java.io.StringWriter ; 32 import java.util.ArrayList ; 33 import java.util.Collections ; 34 import java.util.HashMap ; 35 import java.util.HashSet ; 36 import java.util.Iterator ; 37 import java.util.List ; 38 import java.util.Map ; 39 import java.util.Properties ; 40 import java.util.Set ; 41 import java.util.TreeSet ; 42 import javax.swing.JTextArea ; 43 import org.openide.util.NbBundle; 44 45 50 public class CssStyleData { 51 public final static String PREVIEW_NOT_SUPPORTED = NbBundle.getMessage(CssStyleData.class, "PREVIEW_NOT_SUPPORTED_MSG"); 53 public final static String NOT_SET = NbBundle.getMessage(CssStyleData.class, "NOT_SET"); public final static String VALUE = NbBundle.getMessage(CssStyleData.class, "VALUE"); 56 Properties styleProperties = new Properties (); 57 58 Map fontFaceFamilyMap = new HashMap (); 59 Set fontNames = new HashSet (); 60 61 Font defaultFont = new JTextArea ().getFont(); 62 String defaultFontName = defaultFont.getFontName(); 63 int defaultFontSize = defaultFont.getSize(); 64 int defaultFontStyle = defaultFont.getStyle(); 65 66 69 private String test; 70 71 74 private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport (this); 75 76 public CssStyleData(){ 77 } 78 79 80 83 public Map getPropertyMap(){ 84 Map propertyMap = new HashMap (); 85 for(Iterator iter = styleProperties.keySet().iterator(); iter.hasNext();){ 86 String property = (String )iter.next(); 87 String propertyValue = getProperty(property).trim(); 88 if(!(propertyValue.equals(VALUE) || propertyValue.equals(NOT_SET) || propertyValue.equals(""))){ 89 propertyMap.put(property, propertyValue); 90 } 91 } 92 return propertyMap; 93 } 94 95 99 public String getProperty(String property) { 100 return (String )styleProperties.get(property); 101 } 102 103 107 public void addProperty(String property, String value) { 108 if(value != null){ 109 if (styleProperties.containsKey(property)) { 110 styleProperties.remove(property); 111 } 112 styleProperties.put(property, value.trim()); 113 } 114 } 115 116 120 public void modifyProperty(String property, String newValue) { 121 String oldValue = null; 122 newValue = newValue.trim(); 123 if (styleProperties.containsKey(property)) { 124 oldValue = getProperty(property); 125 styleProperties.remove(property); 127 } 128 if((newValue != null) && (!newValue.equals(""))){ 129 styleProperties.put(property, newValue); 130 } 131 propertyChangeSupport.firePropertyChange("property", oldValue, newValue); } 133 134 public String getStyleValue(){ 135 return toString(); 136 } 137 138 142 public void removeProperty(String property) { 143 if (styleProperties.containsKey(property)) { 144 String oldValue = getProperty(property); 145 styleProperties.remove(property); 146 propertyChangeSupport.firePropertyChange("property", oldValue, null); } 148 } 149 150 public String toString(){ 151 StringWriter strWriter = new StringWriter (); 152 for(Iterator iter = styleProperties.keySet().iterator(); iter.hasNext();){ 153 String property = (String )iter.next(); 154 strWriter.write(property); 155 strWriter.write(":"); 156 strWriter.write(getProperty(property)); 157 if(iter.hasNext()) strWriter.write("; "); 158 } 159 return strWriter.toString(); 161 } 162 163 public String getFormattedString(){ 164 StringWriter strWriter = new StringWriter (); 165 strWriter.write("\n"); TreeSet sortedProperties = new TreeSet (); 167 for(Iterator iter = styleProperties.keySet().iterator(); iter.hasNext();){ 168 sortedProperties.add(iter.next()); 169 } 170 for(Iterator iter = sortedProperties.iterator(); iter.hasNext();){ 171 String property = (String )iter.next(); 172 String propertyValue = getProperty(property).trim(); 173 if(!(propertyValue.equals(NOT_SET) || propertyValue.equals(""))){ 174 strWriter.write(" " + property); 175 strWriter.write(": "); 176 strWriter.write(propertyValue); 177 if(iter.hasNext()) { 178 strWriter.write(";\n"); }else{ 180 strWriter.write("\n"); } 182 } 183 } 184 return strWriter.toString(); 185 } 186 187 191 public void addPropertyChangeListener(PropertyChangeListener listener) { 192 propertyChangeSupport.addPropertyChangeListener(listener); 193 } 194 195 199 public void removePropertyChangeListener(PropertyChangeListener listener) { 200 propertyChangeSupport.removePropertyChangeListener(listener); 201 } 202 } 203 | Popular Tags |