//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ // \\ // Centre for Speech Technology Research \\ // University of Edinburgh, UK \\ // Copyright (c) 1996,1997 \\ // All Rights Reserved. \\ // Permission is hereby granted, free of charge, to use and distribute \\ // this software and its documentation without restriction, including \\ // without limitation the rights to use, copy, modify, merge, publish, \\ // distribute, sublicense, and/or sell copies of this work, and to \\ // permit persons to whom this work is furnished to do so, subject to \\ // the following conditions: \\ // 1. The code must retain the above copyright notice, this list of \\ // conditions and the following disclaimer. \\ // 2. Any modifications must be clearly marked as such. \\ // 3. Original authors' names are not deleted. \\ // 4. The authors' names are not used to endorse or promote products \\ // derived from this software without specific prior written \\ // permission. \\ // THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK \\ // DISCLAIM ALL WARRANTIES With REGARD TO THIS SOFTWARE, INCLUDING \\ // ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT \\ // SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE \\ // FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES \\ // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN \\ // AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, \\ // ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF \\ // THIS SOFTWARE. \\ // \\ //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ // \\ // Author: Richard Caley (rjc@cstr.ed.ac.uk) \\ // -------------------------------------------------------------------- \\ // An abstration which stands between a component and the AWT to cache \\ // the information painted in an array of images. \\ // \\ //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ package cstr.util ; import java.lang.*; import java.util.*; import java.awt.*; import java.awt.image.*; public class PaintCache { protected Image [] chunks; protected Thread [] threads; protected int chunkSize; protected int numChunks; protected Painter painter; protected Component comp; protected int width; protected int height; protected int running; protected int topPriority; Image dummy; public PaintCache(Component c, Painter p) { this(c, p, 400); } public PaintCache(Component c, Painter p, int cs) { comp=c; painter=p; chunkSize=cs; chunks=null; running=0; topPriority=Thread.currentThread().getPriority()-1; } protected void finalize() { if (threads!=null) for(int i=0; iThread.MIN_PRIORITY && p < op) //threads[ti].setPriority(p+1); if (p>max) { max=p; maxi=ti; } } if (maxi>=0) { // System.out.println("top="+maxi+"="+topPriority); threads[maxi].setPriority(topPriority); } // dumpP(); } } protected synchronized void checkChunk(int i, Graphics g) { if (i Thread.MIN_PRIORITY) // p= topPriority-1; p= Thread.MIN_PRIORITY+1; else p =Thread.MIN_PRIORITY; } else p = topPriority; // p = Thread.MAX_PRIORITY; if (p>=Thread.MIN_PRIORITY) t.setPriority(p); } } // dumpP(); } } } public void paint(Graphics g) { Rectangle r = g.getClipBounds(); int c1 = r.x / chunkSize; int cn = (r.x+r.width) / chunkSize; if (cn >= chunks.length) cn = chunks.length-1; if ( c1 == cn) { checkChunk(c1, g); int ix = r.x % chunkSize; g.drawImage(chunks[c1], r.x, r.y, r.x+r.width, r.y+r.height, ix, r.y, ix+r.width, r.y+r.height, comp); } else { int ix = r.x % chunkSize; int wx = r.x; int w = chunkSize - ix; checkChunk(c1, g); g.drawImage(chunks[c1], wx, r.y, wx+w, r.y+r.height, ix, r.y, ix+w, r.y+r.height, comp); for(int c = c1+1; c < cn; c++) { ix = 0; wx = c * chunkSize; w = chunkSize; checkChunk(c, g); g.drawImage(chunks[c], wx, r.y, wx+w, r.y+r.height, ix, r.y, ix+w, r.y+r.height, comp); } ix = 0; wx = cn * chunkSize; w = (r.x + r.width) % chunkSize; checkChunk(cn, g); g.drawImage(chunks[cn], wx, r.y, wx+w, r.y+r.height, ix, r.y, ix+w, r.y+r.height, comp); } } protected synchronized void blit(Graphics g, int i) { g.setClip(0,0, width, height); if (i