Mercurial > hg > digilib-old
comparison common/src/main/java/digilib/io/ImageSet.java @ 903:7779b37d1d05
refactored into maven modules per servlet type.
can build servlet-api 2.3 and 3.0 via profile now!
author | robcast |
---|---|
date | Tue, 26 Apr 2011 20:24:31 +0200 |
parents | servlet/src/main/java/digilib/io/ImageSet.java@ba1eb2d821a2 |
children |
comparison
equal
deleted
inserted
replaced
902:89ba3ffcf552 | 903:7779b37d1d05 |
---|---|
1 /* ImageSet -- digilib image file info class. | |
2 * Digital Image Library servlet components | |
3 * Copyright (C) 2003 Robert Casties (robcast@mail.berlios.de) | |
4 * | |
5 * This program is free software; you can | |
6 * redistribute it and/or modify it under the terms of the GNU General Public | |
7 * License as published by the Free Software Foundation; either version 2 of | |
8 * the License, or (at your option) any later version. | |
9 * | |
10 * Please read license.txt for the full details. A copy of the GPL may be | |
11 * found at http://www.gnu.org/copyleft/lgpl.html | |
12 * | |
13 * You should have received a copy of the GNU General Public License along | |
14 * with this program; if not, write to the Free Software Foundation, Inc., | |
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
16 */ | |
17 | |
18 package digilib.io; | |
19 | |
20 import java.util.ArrayList; | |
21 import java.util.List; | |
22 import java.util.ListIterator; | |
23 | |
24 import digilib.util.ImageSize; | |
25 | |
26 /** | |
27 * @author casties | |
28 */ | |
29 public class ImageSet { | |
30 | |
31 /** list of files (ImageFile) */ | |
32 protected List<ImageInput> list = null; | |
33 | |
34 /** aspect ratio (width/height) */ | |
35 protected float aspect = 0f; | |
36 | |
37 /** resolution of the biggest image (DPI) */ | |
38 protected float resX = 0f; | |
39 | |
40 /** resolution of the biggest image (DPI) */ | |
41 protected float resY = 0f; | |
42 | |
43 /** | |
44 * Creator for empty fileset. | |
45 * | |
46 * | |
47 * @param initialCapacity | |
48 */ | |
49 public ImageSet() { | |
50 list = new ArrayList<ImageInput>(); | |
51 } | |
52 | |
53 /** | |
54 * The number of image files in this Fileset. | |
55 * | |
56 * | |
57 * @return number of image files | |
58 */ | |
59 public int size() { | |
60 return (list != null) ? list.size() : 0; | |
61 } | |
62 | |
63 /** | |
64 * Gets the default Input. | |
65 * | |
66 */ | |
67 public ImageInput get() { | |
68 return (list != null) ? list.get(0) : null; | |
69 } | |
70 | |
71 /** | |
72 * Get the ImageFile at the index. | |
73 * | |
74 * | |
75 * @param index | |
76 * @return | |
77 */ | |
78 public ImageInput get(int index) { | |
79 return list.get(index); | |
80 } | |
81 | |
82 /** | |
83 * Get the next smaller ImageFile than the given size. | |
84 * | |
85 * Returns the ImageFile from the set that has a width and height smaller or | |
86 * equal the given size. Returns null if there isn't any smaller image. | |
87 * | |
88 * @param size | |
89 * @param info | |
90 * @return | |
91 */ | |
92 public ImageInput getNextSmaller(ImageSize size) { | |
93 for (ListIterator<ImageInput> i = getHiresIterator(); i.hasNext();) { | |
94 ImageInput f = i.next(); | |
95 ImageSize is = f.getSize(); | |
96 if (is != null && is.isTotallySmallerThan(size)) { | |
97 return f; | |
98 } | |
99 } | |
100 return null; | |
101 } | |
102 | |
103 /** | |
104 * Get the next bigger ImageFile than the given size. | |
105 * | |
106 * Returns the ImageFile from the set that has a width or height bigger or | |
107 * equal the given size. Returns null if there isn't any bigger image. | |
108 * | |
109 * @param size | |
110 * @param info | |
111 * @return | |
112 */ | |
113 public ImageInput getNextBigger(ImageSize size) { | |
114 for (ListIterator<ImageInput> i = getLoresIterator(); i.hasPrevious();) { | |
115 ImageInput f = i.previous(); | |
116 ImageSize is = f.getSize(); | |
117 if (is != null && is.isBiggerThan(size)) { | |
118 return f; | |
119 } | |
120 } | |
121 return null; | |
122 } | |
123 | |
124 /** | |
125 * Returns the biggest ImageFile in the set. | |
126 * | |
127 * | |
128 * @return | |
129 */ | |
130 public ImageInput getBiggest() { | |
131 return this.get(0); | |
132 } | |
133 | |
134 /** | |
135 * Returns the biggest ImageFile in the set. | |
136 * | |
137 * | |
138 * @return | |
139 */ | |
140 public ImageInput getSmallest() { | |
141 return this.get(this.size() - 1); | |
142 } | |
143 | |
144 /** | |
145 * Get an Iterator for this Fileset starting at the highest resolution | |
146 * images. | |
147 * | |
148 * | |
149 * @return | |
150 */ | |
151 public ListIterator<ImageInput> getHiresIterator() { | |
152 return list.listIterator(); | |
153 } | |
154 | |
155 /** | |
156 * Get an Iterator for this Fileset starting at the lowest resolution | |
157 * images. | |
158 * | |
159 * The Iterator starts at the last element, so you have to use it backwards | |
160 * with hasPrevious() and previous(). | |
161 * | |
162 * | |
163 * @return | |
164 */ | |
165 public ListIterator<ImageInput> getLoresIterator() { | |
166 return list.listIterator(list.size()); | |
167 } | |
168 | |
169 /** | |
170 * @return | |
171 */ | |
172 public float getResX() { | |
173 return resX; | |
174 } | |
175 | |
176 /** | |
177 * @return | |
178 */ | |
179 public float getResY() { | |
180 return resY; | |
181 } | |
182 | |
183 /** | |
184 * Sets the aspect ratio from an ImageSize. | |
185 * | |
186 * | |
187 * @param f | |
188 */ | |
189 public void setAspect(ImageSize s) { | |
190 aspect = s.getAspect(); | |
191 } | |
192 | |
193 /** | |
194 * Returns the aspect ratio. | |
195 * | |
196 * Aspect ratio is (width/height). So it's <1 for portrait and >1 for | |
197 * landscape. | |
198 * | |
199 * | |
200 * @return | |
201 */ | |
202 public float getAspect() { | |
203 return aspect; | |
204 } | |
205 | |
206 public void checkMeta() { | |
207 // TODO Auto-generated method stub | |
208 | |
209 } | |
210 | |
211 } |