1 19 20 25 26 package org.netbeans.modules.css.visual.ui; 27 28 import org.netbeans.modules.css.visual.model.CssStyleData; 29 import java.beans.PropertyChangeEvent ; 30 import java.beans.PropertyChangeListener ; 31 import java.beans.PropertyChangeSupport ; 32 import javax.swing.Icon ; 33 import javax.swing.JPanel ; 34 35 40 abstract public class StyleEditor extends JPanel { 41 42 PropertyChangeSupport cssPropertyChangeSupport = new PropertyChangeSupport (this); 43 44 CssPropertyChangeListener cssPropertyChangeListener = new CssPropertyChangeListener(); 45 46 boolean listenerAdded = false; 47 48 54 abstract protected void setCssPropertyValues(CssStyleData styleData); 55 56 59 public void setCssPropertyChangeListener(CssStyleData styleData){ 60 synchronized(StyleEditor.class){ 63 if (!listenerAdded){ 64 listenerAdded = true; 65 cssPropertyChangeListener.setCssStyleData(styleData); 66 cssPropertyChangeSupport.addPropertyChangeListener(cssPropertyChangeListener); 67 } 68 } 69 } 70 71 74 public void removeCssPropertyChangeListener(){ 75 synchronized(StyleEditor.class){ 76 if (listenerAdded){ 77 listenerAdded = false; 78 cssPropertyChangeSupport.removePropertyChangeListener(cssPropertyChangeListener); 79 } 80 } 81 } 82 83 84 87 private String displayName; 88 89 92 private Icon icon; 93 94 98 public String getDisplayName() { 99 return this.displayName; 100 } 101 102 106 public void setDisplayName(String displayName) { 107 this.displayName = displayName; 108 } 109 110 114 public Icon getIcon() { 115 return this.icon; 116 } 117 118 122 public void setIcon(Icon icon) { 123 this.icon = icon; 124 } 125 126 static class CssPropertyChangeListener implements PropertyChangeListener { 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 evt) { 141 cssStyleData.modifyProperty(evt.getPropertyName(), (String )evt.getNewValue()); 142 } 143 } 144 } 145 | Popular Tags |