-/*\r
- * Village icon renderer for JTree\r
- *\r
- * Copyright(c) 2008 olyutorskii\r
- * $Id: VillageIconRenderer.java 888 2009-11-04 06:23:35Z olyutorskii $\r
- */\r
-\r
-package jp.sourceforge.jindolf;\r
-\r
-import java.awt.Component;\r
-import java.net.URL;\r
-import javax.swing.ImageIcon;\r
-import javax.swing.JTree;\r
-import javax.swing.tree.DefaultTreeCellRenderer;\r
-\r
-/**\r
- * JTreeの村別アイコン表示。\r
- */\r
-@SuppressWarnings("serial")\r
-public class VillageIconRenderer extends DefaultTreeCellRenderer{\r
-\r
- private static final ImageIcon ICON_PROLOGUE;\r
- private static final ImageIcon ICON_PROGRESS;\r
- private static final ImageIcon ICON_EPILOGUE;\r
- private static final ImageIcon ICON_GAMEOVER;\r
- private static final ImageIcon ICON_INVALID;\r
-\r
- static{\r
- URL url;\r
- url = Jindolf.getResource("resources/image/prologue.png");\r
- ICON_PROLOGUE = new ImageIcon(url);\r
- url = Jindolf.getResource("resources/image/progress.png");\r
- ICON_PROGRESS = new ImageIcon(url);\r
- url = Jindolf.getResource("resources/image/epilogue.png");\r
- ICON_EPILOGUE = new ImageIcon(url);\r
- url = Jindolf.getResource("resources/image/gameover.png");\r
- ICON_GAMEOVER = new ImageIcon(url);\r
- url = Jindolf.getResource("resources/image/cross.png");\r
- ICON_INVALID = new ImageIcon(url);\r
- }\r
-\r
- /**\r
- * コンストラクタ。\r
- */\r
- public VillageIconRenderer(){\r
- super();\r
- return;\r
- }\r
-\r
- /**\r
- * {@inheritDoc}\r
- * 村種別によってツリーリストアイコンを書き分ける。\r
- * @param tree {@inheritDoc}\r
- * @param value {@inheritDoc}\r
- * @param sel {@inheritDoc}\r
- * @param expanded {@inheritDoc}\r
- * @param leaf {@inheritDoc}\r
- * @param row {@inheritDoc}\r
- * @param hasFocus {@inheritDoc}\r
- * @return {@inheritDoc}\r
- */\r
- @Override\r
- public Component getTreeCellRendererComponent(\r
- JTree tree,\r
- Object value,\r
- boolean sel,\r
- boolean expanded,\r
- boolean leaf,\r
- int row,\r
- boolean hasFocus ){\r
- if(leaf && value instanceof Village){\r
- Village village = (Village) value;\r
- ImageIcon icon = null;\r
- switch(village.getState()){\r
- case PROLOGUE: icon = ICON_PROLOGUE; break;\r
- case PROGRESS: icon = ICON_PROGRESS; break;\r
- case EPILOGUE: icon = ICON_EPILOGUE; break;\r
- case GAMEOVER: icon = ICON_GAMEOVER; break;\r
- default: assert false; break;\r
- }\r
- if( ! village.isValid()) icon = ICON_INVALID;\r
- setLeafIcon(icon);\r
- }\r
-\r
- Component comp =\r
- super\r
- .getTreeCellRendererComponent(\r
- tree,\r
- value,\r
- sel,\r
- expanded,\r
- leaf,\r
- row,\r
- hasFocus\r
- );\r
-\r
- return comp;\r
- }\r
-\r
-}\r
+/*
+ * Village icon renderer for JTree
+ *
+ * License : The MIT License
+ * Copyright(c) 2008 olyutorskii
+ */
+
+package jp.sfjp.jindolf.view;
+
+import java.awt.Component;
+import javax.swing.Icon;
+import javax.swing.JTree;
+import javax.swing.tree.DefaultTreeCellRenderer;
+import jp.sfjp.jindolf.ResourceManager;
+import jp.sfjp.jindolf.data.Village;
+
+/**
+ * JTreeの村別アイコン表示。
+ */
+@SuppressWarnings("serial")
+public class VillageIconRenderer extends DefaultTreeCellRenderer{
+
+ private static final Icon ICON_PROLOGUE;
+ private static final Icon ICON_PROGRESS;
+ private static final Icon ICON_EPILOGUE;
+ private static final Icon ICON_GAMEOVER;
+ private static final Icon ICON_INVALID;
+
+ private static final int MARK_SZ = 16;
+
+ static{
+ ICON_PROLOGUE = ResourceManager
+ .getSquareIcon("resources/image/vs_prologue.png", MARK_SZ);
+ ICON_PROGRESS = ResourceManager
+ .getSquareIcon("resources/image/vs_progress.png", MARK_SZ);
+ ICON_EPILOGUE = ResourceManager
+ .getSquareIcon("resources/image/vs_epilogue.png", MARK_SZ);
+ ICON_GAMEOVER = ResourceManager
+ .getSquareIcon("resources/image/vs_gameover.png", MARK_SZ);
+ ICON_INVALID = ResourceManager
+ .getSquareIcon("resources/image/vs_cross.png", MARK_SZ);
+ }
+
+ /**
+ * コンストラクタ。
+ */
+ public VillageIconRenderer(){
+ super();
+ return;
+ }
+
+ /**
+ * {@inheritDoc}
+ * 村種別によってツリーリストアイコンを書き分ける。
+ * @param tree {@inheritDoc}
+ * @param value {@inheritDoc}
+ * @param sel {@inheritDoc}
+ * @param expanded {@inheritDoc}
+ * @param leaf {@inheritDoc}
+ * @param row {@inheritDoc}
+ * @param hasFocus {@inheritDoc}
+ * @return {@inheritDoc}
+ */
+ @Override
+ public Component getTreeCellRendererComponent(
+ JTree tree,
+ Object value,
+ boolean sel,
+ boolean expanded,
+ boolean leaf,
+ int row,
+ boolean hasFocus ){
+ if(leaf && value instanceof Village){
+ Village village = (Village) value;
+ Icon icon = null;
+ switch(village.getState()){
+ case PROLOGUE: icon = ICON_PROLOGUE; break;
+ case PROGRESS: icon = ICON_PROGRESS; break;
+ case EPILOGUE: icon = ICON_EPILOGUE; break;
+ case GAMEOVER: icon = ICON_GAMEOVER; break;
+ default: assert false; break;
+ }
+ if( ! village.isValid()) icon = ICON_INVALID;
+ setLeafIcon(icon);
+ }
+
+ Component comp =
+ super
+ .getTreeCellRendererComponent(
+ tree,
+ value,
+ sel,
+ expanded,
+ leaf,
+ row,
+ hasFocus
+ );
+
+ return comp;
+ }
+
+}