Mercurial > hg > digilib-old
annotate common/src/main/java/digilib/io/ImageFile.java @ 1028:7c401c168a95
Merge with 01ea28b6fe11cfb21d9cbc76b7f66e52569d7f50
author | robcast |
---|---|
date | Wed, 07 Mar 2012 17:27:30 +0100 |
parents | 7779b37d1d05 |
children |
rev | line source |
---|---|
159 | 1 /* ImageFile.java -- digilib image file class. |
2 | |
3 Digital Image Library servlet components | |
4 | |
5 Copyright (C) 2003 Robert Casties (robcast@mail.berlios.de) | |
6 | |
7 This program is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
9 Free Software Foundation; either version 2 of the License, or (at your | |
10 option) any later version. | |
11 | |
12 Please read license.txt for the full details. A copy of the GPL | |
13 may be found at http://www.gnu.org/copyleft/lgpl.html | |
14 | |
15 You should have received a copy of the GNU General Public License | |
16 along with this program; if not, write to the Free Software | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 * Created on 25.02.2003 | |
20 */ | |
21 | |
22 package digilib.io; | |
23 | |
24 import java.io.File; | |
585 | 25 import java.io.IOException; |
590 | 26 import java.io.RandomAccessFile; |
159 | 27 |
590 | 28 import javax.imageio.stream.FileImageInputStream; |
29 import javax.imageio.stream.ImageInputStream; | |
159 | 30 |
585 | 31 import digilib.servlet.DigilibConfiguration; |
596 | 32 import digilib.util.ImageSize; |
159 | 33 |
34 /** | |
35 * @author casties | |
36 */ | |
568 | 37 public class ImageFile extends ImageInput { |
159 | 38 |
583 | 39 // file |
40 private File file = null; | |
159 | 41 // file name |
583 | 42 private String name = null; |
159 | 43 // parent directory |
44 private Directory dir = null; | |
579
efd7a223f819
try: ImageInput as interface, ImageFile inherits from Dirent and implements ImageInput
robcast
parents:
574
diff
changeset
|
45 |
583 | 46 /** Constructor with File. |
47 * | |
48 * @param f | |
49 * @param parent | |
50 * @param dir | |
51 */ | |
52 public ImageFile(File f, ImageSet parent, Directory dir) { | |
53 this.file = f; | |
54 this.name = f.getName(); | |
159 | 55 this.parent = parent; |
56 this.dir = dir; | |
57 } | |
58 | |
583 | 59 /** Constructor with filename (without path). |
60 * @param fn | |
61 * @param parent | |
62 * @param dir | |
63 */ | |
64 public ImageFile(String fn, ImageSet parent, Directory dir) { | |
65 this.name = fn; | |
66 this.dir = dir; | |
67 this.file = new File(this.dir.getDir(), fn); | |
68 this.parent = parent; | |
159 | 69 } |
70 | |
566 | 71 |
585 | 72 /** Checks the image and sets size and type. |
73 * | |
74 */ | |
75 public void check() { | |
76 if (pixelSize == null) { | |
77 try { | |
78 // use the configured toolkit to identify the image | |
79 DigilibConfiguration.identifyDocuImage(this); | |
80 } catch (IOException e) { | |
81 // nothing much to do... | |
82 } | |
83 } | |
84 } | |
85 | |
86 /* (non-Javadoc) | |
87 * @see digilib.io.ImageInput#getSize() | |
88 */ | |
89 @Override | |
90 public ImageSize getSize() { | |
91 check(); | |
92 return pixelSize; | |
93 } | |
94 | |
95 /* (non-Javadoc) | |
96 * @see digilib.io.ImageInput#getMimetype() | |
97 */ | |
98 @Override | |
99 public String getMimetype() { | |
100 check(); | |
101 return mimetype; | |
102 } | |
103 | |
104 /* (non-Javadoc) | |
105 * @see digilib.io.ImageInput#getAspect() | |
106 */ | |
107 @Override | |
108 public float getAspect() { | |
109 check(); | |
110 return (pixelSize != null) ? pixelSize.getAspect() : 0f; | |
111 } | |
112 | |
113 /** Returns the file name (without path). | |
159 | 114 * |
115 * @return | |
116 */ | |
117 public String getName() { | |
583 | 118 return name; |
159 | 119 } |
120 | |
590 | 121 |
122 /* (non-Javadoc) | |
123 * @see digilib.io.ImageInput#hasImageInputStream() | |
124 */ | |
125 @Override | |
126 public boolean hasImageInputStream() { | |
127 return true; | |
128 } | |
159 | 129 |
590 | 130 /* (non-Javadoc) |
131 * @see digilib.io.ImageInput#getImageInputStream() | |
132 */ | |
133 @Override | |
134 public ImageInputStream getImageInputStream() { | |
135 try { | |
136 RandomAccessFile rf = new RandomAccessFile(file, "r"); | |
137 return new FileImageInputStream(rf); | |
138 } catch (IOException e) { | |
139 // what now? | |
140 } | |
141 return null; | |
142 } | |
143 | |
144 /* (non-Javadoc) | |
145 * @see digilib.io.ImageInput#hasFile() | |
146 */ | |
147 @Override | |
148 public boolean hasFile() { | |
149 return true; | |
150 } | |
151 | |
152 /* (non-Javadoc) | |
153 * @see digilib.io.ImageInput#getFile() | |
159 | 154 */ |
155 public File getFile() { | |
583 | 156 return file; |
159 | 157 } |
158 | |
566 | 159 /* (non-Javadoc) |
568 | 160 * @see digilib.io.ImageInput#setSize(digilib.image.ImageSize) |
159 | 161 */ |
568 | 162 public void setSize(ImageSize imageSize) { |
163 this.pixelSize = imageSize; | |
164 // pass on to parent | |
165 if (this.parent != null) { | |
166 this.parent.setAspect(imageSize); | |
167 } | |
566 | 168 } |
579
efd7a223f819
try: ImageInput as interface, ImageFile inherits from Dirent and implements ImageInput
robcast
parents:
574
diff
changeset
|
169 |
efd7a223f819
try: ImageInput as interface, ImageFile inherits from Dirent and implements ImageInput
robcast
parents:
574
diff
changeset
|
170 /* (non-Javadoc) |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
171 * @see java.lang.Object#toString() |
579
efd7a223f819
try: ImageInput as interface, ImageFile inherits from Dirent and implements ImageInput
robcast
parents:
574
diff
changeset
|
172 */ |
efd7a223f819
try: ImageInput as interface, ImageFile inherits from Dirent and implements ImageInput
robcast
parents:
574
diff
changeset
|
173 @Override |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
174 public String toString() { |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
175 // try to use File.toString |
583 | 176 if (file != null) { |
177 return file.toString(); | |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
178 } |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
179 return super.toString(); |
579
efd7a223f819
try: ImageInput as interface, ImageFile inherits from Dirent and implements ImageInput
robcast
parents:
574
diff
changeset
|
180 } |
efd7a223f819
try: ImageInput as interface, ImageFile inherits from Dirent and implements ImageInput
robcast
parents:
574
diff
changeset
|
181 |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
182 |
159 | 183 } |