001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.vmd.game.view;
042:
043: import java.awt.Component;
044: import javax.swing.ImageIcon;
045:
046: import javax.swing.JTree;
047: import javax.swing.tree.DefaultTreeCellRenderer;
048: import javax.swing.tree.TreeCellRenderer;
049:
050: import org.netbeans.modules.vmd.game.model.GlobalRepository;
051: import org.netbeans.modules.vmd.game.model.Scene;
052: import org.netbeans.modules.vmd.game.model.Sprite;
053: import org.netbeans.modules.vmd.game.model.TiledLayer;
054: import org.openide.util.NbBundle;
055: import org.openide.util.Utilities;
056:
057: public class GameDesignTreeNodeRenderer implements TreeCellRenderer {
058:
059: private static ImageIcon imgGame;
060: private static ImageIcon imgSprite;
061: private static ImageIcon imgTiled;
062: private static ImageIcon imgScene;
063:
064: static {
065: imgGame = new ImageIcon(
066: Utilities
067: .loadImage("org/netbeans/modules/vmd/game/integration/res/gamer_16.png"));
068: imgSprite = new ImageIcon(
069: Utilities
070: .loadImage("org/netbeans/modules/vmd/game/model/adapter/res/sprite.png"));
071: imgTiled = new ImageIcon(
072: Utilities
073: .loadImage("org/netbeans/modules/vmd/game/model/adapter/res/tiled.png"));
074: imgScene = new ImageIcon(
075: Utilities
076: .loadImage("org/netbeans/modules/vmd/game/model/adapter/res/scene.png"));
077: }
078:
079: public Component getTreeCellRendererComponent(JTree tree,
080: Object value, boolean selected, boolean expanded,
081: boolean leaf, int row, boolean hasFocus) {
082: if (value instanceof Scene) {
083: return new SceneNodeRenderer()
084: .getTreeCellRendererComponent(tree, value,
085: selected, expanded, leaf, row, hasFocus);
086: } else if (value instanceof TiledLayer) {
087: return new TiledLayerNodeRenderer()
088: .getTreeCellRendererComponent(tree, value,
089: selected, expanded, leaf, row, hasFocus);
090: } else if (value instanceof Sprite) {
091: return new SpriteNodeRenderer()
092: .getTreeCellRendererComponent(tree, value,
093: selected, expanded, leaf, row, hasFocus);
094: } else if (value instanceof GlobalRepository) {
095: return new GlobalRepositoryNodeRenderer()
096: .getTreeCellRendererComponent(tree, value,
097: selected, expanded, leaf, row, hasFocus);
098: } else {
099: return new DefaultTreeCellRenderer()
100: .getTreeCellRendererComponent(tree, value,
101: selected, expanded, leaf, row, hasFocus);
102: }
103: }
104:
105: private class GlobalRepositoryNodeRenderer extends
106: DefaultTreeCellRenderer {
107: public Component getTreeCellRendererComponent(JTree tree,
108: Object value, boolean sel, boolean expanded,
109: boolean leaf, int row, boolean hasFocus) {
110: GlobalRepository gr = (GlobalRepository) value;
111: DefaultTreeCellRenderer r = (DefaultTreeCellRenderer) super
112: .getTreeCellRendererComponent(tree, value, sel,
113: expanded, leaf, row, hasFocus);
114: r.setText(NbBundle.getMessage(
115: GameDesignTreeNodeRenderer.class,
116: "GameDesignTreeNodeRenderer.GameDesignNode.name"));
117: r.setIcon(imgGame); // NOI18N
118: this
119: .setToolTipText(NbBundle
120: .getMessage(
121: GameDesignTreeNodeRenderer.class,
122: "GameDesignTreeNodeRenderer.GameDesignNode.tooltip"));
123: return r;
124: }
125: }
126:
127: private class SceneNodeRenderer extends DefaultTreeCellRenderer {
128: public Component getTreeCellRendererComponent(JTree tree,
129: Object value, boolean sel, boolean expanded,
130: boolean leaf, int row, boolean hasFocus) {
131: Scene scene = (Scene) value;
132: DefaultTreeCellRenderer r = (DefaultTreeCellRenderer) super
133: .getTreeCellRendererComponent(tree, value, sel,
134: expanded, leaf, row, hasFocus);
135: r.setText(scene.getName()); // NOI18N
136: r.setIcon(imgScene); // NOI18N
137: r.setToolTipText(NbBundle.getMessage(
138: GameDesignTreeNodeRenderer.class,
139: "GameDesignTreeNodeRenderer.SceneNode.tooltip",
140: scene.getName()));
141: return r;
142: }
143: }
144:
145: private class TiledLayerNodeRenderer extends
146: DefaultTreeCellRenderer {
147: public Component getTreeCellRendererComponent(JTree tree,
148: Object value, boolean sel, boolean expanded,
149: boolean leaf, int row, boolean hasFocus) {
150: TiledLayer tiledLayer = (TiledLayer) value;
151: DefaultTreeCellRenderer r = (DefaultTreeCellRenderer) super
152: .getTreeCellRendererComponent(tree, value, sel,
153: expanded, leaf, row, hasFocus);
154: r.setText(tiledLayer.getName());
155: r.setIcon(imgTiled); // NOI18N
156: r
157: .setToolTipText(NbBundle
158: .getMessage(
159: GameDesignTreeNodeRenderer.class,
160: "GameDesignTreeNodeRenderer.TiledLayerNode.tooltip",
161: tiledLayer.getName()));
162: return r;
163: }
164: }
165:
166: private class SpriteNodeRenderer extends DefaultTreeCellRenderer {
167: public Component getTreeCellRendererComponent(JTree tree,
168: Object value, boolean sel, boolean expanded,
169: boolean leaf, int row, boolean hasFocus) {
170: Sprite sprite = (Sprite) value;
171: DefaultTreeCellRenderer r = (DefaultTreeCellRenderer) super
172: .getTreeCellRendererComponent(tree, value, sel,
173: expanded, leaf, row, hasFocus);
174: r.setText(sprite.getName());
175: r.setIcon(imgSprite); // NOI18N
176: r.setToolTipText(NbBundle.getMessage(
177: GameDesignTreeNodeRenderer.class,
178: "GameDesignTreeNodeRenderer.SpriteNode.tooltip",
179: sprite.getName()));
180: return r;
181: }
182: }
183:
184: }
|