1 26 27 package org.nightlabs.editor2d.impl; 28 29 import java.beans.PropertyChangeListener ; 30 import java.beans.PropertyChangeSupport ; 31 import java.util.ArrayList ; 32 import java.util.List ; 33 34 import org.nightlabs.editor2d.EditorGuide; 35 import org.nightlabs.editor2d.EditorRuler; 36 37 public class EditorRulerImpl 38 implements EditorRuler 39 { 40 48 protected List guides = null; 49 50 58 protected static final boolean HORIZONTAL_EDEFAULT = false; 59 60 68 protected boolean horizontal = HORIZONTAL_EDEFAULT; 69 70 78 protected static final int UNIT_EDEFAULT = 0; 79 80 88 protected int unit = UNIT_EDEFAULT; 89 90 98 protected static final boolean HIDDEN_EDEFAULT = false; 99 100 108 protected boolean hidden = HIDDEN_EDEFAULT; 109 110 118 protected static final PropertyChangeSupport LISTENERS_EDEFAULT = null; 119 120 128 protected PropertyChangeSupport listeners = new PropertyChangeSupport (this); 130 131 136 public EditorRulerImpl() { 137 super(); 138 } 139 140 145 public List getGuides() { 146 if (guides == null) { 147 guides = new ArrayList (); 148 } 149 return guides; 150 } 151 152 157 public boolean isHorizontal() { 158 return horizontal; 159 } 160 161 166 public void setHorizontal(boolean newHorizontal) { 167 horizontal = newHorizontal; 168 } 169 170 175 public int getUnit() { 176 return unit; 177 } 178 179 184 public void setUnit(int newUnit) { 185 if (unit != newUnit) { 186 int oldUnit = unit; 187 unit = newUnit; 188 listeners.firePropertyChange(PROPERTY_UNIT, oldUnit, newUnit); 189 } 190 } 191 192 197 public boolean isHidden() { 198 return hidden; 199 } 200 201 206 public void setHidden(boolean newHidden) { 207 hidden = newHidden; 208 } 209 210 215 public void addGuide(EditorGuide guide) { 216 if (!guides.contains(guide)) { 217 guide.setHorizontal(!isHorizontal()); 218 guides.add(guide); 219 listeners.firePropertyChange(PROPERTY_CHILDREN, null, guide); 220 } 221 } 222 223 228 public void removeGuide(EditorGuide guide) { 229 if (guides.remove(guide)) { 230 listeners.firePropertyChange(PROPERTY_CHILDREN, null, guide); 231 } 232 } 233 234 239 public void addPropertyChangeListener(PropertyChangeListener listener) { 240 listeners.addPropertyChangeListener(listener); 241 } 242 243 248 public void removePropertyChangeListener(PropertyChangeListener listener) { 249 listeners.removePropertyChangeListener(listener); 250 } 251 252 257 public String toString() 258 { 259 StringBuffer result = new StringBuffer (super.toString()); 260 result.append(" (horizontal: "); 261 result.append(horizontal); 262 result.append(", unit: "); 263 result.append(unit); 264 result.append(", hidden: "); 265 result.append(hidden); 266 result.append(", listeners: "); 267 result.append(')'); 268 return result.toString(); 269 } 270 271 } | Popular Tags |