annotate servlet/src/digilib/io/ImageFileSet.java @ 580:50bd3d9759f3 stream

small cleanup
author robcast
date Wed, 22 Dec 2010 20:39:09 +0100
parents dad720e9b12b
children bb8dfc05674f
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 public String getName() {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
45 // TODO Auto-generated method stub
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
46 return null;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
47 }
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 /* (non-Javadoc)
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
50 * @see digilib.io.DocuDirent#getParent()
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
51 */
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
52 public Directory getParent() {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
53 // TODO Auto-generated method stub
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
54 return null;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
55 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
56
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
57 /* (non-Javadoc)
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
58 * @see digilib.io.DocuDirent#setParent(digilib.io.Directory)
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
59 */
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
60 public void setParent(Directory parent) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
61 // TODO Auto-generated method stub
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
62
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
63 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
64
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
65 /* (non-Javadoc)
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
66 * @see digilib.io.DocuDirent#getFileMeta()
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 public MetadataMap getFileMeta() {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
69 // TODO Auto-generated method stub
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
70 return null;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
71 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
72
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
73 /* (non-Javadoc)
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
74 * @see digilib.io.DocuDirent#setFileMeta(digilib.io.MetadataMap)
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 public void setFileMeta(MetadataMap fileMeta) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
77 // TODO Auto-generated method stub
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
78
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
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
81 /* (non-Javadoc)
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
82 * @see digilib.io.DocuDirent#isMetaChecked()
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 public boolean isMetaChecked() {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
85 // TODO Auto-generated method stub
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
86 return false;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
87 }
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 /* (non-Javadoc)
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
90 * @see digilib.io.DocuDirent#compareTo(java.lang.Object)
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
91 */
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
92 public int compareTo(Object arg0) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
93 // TODO Auto-generated method stub
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
94 return 0;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
95 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
96
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
97 public File getInput() {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
98 // TODO Auto-generated method stub
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
99 return null;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
100 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
101
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 * Adds an ImageFile to this Fileset.
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
104 *
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
105 * 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
106 * The first file is considered the hires "original".
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
107 *
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 * @param f
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
110 * file to add
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
111 * @return true (always)
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 public boolean add(ImageFile f) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
114 f.setParent(this);
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
115 return list.add(f);
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
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
118 /**
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
119 * 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
120 *
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
121 *
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
122 * @param dirs
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
123 * list of base directories
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
124 * @param fl
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
125 * file (from first base dir)
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
126 * @param hints
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
127 *
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 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
130 int nb = dirs.length;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
131 String fn = fl.getName();
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
132 String baseFn = FileOps.basename(fn);
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
133 // add the first ImageFile to the ImageSet
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
134 add(new ImageFile(fn, this, parent));
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
135 // iterate the remaining base directories
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
136 for (int dirIdx = 1; dirIdx < nb; dirIdx++) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
137 if (dirs[dirIdx] == null) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
138 continue;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
139 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
140 // read the directory
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
141 if (dirs[dirIdx].getFilenames() == null) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
142 dirs[dirIdx].readDir();
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
143 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
144 String[] dirFiles = dirs[dirIdx].getFilenames();
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
145 // try the same filename as the original
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
146 int fileIdx = Arrays.binarySearch(dirFiles, fn);
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
147 if (fileIdx < 0) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
148 // try closest matches without extension
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
149 fileIdx = -fileIdx - 1;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
150 // try idx
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
151 if ((fileIdx < dirFiles.length)
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
152 && (FileOps.basename(dirFiles[fileIdx]).equals(baseFn))) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
153 // idx ok
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
154 } else if ((fileIdx > 0)
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
155 && (FileOps.basename(dirFiles[fileIdx - 1])
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
156 .equals(baseFn))) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
157 // idx-1 ok
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
158 fileIdx = fileIdx - 1;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
159 } else if ((fileIdx+1 < dirFiles.length)
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
160 && (FileOps.basename(dirFiles[fileIdx + 1])
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
161 .equals(baseFn))) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
162 // idx+1 ok
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
163 fileIdx = fileIdx + 1;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
164 } else {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
165 // basename doesn't match
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
166 continue;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
167 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
168 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
169 if (FileOps.classForFilename(dirFiles[fileIdx]) == fileClass) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
170 /* logger.debug("adding file " + dirFiles[fileIdx]
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
171 + " to Fileset " + this.getName()); */
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
172 add(new ImageFile(dirFiles[fileIdx], this, dirs[dirIdx]));
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
173 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
174 }
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 /**
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
178 * 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
179 *
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
180 */
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
181 public void checkMeta() {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
182 if (metaChecked) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
183 return;
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 if (fileMeta == null) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
186 // try to read metadata file
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
187 readMeta();
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
188 if (fileMeta == null) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
189 // try directory metadata
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
190 ((DocuDirectory) parent).checkMeta();
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
191 if (((DocuDirectory) parent).getDirMeta() != null) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
192 fileMeta = ((DocuDirectory) parent).getDirMeta();
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
193 } else {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
194 // try parent directory metadata
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
195 DocuDirectory gp = (DocuDirectory) parent.getParent();
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
196 if (gp != null) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
197 gp.checkMeta();
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
198 if (gp.getDirMeta() != null) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
199 fileMeta = gp.getDirMeta();
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
200 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
201 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
202 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
203 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
204 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
205 if (fileMeta == null) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
206 // no metadata available
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
207 metaChecked = true;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
208 return;
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 metaChecked = true;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
211 float dpi = 0;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
212 float dpix = 0;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
213 float dpiy = 0;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
214 float sizex = 0;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
215 float sizey = 0;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
216 float pixx = 0;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
217 float pixy = 0;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
218 // DPI is valid for X and Y
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
219 if (fileMeta.containsKey("original-dpi")) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
220 try {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
221 dpi = Float.parseFloat((String) fileMeta.get("original-dpi"));
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
222 } catch (NumberFormatException e) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
223 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
224 if (dpi != 0) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
225 resX = dpi;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
226 resY = dpi;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
227 return;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
228 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
229 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
230 // DPI-X and DPI-Y
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
231 if (fileMeta.containsKey("original-dpi-x")
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
232 && fileMeta.containsKey("original-dpi-y")) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
233 try {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
234 dpix = Float.parseFloat((String) fileMeta
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
235 .get("original-dpi-x"));
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
236 dpiy = Float.parseFloat((String) fileMeta
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
237 .get("original-dpi-y"));
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
238 } catch (NumberFormatException e) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
239 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
240 if ((dpix != 0) && (dpiy != 0)) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
241 resX = dpix;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
242 resY = dpiy;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
243 return;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
244 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
245 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
246 // 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
247 if (fileMeta.containsKey("original-size-x")
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
248 && fileMeta.containsKey("original-size-y")
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
249 && fileMeta.containsKey("original-pixel-x")
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
250 && fileMeta.containsKey("original-pixel-y")) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
251 try {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
252 sizex = Float.parseFloat((String) fileMeta
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
253 .get("original-size-x"));
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
254 sizey = Float.parseFloat((String) fileMeta
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
255 .get("original-size-y"));
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
256 pixx = Float.parseFloat((String) fileMeta
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
257 .get("original-pixel-x"));
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
258 pixy = Float.parseFloat((String) fileMeta
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
259 .get("original-pixel-y"));
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
260 } catch (NumberFormatException e) {
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
261 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
262 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
263 resX = pixx / (sizex * 100 / 2.54f);
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
264 resY = pixy / (sizey * 100 / 2.54f);
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
265 return;
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
266 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
267 }
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
268 }
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 public void readMeta() {
580
50bd3d9759f3 small cleanup
robcast
parents: 576
diff changeset
271 // FIXME: what to do?
576
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
272
dad720e9b12b try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff changeset
273 }
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 }