001: //THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
002: //CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
003: //BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
004: //FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
005: //OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
006: //INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
007: //LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
008: //OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
009: //LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
010: //NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
011: //EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
012: //POSSIBILITY OF SUCH DAMAGE.
013: //
014: //Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
015: package com.metaboss.applications.designstudio.usecasesmodel;
016:
017: import java.awt.Dimension;
018: import java.awt.Graphics;
019: import java.awt.Rectangle;
020:
021: import org.jgraph.graph.CellMapper;
022: import org.jgraph.graph.CellViewRenderer;
023:
024: import com.metaboss.applications.designstudio.components.ClassCellRenderer;
025: import com.metaboss.applications.designstudio.components.DesignGraph;
026: import com.metaboss.applications.designstudio.components.VertexCellView;
027:
028: /* Use case vertex view */
029:
030: public class ActorVertexView extends VertexCellView {
031: public ActorVertexView(Object cell, DesignGraph graph, CellMapper cm) {
032: super (cell, graph, cm);
033: }
034:
035: public CellViewRenderer getRenderer() {
036: return new ActorVertexRenderer();
037: }
038:
039: /* Entity vertex renderer class */
040:
041: public class ActorVertexRenderer extends ClassCellRenderer {
042: public static final int E_WIDTH = 30;
043: public static final int E_HEIGHT = 60;
044:
045: public Dimension getPreferredSize() {
046: if (getViewAsClass())
047: return super .getPreferredSize();
048: else {
049: Dimension lDimension = calculatePreferredSize(0, 0,
050: 300, 300);
051:
052: int lWidth = E_WIDTH + 4;
053: int lHeight = E_HEIGHT + 4;
054:
055: if (lDimension.width < lWidth)
056: lDimension.width = lWidth;
057: lDimension.height += lHeight;
058:
059: return lDimension;
060: }
061: }
062:
063: protected void paintComponent(Graphics g) {
064: if (getViewAsClass())
065: super .paintComponent(g);
066: else {
067: Dimension lSize = getSize();
068: Rectangle lEntityRect = new Rectangle(0, 0,
069: lSize.width, E_HEIGHT);
070: Rectangle lCaptionRect = new Rectangle(0,
071: lEntityRect.height, lSize.width, lSize.height
072: - E_HEIGHT);
073:
074: int lx = (lSize.width - E_WIDTH) / 2;
075: lEntityRect.x = lx;
076: lEntityRect.y += 2;
077: lEntityRect.width = E_WIDTH;
078:
079: paintActor(g, lEntityRect);
080: paintCaption(g, lCaptionRect);
081: }
082: }
083:
084: private void paintActor(Graphics g, Rectangle pRect) {
085: int lSize = pRect.height / 3;
086: Rectangle lHeadRect = new Rectangle(pRect);
087: Rectangle lBodyRect = new Rectangle(pRect);
088: Rectangle lLegsRect = new Rectangle(pRect);
089:
090: lHeadRect.height = lSize;
091: lBodyRect.y = lHeadRect.y + lHeadRect.height;
092: lBodyRect.height = lSize;
093: lLegsRect.y = lBodyRect.y + lBodyRect.height;
094: lLegsRect.height = lSize;
095:
096: //head
097: g.setColor(getBackground());
098: fillOval(g, lHeadRect);
099: g.setColor(getForeground());
100: g.drawOval(lHeadRect.x, lHeadRect.y, lHeadRect.width,
101: lHeadRect.height);
102: //body
103: g.drawLine(lBodyRect.x + lBodyRect.width / 2, lBodyRect.y,
104: lBodyRect.x + lBodyRect.width / 2, lBodyRect.y
105: + lBodyRect.height);
106: g.drawLine(lBodyRect.x, lBodyRect.y + lBodyRect.height / 2,
107: lBodyRect.x + lBodyRect.width, lBodyRect.y
108: + lBodyRect.height / 2);
109: //legs
110: g.drawLine(lLegsRect.x + lLegsRect.width / 2, lLegsRect.y,
111: lBodyRect.x, lLegsRect.y + lLegsRect.height);
112: g.drawLine(lLegsRect.x + lLegsRect.width / 2, lLegsRect.y,
113: lBodyRect.x + lBodyRect.width, lLegsRect.y
114: + lLegsRect.height);
115: }
116:
117: private boolean getViewAsClass() {
118: DesignGraph lGraph = (DesignGraph) getGraph();
119: return (lGraph.getShowClassVertex() && lGraph
120: .getShowVertexFields());
121: }
122: }
123: }
|