/*--------------------------------------------------------------------------- File: GraphicStore.java Package: JAWAA Beta Version 0.1 Author: Will Pierson (wcp@acpub.duke.edu) Description of Contents: Provides storage for graphics objects --------------------------------------------------------------------------*/ /* * Susan H. Rodger, Will Pierson * Computer Science Department * Duke University * December 1996 * * Copyright (c) 1996 * All rights reserved. * * Redistribution and use in source and binary forms are permitted * provided that the above copyright notice and this paragraph are * duplicated in all such forms and that any documentation, * advertising materials, and other materials related to such * distribution and use acknowledge that the software was developed * by the author. The name of the author may not be used to * endorse or promote products derived from this software without * specific prior written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ import java.awt.*; import java.util.*; //organizes storage of graphic objects for easy addition and searching class GraphicStore{ Hashtable hTable; Vector v; Enumeration vEnum; static final int NODE = 0; static final int ARC = 1; static final int MARKER = 2; static final int TEXT = 3; static final int CIRCLE = 4; static final int LINE = 5; static final int RECTANGLE = 6; static final int POLYGON = 7; static final int STACK = 8; static final int ARRAY = 9; static final int GROUP = 10; static final int TREE = 11; static final int QUEUE = 12; static final int GRAPH = 13; public GraphicStore(){ hTable = new Hashtable(); v = new Vector(); } static void goCopy(GraphicObject t, GraphicObject s){ t.x = s.x; t.y = s.y; t.name = s.name; t.aux = new int[10]; try{ for(int i = 0; i< 10 ; i++){ t.aux[i] = s.aux[i]; } } catch (Exception e){ } t.daux = new double[10]; try{ for(int i = 0; i< 10 ; i++){ t.daux[i] = s.daux[i]; } } catch (Exception e){ } t.type = s.type; t.col = s.col; t.col2 = s.col2; t.as = new String[10]; try{ for(int i = 0; i< 10 ; i++){ t.as[i] = new String(s.as[i]); } } catch (Exception e){ } } public boolean add(String name, int x, int y, int type, String[] as, int aux[], double daux[], Color col2, Color col){ GraphicObject newObj = new GraphicObject(); int i; newObj.x = x; newObj.y = y; newObj.name = name; newObj.type = type; newObj.as = as; newObj.col = col; newObj.col2 = col2; newObj.aux = aux; newObj.daux = daux; hTable.put(name, newObj); if(!v.contains(name)){ v.addElement(name); } return true; } // used in 'for' loop, gets public GraphicObject getObj(){ if(vEnum == null) vEnum = v.elements(); if (!vEnum.hasMoreElements()){ vEnum = null; // System.out.println("-------------------------------"); // print(); return null; } return (GraphicObject)hTable.get(vEnum.nextElement()); } // get object by name public GraphicObject getObj(String name){ GraphicObject temp = (GraphicObject)hTable.get(name); return temp; } //remove object from list public boolean remove(String name){ if(hTable.remove(name) == null){ return false; } v.removeElement(name); return true; } public void print(){ for (Enumeration e = hTable.elements() ; e.hasMoreElements() ;) { System.out.println(((GraphicObject)e.nextElement()).name); } } public void print(String name){ GraphicObject temp = getObj(name); System.out.println("Name: "+temp.name+ " X: "+temp.x+" Y: "+temp.y); System.out.print("String Array: "); try{ for(int i = 0; i< 10 ; i++){ System.out.print(i+": "+temp.as[i]+" "); } } catch (Exception e){ } System.out.println(); System.out.print("Integer Array: "); try{ for(int i = 0; i< 10 ; i++){ System.out.print(i+": "+temp.aux[i]+" "); } } catch (Exception e){ } System.out.println(); } }