annotate servlet/src/digilib/io/ImageFileSet.java @ 576:dad720e9b12b stream

try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
author robcast
date Wed, 22 Dec 2010 20:19:06 +0100
parents
children 50bd3d9759f3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
576
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
1 /**
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
2 *
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
3 */
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
4 package digilib.io;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
5
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
6 import java.io.File;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
7 import java.util.ArrayList;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
8 import java.util.Arrays;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
9 import java.util.Map;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
10
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
11 import digilib.io.FileOps.FileClass;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
12
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
13 /**
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
14 * @author casties
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
15 *
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
16 */
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
17 public class ImageFileSet extends ImageSet implements DocuDirent {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
18
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
19 /** this is an image file */
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
20 protected static FileClass fileClass = FileClass.IMAGE;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
21 private Directory parent;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
22 private boolean metaChecked;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
23 private Map fileMeta;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
24
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
25 /**
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
26 * Constructor with a file and hints.
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
27 *
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
28 * The hints are expected to contain 'basedirs' and 'scaledfilext' keys.
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
29 *
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
30 * @param file
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
31 * @param hints
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
32 */
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
33 public ImageFileSet(File file, Map<Integer,Object> hints) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
34 Directory[] dirs = (Directory[]) hints.get(FileOps.HINT_BASEDIRS);
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
35 int nb = dirs.length;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
36 list = new ArrayList<ImageInput>(nb);
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
37 parent = dirs[0];
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
38 fill(dirs, file, hints);
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
39 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
40
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
41 /* (non-Javadoc)
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
42 * @see digilib.io.DocuDirent#getName()
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
43 */
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
44 @Override
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
45 public String getName() {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
46 // TODO Auto-generated method stub
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
47 return null;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
48 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
49
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
50 /* (non-Javadoc)
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
51 * @see digilib.io.DocuDirent#getParent()
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
52 */
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
53 @Override
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
54 public Directory getParent() {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
55 // TODO Auto-generated method stub
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
56 return null;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
57 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
58
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
59 /* (non-Javadoc)
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
60 * @see digilib.io.DocuDirent#setParent(digilib.io.Directory)
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
61 */
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
62 @Override
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
63 public void setParent(Directory parent) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
64 // TODO Auto-generated method stub
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
65
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
66 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
67
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
68 /* (non-Javadoc)
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
69 * @see digilib.io.DocuDirent#getFileMeta()
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
70 */
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
71 @Override
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
72 public MetadataMap getFileMeta() {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
73 // TODO Auto-generated method stub
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
74 return null;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
75 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
76
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
77 /* (non-Javadoc)
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
78 * @see digilib.io.DocuDirent#setFileMeta(digilib.io.MetadataMap)
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
79 */
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
80 @Override
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
81 public void setFileMeta(MetadataMap fileMeta) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
82 // TODO Auto-generated method stub
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
83
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
84 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
85
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
86 /* (non-Javadoc)
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
87 * @see digilib.io.DocuDirent#isMetaChecked()
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
88 */
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
89 @Override
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
90 public boolean isMetaChecked() {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
91 // TODO Auto-generated method stub
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
92 return false;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
93 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
94
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
95 /* (non-Javadoc)
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
96 * @see digilib.io.DocuDirent#compareTo(java.lang.Object)
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
97 */
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
98 @Override
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
99 public int compareTo(Object arg0) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
100 // TODO Auto-generated method stub
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
101 return 0;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
102 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
103
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
104 @Override
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
105 public File getInput() {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
106 // TODO Auto-generated method stub
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
107 return null;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
108 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
109
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
110 /**
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
111 * Adds an ImageFile to this Fileset.
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
112 *
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
113 * The files should be added in the order of higher to lower resolutions.
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
114 * The first file is considered the hires "original".
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
115 *
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
116 *
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
117 * @param f
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
118 * file to add
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
119 * @return true (always)
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
120 */
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
121 public boolean add(ImageFile f) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
122 f.setParent(this);
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
123 return list.add(f);
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
124 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
125
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
126 /**
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
127 * Fill the ImageSet with files from different base directories.
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
128 *
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
129 *
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
130 * @param dirs
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
131 * list of base directories
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
132 * @param fl
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
133 * file (from first base dir)
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
134 * @param hints
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
135 *
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
136 */
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
137 void fill(Directory[] dirs, File fl, Map<Integer,Object> hints) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
138 int nb = dirs.length;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
139 String fn = fl.getName();
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
140 String baseFn = FileOps.basename(fn);
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
141 // add the first ImageFile to the ImageSet
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
142 add(new ImageFile(fn, this, parent));
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
143 // iterate the remaining base directories
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
144 for (int dirIdx = 1; dirIdx < nb; dirIdx++) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
145 if (dirs[dirIdx] == null) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
146 continue;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
147 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
148 // read the directory
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
149 if (dirs[dirIdx].getFilenames() == null) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
150 dirs[dirIdx].readDir();
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
151 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
152 String[] dirFiles = dirs[dirIdx].getFilenames();
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
153 // try the same filename as the original
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
154 int fileIdx = Arrays.binarySearch(dirFiles, fn);
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
155 if (fileIdx < 0) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
156 // try closest matches without extension
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
157 fileIdx = -fileIdx - 1;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
158 // try idx
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
159 if ((fileIdx < dirFiles.length)
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
160 && (FileOps.basename(dirFiles[fileIdx]).equals(baseFn))) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
161 // idx ok
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
162 } else if ((fileIdx > 0)
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
163 && (FileOps.basename(dirFiles[fileIdx - 1])
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
164 .equals(baseFn))) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
165 // idx-1 ok
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
166 fileIdx = fileIdx - 1;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
167 } else if ((fileIdx+1 < dirFiles.length)
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
168 && (FileOps.basename(dirFiles[fileIdx + 1])
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
169 .equals(baseFn))) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
170 // idx+1 ok
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
171 fileIdx = fileIdx + 1;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
172 } else {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
173 // basename doesn't match
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
174 continue;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
175 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
176 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
177 if (FileOps.classForFilename(dirFiles[fileIdx]) == fileClass) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
178 /* logger.debug("adding file " + dirFiles[fileIdx]
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
179 + " to Fileset " + this.getName()); */
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
180 add(new ImageFile(dirFiles[fileIdx], this, dirs[dirIdx]));
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
181 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
182 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
183 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
184
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
185 /**
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
186 * Checks metadata and sets resolution in resX and resY.
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
187 *
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
188 */
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
189 public void checkMeta() {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
190 if (metaChecked) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
191 return;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
192 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
193 if (fileMeta == null) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
194 // try to read metadata file
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
195 readMeta();
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
196 if (fileMeta == null) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
197 // try directory metadata
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
198 ((DocuDirectory) parent).checkMeta();
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
199 if (((DocuDirectory) parent).getDirMeta() != null) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
200 fileMeta = ((DocuDirectory) parent).getDirMeta();
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
201 } else {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
202 // try parent directory metadata
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
203 DocuDirectory gp = (DocuDirectory) parent.getParent();
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
204 if (gp != null) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
205 gp.checkMeta();
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
206 if (gp.getDirMeta() != null) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
207 fileMeta = gp.getDirMeta();
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
208 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
209 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
210 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
211 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
212 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
213 if (fileMeta == null) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
214 // no metadata available
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
215 metaChecked = true;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
216 return;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
217 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
218 metaChecked = true;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
219 float dpi = 0;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
220 float dpix = 0;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
221 float dpiy = 0;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
222 float sizex = 0;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
223 float sizey = 0;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
224 float pixx = 0;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
225 float pixy = 0;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
226 // DPI is valid for X and Y
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
227 if (fileMeta.containsKey("original-dpi")) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
228 try {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
229 dpi = Float.parseFloat((String) fileMeta.get("original-dpi"));
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
230 } catch (NumberFormatException e) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
231 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
232 if (dpi != 0) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
233 resX = dpi;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
234 resY = dpi;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
235 return;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
236 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
237 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
238 // DPI-X and DPI-Y
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
239 if (fileMeta.containsKey("original-dpi-x")
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
240 && fileMeta.containsKey("original-dpi-y")) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
241 try {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
242 dpix = Float.parseFloat((String) fileMeta
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
243 .get("original-dpi-x"));
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
244 dpiy = Float.parseFloat((String) fileMeta
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
245 .get("original-dpi-y"));
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
246 } catch (NumberFormatException e) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
247 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
248 if ((dpix != 0) && (dpiy != 0)) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
249 resX = dpix;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
250 resY = dpiy;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
251 return;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
252 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
253 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
254 // SIZE-X and SIZE-Y and PIXEL-X and PIXEL-Y
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
255 if (fileMeta.containsKey("original-size-x")
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
256 && fileMeta.containsKey("original-size-y")
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
257 && fileMeta.containsKey("original-pixel-x")
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
258 && fileMeta.containsKey("original-pixel-y")) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
259 try {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
260 sizex = Float.parseFloat((String) fileMeta
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
261 .get("original-size-x"));
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
262 sizey = Float.parseFloat((String) fileMeta
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
263 .get("original-size-y"));
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
264 pixx = Float.parseFloat((String) fileMeta
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
265 .get("original-pixel-x"));
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
266 pixy = Float.parseFloat((String) fileMeta
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
267 .get("original-pixel-y"));
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
268 } catch (NumberFormatException e) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
269 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
270 if ((sizex != 0) && (sizey != 0) && (pixx != 0) && (pixy != 0)) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
271 resX = pixx / (sizex * 100 / 2.54f);
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
272 resY = pixy / (sizey * 100 / 2.54f);
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
273 return;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
274 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
275 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
276 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
277
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
278 public void readMeta() {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
279 // TODO Auto-generated method stub
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
280
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
281 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
282
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
283 }