From: <aki...@us...> - 2006-12-23 13:09:46
|
Revision: 1222 http://svn.sourceforge.net/gridarta/?rev=1222&view=rev Author: akirschbaum Date: 2006-12-23 05:09:46 -0800 (Sat, 23 Dec 2006) Log Message: ----------- Move cell renderer class of MapTileListView into separate java file. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gui/maptilelist/MapTileListView.java trunk/daimonin/src/daieditor/gui/maptilelist/MapTileListView.java Added Paths: ----------- trunk/crossfire/src/cfeditor/gui/maptilelist/CellRenderer.java trunk/daimonin/src/daieditor/gui/maptilelist/CellRenderer.java Added: trunk/crossfire/src/cfeditor/gui/maptilelist/CellRenderer.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/maptilelist/CellRenderer.java (rev 0) +++ trunk/crossfire/src/cfeditor/gui/maptilelist/CellRenderer.java 2006-12-23 13:09:46 UTC (rev 1222) @@ -0,0 +1,110 @@ +/* + * Gridarta Java Editor. + * Copyright (C) 2006 The Gridarta Developers + * + * (code based on: Gridder. 2D grid based level editor. (C) 2000 Pasi Keränen) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +package cfeditor.gui.maptilelist; + +import cfeditor.CMainControl; +import cfeditor.gameobject.ArchetypeSet; +import cfeditor.gameobject.GameObject; +import java.awt.Component; +import javax.swing.BorderFactory; +import javax.swing.DefaultListCellRenderer; +import javax.swing.JList; +import net.sf.gridarta.gameobject.GameObjectContainer; +import org.jetbrains.annotations.NotNull; + +/** + * CellRenderer for rendering ArchObjects on a certain map tile in a list. + */ +public final class CellRenderer extends DefaultListCellRenderer { + + /** Serial Version UID. */ + private static final long serialVersionUID = 1L; + + /** The archetype set. */ + @NotNull private final ArchetypeSet archetypeSet; + + public CellRenderer(@NotNull final ArchetypeSet archetypeSet) { + this.archetypeSet = archetypeSet; + } + + /** {@inheritDoc} */ + @Override public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) { + super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + + GameObject arch = (GameObject) value; + + // arch == null should not happen, but it *can* happen when the active + // window gets changed by user and java is still blitting here + if (arch != null) { + arch = arch.getHead(); + + if (!arch.hasArchetype()) { + setIcon(CMainControl.getNoarchTileIcon()); + } else if (arch.getFaceFlag()) { + setIcon(CMainControl.getNofaceTileIcon()); + } else if (arch.getFaceNr() == -1) { + setIcon(CMainControl.getUnknownTileIcon()); + } else { + setIcon(archetypeSet.getFace(arch.getFaceNr())); + } + + // In the map-tile-window the object names are displayed + // next to the icons + if (arch.getObjName() != null && arch.getObjName().length() > 0) { + setText(arch.getObjName()); // special name + } else { + final String defname; + if (arch.hasArchetype()) { + defname = arch.getArchetype().getObjName(); + } else { + defname = null; + } + + if (defname != null && defname.length() > 0) { + setText(defname); // default name + } else { + setText(arch.getArchetypeName()); // arch name + } + } + } else { + setIcon(CMainControl.getUnknownTileIcon()); + setText("?"); + } + + int indent = 0; + for (;;) { + final GameObjectContainer<GameObject> env = arch.getContainer(); + if (env == null || !(env instanceof GameObject)) { + break; + } + arch = (GameObject) env; + indent++; + } + if (indent > 1) { + setBorder(BorderFactory.createEmptyBorder(0, (indent - 1) * 16, 0, 0)); // indentation + } + + return this; + } + +} // class CellRenderer Property changes on: trunk/crossfire/src/cfeditor/gui/maptilelist/CellRenderer.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: trunk/crossfire/src/cfeditor/gui/maptilelist/MapTileListView.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/maptilelist/MapTileListView.java 2006-12-23 12:45:27 UTC (rev 1221) +++ trunk/crossfire/src/cfeditor/gui/maptilelist/MapTileListView.java 2006-12-23 13:09:46 UTC (rev 1222) @@ -32,12 +32,10 @@ import cfeditor.map.MapControl; import java.awt.BorderLayout; import java.awt.Color; -import java.awt.Component; import java.awt.GridLayout; import java.awt.Rectangle; import java.awt.event.MouseEvent; import javax.swing.BorderFactory; -import javax.swing.DefaultListCellRenderer; import javax.swing.DefaultListModel; import javax.swing.JList; import javax.swing.JPanel; @@ -94,7 +92,7 @@ model = new DefaultListModel(); list = new JList(model); - list.setCellRenderer(new MyCellRenderer()); + list.setCellRenderer(new CellRenderer(mainControl.getArchetypeSet())); list.setBackground(Color.lightGray); final JScrollPane scrollPane = new JScrollPane(list); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); @@ -336,72 +334,4 @@ } } - /** CellRenderer for rendering ArchObjects on a certain map tile in a list. */ - private final class MyCellRenderer extends DefaultListCellRenderer { - - /** Serial Version UID. */ - private static final long serialVersionUID = 1L; - - /** {@inheritDoc} */ - @Override public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) { - super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); - - GameObject arch = (GameObject) value; - - // arch == null should not happen, but it *can* happen when the active - // window gets changed by user and java is still blitting here - if (arch != null) { - arch = arch.getHead(); - - if (!arch.hasArchetype()) { - setIcon(CMainControl.getNoarchTileIcon()); - } else if (arch.getFaceFlag()) { - setIcon(CMainControl.getNofaceTileIcon()); - } else if (arch.getFaceNr() == -1) { - setIcon(CMainControl.getUnknownTileIcon()); - } else { - setIcon(mainControl.getFace(arch.getFaceNr())); - } - - // In the map-tile-window the object names are displayed - // next to the icons - if (arch.getObjName() != null && arch.getObjName().length() > 0) { - setText(arch.getObjName()); // special name - } else { - final String defname; - if (arch.hasArchetype()) { - defname = arch.getArchetype().getObjName(); - } else { - defname = null; - } - - if (defname != null && defname.length() > 0) { - setText(defname); // default name - } else { - setText(arch.getArchetypeName()); // arch name - } - } - } else { - setIcon(CMainControl.getUnknownTileIcon()); - setText("?"); - } - - int indent = 0; - for (;;) { - final GameObjectContainer<GameObject> env = arch.getContainer(); - if (env == null || !(env instanceof GameObject)) { - break; - } - arch = (GameObject) env; - indent++; - } - if (indent > 1) { - setBorder(BorderFactory.createEmptyBorder(0, (indent - 1) * 16, 0, 0)); // indentation - } - - return this; - } - - } // class MyCellRenderer - } // class MapTileListView Added: trunk/daimonin/src/daieditor/gui/maptilelist/CellRenderer.java =================================================================== --- trunk/daimonin/src/daieditor/gui/maptilelist/CellRenderer.java (rev 0) +++ trunk/daimonin/src/daieditor/gui/maptilelist/CellRenderer.java 2006-12-23 13:09:46 UTC (rev 1222) @@ -0,0 +1,93 @@ +/* + * Gridarta Java Editor. + * Copyright (C) 2006 The Gridarta Developers + * + * (code based on: Gridder. 2D grid based level editor. (C) 2000 Pasi Keränen) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +package daieditor.gui.maptilelist; + +import daieditor.CMainControl; +import daieditor.gameobject.ArchetypeSet; +import daieditor.gameobject.GameObject; +import java.awt.Component; +import javax.swing.DefaultListCellRenderer; +import javax.swing.ImageIcon; +import javax.swing.JList; +import org.jetbrains.annotations.NotNull; + +/** + * CellRenderer for rendering ArchObjects on a certain map tile in a list. + */ +public final class CellRenderer extends DefaultListCellRenderer { + + /** Serial Version UID. */ + private static final long serialVersionUID = 1L; + + /** The archetype set. */ + @NotNull private final ArchetypeSet archetypeSet; + + public CellRenderer(@NotNull final ArchetypeSet archetypeSet) { + this.archetypeSet = archetypeSet; + } + + /** {@inheritDoc} */ + @Override public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) { + super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + + GameObject arch = (GameObject) value; + + // arch == null should not happen, but it *can* happen when the active + // window gets changed by user and java is still blitting here + if (arch != null) { + arch = arch.getHead(); + + if (!arch.hasArchetype()) { + setIcon(CMainControl.getNoarchTileIcon()); + } else if (arch.hasFaceObject()) { + setIcon(CMainControl.getNofaceTileIcon()); + } else { + final String faceObjName = arch.getFaceObjName(); + final ImageIcon icon = faceObjName != null ? archetypeSet.getFace(faceObjName) : null; + setIcon(icon != null ? icon : CMainControl.getUnknownTileIcon()); + } + + // In the map-tile-window the object names are displayed + // next to the icons + if (arch.getObjName() != null && arch.getObjName().length() > 0) { + setText(arch.getObjName()); // special name + } else { + final String defname; + if (arch.hasArchetype()) { + defname = arch.getArchetype().getObjName(); + } else { + defname = null; + } + + if (defname != null && defname.length() > 0) { + setText(defname); // default name + } else { + setText(arch.getArchetypeName()); // arch name + } + } + } + + return this; + } + +} // class CellRenderer Property changes on: trunk/daimonin/src/daieditor/gui/maptilelist/CellRenderer.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: trunk/daimonin/src/daieditor/gui/maptilelist/MapTileListView.java =================================================================== --- trunk/daimonin/src/daieditor/gui/maptilelist/MapTileListView.java 2006-12-23 12:45:27 UTC (rev 1221) +++ trunk/daimonin/src/daieditor/gui/maptilelist/MapTileListView.java 2006-12-23 13:09:46 UTC (rev 1222) @@ -33,14 +33,11 @@ import daieditor.map.MapControl; import java.awt.BorderLayout; import java.awt.Color; -import java.awt.Component; import java.awt.GridLayout; import java.awt.Insets; import java.awt.Rectangle; import java.awt.event.MouseEvent; -import javax.swing.DefaultListCellRenderer; import javax.swing.DefaultListModel; -import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JList; @@ -100,7 +97,7 @@ model = new DefaultListModel(); list = new JList(model); - list.setCellRenderer(new MyCellRenderer()); + list.setCellRenderer(new CellRenderer(mainControl.getArchetypeSet())); list.setBackground(Color.lightGray); final JScrollPane scrollPane = new JScrollPane(list); scrollPane.setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_NEVER); @@ -318,56 +315,4 @@ } } - /** CellRenderer for rendering ArchObjects on a certain map tile in a list. */ - private final class MyCellRenderer extends DefaultListCellRenderer { - - /** Serial Version UID. */ - private static final long serialVersionUID = 1L; - - /** {@inheritDoc} */ - @Override public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) { - super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); - - GameObject arch = (GameObject) value; - - // arch == null should not happen, but it *can* happen when the active - // window gets changed by user and java is still blitting here - if (arch != null) { - arch = arch.getHead(); - - if (!arch.hasArchetype()) { - setIcon(CMainControl.getNoarchTileIcon()); - } else if (arch.hasFaceObject()) { - setIcon(CMainControl.getNofaceTileIcon()); - } else { - final String faceObjName = arch.getFaceObjName(); - final ImageIcon icon = faceObjName != null ? mainControl.getArchetypeSet().getFace(faceObjName) : null; - setIcon(icon != null ? icon : CMainControl.getUnknownTileIcon()); - } - - // In the map-tile-window the object names are displayed - // next to the icons - if (arch.getObjName() != null && arch.getObjName().length() > 0) { - setText(arch.getObjName()); // special name - } else { - final String defname; - if (arch.hasArchetype()) { - defname = arch.getArchetype().getObjName(); - } else { - defname = null; - } - - if (defname != null && defname.length() > 0) { - setText(defname); // default name - } else { - setText(arch.getArchetypeName()); // arch name - } - } - } - - return this; - } - - } // class MyCellRenderer - } // class MapTileListView This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |