KickJava   Java API By Example, From Geeks To Geeks.

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


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.Collections JavaDoc;
32 import java.util.List JavaDoc;
33
34 import org.eclipse.draw2d.FreeformLayout;
35 import org.eclipse.draw2d.IFigure;
36 import org.eclipse.ui.views.properties.IPropertySource;
37 import org.nightlabs.editor2d.Layer;
38 import org.nightlabs.editor2d.figures.ContainerFreeformLayer;
39 import org.nightlabs.editor2d.model.LayerPropertySource;
40
41 public class LayerEditPart
42 extends AbstractDrawComponentContainerEditPart
43 {
44   /**
45    * @param layer the Layer for the LayerEditPart
46    * @see org.nightlabs.editor2d.Layer
47    */

48   public LayerEditPart(Layer layer) {
49     super(layer);
50   }
51     
52   /**
53    * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure()
54    */

55   protected IFigure createFigure()
56   {
57 // IFigure f = new FreeformLayer();
58

59 // Figure f = new OversizedBufferFreeformLayer();
60
// ((BufferedFreeformLayer)f).init(this);
61

62 // DrawComponentFigure f = new ContainerDrawComponentFigure();
63
// f.setDrawComponent(getDrawComponent());
64
// addRenderer(f);
65
// addZoomListener(f);
66

67     IFigure f = new ContainerFreeformLayer();
68     
69         f.setLayoutManager(new FreeformLayout());
70         return f;
71   }
72     
73   public Layer getLayer() {
74     return (Layer) getModel();
75   }
76   
77   /* (non-Javadoc)
78    * @see org.eclipse.gef.editparts.AbstractEditPart#getModelChildren()
79    */

80   protected List JavaDoc getModelChildren()
81   {
82     if (getLayer().isVisible()) {
83       return getLayer().getDrawComponents();
84     } else {
85       return Collections.EMPTY_LIST;
86     }
87   }
88     
89 // public BufferedFreeformLayer getBufferedFreeformLayer()
90
// {
91
// if (getFigure() instanceof BufferedFreeformLayer)
92
// return (BufferedFreeformLayer) getFigure();
93
// else
94
// return null;
95
// }
96

97     protected void propertyChanged(PropertyChangeEvent JavaDoc evt)
98     {
99         super.propertyChanged(evt);
100         String JavaDoc propertyName = evt.getPropertyName();
101         if (propertyName.equals(Layer.PROP_VISIBLE)) {
102             LOGGER.debug(propertyName +" changed!");
103 // refreshChildren();
104
refresh();
105         }
106     }
107     
108   /* (non-Javadoc)
109    * @see com.ibm.itso.sal330r.gefdemo.edit.WorkflowElementEditPart#getPropertySource()
110    */

111   protected IPropertySource getPropertySource()
112   {
113     if (propertySource == null)
114     {
115       propertySource =
116         new LayerPropertySource(getLayer());
117     }
118     return propertySource;
119   }
120   
121 }
122
Popular Tags