001: /*
002: * $Header: /cvs/j3dfly/J3dEditor/src/org/jdesktop/j3dedit/scenegrapheditor/treeview/TVGeometryPrimitive.java,v 1.1 2005/04/20 22:21:27 paulby Exp $
003: *
004: * Sun Public License Notice
005: *
006: * The contents of this file are subject to the Sun Public License Version
007: * 1.0 (the "License"). You may not use this file except in compliance with
008: * the License. A copy of the License is available at http://www.sun.com/
009: *
010: * The Original Code is the Java 3D(tm) Scene Graph Editor.
011: * The Initial Developer of the Original Code is Paul Byrne.
012: * Portions created by Paul Byrne are Copyright (C) 2002.
013: * All Rights Reserved.
014: *
015: * Contributor(s): Paul Byrne.
016: *
017: **/
018: package org.jdesktop.j3dedit.scenegrapheditor.treeview;
019:
020: import java.awt.Graphics;
021: import java.awt.Graphics2D;
022: import java.awt.Point;
023: import java.awt.Shape;
024: import java.awt.Color;
025: import java.awt.geom.GeneralPath;
026: import java.awt.Polygon;
027: import java.awt.Dimension;
028: import java.awt.Font;
029: import java.awt.font.GlyphVector;
030: import java.awt.font.FontRenderContext;
031: import java.awt.geom.AffineTransform;
032: import java.util.Properties;
033: import org.jdesktop.j3dedit.scenegraph.SGGroup;
034: import org.jdesktop.j3dedit.scenegraph.SGObject;
035:
036: /**
037: * @author Paul Byrne
038: * @version 1.4, 01/18/02
039: */
040: public class TVGeometryPrimitive extends TVGroup {
041:
042: private GlyphVector text = null;
043: private int textYOffset;
044: private int textXOffset;
045:
046: /** Creates new groupTreeNode */
047: public TVGeometryPrimitive(SGObject object) {
048: super (object);
049: }
050:
051: private void createGlyphVector() {
052: Font font = new Font("dialog", Font.PLAIN, 9);
053: FontRenderContext context = new FontRenderContext(
054: new AffineTransform(), false, false);
055: if (sgObject.getJ3dSceneGraphObject() instanceof com.sun.j3d.utils.geometry.Box)
056: text = font.createGlyphVector(context, "Box".toCharArray());
057: else if (sgObject.getJ3dSceneGraphObject() instanceof com.sun.j3d.utils.geometry.Sphere)
058: text = font.createGlyphVector(context, "Sph".toCharArray());
059: else if (sgObject.getJ3dSceneGraphObject() instanceof com.sun.j3d.utils.geometry.Cone)
060: text = font.createGlyphVector(context, "Con".toCharArray());
061: else if (sgObject.getJ3dSceneGraphObject() instanceof com.sun.j3d.utils.geometry.Cylinder)
062: text = font.createGlyphVector(context, "Cyl".toCharArray());
063: else
064: text = font
065: .createGlyphVector(context, "Prim".toCharArray());
066:
067: textYOffset = (int) (text.getLogicalBounds().getHeight());
068: textXOffset = (getNodeSize().height - (int) (text
069: .getLogicalBounds().getWidth())) / 2;
070: }
071:
072: public void drawNode(Graphics2D g) {
073: super .drawNode(g);
074: Point computedPosition = getComputedPosition();
075: Dimension nodeSize = getNodeSize();
076:
077: Color origColor = g.getColor();
078:
079: if (((SGGroup) sgObject).childrenHidden()) {
080: g.translate(computedPosition.x, computedPosition.y
081: + nodeSize.height);
082: g.setColor(Color.gray);
083: g.draw(hiddenLink);
084: g.translate(-computedPosition.x,
085: -(computedPosition.y + nodeSize.height));
086: }
087:
088: if (text == null)
089: createGlyphVector();
090:
091: g.setColor(Color.white);
092: g.fillRoundRect(computedPosition.x, computedPosition.y,
093: nodeSize.width, nodeSize.height,
094: (int) (nodeSize.width / 2.1),
095: (int) (nodeSize.height / 2.1));
096: g.setColor(Color.black);
097: g.drawRoundRect(computedPosition.x, computedPosition.y,
098: nodeSize.width, nodeSize.height,
099: (int) (nodeSize.width / 2.1),
100: (int) (nodeSize.height / 2.1));
101:
102: g.drawGlyphVector(text,
103: (float) (computedPosition.x + textXOffset),
104: (float) (computedPosition.y + textYOffset));
105:
106: g.setColor(origColor);
107: drawNameLabel(g);
108: }
109:
110: }
|