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.selection;
021:
022: import java.awt.Color;
023: import java.awt.Graphics2D;
024: import java.awt.RenderingHints;
025: import org.netbeans.modules.bpel.design.geometry.FEllipse;
026: import org.netbeans.modules.bpel.design.geometry.FPath;
027: import org.netbeans.modules.bpel.design.geometry.FPoint;
028: import org.netbeans.modules.bpel.design.geometry.FShape;
029: import org.netbeans.modules.bpel.design.geometry.FStroke;
030: import org.netbeans.modules.bpel.design.model.patterns.Pattern;
031:
032: public abstract class PlaceHolder {
033:
034: private Pattern ownerPattern;
035: private Pattern draggedPattern;
036: private boolean mouseHover;
037: private FPath path;
038: private FShape shape;
039:
040: public PlaceHolder(Pattern ownerPattern, Pattern draggedPattern,
041: double cx, double cy) {
042: this (ownerPattern, draggedPattern, cx, cy, null);
043: }
044:
045: public PlaceHolder(Pattern ownerPattern, Pattern draggedPattern,
046: FPoint center) {
047: this (ownerPattern, draggedPattern, center.x, center.y, null);
048: }
049:
050: public PlaceHolder(Pattern ownerPattern, Pattern draggedPattern,
051: FPath path) {
052: this (ownerPattern, draggedPattern, path.point(0.5f), path);
053: }
054:
055: public PlaceHolder(Pattern ownerPattern, Pattern draggedPattern,
056: FPoint center, FPath path) {
057: this (ownerPattern, draggedPattern, center.x, center.y, path);
058: }
059:
060: public PlaceHolder(Pattern ownerPattern, Pattern draggedPattern,
061: double cx, double cy, FPath path) {
062: this .ownerPattern = ownerPattern;
063: this .draggedPattern = draggedPattern;
064: this .shape = SHAPE.moveCenter(cx, cy);
065: this .path = path;
066: }
067:
068: public boolean contains(double px, double py) {
069: return shape.contains(px, py);
070: }
071:
072: public Pattern getDraggedPattern() {
073: return draggedPattern;
074: }
075:
076: public Pattern getOwnerPattern() {
077: return ownerPattern;
078: }
079:
080: public boolean isMouseHover() {
081: return mouseHover;
082: }
083:
084: public void dragEnter() {
085: mouseHover = true;
086: }
087:
088: public void dragExit() {
089: mouseHover = false;
090: }
091:
092: public abstract void drop();
093:
094: public void paint(Graphics2D g2) {
095: g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
096: RenderingHints.VALUE_STROKE_NORMALIZE);
097: g2.setPaint(OUTER_FILL);
098: g2.fill(shape);
099:
100: g2.setStroke(OUTER_STROKE.createStroke(g2));
101: g2.setPaint(OUTER_STROKE_COLOR);
102: g2.draw(shape);
103:
104: FPoint realCenter = shape.getNormalizedCenter(g2);
105:
106: g2.translate(realCenter.x, realCenter.y);
107:
108: g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
109: RenderingHints.VALUE_STROKE_NORMALIZE);
110: g2.setPaint((isMouseHover()) ? INNER_FILL_MOUSE_HOVER
111: : INNER_FILL);
112: g2.fill(INNER_SHAPE);
113:
114: g2.setPaint(INNER_STROKE_COLOR);
115: g2.setStroke(INNER_STROKE.createStroke(g2));
116: g2.draw(INNER_SHAPE);
117:
118: g2.translate(-realCenter.x, -realCenter.y);
119: }
120:
121: public FShape getShape() {
122: return shape;
123: }
124:
125: private static final FShape INNER_SHAPE = new FEllipse(-5, -5, 10,
126: 10);
127:
128: private static final FShape SHAPE = new FEllipse(20);
129:
130: private static final Color OUTER_FILL = new Color(0xFCFAF5);
131: private static final Color OUTER_STROKE_COLOR = new Color(0xFF9900);
132: private static final Color INNER_FILL = new Color(0xFFFFFF);
133: private static final Color INNER_FILL_MOUSE_HOVER = new Color(
134: 0xFF9900);
135: private static final Color INNER_STROKE_COLOR = new Color(0xB3B3B3);
136:
137: private static final FStroke OUTER_STROKE = new FStroke(1, 3);
138: private static final FStroke INNER_STROKE = new FStroke(1);
139: }
|