01: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
02: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
03: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
04: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
05: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
06: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
07: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
08: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
09: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
10: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
11: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
12: // POSSIBILITY OF SUCH DAMAGE.
13: //
14: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
15: package com.metaboss.applications.designstudio.statesmodel;
16:
17: import java.awt.Dimension;
18: import java.awt.Graphics;
19: import java.awt.Rectangle;
20:
21: import org.jgraph.graph.CellMapper;
22: import org.jgraph.graph.CellViewRenderer;
23: import org.jgraph.graph.DefaultGraphCell;
24:
25: import com.metaboss.applications.designstudio.components.DesignGraph;
26: import com.metaboss.applications.designstudio.components.VertexCellRenderer;
27: import com.metaboss.applications.designstudio.components.VertexCellView;
28: import com.metaboss.applications.designstudio.userobjects.StateUserObject;
29: import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.State;
30: import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.StateTypeEnum;
31:
32: public class StateVertexView extends VertexCellView {
33: public StateVertexView(Object cell, DesignGraph graph, CellMapper cm) {
34: super (cell, graph, cm);
35: }
36:
37: // Returns the Renderer for this View
38: public CellViewRenderer getRenderer() {
39: DefaultGraphCell lCell = (DefaultGraphCell) getCell();
40: if (lCell != null) {
41: Object lObject = lCell.getUserObject();
42: if (lObject instanceof StateUserObject) {
43: State lState = ((StateUserObject) lObject).getState();
44: try {
45: if (lState != null
46: && (lState.getType() == StateTypeEnum.FINAL || lState
47: .getType() == StateTypeEnum.INITIAL))
48: return super .getRenderer();
49: } catch (Exception e) {
50: e.printStackTrace();
51: }
52: }
53: }
54: return new StateVertexRenderer();
55: }
56:
57: /* State vertex renderer class */
58:
59: public class StateVertexRenderer extends VertexCellRenderer {
60: public static final int MIN_WIDTH = 80;
61: public static final int MIN_HEIGHT = 50;
62: public static final int MAX_WIDTH = 200;
63: public static final int MAX_HEIGHT = 200;
64: public static final int ARC_SIZE = 30;
65:
66: public Dimension getPreferredSize() {
67: return calculatePreferredSize(MIN_WIDTH, MIN_HEIGHT,
68: MAX_WIDTH, MAX_HEIGHT);
69: }
70:
71: protected void paintComponent(Graphics g) {
72: Dimension lSize = getSize();
73:
74: g.setColor(getBackground());
75: fillRoundRect(g, new Rectangle(0, 0, lSize.width - 1,
76: lSize.height - 1), ARC_SIZE, ARC_SIZE);
77: g.setColor(getForeground());
78: g.drawRoundRect(0, 0, lSize.width - 1, lSize.height - 1,
79: ARC_SIZE, ARC_SIZE);
80:
81: Rectangle viewR = new Rectangle(0, 0, lSize.width - 1,
82: lSize.height - 1);
83: paintCaption(g, viewR);
84: }
85: }
86: }
|