/** * @file SolidObjectList.java * @author Robert S Laramee * @version 1.0 * Start Date Saturday, 21 Nov 98 * "Finish" Date Thursday, 03 Dec 198 * * Description This class contains the methods and data necessary for * keeping a list of user defined solid objects */ import java.awt.*; // for Graphics class import java.util.*; // for Vector class public class SolidObjectList { Vector SOlist; // to store solid objects /** * constructor * A new solid object is created when the user selects "New Solid Object" * from the Drawing Mode menu (from DrawCanvas.java). */ public SolidObjectList() { SOlist = new Vector(); } /** * Add a solid object to the list. Don't add one that is already there. * @param so -the solid object to add to the list */ public void add(SolidObject so) { SolidObject so2; for (int i = 0; i < SOlist.size(); i++ ) { so2 = getSolidObject(i); if (so2.getName().equals(so.getName())) { System.out.println("** Warning, object: " + so.getName() + " already defined."); return; } } SOlist.addElement(so); System.out.println("New item: " + so.getName() + " added to solid " + "object list, length = " + SOlist.size()); } /** * checkName() returns TRUE if a valid name was given * @param newName -the user supplied name to check * @return TRUE if the name is valid */ public boolean checkName(String newName) { SolidObject so; for (int i = 0; i < SOlist.size(); i++ ) { so = getSolidObject(i); if (so.getName().equals(newName)) { return false; } } return true; } /** * @return the length of the solid object list */ public int size() { return SOlist.size(); } /** * return a Solid Object off of the Solid Object List * @param i -the index of solid object to return * @return -the Solid Object */ public SolidObject getSolidObject(int i) { return (SolidObject)SOlist.elementAt(i); } /** * return a Solid Object off of the Solid Object List * @param name -the name of solid object to return * @return -the Solid Object */ public SolidObject getSolidObject(String name) { SolidObject so; for (int i = 0; i < SOlist.size(); i++) { so = (SolidObject)SOlist.elementAt(i); if (so.getName().equals(name)) { return so; } } System.out.println("** Error: name " + name + " not found"); return null; } /** * print(): prints out the solid object definition */ public void print() { for(int i = 0; i < SOlist.size(); i++) { } } /** * toString() * @return a string representation of the solid object points */ public String toString() { return new String("null"); } }