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.domainmodel;
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: public class EntityVertexView extends VertexCellView {
029: public EntityVertexView(Object cell, DesignGraph graph,
030: CellMapper cm) {
031: super (cell, graph, cm);
032: }
033:
034: public CellViewRenderer getRenderer() {
035: return new EntityVertexRenderer();
036: }
037:
038: /* Entity vertex renderer class */
039:
040: public class EntityVertexRenderer extends ClassCellRenderer {
041: public static final int E_WIDTH = 50;
042: public static final int E_HEIGHT = 50;
043:
044: public Dimension getPreferredSize() {
045: if (getViewAsClass())
046: return super .getPreferredSize();
047: else {
048: Dimension lDimension = calculatePreferredSize(0, 0,
049: 300, 300);
050:
051: int lWidth = E_WIDTH + 4;
052: int lHeight = E_HEIGHT + 4;
053:
054: if (lDimension.width < lWidth)
055: lDimension.width = lWidth;
056: lDimension.height += lHeight;
057:
058: return lDimension;
059: }
060: }
061:
062: protected void paintComponent(Graphics g) {
063: if (getViewAsClass())
064: super .paintComponent(g);
065: else {
066: Dimension lSize = getSize();
067: Rectangle lEntityRect = new Rectangle(0, 0,
068: lSize.width, E_HEIGHT);
069: Rectangle lCaptionRect = new Rectangle(0,
070: lEntityRect.height, lSize.width, lSize.height
071: - E_HEIGHT);
072:
073: int lx = (lSize.width - E_WIDTH) / 2;
074: lEntityRect.x = lx;
075: lEntityRect.y += 2;
076: lEntityRect.width = E_WIDTH;
077:
078: paintEntity(g, lEntityRect);
079: paintCaption(g, lCaptionRect);
080: }
081: }
082:
083: private void paintEntity(Graphics g, Rectangle pRect) {
084: g.setColor(getBackground());
085: fillOval(g, pRect);
086: g.setColor(getForeground());
087: g.drawOval(pRect.x, pRect.y, pRect.width, pRect.height);
088:
089: int ly = pRect.y + pRect.height;
090: g.drawLine(pRect.x, ly, pRect.x + pRect.width, ly);
091: g.drawLine(pRect.x + pRect.width / 2, ly, pRect.x
092: + pRect.width, pRect.y + pRect.height / 2);
093: }
094:
095: private boolean getViewAsClass() {
096: DesignGraph lGraph = (DesignGraph) getGraph();
097: return (lGraph.getShowClassVertex() && lGraph
098: .getShowVertexFields());
099: }
100: }
101: }
|