4 * License : The MIT License
5 * Copyright(c) 2008 olyutorskii
8 package jp.sfjp.jindolf.data;
10 import java.awt.image.BufferedImage;
11 import java.io.IOException;
12 import java.net.MalformedURLException;
15 import java.util.Collections;
16 import java.util.LinkedList;
17 import java.util.List;
18 import java.util.logging.Level;
19 import java.util.logging.Logger;
20 import jp.sfjp.jindolf.net.ServerAccess;
21 import jp.sourceforge.jindolf.corelib.LandDef;
28 private static final Logger LOGGER = Logger.getAnonymousLogger();
31 private final LandDef landDef;
32 private final ServerAccess serverAccess;
34 private final List<Village> villageList = new LinkedList<>();
40 * @throws java.lang.IllegalArgumentException 不正な国定義
42 public Land(LandDef landDef) throws IllegalArgumentException{
45 this.landDef = landDef;
49 url = this.landDef.getCgiURI().toURL();
50 }catch(MalformedURLException e){
51 throw new IllegalArgumentException(e);
53 this.serverAccess = new ServerAccess(url, this.landDef.getEncoding());
63 public LandDef getLandDef(){
69 * @return ServerAccessインスタンス
71 public ServerAccess getServerAccess(){
72 return this.serverAccess;
77 * @param index 0から始まるインデックス値
80 public Village getVillage(int index){
81 if(index < 0) return null;
82 if(index >= getVillageCount()) return null;
84 Village result = this.villageList.get(index);
92 public int getVillageCount(){
93 int result = this.villageList.size();
101 // TODO インスタンス変数でいいはず。
102 public List<Village> getVillageList(){
103 return Collections.unmodifiableList(this.villageList);
107 * 絶対または相対URLの指すパーマネントなイメージ画像をダウンロードする。
108 * ※ A,B,D 国の顔アイコンは絶対パスらしい…。
109 * @param imageURL 画像URL文字列
112 public BufferedImage downloadImage(String imageURL){
113 ServerAccess server = getServerAccess();
116 image = server.downloadImage(imageURL);
117 }catch(IOException e){
118 LOGGER.log(Level.WARNING,
119 "イメージ[" + imageURL + "]"
131 public BufferedImage getGraveIconImage(){
132 URI uri = getLandDef().getTombFaceIconURI();
133 BufferedImage result = downloadImage(uri.toASCIIString());
139 * @return 墓アイコンイメージ(大)
141 public BufferedImage getGraveBodyImage(){
142 URI uri = getLandDef().getTombBodyIconURI();
143 BufferedImage result = downloadImage(uri.toASCIIString());
149 * @param vset ソート済みの村一覧
151 public void updateVillageList(List<Village> vset){
152 // TODO 村リスト更新のイベントリスナがあると便利か?
153 this.villageList.clear();
154 this.villageList.addAll(vset);
163 public String toString(){
164 return getLandDef().getLandName();