001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.modules.bpel.design.model.elements;
021:
022: import java.awt.Color;
023: import java.awt.Graphics2D;
024: import java.awt.Paint;
025: import java.awt.RenderingHints;
026: import java.awt.TexturePaint;
027: import org.netbeans.modules.bpel.design.geometry.FEllipse;
028: import org.netbeans.modules.bpel.design.geometry.FPoint;
029: import org.netbeans.modules.bpel.design.geometry.FRectangle;
030: import org.netbeans.modules.bpel.design.geometry.FRoumb;
031: import org.netbeans.modules.bpel.design.geometry.FShape;
032: import org.netbeans.modules.bpel.design.geometry.FStroke;
033: import org.netbeans.modules.bpel.design.model.elements.icons.ANDIcon2D;
034: import org.netbeans.modules.bpel.design.model.elements.icons.AssignIcon2D;
035: import org.netbeans.modules.bpel.design.model.elements.icons.CompensateBadgeIcon2D;
036: import org.netbeans.modules.bpel.design.model.elements.icons.CompensateIcon2D;
037: import org.netbeans.modules.bpel.design.model.elements.icons.CompensateScopeIcon2D;
038: import org.netbeans.modules.bpel.design.model.elements.icons.EndEventIcon2D;
039: import org.netbeans.modules.bpel.design.model.elements.icons.EventBadgeIcon2D;
040: import org.netbeans.modules.bpel.design.model.elements.icons.EventIcon2D;
041: import org.netbeans.modules.bpel.design.model.elements.icons.ExitIcon2D;
042: import org.netbeans.modules.bpel.design.model.elements.icons.FaultBadgeIcon2D;
043: import org.netbeans.modules.bpel.design.model.elements.icons.ForEachIcon2D;
044: import org.netbeans.modules.bpel.design.model.elements.icons.Icon2D;
045: import org.netbeans.modules.bpel.design.model.elements.icons.InvokeIcon2D;
046: import org.netbeans.modules.bpel.design.model.elements.icons.MessageIcon2D;
047: import org.netbeans.modules.bpel.design.model.elements.icons.ReceiveIcon2D;
048: import org.netbeans.modules.bpel.design.model.elements.icons.RepeatUntilIcon2D;
049: import org.netbeans.modules.bpel.design.model.elements.icons.ReplyIcon2D;
050: import org.netbeans.modules.bpel.design.model.elements.icons.ReThrowIcon2D;
051: import org.netbeans.modules.bpel.design.model.elements.icons.TerminationBadgeIcon2D;
052: import org.netbeans.modules.bpel.design.model.elements.icons.ThrowIcon2D;
053: import org.netbeans.modules.bpel.design.model.elements.icons.TimerIcon2D;
054: import org.netbeans.modules.bpel.design.model.elements.icons.WhileIcon2D;
055: import org.netbeans.modules.bpel.design.model.elements.icons.XORIcon2D;
056: import org.netbeans.modules.bpel.design.model.elements.icons.XORSmallIcon2D;
057: import org.netbeans.modules.bpel.design.model.patterns.CompositePattern;
058: import org.netbeans.modules.bpel.design.model.patterns.Pattern;
059:
060: /**
061: *
062: * @author anjeleevich
063: */
064: public class ContentElement extends VisualElement {
065:
066: private Icon2D icon;
067:
068: public ContentElement(Icon2D icon) {
069: this (TASK_SHAPE, icon);
070: }
071:
072: public ContentElement(FShape shape, Icon2D icon) {
073: super (shape);
074: this .icon = icon;
075: }
076:
077: public void paint(Graphics2D g2) {
078: FShape shape = this .shape;
079:
080: // draw background;
081: g2.setPaint(new TexturePaint(GRADIENT_TEXTURE, shape
082: .getBounds2D()));
083: g2.fill(shape);
084:
085: // draw icon
086: if (icon != null) {
087: g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
088: RenderingHints.VALUE_STROKE_PURE);
089: FPoint center = shape.getNormalizedCenter(g2);
090: g2.translate(center.x, center.y);
091: icon.paint(g2);
092: g2.translate(-center.x, -center.y);
093: }
094:
095: // draw border
096: g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
097: RenderingHints.VALUE_STROKE_NORMALIZE);
098: g2.setStroke(STROKE.createStroke(g2));
099: g2.setPaint(STROKE_COLOR);
100: g2.draw(shape);
101:
102: if (isPaintText()) {
103: BorderElement border = null;
104: for (Pattern p = getPattern(); p != null; p = p.getParent()) {
105: if (p instanceof CompositePattern) {
106: border = ((CompositePattern) p).getBorder();
107: if (border != null)
108: break;
109: }
110: }
111:
112: if (border != null) {
113: double cx = getCenterX();
114: double x1 = border.getX();
115: double x2 = x1 + border.getWidth();
116:
117: double hw = Math.min(Math.abs(x2 - cx), Math.abs(x1
118: - cx)) - 4;
119:
120: if (hw > 0) {
121: g2.setPaint(getTextColor());
122: drawXCenteredString(g2, getText(), cx, getY()
123: + getHeight(), hw * 2);
124: }
125: }
126: }
127: }
128:
129: public void paintThumbnail(Graphics2D g2) {
130: FShape shape = this .shape;
131:
132: // draw background;
133: g2.setPaint(GRADIENT_TEXTURE_COLOR);
134: g2.fill(shape);
135:
136: // draw border
137: g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
138: RenderingHints.VALUE_STROKE_NORMALIZE);
139: g2.setStroke(STROKE.createStroke(g2));
140: g2.setPaint(STROKE_COLOR);
141: g2.draw(shape);
142: }
143:
144: public Icon2D getIcon() {
145: return icon;
146: }
147:
148: public static ContentElement createAssign() {
149: return new ContentElement(TASK_SHAPE, AssignIcon2D.INSTANCE);
150: }
151:
152: public static ContentElement createEmpty() {
153: return new ContentElement(TASK_SHAPE, null);
154: }
155:
156: public static ContentElement createReply() {
157: return new ContentElement(TASK_SHAPE, ReplyIcon2D.INSTANCE);
158: }
159:
160: public static ContentElement createInvoke() {
161: return new ContentElement(TASK_SHAPE, InvokeIcon2D.INSTANCE);
162: }
163:
164: public static ContentElement createReceive() {
165: return new ContentElement(EVENT_SHAPE, ReceiveIcon2D.INSTANCE);
166: }
167:
168: public static ContentElement createExit() {
169: return new ContentElement(EVENT_SHAPE, ExitIcon2D.INSTANCE);
170: }
171:
172: public static ContentElement createCompensate() {
173: return new ContentElement(EVENT_SHAPE,
174: CompensateIcon2D.INSTANCE);
175: }
176:
177: public static ContentElement createCompensateScope() {
178: return new ContentElement(EVENT_SHAPE,
179: CompensateScopeIcon2D.INSTANCE);
180: }
181:
182: public static ContentElement createWait() {
183: return new ContentElement(EVENT_SHAPE, TimerIcon2D.INSTANCE);
184: }
185:
186: public static ContentElement createCompensateBadge() {
187: return new ContentElement(BADGE_SHAPE,
188: CompensateBadgeIcon2D.INSTANCE);
189: }
190:
191: public static ContentElement createFaultBadge() {
192: return new ContentElement(BADGE_SHAPE,
193: FaultBadgeIcon2D.INSTANCE);
194: }
195:
196: public static ContentElement createEventBadge() {
197: return new ContentElement(BADGE_SHAPE,
198: EventBadgeIcon2D.INSTANCE);
199: }
200:
201: public static ContentElement createTerminationBadge() {
202: return new ContentElement(BADGE_SHAPE,
203: TerminationBadgeIcon2D.INSTANCE);
204: }
205:
206: public static ContentElement createMessageEvent() {
207: return new ContentElement(EVENT_SHAPE, MessageIcon2D.INSTANCE);
208: }
209:
210: public static ContentElement createTimerEvent() {
211: return new ContentElement(EVENT_SHAPE, TimerIcon2D.INSTANCE);
212: }
213:
214: public static ContentElement createThrow() {
215: return new ContentElement(EVENT_SHAPE, ThrowIcon2D.INSTANCE);
216: }
217:
218: public static ContentElement createReThrow() {
219: return new ContentElement(EVENT_SHAPE, ReThrowIcon2D.INSTANCE);
220: }
221:
222: public static ContentElement createEndEvent() {
223: return new ContentElement(EVENT_SHAPE, EndEventIcon2D.INSTANCE);
224: }
225:
226: public static ContentElement createStartEvent() {
227: return new ContentElement(EVENT_SHAPE, null);
228: }
229:
230: public static ContentElement createIfGateway() {
231: return new ContentElement(GATEWAY_SHAPE, XORIcon2D.INSTANCE);
232: }
233:
234: public static ContentElement createWhileGateway() {
235: return new ContentElement(GATEWAY_SHAPE, WhileIcon2D.INSTANCE);
236: }
237:
238: public static ContentElement createRepeatUntilGateway() {
239: return new ContentElement(GATEWAY_SHAPE,
240: RepeatUntilIcon2D.INSTANCE);
241: }
242:
243: public static ContentElement createForEachGateway() {
244: return new ContentElement(GATEWAY_SHAPE, ForEachIcon2D.INSTANCE);
245: }
246:
247: public static ContentElement createPickGateway() {
248: return new ContentElement(GATEWAY_SHAPE, EventIcon2D.INSTANCE);
249: }
250:
251: public static ContentElement createFlowGateway() {
252: return new ContentElement(GATEWAY_SHAPE, ANDIcon2D.INSTANCE);
253: }
254:
255: public static ContentElement createElseIfGateway() {
256: return new ContentElement(SMALL_GATEWAY_SHAPE,
257: XORSmallIcon2D.INSTANCE);
258: }
259:
260: public static final FShape BADGE_SHAPE = new FEllipse(16, 16);
261: public static final FShape EVENT_SHAPE = new FEllipse(24, 24);
262: public static final FShape GATEWAY_SHAPE = new FRoumb(40, 40);
263: public static final FShape SMALL_GATEWAY_SHAPE = new FRoumb(24, 24);
264: public static final FShape TASK_SHAPE = new FRectangle(72, 40, 8);
265: public static final FShape COLLAPSED_SHAPE = new FRectangle(40, 40,
266: 8);
267:
268: private static final FStroke STROKE = new FStroke(1);
269:
270: public static final Paint STROKE_COLOR = new Color(0xA7A2A7);
271: }
|