/* PageImageSpan.java * * Copyright (c) 2001, Ted Nelson and Tuomas Lukka * * This file is part of Gzz. * * Gzz is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Gzz is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General * Public License for more details. * * You should have received a copy of the GNU Lesser General * Public License along with Gzz; if not, write to the Free * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * * */ /* * Written by Tuomas Lukka */ package org.nongnu.alph.impl; import org.nongnu.alph.*; import org.nongnu.storm.*; import java.awt.*; import java.awt.image.*; import java.io.*; import java.util.*; /** An scrollblock containing paged media (PS/PDF). */ public class PageImageScroll implements ScrollBlockManager.MediaserverScrollBlock { String rcsid = "$Id: PageImageScroll.java,v 1.1 2003/03/25 14:36:12 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); } int WIDTH=612; // Letter size fixed, for now, in points, 1/72ths of inches.. int HEIGHT=792; /** Resolution of the images to use. */ int RESOLUTION=170; // sigh String DIR="../mstmpimg/"; // XXX Non-platform-independent! int pages; Mediaserver ms; Mediaserver.Id id; public String getID() { return id.getString(); } public Mediaserver.Id saveOrGetId(Mediaserver ms) { return id; } public boolean equals(Object o) { if(!(o instanceof ScrollBlock)) return false; ScrollBlock sb = (ScrollBlock)o; return sb.getID().equals(getID()); } public int hashCode() { return getID().hashCode(); } // Mediaserver.Block block; public PageImageScroll(Mediaserver ms, Mediaserver.Id id) { this.ms = ms; this.id = id; checkLen(); } /** Return the image file name for the given, 0-based page. */ public String imageFilename(int page) { return new String(DIR+getID()+"-"+RESOLUTION+"-"+(page+1)); } /** The resolution of the images. */ public float imageFileResolution(int page) { return RESOLUTION; } /** The resolution of the coordinates on the original paper. */ public float coordinateResolution() { return 72; } private void checkLen() { int i=0; while(new File(imageFilename(i)).exists()) i++; pages = i; pa("Checked document of "+i+" pages"); } /** DO NOT USE EXCEPT WHEN CREATING FAKE PAGESPANS * FOR TESTS. */ public void forcelengthKLUDGE(int len) { pages = len; } public Span getCurrent() { return new SimplePageSpan(0, pages, 0, 0, WIDTH, HEIGHT); } 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; } // ----- 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 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"); } } }