KickJava   Java API By Example, From Geeks To Geeks.

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


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.HashMap JavaDoc;
32 import java.util.Map JavaDoc;
33 import java.util.Set JavaDoc;
34
35 import org.nightlabs.editor2d.DrawComponent;
36 import org.nightlabs.editor2d.EditorGuide;
37
38 /**
39  * <!-- begin-user-doc -->
40  * An implementation of the model object '<em><b>Editor Guide</b></em>'.
41  * <!-- end-user-doc -->
42  * <p>
43  * The following features are implemented:
44  * <ul>
45  * <li>{@link org.nightlabs.editor2d.impl.EditorGuideImpl#isHorizontal <em>Horizontal</em>}</li>
46  * <li>{@link org.nightlabs.editor2d.impl.EditorGuideImpl#getPosition <em>Position</em>}</li>
47  * <li>{@link org.nightlabs.editor2d.impl.EditorGuideImpl#getMap <em>Map</em>}</li>
48  * <li>{@link org.nightlabs.editor2d.impl.EditorGuideImpl#getListeners <em>Listeners</em>}</li>
49  * </ul>
50  * </p>
51  *
52  * @generated
53  */

54 public class EditorGuideImpl
55 implements EditorGuide
56 {
57   /**
58    * @return the set of all the parts attached to this guide; a set is used because a part
59    * can only be attached to a guide along one edge.
60    */

61   public Set JavaDoc getParts() {
62     return getMap().keySet();
63   }
64   
65     /**
66      * The default value of the '{@link #isHorizontal() <em>Horizontal</em>}' attribute.
67      * <!-- begin-user-doc -->
68    * <!-- end-user-doc -->
69      * @see #isHorizontal()
70      * @generated
71      * @ordered
72      */

73   protected static final boolean HORIZONTAL_EDEFAULT = false;
74
75     /**
76      * The cached value of the '{@link #isHorizontal() <em>Horizontal</em>}' attribute.
77      * <!-- begin-user-doc -->
78    * <!-- end-user-doc -->
79      * @see #isHorizontal()
80      * @generated
81      * @ordered
82      */

83   protected boolean horizontal = HORIZONTAL_EDEFAULT;
84
85     /**
86      * The default value of the '{@link #getPosition() <em>Position</em>}' attribute.
87      * <!-- begin-user-doc -->
88    * <!-- end-user-doc -->
89      * @see #getPosition()
90      * @generated
91      * @ordered
92      */

93   protected static final int POSITION_EDEFAULT = 0;
94
95     /**
96      * The cached value of the '{@link #getPosition() <em>Position</em>}' attribute.
97      * <!-- begin-user-doc -->
98    * <!-- end-user-doc -->
99      * @see #getPosition()
100      * @generated
101      * @ordered
102      */

103   protected int position = POSITION_EDEFAULT;
104
105     /**
106      * The default value of the '{@link #getMap() <em>Map</em>}' attribute.
107      * <!-- begin-user-doc -->
108    * <!-- end-user-doc -->
109      * @see #getMap()
110      * @generated
111      * @ordered
112      */

113   protected static final Map JavaDoc MAP_EDEFAULT = null;
114
115     /**
116      * The cached value of the '{@link #getMap() <em>Map</em>}' attribute.
117      * <!-- begin-user-doc -->
118    * <!-- end-user-doc -->
119      * @see #getMap()
120      * @generated
121      * @ordered
122      */

123   protected Map JavaDoc map = MAP_EDEFAULT;
124
125     /**
126      * The default value of the '{@link #getListeners() <em>Listeners</em>}' attribute.
127      * <!-- begin-user-doc -->
128    * <!-- end-user-doc -->
129      * @see #getListeners()
130      * @generated
131      * @ordered
132      */

133   protected static final PropertyChangeSupport JavaDoc LISTENERS_EDEFAULT = null;
134
135   /**
136    * The cached value of the '{@link #getListeners() <em>Listeners</em>}' attribute.
137    * <!-- begin-user-doc -->
138    * <!-- end-user-doc -->
139    * @see #getListeners()
140    *
141    * @ordered
142    */

143 // protected PropertyChangeSupport listeners = LISTENERS_EDEFAULT;
144
protected PropertyChangeSupport JavaDoc listeners = new PropertyChangeSupport JavaDoc(this);
145
146     /**
147      * This is true if the Listeners attribute has been set.
148      * <!-- begin-user-doc -->
149    * <!-- end-user-doc -->
150      * @generated
151      * @ordered
152      */

153   protected boolean listenersESet = false;
154
155     /**
156      * <!-- begin-user-doc -->
157    * <!-- end-user-doc -->
158      *
159      */

160   public EditorGuideImpl() {
161         super();
162     }
163
164     /**
165      * <!-- begin-user-doc -->
166    * <!-- end-user-doc -->
167      * @generated
168      */

169   public boolean isHorizontal() {
170         return horizontal;
171     }
172
173     /**
174      * <!-- begin-user-doc -->
175    * <!-- end-user-doc -->
176      * @generated
177      */

178   public void setHorizontal(boolean newHorizontal) {
179         horizontal = newHorizontal;
180     }
181
182     /**
183      * <!-- begin-user-doc -->
184    * <!-- end-user-doc -->
185      * @generated
186      */

187   public int getPosition() {
188         return position;
189     }
190
191   /**
192    * <!-- begin-user-doc -->
193    * <!-- end-user-doc -->
194    */

195   public void setPosition(int newPosition)
196   {
197     if (position != newPosition) {
198         int oldValue = position;
199         position = newPosition;
200         listeners.firePropertyChange(PROPERTY_POSITION, new Integer JavaDoc(oldValue),
201                 new Integer JavaDoc(position));
202     }
203   }
204   
205   /**
206    * <!-- begin-user-doc -->
207    * <!-- end-user-doc -->
208    *
209    */

210   public Map JavaDoc getMap() {
211     if (map == null) {
212         map = new HashMap JavaDoc();
213     }
214     return map;
215   }
216   
217     /**
218      * <!-- begin-user-doc -->
219    * <!-- end-user-doc -->
220      * @generated
221      */

222   public void setMap(Map JavaDoc newMap) {
223         map = newMap;
224     }
225
226   /**
227    * <!-- begin-user-doc -->
228    * <!-- end-user-doc -->
229    *
230    */

231   public void attachPart(DrawComponent drawComponent, int alignment)
232   {
233     if (getMap().containsKey(drawComponent) && getAlignment(drawComponent) == alignment)
234         return;
235     
236     getMap().put(drawComponent, new Integer JavaDoc(alignment));
237     EditorGuide parent = isHorizontal() ? drawComponent.getHorizontalGuide() : drawComponent.getVerticalGuide();
238     if (parent != null && parent != this) {
239         parent.detachPart(drawComponent);
240     }
241     if (isHorizontal()) {
242       drawComponent.setHorizontalGuide(this);
243     } else {
244       drawComponent.setVerticalGuide(this);
245     }
246     listeners.firePropertyChange(PROPERTY_CHILDREN, null, drawComponent);
247   }
248
249   /**
250    * <!-- begin-user-doc -->
251    * <!-- end-user-doc -->
252    *
253    */

254   public void detachPart(DrawComponent drawComponent)
255   {
256     if (getMap().containsKey(drawComponent)) {
257         getMap().remove(drawComponent);
258         if (isHorizontal()) {
259           drawComponent.setHorizontalGuide(null);
260         } else {
261           drawComponent.setVerticalGuide(null);
262         }
263         listeners.firePropertyChange(PROPERTY_CHILDREN, null, drawComponent);
264     }
265   }
266
267   /**
268    * <!-- begin-user-doc -->
269    * <!-- end-user-doc -->
270    *
271    */

272   public int getAlignment(DrawComponent drawComponent)
273   {
274     if (getMap().get(drawComponent) != null)
275         return ((Integer JavaDoc)getMap().get(drawComponent)).intValue();
276     return -2;
277   }
278
279   /**
280    * <!-- begin-user-doc -->
281    * <!-- end-user-doc -->
282    *
283    */

284   public void addPropertyChangeListener(PropertyChangeListener JavaDoc listener) {
285     listeners.addPropertyChangeListener(listener);
286   }
287
288   /**
289    * <!-- begin-user-doc -->
290    * <!-- end-user-doc -->
291    *
292    */

293   public void removePropertyChangeListener(PropertyChangeListener JavaDoc listener) {
294     listeners.removePropertyChangeListener(listener);
295   }
296
297     /**
298      * <!-- begin-user-doc -->
299    * <!-- end-user-doc -->
300      * @generated
301      */

302   public String JavaDoc toString()
303   {
304         StringBuffer JavaDoc result = new StringBuffer JavaDoc(super.toString());
305         result.append(" (horizontal: ");
306         result.append(horizontal);
307         result.append(", position: ");
308         result.append(position);
309         result.append(", map: ");
310         result.append(map);
311         result.append(", listeners: ");
312         result.append(')');
313         return result.toString();
314     }
315
316 } //EditorGuideImpl
317
Popular Tags