KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nightlabs > editor2d > util > FeedbackUtil


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.util;
29
30 import org.eclipse.draw2d.ColorConstants;
31 import org.eclipse.swt.graphics.Color;
32 import org.nightlabs.editor2d.DrawComponentContainer;
33 import org.nightlabs.editor2d.ImageDrawComponent;
34 import org.nightlabs.editor2d.ShapeDrawComponent;
35 import org.nightlabs.editor2d.figures.FeedbackShapeFigure;
36 import org.nightlabs.editor2d.figures.ShapeFigure;
37 import org.nightlabs.editor2d.j2d.GeneralShape;
38 import org.nightlabs.editor2d.j2d.GeneralShapeFactory;
39
40
41 public class FeedbackUtil
42 {
43 // protected static DefaultFeedbackConfigModule defaultFeedbackConfig;
44

45   public FeedbackUtil()
46   {
47     super();
48 // try {
49
// defaultFeedbackConfig = (DefaultFeedbackConfigModule) Config.sharedInstance().createConfigModule(DefaultFeedbackConfigModule.class);
50
// } catch (ConfigException e) {
51
// // TODO Auto-generated catch block
52
// e.printStackTrace();
53
// }
54
}
55   
56   public static Color GHOST_FILL_COLOR = new Color(null, 31, 31, 31);
57   public static final Color DEFAULT_BGCOLOR = ColorConstants.darkGray;
58   public static final Color DEFAULT_FGCOLOR = ColorConstants.white;
59   
60   protected static Color bgColor = DEFAULT_BGCOLOR;
61   public static Color getBackgroundColor() {
62     return bgColor;
63   }
64   
65   protected static Color fgColor = DEFAULT_FGCOLOR;
66   public static Color getForegroundColor() {
67     return fgColor;
68   }
69   
70   public static ShapeFigure getCustomFeedbackFigure(Object JavaDoc modelPart)
71     //protected IFigure getCustomFeedbackFigure(Object modelPart)
72
{
73       GeneralShape gs = null;
74       if (modelPart instanceof ShapeDrawComponent) {
75         ShapeDrawComponent sdc = (ShapeDrawComponent) modelPart;
76         gs = (GeneralShape)sdc.getGeneralShape().clone();
77       }
78       else if (modelPart instanceof ImageDrawComponent) {
79         ImageDrawComponent idc = (ImageDrawComponent) modelPart;
80         gs = (GeneralShape) idc.getImageShape().clone();
81       }
82       else if (modelPart instanceof DrawComponentContainer)
83       {
84         DrawComponentContainer container = (DrawComponentContainer) modelPart;
85         ShapeFigure containerFigure = new FeedbackShapeFigure();
86         GeneralShape containerShape = GeneralShapeFactory.createRectangle(1,1,1,1);
87         containerFigure.setGeneralShape(containerShape);
88         containerFigure.setXOR(true);
89         containerFigure.setFill(true);
90         containerFigure.setBackgroundColor(bgColor);
91         containerFigure.setForegroundColor(fgColor);
92     // for (Iterator it = container.getDrawComponents().iterator(); it.hasNext(); ) {
93
// DrawComponent dc = (DrawComponent) it.next();
94
// ShapeFigure figure = getCustomFeedbackFigure(dc);
95
// containerFigure.add(figure);
96
// }
97
return containerFigure;
98       }
99       else {
100         gs = GeneralShapeFactory.createRectangle(0, 0, 10, 10);
101       }
102       ShapeFigure shapeFigure = new FeedbackShapeFigure();
103       shapeFigure.setGeneralShape(gs);
104       shapeFigure.setXOR(true);
105       shapeFigure.setFill(true);
106       shapeFigure.setBackgroundColor(bgColor);
107       shapeFigure.setForegroundColor(fgColor);
108       return shapeFigure;
109     }
110   
111 // public static ShapeFigure createCustomFeedbackFigure(Object modelPart)
112
// {
113
// GeneralShape gs = null;
114
// if (modelPart instanceof ShapeDrawComponent) {
115
// ShapeDrawComponent sdc = (ShapeDrawComponent) modelPart;
116
// gs = (GeneralShape)sdc.getGeneralShape().clone();
117
// }
118
// else if (modelPart instanceof ImageDrawComponent) {
119
// ImageDrawComponent idc = (ImageDrawComponent) modelPart;
120
// gs = (GeneralShape) idc.getImageShape().clone();
121
// }
122
// else if (modelPart instanceof DrawComponentContainer)
123
// {
124
// DrawComponentContainer container = (DrawComponentContainer) modelPart;
125
// ShapeFigure containerFigure = new FeedbackShapeFigure();
126
// GeneralShape containerShape = GeneralShapeFactory.createRectangle(1,1,1,1);
127
// containerFigure.setGeneralShape(containerShape);
128
// containerFigure.setXOR(true);
129
// containerFigure.setFill(true);
130
// containerFigure.setBackgroundColor(ColorConstants.darkGray);
131
// containerFigure.setForegroundColor(ColorConstants.white);
132
// for (Iterator it = container.getDrawComponents().iterator(); it.hasNext(); ) {
133
// DrawComponent dc = (DrawComponent) it.next();
134
// ShapeFigure figure = createCustomFeedbackFigure(dc);
135
// containerFigure.add(figure);
136
// }
137
// return containerFigure;
138
// }
139
// else {
140
// gs = GeneralShapeFactory.createRectangle(0, 0, 10, 10);
141
// }
142
// ShapeFigure shapeFigure = new FeedbackShapeFigure();
143
// shapeFigure.setGeneralShape(gs);
144
// shapeFigure.setXOR(true);
145
// shapeFigure.setFill(true);
146
// shapeFigure.setBackgroundColor(ColorConstants.darkGray);
147
// shapeFigure.setForegroundColor(ColorConstants.white);
148
// return shapeFigure;
149
// }
150

151 //public static ShapeFigure getCustomFeedbackFigure(Object modelPart)
152
//{
153
// GeneralShape gs = null;
154
// if (modelPart instanceof ShapeDrawComponent) {
155
// ShapeDrawComponent sdc = (ShapeDrawComponent) modelPart;
156
// gs = (GeneralShape)sdc.getGeneralShape().clone();
157
// }
158
// else if (modelPart instanceof ImageDrawComponent) {
159
// ImageDrawComponent idc = (ImageDrawComponent) modelPart;
160
// gs = (GeneralShape) idc.getImageShape().clone();
161
// }
162
// else if (modelPart instanceof DrawComponentContainer)
163
// {
164
// DrawComponentContainer container = (DrawComponentContainer) modelPart;
165
// ShapeFigure containerFigure = new FeedbackShapeFigure();
166
// GeneralShape containerShape = GeneralShapeFactory.createRectangle(1,1,1,1);
167
// containerFigure.setGeneralShape(containerShape);
168
// setDefaultFeedback(containerFigure);
169
// for (Iterator it = container.getDrawComponents().iterator(); it.hasNext(); ) {
170
// DrawComponent dc = (DrawComponent) it.next();
171
// ShapeFigure figure = getCustomFeedbackFigure(dc);
172
// containerFigure.add(figure);
173
// }
174
// return containerFigure;
175
// }
176
// else {
177
// gs = GeneralShapeFactory.createRectangle(0, 0, 10, 10);
178
// }
179
// ShapeFigure shapeFigure = new FeedbackShapeFigure();
180
// shapeFigure.setGeneralShape(gs);
181
// setDefaultFeedback(shapeFigure);
182
// return shapeFigure;
183
//}
184

185 // public static void setDefaultFeedback(ShapeFigure sf)
186
// {
187
// sf.setBackgroundColor(J2DUtil.toSWTColor(defaultFeedbackConfig.getBgColor()));
188
// sf.setForegroundColor(J2DUtil.toSWTColor(defaultFeedbackConfig.getFgColor()));
189
// sf.setXOR(defaultFeedbackConfig.isXor());
190
// sf.setFill(defaultFeedbackConfig.isFill());
191
// }
192

193   
194 }
195
Popular Tags