001: /*
002: * $Header: /cvs/j3dfly/J3dEditor/src/org/jdesktop/j3dedit/scenegrapheditor/treeview/TVLoader.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.Point;
021: import java.awt.Dimension;
022: import java.awt.Color;
023: import java.awt.Graphics2D;
024: import java.awt.Font;
025: import java.awt.font.GlyphVector;
026: import java.awt.font.FontRenderContext;
027: import java.awt.geom.AffineTransform;
028: import org.jdesktop.j3dedit.scenegraph.SGGroup;
029: import org.jdesktop.j3dedit.scenegraph.SGObject;
030:
031: /**
032: * @author Paul Byrne
033: * @version 1.4, 01/18/02
034: */
035: public class TVLoader extends TVGroup {
036:
037: private GlyphVector text = null;
038: private int textYOffset;
039: private int textXOffset;
040:
041: /** Creates new LoaderTreeNode */
042: public TVLoader(SGObject sgObject) {
043: super (sgObject);
044: }
045:
046: private void createGlyphVector() {
047: Font font = new Font("dialog", Font.PLAIN, 10);
048: FontRenderContext context = new FontRenderContext(
049: new AffineTransform(), false, false);
050:
051: //LoaderPersistance props = (LoaderPersistance)getNode().getUserData();
052: //String extension = props.getData( "LOADER_EXT" );
053: //if (extension==null)
054: String extension = "Ldr";
055:
056: text = font.createGlyphVector(context, extension.toCharArray());
057:
058: textYOffset = ((int) (text.getLogicalBounds().getHeight())) / 2
059: + getNodeSize().height / 2;
060: textXOffset = (getNodeSize().width - (int) (text
061: .getLogicalBounds().getWidth())) / 2;
062: }
063:
064: public void drawNode(Graphics2D g) {
065: super .drawNode(g);
066: Point computedPosition = getComputedPosition();
067: Dimension nodeSize = getNodeSize();
068:
069: Color origColor = g.getColor();
070:
071: if (((SGGroup) sgObject).childrenHidden()) {
072: currentColor = g.getColor();
073: g.translate(computedPosition.x, computedPosition.y
074: + nodeSize.height);
075: g.setColor(Color.gray);
076: g.draw(hiddenLink);
077: g.translate(-computedPosition.x,
078: -(computedPosition.y + nodeSize.height));
079: g.setColor(currentColor);
080: }
081:
082: if (icon != null && drawAsIcon) {
083: g.drawImage(icon, computedPosition.x, computedPosition.y,
084: null);
085: } else {
086: if (text == null)
087: createGlyphVector();
088:
089: g.setColor(Color.white);
090: g.fillOval(computedPosition.x, computedPosition.y,
091: nodeSize.width, nodeSize.height);
092: g.setColor(Color.black);
093: g.drawOval(computedPosition.x, computedPosition.y,
094: nodeSize.width, nodeSize.height);
095:
096: g.drawGlyphVector(text,
097: (float) (computedPosition.x + textXOffset),
098: (float) (computedPosition.y + textYOffset));
099: }
100:
101: g.setColor(origColor);
102: drawNameLabel(g);
103: }
104:
105: }
|