Mercurial > hg > digilib-old
annotate servlet/src/digilib/io/ImageSet.java @ 882:07926f0b9a1a jquery
make digilib.html use new jquery. sync jquery-1.5.1.js and jquery.js.
author | robcast |
---|---|
date | Tue, 22 Mar 2011 12:31:41 +0100 |
parents | f210731dc6cc |
children |
rev | line source |
---|---|
574 | 1 /* ImageSet -- digilib image file info class. |
176 | 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 | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
6 * redistribute it and/or modify it under the terms of the GNU General Public |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
7 * License as published by the Free Software Foundation; either version 2 of |
176 | 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 | |
159 | 16 */ |
176 | 17 |
159 | 18 package digilib.io; |
19 | |
20 import java.util.ArrayList; | |
531 | 21 import java.util.List; |
159 | 22 import java.util.ListIterator; |
23 | |
596 | 24 import digilib.util.ImageSize; |
159 | 25 |
26 /** | |
27 * @author casties | |
28 */ | |
574 | 29 public class ImageSet { |
159 | 30 |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
31 /** list of files (ImageFile) */ |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
32 protected List<ImageInput> list = null; |
233 | 33 |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
34 /** aspect ratio (width/height) */ |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
35 protected float aspect = 0f; |
574 | 36 |
37 /** resolution of the biggest image (DPI) */ | |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
38 protected float resX = 0f; |
233 | 39 |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
40 /** resolution of the biggest image (DPI) */ |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
41 protected float resY = 0f; |
159 | 42 |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
43 /** |
259 | 44 * Creator for empty fileset. |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
45 * |
159 | 46 * |
47 * @param initialCapacity | |
48 */ | |
574 | 49 public ImageSet() { |
50 list = new ArrayList<ImageInput>(); | |
159 | 51 } |
52 | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
53 /** |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
54 * The number of image files in this Fileset. |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
55 * |
159 | 56 * |
57 * @return number of image files | |
58 */ | |
59 public int size() { | |
60 return (list != null) ? list.size() : 0; | |
61 } | |
62 | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
63 /** |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
64 * Gets the default Input. |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
65 * |
159 | 66 */ |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
67 public ImageInput get() { |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
68 return (list != null) ? list.get(0) : null; |
159 | 69 } |
70 | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
71 /** |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
72 * Get the ImageFile at the index. |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
73 * |
159 | 74 * |
75 * @param index | |
76 * @return | |
77 */ | |
574 | 78 public ImageInput get(int index) { |
531 | 79 return list.get(index); |
159 | 80 } |
81 | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
82 /** |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
83 * Get the next smaller ImageFile than the given size. |
159 | 84 * |
233 | 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. | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
87 * |
159 | 88 * @param size |
89 * @param info | |
90 * @return | |
91 */ | |
574 | 92 public ImageInput getNextSmaller(ImageSize size) { |
93 for (ListIterator<ImageInput> i = getHiresIterator(); i.hasNext();) { | |
94 ImageInput f = i.next(); | |
819
a23c4c15a6a8
clean up possible resource leaks. better behaviour with unknown image types.
robcast
parents:
596
diff
changeset
|
95 ImageSize is = f.getSize(); |
a23c4c15a6a8
clean up possible resource leaks. better behaviour with unknown image types.
robcast
parents:
596
diff
changeset
|
96 if (is != null && is.isTotallySmallerThan(size)) { |
581 | 97 return f; |
159 | 98 } |
99 } | |
100 return null; | |
101 } | |
102 | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
103 /** |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
104 * Get the next bigger ImageFile than the given size. |
159 | 105 * |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
106 * Returns the ImageFile from the set that has a width or height bigger or |
581 | 107 * equal the given size. Returns null if there isn't any bigger image. |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
108 * |
159 | 109 * @param size |
110 * @param info | |
111 * @return | |
112 */ | |
574 | 113 public ImageInput getNextBigger(ImageSize size) { |
114 for (ListIterator<ImageInput> i = getLoresIterator(); i.hasPrevious();) { | |
115 ImageInput f = i.previous(); | |
819
a23c4c15a6a8
clean up possible resource leaks. better behaviour with unknown image types.
robcast
parents:
596
diff
changeset
|
116 ImageSize is = f.getSize(); |
a23c4c15a6a8
clean up possible resource leaks. better behaviour with unknown image types.
robcast
parents:
596
diff
changeset
|
117 if (is != null && is.isBiggerThan(size)) { |
581 | 118 return f; |
159 | 119 } |
120 } | |
121 return null; | |
122 } | |
123 | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
124 /** |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
125 * Returns the biggest ImageFile in the set. |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
126 * |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
127 * |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
128 * @return |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
129 */ |
574 | 130 public ImageInput getBiggest() { |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
131 return this.get(0); |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
132 } |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
133 |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
134 /** |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
135 * Returns the biggest ImageFile in the set. |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
136 * |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
137 * |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
138 * @return |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
139 */ |
574 | 140 public ImageInput getSmallest() { |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
141 return this.get(this.size() - 1); |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
142 } |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
143 |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
144 /** |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
145 * Get an Iterator for this Fileset starting at the highest resolution |
159 | 146 * images. |
147 * | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
148 * |
159 | 149 * @return |
150 */ | |
574 | 151 public ListIterator<ImageInput> getHiresIterator() { |
159 | 152 return list.listIterator(); |
153 } | |
154 | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
155 /** |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
156 * Get an Iterator for this Fileset starting at the lowest resolution |
159 | 157 * images. |
158 * | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
159 * The Iterator starts at the last element, so you have to use it backwards |
159 | 160 * with hasPrevious() and previous(). |
161 * | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
162 * |
159 | 163 * @return |
164 */ | |
574 | 165 public ListIterator<ImageInput> getLoresIterator() { |
159 | 166 return list.listIterator(list.size()); |
167 } | |
168 | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
169 /** |
159 | 170 * @return |
171 */ | |
295
90bab835fc25
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
284
diff
changeset
|
172 public float getResX() { |
159 | 173 return resX; |
174 } | |
175 | |
176 /** | |
177 * @return | |
178 */ | |
295
90bab835fc25
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
284
diff
changeset
|
179 public float getResY() { |
159 | 180 return resY; |
181 } | |
182 | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
183 /** |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
184 * Sets the aspect ratio from an ImageSize. |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
185 * |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
186 * |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
187 * @param f |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
188 */ |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
189 public void setAspect(ImageSize s) { |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
190 aspect = s.getAspect(); |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
191 } |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
192 |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
193 /** |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
194 * Returns the aspect ratio. |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
195 * |
233 | 196 * Aspect ratio is (width/height). So it's <1 for portrait and >1 for |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
197 * landscape. |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
198 * |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
199 * |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
200 * @return |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
201 */ |
295
90bab835fc25
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
284
diff
changeset
|
202 public float getAspect() { |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
203 return aspect; |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
204 } |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
205 |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
206 public void checkMeta() { |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
207 // TODO Auto-generated method stub |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
208 |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
209 } |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
210 |
233 | 211 } |