[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gzz-commits] alph/org/nongnu/alph PageSpan.java impl/PageIma...
From: |
Tuomas J. Lukka |
Subject: |
[Gzz-commits] alph/org/nongnu/alph PageSpan.java impl/PageIma... |
Date: |
Mon, 21 Apr 2003 14:50:36 -0400 |
CVSROOT: /cvsroot/alph
Module name: alph
Changes by: Tuomas J. Lukka <address@hidden> 03/04/21 14:50:35
Modified files:
org/nongnu/alph: PageSpan.java
org/nongnu/alph/impl: PageImageScroll.java
PermanentTextScroll.java
ScrollBlockManager.java
SimpleImageScroll.java
TransientTextScroll.java
Added files:
org/nongnu/alph: PageScrollBlock.java
org/nongnu/alph/impl: AbstractImageSpan.java AbstractSpan.java
AbstractSpan1D.java StdPageSpan.java
StdTextSpan.java
Log message:
More refactoring
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/alph/alph/org/nongnu/alph/PageScrollBlock.java?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/alph/alph/org/nongnu/alph/PageSpan.java.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/alph/alph/org/nongnu/alph/impl/AbstractImageSpan.java?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/alph/alph/org/nongnu/alph/impl/AbstractSpan.java?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/alph/alph/org/nongnu/alph/impl/AbstractSpan1D.java?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/alph/alph/org/nongnu/alph/impl/StdPageSpan.java?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/alph/alph/org/nongnu/alph/impl/StdTextSpan.java?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/alph/alph/org/nongnu/alph/impl/PageImageScroll.java.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/alph/alph/org/nongnu/alph/impl/PermanentTextScroll.java.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/alph/alph/org/nongnu/alph/impl/ScrollBlockManager.java.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/alph/alph/org/nongnu/alph/impl/SimpleImageScroll.java.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/alph/alph/org/nongnu/alph/impl/TransientTextScroll.java.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
Patches:
Index: alph/org/nongnu/alph/PageSpan.java
diff -u alph/org/nongnu/alph/PageSpan.java:1.2
alph/org/nongnu/alph/PageSpan.java:1.3
--- alph/org/nongnu/alph/PageSpan.java:1.2 Tue Mar 25 07:25:29 2003
+++ alph/org/nongnu/alph/PageSpan.java Mon Apr 21 14:50:35 2003
@@ -31,23 +31,17 @@
import java.awt.*;
/** A page span - contiguous piece of a permascroll consisting of
- * pages of the same size - e.g.postscript or pdf file.
- * These spans are rectangular regions of one or more pages.
- * <p>
- * ImageSpan.getImage should return the image of a page when a single
- * page is in the span, calling getImage for a PageSpan of more than one
- * page is currently undefined (!!), waiting for a decision between showing
- * the first page, the first page in a graphical representation showing
- * a stack of pages, some type of splicing of the pages or whatever.
- * It is also possible that it will be decided that an IllegalArgumentException
- * should be thrown in this case.
+ * pages - e.g.postscript or pdf file.
+ * These spans are regions of one or more pages.
+ * It used to be possible to also specify an area here - not any
+ * more: now, you can either have a pagespan of pages, or an imagespan
+ * of an area on one page.
*/
-public interface PageSpan extends ImageSpan, Span1D {
- /** Get a subspan of the current span.
- * The coordinates are <b>relative to this span</b>.
+public interface PageSpan extends Span1D {
+ /** Get the imagespan pointing to the given page
+ * of this span.
*/
- PageSpan subArea(int page0, int page1, int x, int y, int w, int h);
- PageSpan subArea(int page0, int page1);
+ ImageSpan getPage(int ind);
}
Index: alph/org/nongnu/alph/impl/PageImageScroll.java
diff -u alph/org/nongnu/alph/impl/PageImageScroll.java:1.5
alph/org/nongnu/alph/impl/PageImageScroll.java:1.6
--- alph/org/nongnu/alph/impl/PageImageScroll.java:1.5 Mon Apr 21 12:31:23 2003
+++ alph/org/nongnu/alph/impl/PageImageScroll.java Mon Apr 21 14:50:35 2003
@@ -38,8 +38,8 @@
/** An scrollblock containing paged media (PS/PDF).
*/
-public class PageImageScroll extends AbstractScrollBlock {
-String rcsid = "$Id: PageImageScroll.java,v 1.5 2003/04/21 16:31:23 tjl Exp $";
+public class PageImageScroll extends AbstractScrollBlock implements
PageScrollBlock{
+String rcsid = "$Id: PageImageScroll.java,v 1.6 2003/04/21 18:50:35 tjl Exp $";
public static boolean dbg = true;
final static void p(String s) { if(dbg) System.out.println(s); }
final static void pa(String s) { System.out.println(s); }
@@ -105,30 +105,35 @@
}
public Span getCurrent() {
- return new SimplePageSpan(0, pages, 0, 0, WIDTH, HEIGHT);
+ return new StdPageSpan(this, 0, pages);
}
-
- 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 Span getSpan(int p0, int p1) {
+ return new StdPageSpan(this, p0, p1);
}
+ private static class PageImageSpan extends AbstractImageSpan {
+ int page;
- // ----- Spans ---
-
- class SimplePageSpan extends ScrollBlockManager.PageSpanBase {
- SimplePageSpan(int p0, int p1, int x, int y, int w, int h) {
- super(PageImageScroll.this, p0, p1, x, y, w, h);
+ protected AbstractImageSpan
+ createNew(int x, int y, int w, int h) {
+ return new PageImageSpan(scrollBlock, page, x, y, w, h);
}
+ public PageImageSpan(ScrollBlock sb, int page, int x, int y, int w, int
h) {
+ super(sb, x, y, w, h);
+ this.page = page;
- protected ScrollBlockManager.PageSpanBase
- createNew(int p0, int p1, int x, int y, int w, int h) {
- return new SimplePageSpan(p0, p1, x, y, w, h);
}
+ }
- public Image getImage() {
- throw new UnsupportedOperationException("Use gzz.client to create
image");
- }
+ public ImageSpan getPage(int p) {
+ return new PageImageSpan(this, p, 0, 0, WIDTH, HEIGHT);
+ }
+
+ /*
+ public Span getSpan(int p0, int p1, int x, int y, int w, int h) {
+ return new StdPageSpan(p0, p1, x, y, w, h);
}
+ */
}
Index: alph/org/nongnu/alph/impl/PermanentTextScroll.java
diff -u alph/org/nongnu/alph/impl/PermanentTextScroll.java:1.4
alph/org/nongnu/alph/impl/PermanentTextScroll.java:1.5
--- alph/org/nongnu/alph/impl/PermanentTextScroll.java:1.4 Mon Apr 21
12:31:23 2003
+++ alph/org/nongnu/alph/impl/PermanentTextScroll.java Mon Apr 21 14:50:35 2003
@@ -38,7 +38,7 @@
public class PermanentTextScroll extends AbstractScrollBlock
implements TextScrollBlock
{
-String rcsid = "$Id: PermanentTextScroll.java,v 1.4 2003/04/21 16:31:23 tjl
Exp $";
+String rcsid = "$Id: PermanentTextScroll.java,v 1.5 2003/04/21 18:50:35 tjl
Exp $";
char[] chars;
boolean loadingFailed;
@@ -92,11 +92,11 @@
public Span getCurrent() {
load();
- return new ScrollBlockManager.SimpleTextSpan(this, 0, chars.length);
+ return new StdTextSpan(this, 0, chars.length);
}
public Span getSpan(int offs1, int offs2) {
- return new ScrollBlockManager.SimpleTextSpan(this, offs1, offs2);
+ return new StdTextSpan(this, offs1, offs2);
}
Index: alph/org/nongnu/alph/impl/ScrollBlockManager.java
diff -u alph/org/nongnu/alph/impl/ScrollBlockManager.java:1.6
alph/org/nongnu/alph/impl/ScrollBlockManager.java:1.7
--- alph/org/nongnu/alph/impl/ScrollBlockManager.java:1.6 Mon Apr 21
12:31:23 2003
+++ alph/org/nongnu/alph/impl/ScrollBlockManager.java Mon Apr 21 14:50:35 2003
@@ -41,9 +41,8 @@
*/
public class ScrollBlockManager {
-String rcsid = "$Id: ScrollBlockManager.java,v 1.6 2003/04/21 16:31:23 tjl Exp
$";
+String rcsid = "$Id: ScrollBlockManager.java,v 1.7 2003/04/21 18:50:35 tjl Exp
$";
public static boolean dbg = false;
- final static void p(String s) { if(dbg) System.out.println(s); }
final static void pa(String s) { System.out.println(s); }
/** A scrollblock that is associated with a Mediaserver block.
@@ -53,307 +52,6 @@
BlockId saveOrGetId(StormPool ms) throws java.io.IOException;
}
- /** A base class for physical spans that belong to one
- * particular scrollblock.
- */
- static abstract public class SpanBase implements Span,
- java.io.Serializable {
- transient ScrollBlock sb;
- SpanBase(ScrollBlock sb) { this.sb = sb; }
- public ScrollBlock getScrollBlock() { return sb; }
- public String getScrollId() { return sb.getID(); }
-
- private void writeObject(java.io.ObjectOutputStream out)
- throws java.io.IOException {
- // if(!(out instanceof MediaOutputStream))
- throw new java.io.NotSerializableException(
- "No MediaOutputStream given for serializing span");
-
- //Mediaserver ms = ((MediaOutputStream)out).getMediaserver();
- //out.writeObject(sb.saveOrGetId(ms));
- }
-
- private void readObject(java.io.ObjectInputStream in)
- throws java.io.IOException,
- java.io.NotSerializableException,
- java.lang.ClassNotFoundException {
- //if(!(in instanceof MediaInputStream))
- throw new java.io.NotSerializableException(
- "No MediaInputStream given for deserializing span");
-
- //Mediaserver ms = ((MediaInputStream)in).getMediaserver();
- //Mediaserver.Id blockId = (Mediaserver.Id)in.readObject();
- //this.sb = ScrollBlockManager.getScrollBlock(ms, blockId);
- }
- }
-
- /** A base class for 1-D spans.
- * Implements everything except the actual getText().
- */
- static abstract public class Span1DBase extends SpanBase
- implements Span1D,
- java.io.Serializable {
- protected int offs0, offs1;
-
- public int hashCode() {
- return offs0 ^ offs1 ^ sb.hashCode();
- }
-
- /** Create a new 1-D span, which starts at offs0 and
- * ends just before offs1 - analogous to String.substring.
- */
- protected Span1DBase(ScrollBlock sb, int offs0, int offs1) {
- super(sb);
- this.offs0 = offs0;
- this.offs1 = offs1;
- }
-
- public int offset() { return offs0; }
-
- public int length() { return offs1-offs0; }
-
- public Span1D subSpan(int o1, int o2) {
- if (dbg) pa("o1:"+o1+", o2:"+o2+", length"+length() +" -
"+toString());
- if(o1 < 0 ||
- o2 > length() ||
- o1 > o2)
- throw new IndexOutOfBoundsException();
- return createNew(offs0+o1, offs0+o2);
- }
-
- protected abstract Span1DBase createNew(int offs0, int offs1);
-
- public Span1D subSpan(int o1) {
- return subSpan(o1, length());
- }
-
- public int getRelativeStart(Span1D subspan) {
- Span1DBase sp = (Span1DBase)subspan;
- if(!sp.getScrollBlock().equals(this.getScrollBlock())
- || sp.offs0 < offs0 || sp.offs1 > offs1)
- throw new Error("subspan "+subspan+" not wholly contained "+
- " in this span, "+this);
- return sp.offs0 - offs0;
- }
-
- public int getRelativeEnd(Span1D subspan) {
- Span1DBase sp = (Span1DBase)subspan;
- if(!sp.getScrollBlock().equals(this.getScrollBlock())
- || sp.offs0 < offs0 || sp.offs1 > offs1)
- throw new Error("subspan "+subspan+" not wholly contained "+
- " in this span, "+this);
- return sp.offs1 - offs0;
- }
-
- public Span1D append(Span s) {
- if(!(s instanceof Span1DBase)) return null;
- Span1DBase sts = (Span1DBase)s;
- if(sts.getScrollBlock() != this.getScrollBlock()) return null;
- if(offs1 == sts.offs0)
- return createNew(offs0, sts.offs1);
- return null;
- }
-
- private Span1DBase isSame(Span s) {
- if(!(s instanceof Span1DBase)) return null;
- Span1DBase t = (Span1DBase)s;
- if(!this.getScrollBlock().equals(t.getScrollBlock())) return null;
- return t;
- }
-
- public boolean intersects(Span s) {
- Span1DBase t = isSame(s);
- if(t == null) return false;
- return (offs0 < t.offs1) && (offs1 > t.offs0);
- }
-
- public boolean intersectsAfter(Span s) {
- Span1DBase t = isSame(s);
- if(t == null) return false;
- return (offs0 < t.offs1);
- }
-
- public boolean intersectsBefore(Span s) {
- Span1DBase t = isSame(s);
- if(t == null) return false;
- return (offs1 > t.offs0);
- }
-
- public boolean equals(Object o) {
- if(!(o instanceof Span1DBase)) return false;
- Span1DBase s = (Span1DBase)o;
- return (s.getScrollBlock().equals(this.getScrollBlock())
- && s.offs0 == offs0 && s.offs1 == offs1);
- }
-
- public String toString() {
- return "SPAN1D("+sb+" "+offs0+" "+offs1+")";
- }
-
- }
-
- static public class SimpleTextSpan extends Span1DBase
- implements TextSpan, java.io.Serializable {
- SimpleTextSpan(TextScrollBlock sb, int offs0, int offs1) {
- super(sb, offs0, offs1);
- }
-
- protected ScrollBlockManager.Span1DBase
- createNew(int offs0, int offs1) {
- return new SimpleTextSpan((TextScrollBlock)sb, offs0, offs1);
- }
-
- public String getText() {
- TextScrollBlock sb = (TextScrollBlock)this.sb;
- return new String(sb.getCharArray(), offs0, offs1-offs0);
- }
- }
-
- /** A base class for image spans.
- */
- static abstract public class ImageSpanBase extends SpanBase
- implements ImageSpan {
- protected final int x, y, w, h;
- ImageSpanBase(ScrollBlock sb, int x, int y, int w, int h) {
- super(sb);
- this.x = x;
- this.y = y;
- this.w = w;
- this.h = h;
- }
- protected abstract ImageSpanBase
- createNew(int x, int y, int w, int h);
-
- public int hashCode() {
- return x ^ y ^ w ^ h ^ sb.hashCode();
- }
-
- public Dimension getSize() { return new Dimension(w, h); }
- public Point getLocation() { return new Point(x, y); }
- public ImageSpan subArea(int x0, int y0, int w0, int h0) {
- if(x0 < 0 || y0 < 0)
- throw new Error("Negative coordinates");
- if(x0 + w0 > w || y0 + h0 > h)
- throw new Error("Too large imagearea");
- return createNew(x+x0, y+y0, w0, h0);
- }
-
- private ImageSpanBase isSame(Object s) {
- if(!(s instanceof ImageSpanBase)) return null;
- ImageSpanBase t = (ImageSpanBase)s;
- if(!this.getScrollBlock().equals(t.getScrollBlock())) return null;
- return t;
- }
-
- public boolean intersects(Span s) {
- ImageSpanBase t = isSame(s);
- if(t==null) return false;
- return x < t.x + t.w && x + w > t.x &&
- y < t.y + t.h && y + h > t.y;
- }
-
- public boolean equals(Object o) {
- ImageSpanBase s = isSame(o);
- if(s == null) return false;
- return s.sb == sb &&
- s.x == x &&
- s.y == y &&
- s.w == w &&
- s.h == h;
- }
- }
-
- /** A base class for page spans. This duplicates ImageSpanBase
- * because Java doesn't allow multiple inheritance...
- */
- static abstract public class PageSpanBase extends Span1DBase
- implements PageSpan {
- protected final int x, y, w, h;
- PageSpanBase(ScrollBlock sb, int page0, int page1,
- int x, int y, int w, int h) {
- super(sb, page0, page1);
- this.x = x;
- this.y = y;
- this.w = w;
- this.h = h;
- }
- protected abstract PageSpanBase
- createNew(int page0, int page1, int x, int y, int w, int h);
-
- public int hashCode() {
- return x ^ y ^ w ^ h ^ super.hashCode();
- }
-
- protected Span1DBase createNew(int page0, int page1) {
- return createNew(page0, page1, this.x, this.y, this.w, this.h);
- }
- protected PageSpanBase createNew(int x, int y, int w, int h) {
- return createNew(this.offs0, this.offs1, x, y, w, h);
- }
-
- public Dimension getSize() { return new Dimension(w, h); }
- public Point getLocation() { return new Point(x, y); }
-
- public PageSpan subArea(int p0, int p1, int x0, int y0, int w0, int h0)
{
- if(p0 < 0 || p1 > length() || p0 > p1)
- throw new Error("Invalid pages");
- if(x0 < 0 || y0 < 0)
- throw new Error("Negative coordinates");
- if(x0 + w0 > w || y0 + h0 > h)
- throw new Error("Too large imagearea");
- return createNew(offs0 + p0, offs0+p1, x+x0, y+y0, w0, h0);
- }
- public PageSpan subArea(int p0, int p1) {
- return createNew(offs0 + p0, offs0+p1, x, y, w, h);
- }
-
- public ImageSpan subArea(int x0, int y0, int w0, int h0) {
- if(x0 < 0 || y0 < 0)
- throw new Error("Negative coordinates");
- if(x0 + w0 > w || y0 + h0 > h)
- throw new Error("Too large imagearea");
- return createNew(x+x0, y+y0, w0, h0);
- }
-
- private PageSpanBase isSamePS(Object s) {
- if(!(s instanceof PageSpanBase)) return null;
- PageSpanBase t = (PageSpanBase)s;
- if(!this.getScrollBlock().equals(t.getScrollBlock())) return null;
- return t;
- }
-
- public boolean intersects(Span s) {
- PageSpanBase t = isSamePS(s);
- if(t==null) return false;
- return super.intersects(s) &&
- x < t.x + t.w && x + w > t.x &&
- y < t.y + t.h && y + h > t.y;
- }
-
- public boolean equals(Object o) {
- PageSpanBase s = isSamePS(o);
- if(s == null) return false;
- return super.equals(o) &&
- //s.sb == sb &&
- s.x == x &&
- s.y == y &&
- s.w == w &&
- s.h == h;
- }
-
- public Span1D append(Span s) {
- if(!(s instanceof PageSpanBase)) return null;
- PageSpanBase sts = (PageSpanBase)s;
- if(sts.getScrollBlock() != this.getScrollBlock()) return null;
- if(offs1 != sts.offs0) return null;
- if(x != sts.x || y != sts.y || w != sts.w || h != sts.h) return
null;
- return createNew(offs0, sts.offs1);
- }
-
- }
-
-
-
/** Give an ordering of the given scrollblocks.
* @return 0 if equal, -1 if s1 < s2, 1 if s1 > s2.
*/
@@ -408,7 +106,8 @@
msCache.put(id, block);
}
*/
- return block.getSpan(p0, p1, x, y, w, h);
+// return block.getSpan(p0, p1, x, y, w, h);
+ return null;
}
/** We can use this if we know a specific scroll block is a text
@@ -473,7 +172,7 @@
static private ScrollBlock loadScrollBlock(StormPool ms,
BlockId id)
throws CannotLoadScrollBlockException {
- p("Loading scroll block: "+id);
+ if(dbg) pa("Loading scroll block: "+id);
Block block ;
String ct;
@@ -502,7 +201,7 @@
// return new SimpleImageScroll(ms, id);
} else if(ct.equals("application/postscript") ||
ct.equals("application/pdf")) {
- p("Loaded page image scroll block.");
+ if(dbg) pa("Loaded page image scroll block.");
// return new PageImageScroll(ms, id);
} else {
Index: alph/org/nongnu/alph/impl/SimpleImageScroll.java
diff -u alph/org/nongnu/alph/impl/SimpleImageScroll.java:1.4
alph/org/nongnu/alph/impl/SimpleImageScroll.java:1.5
--- alph/org/nongnu/alph/impl/SimpleImageScroll.java:1.4 Mon Apr 21
12:31:23 2003
+++ alph/org/nongnu/alph/impl/SimpleImageScroll.java Mon Apr 21 14:50:35 2003
@@ -39,7 +39,7 @@
*/
public class SimpleImageScroll extends AbstractScrollBlock {
-String rcsid = "$Id: SimpleImageScroll.java,v 1.4 2003/04/21 16:31:23 tjl Exp
$";
+String rcsid = "$Id: SimpleImageScroll.java,v 1.5 2003/04/21 18:50:35 tjl Exp
$";
int width=-1, height=-1;
@@ -85,12 +85,12 @@
this.height = d.height;
}
- class SimpleImageSpan extends ScrollBlockManager.ImageSpanBase {
+ class SimpleImageSpan extends AbstractImageSpan {
SimpleImageSpan(int x, int y, int w, int h) {
super(SimpleImageScroll.this, x, y, w, h);
}
- protected ScrollBlockManager.ImageSpanBase
+ protected AbstractImageSpan
createNew(int x, int y, int w, int h) {
return new SimpleImageSpan(x, y, w, h);
}
Index: alph/org/nongnu/alph/impl/TransientTextScroll.java
diff -u alph/org/nongnu/alph/impl/TransientTextScroll.java:1.4
alph/org/nongnu/alph/impl/TransientTextScroll.java:1.5
--- alph/org/nongnu/alph/impl/TransientTextScroll.java:1.4 Mon Apr 21
12:31:23 2003
+++ alph/org/nongnu/alph/impl/TransientTextScroll.java Mon Apr 21 14:50:35 2003
@@ -35,7 +35,7 @@
public class TransientTextScroll extends AbstractScrollBlock
implements TextScrollBlock, ScrollBlockManager.StormSaveableScrollBlock
{
-String rcsid = "$Id: TransientTextScroll.java,v 1.4 2003/04/21 16:31:23 tjl
Exp $";
+String rcsid = "$Id: TransientTextScroll.java,v 1.5 2003/04/21 18:50:35 tjl
Exp $";
public TransientTextScroll() {
super(null, null, "text/plain; charset=UTF-8");
@@ -69,7 +69,7 @@
if(finalized)
throw new ImmutableException("Already saved; can't append");
current.append(ch);
- return new ScrollBlockManager.SimpleTextSpan(this, current.length()-1,
current.length());
+ return new StdTextSpan(this, current.length()-1, current.length());
}
public TextSpan append(String s) throws ImmutableException {
@@ -77,16 +77,15 @@
throw new ImmutableException("Already saved; can't append");
int l = s.length();
current.append(s);
- return new ScrollBlockManager.SimpleTextSpan(this, current.length()-l,
current.length());
+ return new StdTextSpan(this, current.length()-l, current.length());
}
public Span getCurrent() {
- return new ScrollBlockManager.SimpleTextSpan(this, 0, current.length());
+ return new StdTextSpan(this, 0, current.length());
}
public Span getSpan(int offs1, int offs2) {
- return new ScrollBlockManager.SimpleTextSpan(
- this, offs1, offs2);
+ return new StdTextSpan(this, offs1, offs2);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gzz-commits] alph/org/nongnu/alph PageSpan.java impl/PageIma...,
Tuomas J. Lukka <=