Mercurial > hg > digilib-old
annotate servlet/src/digilib/io/ImageFile.java @ 588:aee436f0549d stream
more work on stream input
author | robcast |
---|---|
date | Thu, 06 Jan 2011 14:37:50 +0100 |
parents | 95417c4615b8 |
children | 69bc69381ac4 |
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; |
159 | 26 |
27 import digilib.image.ImageSize; | |
585 | 28 import digilib.servlet.DigilibConfiguration; |
159 | 29 |
30 /** | |
31 * @author casties | |
32 */ | |
568 | 33 public class ImageFile extends ImageInput { |
159 | 34 |
583 | 35 // file |
36 private File file = null; | |
159 | 37 // file name |
583 | 38 private String name = null; |
159 | 39 // parent directory |
40 private Directory dir = null; | |
41 | |
583 | 42 /** Constructor with File. |
43 * | |
44 * @param f | |
45 * @param parent | |
46 * @param dir | |
47 */ | |
48 public ImageFile(File f, ImageSet parent, Directory dir) { | |
49 this.file = f; | |
50 this.name = f.getName(); | |
159 | 51 this.parent = parent; |
52 this.dir = dir; | |
53 } | |
54 | |
583 | 55 /** Constructor with filename (without path). |
56 * @param fn | |
57 * @param parent | |
58 * @param dir | |
59 */ | |
60 public ImageFile(String fn, ImageSet parent, Directory dir) { | |
61 this.name = fn; | |
62 this.dir = dir; | |
63 this.file = new File(this.dir.getDir(), fn); | |
64 this.parent = parent; | |
159 | 65 } |
66 | |
585 | 67 |
68 /** Checks the image and sets size and type. | |
69 * | |
70 */ | |
71 public void check() { | |
72 if (pixelSize == null) { | |
73 try { | |
74 // use the configured toolkit to identify the image | |
75 DigilibConfiguration.identifyDocuImage(this); | |
76 } catch (IOException e) { | |
77 // nothing much to do... | |
78 } | |
79 } | |
80 } | |
81 | |
82 /* (non-Javadoc) | |
83 * @see digilib.io.ImageInput#getSize() | |
84 */ | |
85 @Override | |
86 public ImageSize getSize() { | |
87 check(); | |
88 return pixelSize; | |
89 } | |
90 | |
91 /* (non-Javadoc) | |
92 * @see digilib.io.ImageInput#getMimetype() | |
93 */ | |
94 @Override | |
95 public String getMimetype() { | |
96 check(); | |
97 return mimetype; | |
98 } | |
99 | |
100 /* (non-Javadoc) | |
101 * @see digilib.io.ImageInput#getAspect() | |
102 */ | |
103 @Override | |
104 public float getAspect() { | |
105 check(); | |
106 return (pixelSize != null) ? pixelSize.getAspect() : 0f; | |
107 } | |
108 | |
109 /** Returns the file name (without path). | |
159 | 110 * |
111 * @return | |
112 */ | |
113 public String getName() { | |
583 | 114 return name; |
159 | 115 } |
116 | |
117 /** | |
118 * @return File | |
119 */ | |
120 public File getFile() { | |
583 | 121 return file; |
159 | 122 } |
123 | |
566 | 124 /* (non-Javadoc) |
568 | 125 * @see digilib.io.ImageInput#setSize(digilib.image.ImageSize) |
159 | 126 */ |
568 | 127 public void setSize(ImageSize imageSize) { |
128 this.pixelSize = imageSize; | |
129 // pass on to parent | |
130 if (this.parent != null) { | |
131 this.parent.setAspect(imageSize); | |
132 } | |
566 | 133 } |
134 | |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
135 /* (non-Javadoc) |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
136 * @see java.lang.Object#toString() |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
137 */ |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
138 @Override |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
139 public String toString() { |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
140 // try to use File.toString |
583 | 141 if (file != null) { |
142 return file.toString(); | |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
143 } |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
144 return super.toString(); |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
145 } |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
146 |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
147 |
159 | 148 } |