OSDN Git Service

Maven3対応。
[jindolf/Jindolf.git] / src / main / java / jp / sfjp / jindolf / view / VillageIconRenderer.java
1 /*
2  * Village icon renderer for JTree
3  *
4  * License : The MIT License
5  * Copyright(c) 2008 olyutorskii
6  */
7
8 package jp.sfjp.jindolf.view;
9
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;
16
17 /**
18  * JTreeの村別アイコン表示。
19  */
20 @SuppressWarnings("serial")
21 public class VillageIconRenderer extends DefaultTreeCellRenderer{
22
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;
28
29     static{
30         ICON_PROLOGUE =
31             ResourceManager.getImageIcon("resources/image/vs_prologue.png");
32         ICON_PROGRESS =
33             ResourceManager.getImageIcon("resources/image/vs_progress.png");
34         ICON_EPILOGUE =
35             ResourceManager.getImageIcon("resources/image/vs_epilogue.png");
36         ICON_GAMEOVER =
37             ResourceManager.getImageIcon("resources/image/vs_gameover.png");
38         ICON_INVALID =
39             ResourceManager.getImageIcon("resources/image/vs_cross.png");
40     }
41
42     /**
43      * コンストラクタ。
44      */
45     public VillageIconRenderer(){
46         super();
47         return;
48     }
49
50     /**
51      * {@inheritDoc}
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}
61      */
62     @Override
63     public Component getTreeCellRendererComponent(
64             JTree tree,
65             Object value,
66             boolean sel,
67             boolean expanded,
68             boolean leaf,
69             int row,
70             boolean hasFocus ){
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;
80             }
81             if( ! village.isValid()) icon = ICON_INVALID;
82             setLeafIcon(icon);
83         }
84
85         Component comp =
86                 super
87                 .getTreeCellRendererComponent(
88                     tree,
89                     value,
90                     sel,
91                     expanded,
92                     leaf,
93                     row,
94                     hasFocus
95                 );
96
97         return comp;
98     }
99
100 }