53 |
Mediaserver ms; |
Mediaserver ms; |
54 |
Mediaserver.Id id; |
Mediaserver.Id id; |
55 |
|
|
|
Image[] pageimages; |
|
|
|
|
|
|
|
56 |
public String getID() { return id.getString(); } |
public String getID() { return id.getString(); } |
57 |
public Mediaserver.Id saveOrGetId(Mediaserver ms) { return id; } |
public Mediaserver.Id saveOrGetId(Mediaserver ms) { return id; } |
58 |
|
|
64 |
public int hashCode() { |
public int hashCode() { |
65 |
return getID().hashCode(); |
return getID().hashCode(); |
66 |
} |
} |
|
|
|
|
private Image getPageImage(int page) { |
|
|
if(pageimages == null) |
|
|
pageimages = new Image[pages]; |
|
|
if(pageimages[page] == null) |
|
|
try { |
|
|
pageimages[page] = |
|
|
GlobalToolkit.toolkit.getImage(kludgeFilename(page)); |
|
|
} catch (Exception _) { |
|
|
pa("Exception when loading image: "+_); |
|
|
} |
|
|
return pageimages[page]; |
|
|
} |
|
|
|
|
67 |
// Mediaserver.Block block; |
// Mediaserver.Block block; |
68 |
|
|
69 |
public PageImageScroll(Mediaserver ms, Mediaserver.Id id) { |
public PageImageScroll(Mediaserver ms, Mediaserver.Id id) { |
73 |
checkLen(); |
checkLen(); |
74 |
} |
} |
75 |
|
|
76 |
/** 0-based page. |
/** Return the image file name for the given, 0-based page. |
77 |
*/ |
*/ |
78 |
protected String kludgeFilename(int page) { |
public String imageFilename(int page) { |
79 |
return new String(DIR+getID()+"-"+RESOLUTION+"-"+(page+1)); |
return new String(DIR+getID()+"-"+RESOLUTION+"-"+(page+1)); |
80 |
} |
} |
81 |
|
|
82 |
public void checkLen() { |
private void checkLen() { |
83 |
int i=0; |
int i=0; |
84 |
while(new File(kludgeFilename(i)).exists()) |
while(new File(imageFilename(i)).exists()) |
85 |
i++; |
i++; |
86 |
pages = i; |
pages = i; |
87 |
pa("Checked document of "+i+" pages"); |
pa("Checked document of "+i+" pages"); |
88 |
} |
} |
89 |
|
|
90 |
class SimplePageSpan extends ScrollBlockManager.PageSpanBase implements Runnable { |
public Span getCurrent() { |
91 |
|
return new SimplePageSpan(0, pages, 0, 0, WIDTH, HEIGHT); |
92 |
|
} |
93 |
|
|
94 |
|
public Span getSpan(int p0, int p1, int x, int y, int w, int h) { |
95 |
|
return new SimplePageSpan(p0, p1, x, y, w, h); |
96 |
|
} |
97 |
|
|
98 |
|
|
99 |
|
public boolean isFinalized() { return true; } |
100 |
|
|
101 |
|
// ----- Spans --- |
102 |
|
|
103 |
|
class SimplePageSpan extends ScrollBlockManager.PageSpanBase { |
104 |
SimplePageSpan(int p0, int p1, int x, int y, int w, int h) { |
SimplePageSpan(int p0, int p1, int x, int y, int w, int h) { |
105 |
super(PageImageScroll.this, p0, p1, x, y, w, h); |
super(PageImageScroll.this, p0, p1, x, y, w, h); |
106 |
} |
} |
110 |
return new SimplePageSpan(p0, p1, x, y, w, h); |
return new SimplePageSpan(p0, p1, x, y, w, h); |
111 |
} |
} |
112 |
|
|
|
Image cached; |
|
|
|
|
|
Image loadImage() { |
|
|
if(pages == 0) return null; // Don't even try if no pages avail. |
|
|
Image img = getPageImage(offs0); |
|
|
|
|
|
if(img==null) |
|
|
throw new Error("Couldn't load image from file "+kludgeFilename(offs0)); |
|
|
int count = 0; |
|
|
while(img.getWidth(null) < 0 || img.getHeight(null) < 0) { |
|
|
try { |
|
|
count++; |
|
|
if(count > 100) |
|
|
throw new Error("Timeout while loading file "+kludgeFilename(offs0)); |
|
|
Thread.sleep(200); |
|
|
} catch(InterruptedException e) { |
|
|
throw new Error("Interrupted"); |
|
|
} |
|
|
} |
|
|
pa("Returning image"); |
|
|
return img; |
|
|
} |
|
|
|
|
113 |
public Image getImage() { |
public Image getImage() { |
114 |
if(cached != null) return cached; |
throw new UnsupportedOperationException("Use gzz.client to create image"); |
|
if(length() != 1) |
|
|
// return null; |
|
|
throw new ZZError("Must have only one page to show..."); |
|
|
run(); |
|
|
return cached; |
|
|
// XXX |
|
|
// Background.addTask(SimplePageSpan.this); |
|
|
// p("GetImage returning null!!!!!"); |
|
|
// return null; |
|
|
} |
|
|
|
|
|
public void run() { |
|
|
p("Running page: "+cached); |
|
|
if(cached != null) return; |
|
|
cached = loadImage(); |
|
|
p("Loaded image: "+cached); |
|
|
|
|
|
if(x==0 && y==0 && w==WIDTH && h==HEIGHT) |
|
|
return; |
|
|
|
|
|
ImageFilter filter = new CropImageFilter(x,y,w,h); |
|
|
cached = GlobalToolkit.toolkit.createImage |
|
|
(new FilteredImageSource(cached.getSource(), filter)); |
|
|
p("Cropped image: "+cached); |
|
115 |
} |
} |
116 |
} |
} |
117 |
|
|
|
public Span getCurrent() { |
|
|
return new SimplePageSpan(0, pages, 0, 0, WIDTH, HEIGHT); |
|
|
} |
|
118 |
|
|
|
public Span getSpan(int p0, int p1, int x, int y, int w, int h) { |
|
|
return new SimplePageSpan(p0, p1, x, y, w, h); |
|
|
} |
|
|
|
|
|
|
|
|
public boolean isFinalized() { return true; } |
|
119 |
} |
} |
120 |
|
|
121 |
|
|