// // (C) COPYRIGHT International Business Machines Corp. 1997 // All Rights Reserved // Licensed Materials - Property of IBM // // US Government Users Restricted Rights - Use, duplication or // disclosure restricted by GSA ADP Schedule Contract with IBM Corp. // /* * $Header: /home/gda/dxcvs/dx/src/ui++/java/dx/net/SelectionNode.java,v 1.1.1.1 1999/03/24 15:17:31 gda Exp $ */ package dx.net; import java.util.*; import dx.runtime.*; public class SelectionNode extends dx.net.BinaryNode { private Vector strings; protected Vector values; protected Vector selections; private final static int ID_PARAM_NUM = 1; private final static int CSTR_PARAM_NUM = 2; // Current output string private final static int CVAL_PARAM_NUM = 3; // Current output value private final static int STRLIST_PARAM_NUM = 4; // group or stringlist private final static int VALLIST_PARAM_NUM = 5; // integer or value list private final static int CULL_PARAM_NUM = 6; // removes zero length strings private final static int LABEL_PARAM_NUM = 7; private final static int OUTPUT_VALUE = 1; private final static int OUTPUT_NAME = 2; public SelectionNode(Network net, String name, int instance, String notation) { super(net, name, instance, notation); this.selections = null; this.strings = this.values = null; } public void setValues (Vector strings, Vector values) { this.strings = strings; this.values = values; } public void selectOption(int s) { Integer i = new Integer(s); if (this.selections == null) this.selections = new Vector(4); this.selections.addElement(i); } public void installValues (Interactor i) { super.installValues(i); BinaryInstance bi = (BinaryInstance)i; if (this.strings != null) { bi.setOptions(this.strings, this.values); if (this.selections != null) { Enumeration enum = this.selections.elements(); while (enum.hasMoreElements()) { Integer I = (Integer)enum.nextElement(); bi.selectOption(I.intValue()); } } bi.enable(); // // Since we've probably just been data driven, it's time // to set our shadowing inputs. // if ((this.selections != null) && (this.selections.size() > 0)) { int type = bi.getOutputType(); String cstr = null; String cval = null; if (this.selections.size() > 1) { cstr = "{ "; cval = "{ "; Enumeration enum = this.selections.elements(); while (enum.hasMoreElements()) { Integer s = (Integer)enum.nextElement(); int ind = s.intValue() - 1; cstr+= "\"" + (String)this.strings.elementAt(ind) + "\" "; if ((type & BinaryInstance.INTEGER) != 0) cval+= (String)this.values.elementAt(ind) + " "; else cval+= "\"" + (String)this.values.elementAt(ind) + "\" "; } cstr+= " }"; cval+= " }"; } else { Integer s = (Integer)this.selections.elementAt(0); int ind = s.intValue() - 1; cstr = "\"" + (String)this.strings.elementAt(ind) + "\""; if ((type & BinaryInstance.INTEGER) != 0) cval = (String)this.values.elementAt(ind); else cval = "\"" + (String)this.values.elementAt(ind) + "\""; } this.setInputValueQuietly (SelectionNode.CSTR_PARAM_NUM, cstr); this.setInputValueQuietly (SelectionNode.CVAL_PARAM_NUM, cval); } } else { Vector t1 = new Vector(2); Vector t2 = new Vector(2); t1.addElement("(no options)"); t2.addElement("NULL"); bi.setOptions (t1, t2); bi.disable(); } } protected String mungeString(String s) { StringBuffer sb = new StringBuffer(s); boolean changed = false; int ind = s.indexOf("value list="); if (ind != -1) { if (sb.charAt(ind+5) != ' ') System.out.println ("SelectionNode.mungeString(1) error." + ind + ":" +s); sb.setCharAt(ind+5, '_'); changed = true; } ind = s.indexOf("string list="); if (ind != -1) { if (sb.charAt(ind+6) != ' ') System.out.println ("SelectionNode.mungeString(2) error." + ind + ":" +s); sb.setCharAt(ind+6, '_'); changed = true; } if (changed == false) return super.mungeString(s); // // Now replace spaces which occur inside { } with % // Then let the superclass do its thing. // Then replace % which occur inside { } back into spaces // int length = sb.length(); int i = 0; boolean inside = false; while (i