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 org.netbeans.modules.vmd.game.editor.scene.*;
044: import java.awt.Component;
045: import javax.swing.ImageIcon;
046:
047: import javax.swing.JTable;
048: import javax.swing.SwingConstants;
049: import javax.swing.table.DefaultTableCellRenderer;
050: import org.netbeans.modules.vmd.game.model.Layer;
051: import org.netbeans.modules.vmd.game.model.Scene;
052: import org.netbeans.modules.vmd.game.model.TiledLayer;
053: import org.netbeans.modules.vmd.game.model.Sprite;
054: import org.openide.util.NbBundle;
055:
056: public class GameDesignTableCellRenderer extends
057: DefaultTableCellRenderer {
058:
059: private ImageIcon iconSprite = new ImageIcon(this .getClass()
060: .getResource("res/sprite.png")); // NOI18N
061: private ImageIcon iconTiledLayer = new ImageIcon(this .getClass()
062: .getResource("res/tiled.png")); // NOI18N
063: private ImageIcon iconScene = new ImageIcon(this .getClass()
064: .getResource("res/scene.png")); // NOI18N
065:
066: public Component getTableCellRendererComponent(JTable table,
067: final Object value, boolean isSelected, boolean hasFocus,
068: int row, int column) {
069: super .getTableCellRendererComponent(table, value, isSelected,
070: hasFocus, row, column);
071: if (value instanceof Layer) {
072: this .setText(null);
073: this .setHorizontalAlignment(SwingConstants.CENTER);
074: if (value instanceof Sprite) {
075: this .setIcon(iconSprite);
076: this
077: .setToolTipText(NbBundle
078: .getMessage(
079: GameDesignTableCellRenderer.class,
080: "GameDesignTableCellRenderer.iconSprite.tooltip"));
081: } else if (value instanceof TiledLayer) {
082: this .setIcon(iconTiledLayer);
083: this
084: .setToolTipText(NbBundle
085: .getMessage(
086: GameDesignTableCellRenderer.class,
087: "GameDesignTableCellRenderer.iconTiledLayer.tooltip"));
088: }
089: } else if (value instanceof Scene) {
090: this .setIcon(iconScene);
091: this .setToolTipText(NbBundle.getMessage(
092: GameDesignTableCellRenderer.class,
093: "GameDesignTableCellRenderer.iconScene.tooltip"));
094: } else {
095: throw new IllegalArgumentException(
096: "Only Layer or Scene can be rendered."); // NOI18N
097: }
098: return this;
099: }
100:
101: }
|