KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nightlabs > editor2d > impl > EditorRulerImpl


1 /* *****************************************************************************
2  * NightLabs Editor2D - Graphical editor framework *
3  * Copyright (C) 2004-2005 NightLabs - http://NightLabs.org *
4  * *
5  * This library is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or (at your option) any later version. *
9  * *
10  * This library is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
13  * Lesser General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU Lesser General Public *
16  * License along with this library; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin St, Fifth Floor, *
19  * Boston, MA 02110-1301 USA *
20  * *
21  * Or get it online : *
22  * http://www.gnu.org/copyleft/lesser.html *
23  * *
24  * *
25  ******************************************************************************/

26
27 package org.nightlabs.editor2d.impl;
28
29 import java.beans.PropertyChangeListener JavaDoc;
30 import java.beans.PropertyChangeSupport JavaDoc;
31 import java.util.ArrayList JavaDoc;
32 import java.util.List JavaDoc;
33
34 import org.nightlabs.editor2d.EditorGuide;
35 import org.nightlabs.editor2d.EditorRuler;
36
37 public class EditorRulerImpl
38 implements EditorRuler
39 {
40     /**
41      * The cached value of the '{@link #getGuides() <em>Guides</em>}' containment reference list.
42      * <!-- begin-user-doc -->
43    * <!-- end-user-doc -->
44      * @see #getGuides()
45      * @generated
46      * @ordered
47      */

48   protected List JavaDoc guides = null;
49
50     /**
51      * The default value of the '{@link #isHorizontal() <em>Horizontal</em>}' attribute.
52      * <!-- begin-user-doc -->
53    * <!-- end-user-doc -->
54      * @see #isHorizontal()
55      * @generated
56      * @ordered
57      */

58   protected static final boolean HORIZONTAL_EDEFAULT = false;
59
60     /**
61      * The cached value of the '{@link #isHorizontal() <em>Horizontal</em>}' attribute.
62      * <!-- begin-user-doc -->
63    * <!-- end-user-doc -->
64      * @see #isHorizontal()
65      * @generated
66      * @ordered
67      */

68   protected boolean horizontal = HORIZONTAL_EDEFAULT;
69
70     /**
71      * The default value of the '{@link #getUnit() <em>Unit</em>}' attribute.
72      * <!-- begin-user-doc -->
73    * <!-- end-user-doc -->
74      * @see #getUnit()
75      * @generated
76      * @ordered
77      */

78   protected static final int UNIT_EDEFAULT = 0;
79
80     /**
81      * The cached value of the '{@link #getUnit() <em>Unit</em>}' attribute.
82      * <!-- begin-user-doc -->
83    * <!-- end-user-doc -->
84      * @see #getUnit()
85      * @generated
86      * @ordered
87      */

88   protected int unit = UNIT_EDEFAULT;
89
90     /**
91      * The default value of the '{@link #isHidden() <em>Hidden</em>}' attribute.
92      * <!-- begin-user-doc -->
93    * <!-- end-user-doc -->
94      * @see #isHidden()
95      * @generated
96      * @ordered
97      */

98   protected static final boolean HIDDEN_EDEFAULT = false;
99
100     /**
101      * The cached value of the '{@link #isHidden() <em>Hidden</em>}' attribute.
102      * <!-- begin-user-doc -->
103    * <!-- end-user-doc -->
104      * @see #isHidden()
105      * @generated
106      * @ordered
107      */

108   protected boolean hidden = HIDDEN_EDEFAULT;
109
110     /**
111      * The default value of the '{@link #getListeners() <em>Listeners</em>}' attribute.
112      * <!-- begin-user-doc -->
113    * <!-- end-user-doc -->
114      * @see #getListeners()
115      * @generated
116      * @ordered
117      */

118   protected static final PropertyChangeSupport JavaDoc LISTENERS_EDEFAULT = null;
119
120   /**
121    * The cached value of the '{@link #getListeners() <em>Listeners</em>}' attribute.
122    * <!-- begin-user-doc -->
123    * <!-- end-user-doc -->
124    * @see #getListeners()
125    *
126    * @ordered
127    */

128 // protected PropertyChangeSupport listeners = LISTENERS_EDEFAULT;
129
protected PropertyChangeSupport JavaDoc listeners = new PropertyChangeSupport JavaDoc(this);
130
131     /**
132      * <!-- begin-user-doc -->
133    * <!-- end-user-doc -->
134      *
135      */

136   public EditorRulerImpl() {
137         super();
138     }
139
140     /**
141      * <!-- begin-user-doc -->
142    * <!-- end-user-doc -->
143      * @generated
144      */

145   public List JavaDoc getGuides() {
146         if (guides == null) {
147             guides = new ArrayList JavaDoc();
148         }
149         return guides;
150     }
151
152     /**
153      * <!-- begin-user-doc -->
154    * <!-- end-user-doc -->
155      * @generated
156      */

157   public boolean isHorizontal() {
158         return horizontal;
159     }
160
161     /**
162      * <!-- begin-user-doc -->
163    * <!-- end-user-doc -->
164      * @generated
165      */

166   public void setHorizontal(boolean newHorizontal) {
167         horizontal = newHorizontal;
168     }
169
170     /**
171      * <!-- begin-user-doc -->
172    * <!-- end-user-doc -->
173      * @generated
174      */

175   public int getUnit() {
176         return unit;
177     }
178
179     /**
180      * <!-- begin-user-doc -->
181    * <!-- end-user-doc -->
182      * @generated
183      */

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     /**
193      * <!-- begin-user-doc -->
194    * <!-- end-user-doc -->
195      * @generated
196      */

197   public boolean isHidden() {
198         return hidden;
199     }
200
201     /**
202      * <!-- begin-user-doc -->
203    * <!-- end-user-doc -->
204      * @generated
205      */

206   public void setHidden(boolean newHidden) {
207         hidden = newHidden;
208     }
209
210   /**
211    * <!-- begin-user-doc -->
212    * <!-- end-user-doc -->
213    *
214    */

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   /**
224    * <!-- begin-user-doc -->
225    * <!-- end-user-doc -->
226    *
227    */

228   public void removeGuide(EditorGuide guide) {
229     if (guides.remove(guide)) {
230         listeners.firePropertyChange(PROPERTY_CHILDREN, null, guide);
231     }
232   }
233
234   /**
235    * <!-- begin-user-doc -->
236    * <!-- end-user-doc -->
237    *
238    */

239   public void addPropertyChangeListener(PropertyChangeListener JavaDoc listener) {
240     listeners.addPropertyChangeListener(listener);
241   }
242
243   /**
244    * <!-- begin-user-doc -->
245    * <!-- end-user-doc -->
246    *
247    */

248   public void removePropertyChangeListener(PropertyChangeListener JavaDoc listener) {
249     listeners.removePropertyChangeListener(listener);
250   }
251
252     /**
253      * <!-- begin-user-doc -->
254    * <!-- end-user-doc -->
255      * @generated
256      */

257   public String JavaDoc toString()
258   {
259         StringBuffer JavaDoc result = new StringBuffer JavaDoc(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 } //EditorRulerImpl
272
Popular Tags