001: /*
002: * $Header: /cvs/j3dfly/J3dEditor/src/org/jdesktop/j3dedit/scenegrapheditor/treeview/TVLink.java,v 1.1 2005/04/20 22:21:28 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.TreeNode;
035: import org.jdesktop.j3dedit.treelayout.TreeLayout;
036: import org.jdesktop.j3dedit.treelayout.TreePanel;
037: import org.jdesktop.j3dedit.scenegraph.SGObject;
038:
039: public class TVLink extends TVObject {
040:
041: private GlyphVector text = null;
042: private int textYOffset;
043: private int textXOffset;
044: protected GeneralPath hiddenLink;
045: private org.jdesktop.j3dedit.treelayout.TreeNode sharedGroup;
046:
047: private boolean hideChildren = false;
048:
049: /** Creates new groupTreeNode */
050: public TVLink(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 super .numChildren();
068: }
069:
070: public void addSharedGroup(TreeNode node) {
071: this .sharedGroup = node;
072: if (node.getParent() == null)
073: this .addChild(node);
074: }
075:
076: public TreeNode getSharedGroup() {
077: return sharedGroup;
078: }
079:
080: public int numChildren() {
081: if (hideChildren)
082: return 0;
083:
084: return super .numChildren();
085: }
086:
087: public void hideChildren(boolean hide) {
088: hideChildren = hide;
089: }
090:
091: public void setContainer(TreePanel panel) {
092: container = panel;
093:
094: for (int i = 0; i < numChildrenIgnoreHiddenFlag(); i++)
095: getChild(i).setContainer(panel);
096: }
097:
098: public boolean childrenHidden() {
099: return hideChildren;
100: }
101:
102: protected Point getBehaviorLinkEntry(Point behaviorLocation) {
103: return new Point(computedPosition.x + nodeSize.width / 2,
104: computedPosition.y + nodeSize.height / 2);
105: /*
106: if (behaviorLocation.x < computedPosition.x) {
107: return new Point( computedPosition.x,
108: computedPosition.y + nodeSize.height/2);
109: } else {
110: return new Point( computedPosition.x + nodeSize.width,
111: computedPosition.y + nodeSize.height/2 );
112: }
113: */
114: }
115:
116: private void createGlyphVector() {
117: Font font = new Font("dialog", Font.PLAIN, 10);
118: FontRenderContext context = new FontRenderContext(
119: new AffineTransform(), false, false);
120:
121: text = font.createGlyphVector(context, new char[] { 'S', 'G' });
122:
123: textYOffset = (int) (text.getLogicalBounds().getHeight());
124: textXOffset = (getNodeSize().height - (int) (text
125: .getLogicalBounds().getWidth())) / 2;
126: //+ getNodeSize().height/4;
127: }
128:
129: public void drawNode(Graphics2D g) {
130: super .drawNode(g);
131: Point computedPosition = getComputedPosition();
132: Dimension nodeSize = getNodeSize();
133:
134: Color origColor = g.getColor();
135:
136: if (hideChildren) {
137: currentColor = g.getColor();
138: g.translate(computedPosition.x, computedPosition.y
139: + nodeSize.height);
140: g.setColor(Color.gray);
141: g.draw(hiddenLink);
142: g.translate(-computedPosition.x,
143: -(computedPosition.y + nodeSize.height));
144: g.setColor(currentColor);
145: }
146:
147: g.setColor(java.awt.Color.blue);
148: Point sharedPos = sharedGroup.getComputedPosition();
149: g.drawLine(computedPosition.x + getMinimumSize().width / 2,
150: computedPosition.y + getMinimumSize().height / 2,
151: sharedPos.x + getMinimumSize().width / 2, sharedPos.y
152: + getMinimumSize().height / 2);
153:
154: if (icon != null && drawAsIcon) {
155: g.drawImage(icon, computedPosition.x, computedPosition.y,
156: null);
157: } else {
158: if (text == null)
159: createGlyphVector();
160:
161: g.setColor(java.awt.Color.white);
162: g.fillRect(computedPosition.x, computedPosition.y,
163: nodeSize.width, nodeSize.height);
164: g.setColor(java.awt.Color.black);
165: g.drawRect(computedPosition.x, computedPosition.y,
166: nodeSize.width, nodeSize.height);
167:
168: // g.drawGlyphVector( text, (float)(computedPosition.x+textXOffset),
169: // (float)(computedPosition.y+textYOffset) );
170: }
171:
172: g.setColor(origColor);
173: }
174:
175: }
|