001 /* 002 * NodeNetElement.java 003 * 004 * Developed for the "Rethinking CS101" project. See http://www.cs101.org, the 005 * CS101 homepage or email las@olin.edu. 006 * 007 * Please do not redistribute without obtaining permission. 008 */ 009 010 package nodenet; 011 012 import java.awt.Graphics; 013 import java.awt.Point; 014 015 /** 016 * NodeNetElement is an interface implemented by any and all Nodes 017 * and channels. It defines the basic methods any element must 018 * have.<p> 019 * 020 * @author Todd C. Parnell, tparnell@ai.mit.edu 021 * @author Patrick G. Heck, gus.heck@olin.edu 022 * @version $Id: NodeNetElement.java,v 1.5 2004/01/14 21:43:17 gus Exp $ 023 */ 024 public interface NodeNetElement extends Runnable { 025 026 /** 027 * Paint ourself to a graphics context. 028 * 029 * @param g The graphics context on which to render ourself 030 */ 031 public void paint(Graphics g); 032 033 /** 034 * Notify this object that it should render itself as selected or 035 * unselected. 036 * 037 * @param b the new selection state 038 */ 039 public void setSelected(boolean b); 040 041 /** 042 * Determine the selection stae of this element. 043 * 044 * @return the current selection state 045 */ 046 public boolean isSelected(); 047 048 /** 049 * Set the enabled property. This property determines whether or not the 050 * element participates in the simulation. Elements that are disabled 051 * should never have any behavior beyond the fact that they exist. Enabled 052 * elements interact with other elements by generating, absorbing or 053 * transmitting packets. 054 * 055 * @param b the new state of the enabled property 056 */ 057 public void setEnabled(boolean b); 058 059 /** 060 * Determine if this element is enabled. 061 * 062 * @see #setEnabled(boolean) 063 * @return the current state of the enabled property. 064 */ 065 public boolean isEnabled(); 066 067 /** 068 * Determine if this element contains the specified point. 069 * 070 * @param p the point to test 071 * @return true if the point is contained, false otherwise. 072 */ 073 public boolean contains(Point p); 074 075 076 /** 077 * Determine if this element contains the specified point. 078 * 079 * @param x the x coordinate of the point to test 080 * @param y the y coordinate of the point to test 081 * @return true if the point is contained, false otherwise. 082 */ 083 public boolean contains(int x, int y); 084 085 /** 086 * Display a configuratin dialog to the user and record changes made 087 * to the configuration via this dialog. 088 */ 089 public void configure(); 090 091 /** 092 * Set the name of this instance. Names may or may not be unique, and may or 093 * may not play a role in the functionality of the class. 094 * 095 * @param name The name to use for this element. 096 */ 097 public void setName(String name); 098 099 /** 100 * Get the name of this instance. 101 * 102 * @see #setName(String) 103 * @return then name of this element 104 */ 105 public String getName(); 106 107 /** 108 * begin exhibiting the behavior of this element This method 109 * is called when a simulation is started. 110 */ 111 public void start(); 112 113 /** 114 * Stop exhibiting the behavior of this element. This method is called 115 * on all NodeNetElements withing a simulation pannel when a 116 * simulation is stopped. 117 */ 118 public void stop(); 119 120 /** 121 * Permanantly release all resources held by this element, and allow it's 122 * thread to run to completion. This must be called to make an element 123 * eligable for garbage collection 124 */ 125 public void destroy(); 126 127 /** 128 * Test to see if this element has been destroyed. 129 * 130 * @return true if the object is destroyed false otherwise. 131 */ 132 public boolean isDestroyed(); 133 134 /** 135 * Indicate that another element referenced by this object is being 136 * destroyed, and references to the specified element should be dropped. 137 * 138 * @param nne the element that is being destroyed 139 */ 140 public void notifyOfDestruction(NodeNetElement nne); 141 } 142 143 /* 144 * $Log: NodeNetElement.java,v $ 145 * Revision 1.5 2004/01/14 21:43:17 gus 146 * more javadoc, plus reformat 147 * 148 * Revision 1.4 2004/01/14 21:04:16 gus 149 * More javadoc fixes 150 * 151 * Revision 1.3 2004/01/14 20:23:21 gus 152 * Javadoc and comment cleanup 153 * 154 * Revision 1.2 2004/01/13 19:35:27 gus 155 * Simulation Panel, channel and node are all Resettable now. 156 * CountingNodeBehavior refactored into Counter 157 * 158 * Revision 1.1 2002/06/13 17:33:21 gus 159 * Moved all java files into the nodenet directory (who let them out anyway?) 160 * 161 * Revision 1.1.1.1 2002/06/05 21:56:35 root 162 * CS101 comes to Olin finally. 163 * 164 * Revision 1.4 2000/05/09 06:03:54 mharder 165 * Changed packagename from nodeNet to nodenet. 166 * 167 * Revision 1.3 1999/08/04 09:08:53 jsmthng 168 * Added javadoc comments to InputChannelVector and OutputChannelVector; 169 * finished updating the rest of the nodeNet package to reflect new 170 * changes in name and code. 171 * 172 * Modified index.html to reflect the new nodeNet code, as well as to 173 * clarify some parts of the problem set. 174 * 175 * Revision 1.1 1999/07/30 01:09:23 jsmthng 176 * Renaming BinSort package to nodeNet; moving directories and files as 177 * necessary. 178 * 179 * Revision 1.3 1998/08/12 19:29:25 tparnell 180 * Another pass after comments from las & natashao. Added support to 181 * dynamically add NodeBehaviors. Add keyboard shortcuts to menus. Added 182 * workaround to jdk bug relating to lighweight components. Misc other 183 * bugfixes. 184 * 185 * Revision 1.3 1998/08/10 17:45:50 tparnell 186 * Revision to use JDK1.2 and Swing. Redesign of GUI. Removed old kludge 187 * for file I/O and replaced with object serialization. Channel no longer 188 * requires animacy. Removed unnessary dependencies between classes. 189 * Added ability to configure channel's latency and capacity. Added 190 * javadoc to all files. General code cleanup. 191 * 192 */