001: /*
002: * $Header: /cvs/j3dfly/J3dEditor/src/org/jdesktop/j3dedit/scenegrapheditor/treeview/TVGroup.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:
034: import org.jdesktop.j3dedit.treelayout.TreePanel;
035: import org.jdesktop.j3dedit.scenegraph.SGGroup;
036: import org.jdesktop.j3dedit.scenegraph.SGObject;
037:
038: /**
039: * @author Paul Byrne
040: * @version 1.4, 01/18/02
041: */
042: public class TVGroup extends TVObject {
043:
044: private GlyphVector text = null;
045: private int textYOffset;
046: private int textXOffset;
047: protected GeneralPath hiddenLink;
048:
049: /** Creates new groupTreeNode */
050: public TVGroup(SGObject sgObject) {
051: super (29, 29, 29, sgObject);
052: hiddenLink = new GeneralPath();
053:
054: int w = getMinimumSize().width;
055: int h = getMinimumSize().height;
056:
057: hiddenLink.moveTo(w / 2, 0);
058: hiddenLink.lineTo(w / 2, 10);
059:
060: hiddenLink.moveTo(0, 10);
061: hiddenLink.lineTo(0, 5);
062: hiddenLink.lineTo(w, 5);
063: hiddenLink.lineTo(w, 10);
064: }
065:
066: public int numChildrenIgnoreHiddenFlag() {
067: return ((SGGroup) sgObject).numChildren();
068: }
069:
070: public int numChildren() {
071: if (((SGGroup) sgObject).childrenHidden())
072: return 0;
073:
074: return ((SGGroup) sgObject).numChildren();
075: }
076:
077: public org.jdesktop.j3dedit.treelayout.TreeNode getChild(int index) {
078: return (TVObject) ((SGGroup) sgObject).getChild(index)
079: .getTreeViewObject();
080: }
081:
082: public void setContainer(TreePanel panel) {
083: container = panel;
084:
085: for (int i = 0; i < numChildrenIgnoreHiddenFlag(); i++)
086: getChild(i).setContainer(panel);
087: }
088:
089: protected Point getBehaviorLinkEntry(Point behaviorLocation) {
090: return new Point(computedPosition.x + nodeSize.width / 2,
091: computedPosition.y + nodeSize.height / 2);
092: /*
093: if (behaviorLocation.x < computedPosition.x) {
094: return new Point( computedPosition.x,
095: computedPosition.y + nodeSize.height/2);
096: } else {
097: return new Point( computedPosition.x + nodeSize.width,
098: computedPosition.y + nodeSize.height/2 );
099: }
100: */
101: }
102:
103: private void createGlyphVector() {
104: Font font = new Font("dialog", Font.PLAIN, 10);
105: FontRenderContext context = new FontRenderContext(
106: new AffineTransform(), false, false);
107: if (sgObject.getJ3dSceneGraphObject() instanceof com.sun.j3d.utils.universe.ViewingPlatform)
108: text = font.createGlyphVector(context, new char[] { 'V',
109: 'P' });
110: else if (sgObject.getJ3dSceneGraphObject() instanceof javax.media.j3d.BranchGroup)
111: text = font.createGlyphVector(context, new char[] { 'B',
112: 'G' });
113: else if (sgObject.getJ3dSceneGraphObject() instanceof javax.media.j3d.TransformGroup)
114: text = font.createGlyphVector(context, new char[] { 'T',
115: 'G' });
116: else if (sgObject.getJ3dSceneGraphObject() instanceof javax.media.j3d.Switch)
117: text = font.createGlyphVector(context, new char[] { 'S',
118: 'W' });
119: else if (sgObject.getJ3dSceneGraphObject() instanceof javax.media.j3d.SharedGroup)
120: text = font.createGlyphVector(context, new char[] { 'S',
121: 'G' });
122: else if (sgObject.getJ3dSceneGraphObject() instanceof javax.media.j3d.Group)
123: text = font.createGlyphVector(context, new char[] { 'G' });
124:
125: textYOffset = (int) (text.getLogicalBounds().getHeight());
126: textXOffset = (getNodeSize().height - (int) (text
127: .getLogicalBounds().getWidth())) / 2;
128: //+ getNodeSize().height/4;
129: }
130:
131: public void drawNode(Graphics2D g) {
132: super .drawNode(g);
133: Point computedPosition = getComputedPosition();
134: Dimension nodeSize = getNodeSize();
135:
136: Color origColor = g.getColor();
137:
138: if (((SGGroup) sgObject).childrenHidden()) {
139: currentColor = g.getColor();
140: g.translate(computedPosition.x, computedPosition.y
141: + nodeSize.height);
142: g.setColor(Color.gray);
143: g.draw(hiddenLink);
144: g.translate(-computedPosition.x,
145: -(computedPosition.y + nodeSize.height));
146: g.setColor(currentColor);
147: }
148:
149: if (icon != null && drawAsIcon) {
150: g.drawImage(icon, computedPosition.x, computedPosition.y,
151: null);
152: } else {
153: if (text == null)
154: createGlyphVector();
155:
156: g.setColor(Color.white);
157: g.fillOval(computedPosition.x, computedPosition.y,
158: nodeSize.width, nodeSize.height);
159: g.setColor(Color.black);
160: g.drawOval(computedPosition.x, computedPosition.y,
161: nodeSize.width, nodeSize.height);
162:
163: g.drawGlyphVector(text,
164: (float) (computedPosition.x + textXOffset),
165: (float) (computedPosition.y + textYOffset));
166: }
167:
168: g.setColor(origColor);
169: drawNameLabel(g);
170: }
171:
172: }
|