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