1 7 package com.nightlabs.editor2d.impl; 8 9 import java.beans.PropertyChangeListener ; 10 import java.beans.PropertyChangeSupport ; 11 import java.util.ArrayList ; 12 import java.util.List ; 13 14 import com.nightlabs.editor2d.EditorGuide; 15 import com.nightlabs.editor2d.EditorRuler; 16 17 public class EditorRulerImpl 18 implements EditorRuler 19 { 20 28 protected List guides = null; 29 30 38 protected static final boolean HORIZONTAL_EDEFAULT = false; 39 40 48 protected boolean horizontal = HORIZONTAL_EDEFAULT; 49 50 58 protected static final int UNIT_EDEFAULT = 0; 59 60 68 protected int unit = UNIT_EDEFAULT; 69 70 78 protected static final boolean HIDDEN_EDEFAULT = false; 79 80 88 protected boolean hidden = HIDDEN_EDEFAULT; 89 90 98 protected static final PropertyChangeSupport LISTENERS_EDEFAULT = null; 99 100 108 protected PropertyChangeSupport listeners = new PropertyChangeSupport (this); 110 111 116 public EditorRulerImpl() { 117 super(); 118 } 119 120 125 public List getGuides() { 126 if (guides == null) { 127 guides = new ArrayList (); 128 } 129 return guides; 130 } 131 132 137 public boolean isHorizontal() { 138 return horizontal; 139 } 140 141 146 public void setHorizontal(boolean newHorizontal) { 147 horizontal = newHorizontal; 148 } 149 150 155 public int getUnit() { 156 return unit; 157 } 158 159 164 public void setUnit(int newUnit) { 165 if (unit != newUnit) { 166 int oldUnit = unit; 167 unit = newUnit; 168 listeners.firePropertyChange(PROPERTY_UNIT, oldUnit, newUnit); 169 } 170 } 171 172 177 public boolean isHidden() { 178 return hidden; 179 } 180 181 186 public void setHidden(boolean newHidden) { 187 hidden = newHidden; 188 } 189 190 195 public void addGuide(EditorGuide guide) { 196 if (!guides.contains(guide)) { 197 guide.setHorizontal(!isHorizontal()); 198 guides.add(guide); 199 listeners.firePropertyChange(PROPERTY_CHILDREN, null, guide); 200 } 201 } 202 203 208 public void removeGuide(EditorGuide guide) { 209 if (guides.remove(guide)) { 210 listeners.firePropertyChange(PROPERTY_CHILDREN, null, guide); 211 } 212 } 213 214 219 public void addPropertyChangeListener(PropertyChangeListener listener) { 220 listeners.addPropertyChangeListener(listener); 221 } 222 223 228 public void removePropertyChangeListener(PropertyChangeListener listener) { 229 listeners.removePropertyChangeListener(listener); 230 } 231 232 237 public String toString() 238 { 239 StringBuffer result = new StringBuffer (super.toString()); 240 result.append(" (horizontal: "); 241 result.append(horizontal); 242 result.append(", unit: "); 243 result.append(unit); 244 result.append(", hidden: "); 245 result.append(hidden); 246 result.append(", listeners: "); 247 result.append(')'); 248 return result.toString(); 249 } 250 251 } | Popular Tags |