2 * Village icon renderer for JTree
4 * License : The MIT License
5 * Copyright(c) 2008 olyutorskii
8 package jp.sfjp.jindolf.view;
10 import java.awt.Component;
11 import javax.swing.ImageIcon;
12 import javax.swing.JTree;
13 import javax.swing.tree.DefaultTreeCellRenderer;
14 import jp.sfjp.jindolf.ResourceManager;
15 import jp.sfjp.jindolf.data.Village;
20 @SuppressWarnings("serial")
21 public class VillageIconRenderer extends DefaultTreeCellRenderer{
23 private static final ImageIcon ICON_PROLOGUE;
24 private static final ImageIcon ICON_PROGRESS;
25 private static final ImageIcon ICON_EPILOGUE;
26 private static final ImageIcon ICON_GAMEOVER;
27 private static final ImageIcon ICON_INVALID;
31 ResourceManager.getImageIcon("resources/image/vs_prologue.png");
33 ResourceManager.getImageIcon("resources/image/vs_progress.png");
35 ResourceManager.getImageIcon("resources/image/vs_epilogue.png");
37 ResourceManager.getImageIcon("resources/image/vs_gameover.png");
39 ResourceManager.getImageIcon("resources/image/vs_cross.png");
45 public VillageIconRenderer(){
52 * 村種別によってツリーリストアイコンを書き分ける。
53 * @param tree {@inheritDoc}
54 * @param value {@inheritDoc}
55 * @param sel {@inheritDoc}
56 * @param expanded {@inheritDoc}
57 * @param leaf {@inheritDoc}
58 * @param row {@inheritDoc}
59 * @param hasFocus {@inheritDoc}
60 * @return {@inheritDoc}
63 public Component getTreeCellRendererComponent(
71 if(leaf && value instanceof Village){
72 Village village = (Village) value;
73 ImageIcon icon = null;
74 switch(village.getState()){
75 case PROLOGUE: icon = ICON_PROLOGUE; break;
76 case PROGRESS: icon = ICON_PROGRESS; break;
77 case EPILOGUE: icon = ICON_EPILOGUE; break;
78 case GAMEOVER: icon = ICON_GAMEOVER; break;
79 default: assert false; break;
81 if( ! village.isValid()) icon = ICON_INVALID;
87 .getTreeCellRendererComponent(