KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nightlabs > editor2d > edit > AbstractDrawComponentContainerEditPart


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

27
28 package org.nightlabs.editor2d.edit;
29
30 import java.beans.PropertyChangeEvent JavaDoc;
31 import java.util.List JavaDoc;
32
33 import org.apache.log4j.Logger;
34 import org.eclipse.draw2d.FreeformLayout;
35 import org.eclipse.draw2d.IFigure;
36 import org.eclipse.draw2d.XYLayout;
37 import org.eclipse.gef.EditPolicy;
38 import org.eclipse.gef.editpolicies.SnapFeedbackPolicy;
39
40 import org.nightlabs.editor2d.DrawComponentContainer;
41 import org.nightlabs.editor2d.editpolicy.DrawComponentContainerEditPolicy;
42 import org.nightlabs.editor2d.editpolicy.DrawComponentContainerXYLayoutPolicy;
43 import org.nightlabs.editor2d.editpolicy.DrawComponentEditPolicy;
44 import org.nightlabs.editor2d.figures.ContainerDrawComponentFigure;
45
46
47 public abstract class AbstractDrawComponentContainerEditPart
48 extends AbstractDrawComponentEditPart
49 {
50   public static final Logger LOGGER = Logger.getLogger(AbstractDrawComponentContainerEditPart.class);
51   
52   /**
53    * @param drawComponent
54    */

55   public AbstractDrawComponentContainerEditPart(DrawComponentContainer drawComponentContainer) {
56     super(drawComponentContainer);
57   }
58
59 // protected abstract IFigure createFigure();
60
protected IFigure createFigure()
61   {
62     ContainerDrawComponentFigure figure = new ContainerDrawComponentFigure();
63     figure.setLayoutManager(new FreeformLayout());
64     figure.setDrawComponent(getDrawComponent());
65     addRenderer(figure);
66     addZoomListener(figure);
67     return figure;
68   }
69   
70 // /* (non-Javadoc)
71
// * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure()
72
// */
73
// protected IFigure createFigure() {
74
// Figure f = new Figure();
75
// f.setLayoutManager(new FreeformLayout());
76
// return f;
77
// }
78

79   /* (non-Javadoc)
80    * @see org.eclipse.gef.editparts.AbstractEditPart#createEditPolicies()
81    */

82   protected void createEditPolicies()
83   {
84     installEditPolicy(EditPolicy.COMPONENT_ROLE, new DrawComponentEditPolicy());
85         installEditPolicy(EditPolicy.CONTAINER_ROLE, new DrawComponentContainerEditPolicy());
86         XYLayout layout = (XYLayout) getContentPane().getLayoutManager();
87         installEditPolicy(EditPolicy.LAYOUT_ROLE, new DrawComponentContainerXYLayoutPolicy(layout));
88         installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, null);
89         installEditPolicy("Snap Feedback", new SnapFeedbackPolicy()); //$NON-NLS-1$
90
}
91   
92     protected void propertyChanged(PropertyChangeEvent JavaDoc evt)
93     {
94         super.propertyChanged(evt);
95         String JavaDoc propertyName = evt.getPropertyName();
96         if (propertyName.equals(DrawComponentContainer.CHILD_ADDED)) {
97             LOGGER.debug(propertyName);
98             refreshChildren();
99 // refresh();
100
}
101         else if (propertyName.equals(DrawComponentContainer.CHILD_REMOVED)) {
102             LOGGER.debug(propertyName);
103             refreshChildren();
104 // refresh();
105
}
106     }
107     
108   protected List JavaDoc getModelChildren()
109   {
110     return ((DrawComponentContainer)getModel()).getDrawComponents();
111   }
112 }
113
Popular Tags