/* Copyright 2000 Charles G. Wright * This software may be distributed under the terms of the * GNU General Public License. * * $Id: CWmonitoredElements.java,v 1.1 2000-06-15 10:14:52-05 chuckles Exp chuckles $ */ import java.util.*; import java.awt.*; /**

The purpose of this class is to maintain a list of all * information that can be displayed as output. The information * can be retrieved from a variety of classes. If a class can * supply information for monitoring, it must implement the * CWmonitorable interface, meaning that it implements *

*

The class also manages a set of List objects that are used to * select monitored information. As monitored elements are added, * a string representing that object is added to each registered List. */ public class CWmonitoredElements { private static Vector elements = new Vector(); // List objects that must be kept in sync with this list. // As elements are added to the elements list, we need to // add corresponding entries to the List objects. // Right now, the List(s) must be created first. public static Vector lists = new Vector(); //--------------------------------------------------- /** Register all of the monitorable elements for a given class.*/ public static void addElements(CWmonitorable obj){ for (int i = 0; i < obj.getFields().length; i++){ addElement(obj, i); } } //---------------------------------------------------- /** Add a monitorable element to the list.*/ public static void addElement(CWmonitorable obj, int fi){ java.awt.List li; // Create a monitorable element and add to the vector. CWmonitoredElement me = new CWmonitoredElement(obj, fi); elements.addElement(me); // create a string of the form .... String list_entry = obj.getName() + ": " + obj.getFields()[fi]; System.out.println("List entry: " + list_entry); // Add this string to each of the Lists. for (int i = 0; i < lists.size(); i++){ li = (java.awt.List)lists.elementAt(i); li.add(list_entry); } System.out.println("List entry added."); } //-------------------------------------------------- // Add a List that is to be kept current. public static void addList(java.awt.List li){ lists.addElement(li); } //------------------------------------------------ public static int size(){ return(elements.size()); } //------------------------------------------------- public static CWmonitorable objectAt(int i){ CWmonitoredElement me = (CWmonitoredElement)elements.elementAt(i); return (CWmonitorable)me.obj; } //---------------------------------------------- public static int indexAt(int i){ CWmonitoredElement me = (CWmonitoredElement)elements.elementAt(i); return me.index; } }