001package csv2html; 002 003import java.awt.image.BufferedImage; 004import java.io.File; 005import java.util.ArrayList; 006import java.util.List; 007import utility.ImageUtility; 008 009/** 010 * 表:情報テーブル。 011 */ 012public class Table extends Object 013{ 014 /** 015 * 属性リストを記憶するフィールド。 016 */ 017 private Attributes attributes; 018 019 /** 020 * タプル群を記憶するフィールド。 021 */ 022 private List<Tuple> tuples; 023 024 /** 025 * 画像群を記憶するフィールド。 026 */ 027 private List<BufferedImage> images; 028 029 /** 030 * サムネイル画像群を記憶するフィールド。 031 */ 032 private List<BufferedImage> thumbnails; 033 034 /** 035 * テーブルのコンストラクタ。 036 * @param instanceOfAttributes 属性リスト 037 */ 038 public Table(Attributes instanceOfAttributes) 039 { 040 super(); 041 042 this.attributes = instanceOfAttributes; 043 this.tuples = null; 044 this.images = null; 045 this.thumbnails = null; 046 047 return; 048 } 049 050 /** 051 * タプルを追加する。 052 * @param aTuple タプル 053 */ 054 public void add(Tuple aTuple) 055 { 056 this.tuples().add(aTuple); 057 058 return; 059 } 060 061 /** 062 * 属性リストを応答する。 063 * @return 属性リスト 064 */ 065 public Attributes attributes() 066 { 067 return this.attributes; 068 } 069 070 /** 071 * 属性リストを設定する。 072 * @param instanceOfAttributes 属性リスト 073 */ 074 public void attributes(Attributes instanceOfAttributes) 075 { 076 this.attributes = instanceOfAttributes; 077 078 return; 079 } 080 081 /** 082 * 画像群を応答する。 083 * @return 画像群 084 */ 085 public List<BufferedImage> images() 086 { 087 if (this.images != null) { return this.images; } 088 this.images = new ArrayList<BufferedImage>(); 089 for (Tuple aTuple : this.tuples()) 090 { 091 String aString = aTuple.values().get(aTuple.attributes().indexOfImage()); 092 BufferedImage anImage = this.picture(aString); 093 this.images.add(anImage); 094 } 095 096 return this.images; 097 } 098 099 /** 100 * 画像またはサムネイル画像の文字列を受けとって当該画像を応答する。 101 * @param aString 画像またはサムネイル画像の文字列 102 * @return 画像 103 */ 104 private BufferedImage picture(String aString) 105 { 106 List<String> aCollection = IO.splitString(aString, "/"); 107 StringBuffer aBuffer = new StringBuffer(); 108 for (String each : aCollection) 109 { 110 aBuffer.append(File.separator); 111 aBuffer.append(each); 112 } 113 aString = aBuffer.toString(); 114 File aFile = new File(this.attributes().baseDirectory() + aString); 115 BufferedImage anImage = ImageUtility.readImageFromFile(aFile); 116 117 return anImage; 118 } 119 120 /** 121 * サムネイル画像群を応答する。 122 * @return サムネイル画像群 123 */ 124 public List<BufferedImage> thumbnails() 125 { 126 if (thumbnails != null) { return this.thumbnails; } 127 this.thumbnails = new ArrayList<BufferedImage>(); 128 for (Tuple aTuple : this.tuples()) 129 { 130 String aString = aTuple.values().get(aTuple.attributes().indexOfThumbnail()); 131 BufferedImage anImage = this.picture(aString); 132 this.thumbnails.add(anImage); 133 } 134 135 return this.thumbnails; 136 } 137 138 /** 139 * 自分自身を文字列にして、それを応答する。 140 * @return 自分自身の文字列 141 */ 142 public String toString() 143 { 144 StringBuffer aBuffer = new StringBuffer(); 145 Class aClass = this.getClass(); 146 aBuffer.append(aClass.getName()); 147 aBuffer.append("["); 148 aBuffer.append(this.attributes()); 149 for (Tuple aTuple : this.tuples()) 150 { 151 aBuffer.append(","); 152 aBuffer.append(aTuple); 153 } 154 aBuffer.append("]"); 155 156 return aBuffer.toString(); 157 } 158 159 /** 160 * タプル群を応答する。 161 * @return タプル群 162 */ 163 public List<Tuple> tuples() 164 { 165 if (this.tuples != null) { return this.tuples; } 166 this.tuples = new ArrayList<Tuple>(); 167 168 return this.tuples; 169 } 170}