/* DefaultVobMap.java * * Copyright (c) 2000-2002, Ted Nelson and Tuomas Lukka * * You may use and distribute under the terms of either the GNU Lesser * General Public License, either version 2 of the license or, * at your choice, any later version. Alternatively, you may use and * distribute under the terms of the XPL. * * See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of * the licenses. * * This software 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 README * file for more details. * */ /* * Written by Tuomas Lukka */ package gzz.vob.impl; import gzz.vob.*; import java.awt.*; /** An implementation of VobMap. */ public class DefaultVobMap implements VobMap { public static final String rcsid = "$Id: DefaultVobMap.java,v 1.1 2002/11/02 01:23:46 benja Exp $"; public static boolean dbg = false; private static void p(String s) { if(dbg) pa(s); } private static void pa(String s) { System.err.println(s); } int[] moreInts(int[] orig, int n) { int[] arr = new int[n]; System.arraycopy(orig, 0, arr, 0, orig.length); return arr; } Vob[] moreVobs(Vob[] orig, int n) { Vob[] arr = new Vob[n]; System.arraycopy(orig, 0, arr, 0, orig.length); return arr; } /** For each coordinate system, the index of the first vob * stored there. */ int[] vstart = new int[100]; /** For each vob, the index of the next vob in the same * coordinate system. */ int[] vnext = new int[100]; Vob[] vobs = new Vob[100]; /** Indexed like vobs, the second coordinate system for the vob. */ int[] secondcs = new int[100]; int nvobs = 1; public DefaultVobMap() { for(int i=0; i= 0; i = vnext[i]); return vobs[i]; } public void put(Vob vob) { put(vob, 1, -1); } public void put(Vob vob, int coordsys) { put(vob, coordsys, -1); } public void put(Vob vob, int coordsys, int coordsys2) { try { vobs[nvobs] = vob; secondcs[nvobs] = coordsys2; vnext[nvobs] = -1; nvobs++; } catch(ArrayIndexOutOfBoundsException e) { int n = vobs.length * 2; vnext = moreInts(vnext, n); vobs = moreVobs(vobs, n); secondcs = moreInts(secondcs, n); put(vob, coordsys); return; } if(vstart.length <= coordsys) { int n = vstart.length; vstart = moreInts(vstart, coordsys + 50); for(int i=n; i= 0; i = vnext[i]); vnext[i] = nvobs-1; /* // New one goes first in chain; vnext[nvobs-1] = vstart[coordsys]; vstart[coordsys] = nvobs-1; */ } } public void clear() { nvobs = 1; for(int i=0; i= 0; i = vnext[i]) { // pa("Render: "+vobs[i]); if(secondcs[i] >= 0 && setter != null) { if(setter.set(info2, secondcs[i])) vobs[i].render(g, false, info, info2); } else { vobs[i].render(g, false, info, info); } } } public void dump() { pa("VOBMAP"); for(int i=0; i= 0; j = vnext[j]) { pa(" "+j+" "+vobs[j]); } } } }