|
From: Nick C. <sr...@ea...> - 2001-09-04 15:24:12
|
I think Skye's idea is a good one and probably what I'll do but I have a few reservations. 1. A user should be able to set the parameters without pressing start. This is not a problem as we can leave the enter stuff in there. 2. There is at least one simulation that I know of that relies on the proper order of parameters being set -- i.e. can only set y coherently if x is set to 0. Setting all the parameters via the start button means that the user can't use this. Again, this can be overcome by setting the relevant parameters first with enter, although there will need to be some documentation about what's going on. 3. A user may want to set a parameter but not start the simulation. Again, this can probably be taken care of with keeping enter. What I'm really worried about is that setting them at start may break some simulations, although I can't think why this would happen. Thoughts? Nick Thomas Howe wrote: > The thought that skye had (and I think it's a good one) is to have the > model check the parameters whenever the start button is clicked. This > gets around the messy issue of constantly firing events, but still eliminates the need to hit return everytime (which I must say is driving me crazy). > > BTW, I wrote a simulation which seems to work fine, albeit slowly (I have agents giving birth which causes a lot of object creation). I feel like I have a much beeter feel for the framework and I'm ready to get started. If you have any directions that you would like me to work on, let me know. > > -Tom > > On Mon, Sep 03, 2001 at 04:41:57PM -0400, Nick Collier wrote: > >>Hi, >> >>I just checked some code (uchicago/src/reflector/PropertyTextField.java) >>into cvs that will update a text field parameter whenever that field >>loses focus. It seems to work okay on Linux. I do have qualms however, >>and that's why I'm writing this. I've set PropertyTextField to send a >>message to the console whenever focus is lost and thus an update occurs, >>and you'll see that focus is lost for virtually any kind of key-stroke >>or mouse event. I'd rather not be calling methods on the model so often. >>The other thing I'm worried about is call sequence. That is, if the user >> changes a parameter and then clicks start at least two events are >>fired, one is the obvious button click on start, and the second is the >>loss of focus on the parameter text field. Some simple tests on linux >>show the the loss of focus event is handled first, and then the mouse >>click. Does anyone know if this order is guaranteed by the java spec? >>That is, loss of focus broadcast and handled prior to the click that >>cause the loss of focus. Obviously if its not guaranteed the whole thing >>goes out the window. I can look this up, but wanted to know if anyone >>knew offhand. So, thoughts, comment on setting parameters via focus >>adapters? >> >>thanks, >> >>Nick >> >>ps. I've included a sample model that has a few different kind of >>parameters. I've used to it test this new focus parameter setting. Its >>in a test package so you'll need to put in a test directory and compile >>it from there. >> >>n. >> >>-- >>Nick Collier >>Social Science Research Computing >>University of Chicago >>http://repast.sourceforge.net >> >> > >>package test; >> >>import java.util.Hashtable; >> >>import uchicago.src.sim.engine.*; >>import uchicago.src.reflector.*; >> >>/** >> * An example model demonstrating parameter display both unadorned and >> * in PropertyDescriptors. >> */ >>public class UIExample extends SimModelImpl { >> >> // int flags contained in the ListPropertyDescriptor "pd" created >> // below. >> private static final int INT_VALUE_1 = 1; >> private static final int INT_VALUE_2 = 2; >> private static final int INT_VALUE_3 = 3; >> >> private Schedule schedule; >> static OutputFrame output = new OutputFrame(); >> >> // these store the value of this model's parameters, but they >> // themselves are not the parameters, the parameters are defined in >> // the get and set method names. A get and set method (a parameter) >> // could store its value in two variables and thus the variable itself >> // is not the true parameter. >> private ParameterClass pclass = new ParameterClass(); >> private int lpdExample = INT_VALUE_3; >> private double lpdDblExample = 3.1; >> private int intVal = 1; >> private String stringVal = "hello"; >> private boolean boolVal = true; >> >> public UIExample() { >> output.display(); >> >> // this sets up the ListPropertyDescriptor >> Hashtable h = new Hashtable(); >> h.put(new Integer(INT_VALUE_1), "Int Value One"); >> h.put(new Integer(INT_VALUE_2), "Int Value Two"); >> h.put(new Integer(INT_VALUE_3), "Int Value Three"); >> ListPropertyDescriptor pd = new ListPropertyDescriptor("LPDExample", h); >> descriptors.put("LPDExample", pd); >> >> // sets up another ListPropertyDescriptor, this time with an >> // array rather than a Hashtable. >> Double[] doubles = {new Double(3.1), new Double(102.2), new Double(.33)}; >> ListPropertyDescriptor pd1 = new ListPropertyDescriptor("LPDDblExample", >> doubles); >> descriptors.put("LPDDblExample", pd1); >> >> } >> >> // begins the definition of the LPDExample parameter. This parameter >> // is set via the ListPropertyDescriptor "pd" defined above. The current >> // value of the combobox is the hashtable value for the key returned by >> // this getLPDExample method. >> public int getLPDExample() { >> return lpdExample; >> } >> >> // called whenever the combobox for the LPDExample is selected. The >> // key value of the hashtable is set here. >> public void setLPDExample(int val) { >> lpdExample = val; >> output.append("LPDVal: " + lpdExample); >> } >> // ends the definition of the LPDExample parameter. >> >> // begins the definition of the LPDDblParameter. This is set via >> // the ListPropertyDescriptor "pd1". >> public void setLPDDblExample(double val) { >> lpdDblExample = val; >> output.append("LPDDblVal: " + lpdDblExample); >> } >> >> public double getLPDDblExample() { >> return lpdDblExample; >> } >> >> // ends the definition of LPDblExample >> >> // int values are displayed and set via their string representation >> // in a text box. >> public int getIntVal() { >> return intVal; >> } >> >> public void setIntVal(int val) { >> intVal = val; >> output.append("IntVal: " + intVal); >> } >> >> // String values are displayed and set in a text box. >> public String getStringVal() { >> return stringVal; >> } >> >> public void setStringVal(String val) { >> stringVal = val; >> output.append("StringVal: " + stringVal); >> } >> >> // boolean values are displayed and set via a checkbox. This >> // BooleanPropertyDescriptor is created automatically by repast. >> public boolean getBooleanVal() { >> return boolVal; >> } >> >> public void setBooleanVal(boolean val) { >> boolVal = val; >> output.append("BooleanVal: " + boolVal); >> } >> >> // class type (excluding strings, and the primitive wrappers) parameters >> // are displayed and modified via a button. Clicking the button displays >> // the properties (parameters) of that class which can now be modified. >> public ParameterClass getParameterClass() { >> return pclass; >> } >> >> // this method is necessary otherwise the button for working with >> // the ParameterClass parameters will be disabled, that is, the >> // Parameters is read-only. >> public void setParameterClass(ParameterClass val) {} >> >> private void buildModel() { >> >> } >> >> private void buildDisplay() { >> >> } >> >> >> private void buildSchedule() { >> >> >> } >> >> public void begin() { >> buildModel(); >> buildDisplay(); >> buildSchedule(); >> } >> >> public void setup() { >> schedule = new Schedule(1); >> schedule.scheduleActionBeginning(1, new BasicAction() { >> public void execute() { >> System.out.println(getStringVal() + " @ " + getTickCount()); >> } >> }); >> >> >> } >> >> // the parameters of the model must be returned here if they are >> // to be displayed. The names here are the get and set methods >> // minus the get and set. >> public String[] getInitParam() { >> String[] params = {"ParameterClass", "LPDExample", "LPDDblExample", >> "StringVal", "IntVal", "BooleanVal"}; >> return params; >> } >> >> public Schedule getSchedule() { >> return schedule; >> } >> >> public String getName() { >> return "UIExample"; >> } >> >> >> public static void main(String[] args) { >> SimInit init = new SimInit(); >> UIExample model = new UIExample(); >> if (args.length > 0) { >> init.loadModel(model, args[0], false); >> } else { >> init.loadModel(model, null, false); >> } >> } >>} >> > >>package test; >> >>import java.awt.Color; >>import java.util.Hashtable; >> >>import uchicago.src.sim.space.Multi2DTorus; >>import uchicago.src.sim.util.Random; >>import uchicago.src.sim.gui.*; >>import uchicago.src.reflector.DescriptorContainer; >>import uchicago.src.reflector.ListPropertyDescriptor; >> >>/** >> * An example of a drawable agent. Any agent that is to be visualized must >> * implement the Drawable interface. Agents that want to display their >> * properties in PropertyDescriptors (e.g. ComboBoxes etc.) must implement >> * the DescriptorContainer interface. This is the agent for the UIExample2 >> * model. >> */ >> >>public class UIAgent implements Drawable, DescriptorContainer, Moveable { >> >> // int value flags get and set via the ListPropertyDescriptor set up >> // below. >> private static final int BLUE = 0; >> private static final int RED = 1; >> >> private int x, y; >> private Multi2DTorus space; >> private Hashtable descriptors = new Hashtable(); >> private Color color = Color.red; >> >> public UIAgent(int x, int y, Multi2DTorus space) { >> this.x = x; >> this.y = y; >> this.space = space; >> >> // sets up the propertyDescriptor for this agent. >> Hashtable h = new Hashtable(); >> h.put(new Integer(BLUE), "Blue"); >> h.put(new Integer(RED), "Red"); >> ListPropertyDescriptor lpd = new ListPropertyDescriptor("Color", h); >> descriptors.put("Color", lpd); >> } >> >> public void setColor(int val) { >> if (val == 0) color = Color.blue; >> else color = Color.red; >> } >> >> public int getColor() { >> if (color == Color.blue) return BLUE; >> else return RED; >> } >> >> /** >> * Moves the agent in a random direction in the grid space. >> */ >> public void step() { >> int amt = Random.uniform.nextIntFromTo(1, 10); >> boolean plus = Random.uniform.nextIntFromTo(0, 1) == 0; >> space.removeObjectAt(x, y, this); >> >> if (plus) { >> x += amt; >> } else { >> x -= amt; >> } >> >> amt = Random.uniform.nextIntFromTo(1, 10); >> plus = Random.uniform.nextIntFromTo(0, 1) == 0; >> >> if (plus) { >> y += amt; >> } else { >> y -= amt; >> } >> >> space.putObjectAt(x, y, this); >> >> >> } >> >> // Drawable interface implementation >> >> /** >> * Gets the x coordinate of this agent. >> */ >> public int getX() { >> return x; >> } >> >> /** >> * Gets the y coordinate of this agent. >> */ >> public int getY() { >> return y; >> } >> >> public void setX(int val) { >> space.removeObjectAt(x, y, this); >> space.putObjectAt(val, y, this); >> x = val; >> } >> >> public void setY(int val) { >> space.removeObjectAt(x, y, this); >> space.putObjectAt(x, val, this); >> y = val; >> } >> >> /** >> * Draws this agent as a rounded rectangle. >> */ >> public void draw(SimGraphics sg) { >> sg.drawFastRoundRect(color); >> } >> >> // DescriptorContainer interface >> public Hashtable getParameterDescriptors() { >> return descriptors; >> } >>} >> >> >> >> > >>package test; >>/** >> * A sample class with some simple get and set methods. This is used to >> * illustrate how parameters with class types are manipulated. See >> * UIExample for more info. >> */ >>public class ParameterClass { >> >> private int integerVal = 0; >> private boolean bVal; >> >> >> public boolean getBooleanVal() { >> return bVal; >> } >> >> public void setBooleanVal(boolean val) { >> bVal = val; >> UIExample.output.append(this); >> } >> >> public int getIntegerVal() { >> return integerVal; >> } >> >> public void setIntegerVal(int val) { >> integerVal = val; >> UIExample.output.append(this); >> } >> >> public String toString() { >> return "IntegerVal = " + integerVal + "\n" + "booleanVal = " + bVal; >> } >> >>} >> > > -- Nick Collier Social Science Research Computing University of Chicago http://repast.sourceforge.net |