/** * Create a new icon with the given name in the given container. The container is required to * implement Settable, or an exception will be thrown. * * @param container The container for this attribute. * @param name The name of this attribute. * @exception IllegalActionException If thrown by the parent class or while setting an attribute * @exception NameDuplicationException If the name coincides with an attribute already in the * container. */ public TableIcon(NamedObj container, String name) throws NameDuplicationException, IllegalActionException { super(container, name); variableName = new StringParameter(this, "variableName"); boxColor = new ColorAttribute(this, "boxColor"); boxColor.setExpression("{1.0, 1.0, 1.0, 1.0}"); Variable UNBOUNDED = new Variable(this, "UNBOUNDED"); UNBOUNDED.setVisibility(Settable.NONE); UNBOUNDED.setExpression("0"); maxRows = new Parameter(this, "maxRows"); maxRows.setTypeEquals(BaseType.INT); maxRows.setExpression("UNBOUNDED"); Variable ALL = new Variable(this, "ALL"); ALL.setVisibility(Settable.NONE); Token emptyStringArray = new ArrayToken(BaseType.STRING); ALL.setToken(emptyStringArray); fields = new Parameter(this, "fields"); fields.setTypeEquals(new ArrayType(BaseType.STRING)); fields.setExpression("ALL"); colorKey = new StringParameter(this, "colorKey"); }
/** * Override the base class to set type constraints between the output ports and parameters of this * actor whose name matches the output port. If there is no such parameter, then create an * instance of Variable with a matching name and set up the type constraints to that instance. The * type of the output port is constrained to be at least that of the parameter or variable. * * @exception IllegalActionException If there is no director, or if the director's preinitialize() * method throws it, or if this actor is not opaque. */ public void preinitialize() throws IllegalActionException { super.preinitialize(); Iterator ports = outputPortList().iterator(); while (ports.hasNext()) { TypedIOPort port = (TypedIOPort) ports.next(); // Ensure that the production rate is one. // FIXME: This may not be right if there is no // actual source of data for this port (e.g. no // SetVariable actor). Variable rate = (Variable) port.getAttribute("tokenProductionRate"); if (rate == null) { try { rate = new Variable(port, "tokenProductionRate"); } catch (NameDuplicationException e) { throw new InternalErrorException(e); } } rate.setToken(new IntToken(1)); String portName = port.getName(); Attribute attribute = getAttribute(portName); if (attribute == null) { try { workspace().getWriteAccess(); attribute = new Variable(this, portName); } catch (NameDuplicationException ex) { throw new InternalErrorException(ex); } finally { workspace().doneWriting(); } } // attribute is now assured to be non-null. if (attribute instanceof Variable) { port.setTypeAtLeast((Variable) attribute); } else { // Assume the port type must be a string. port.setTypeEquals(BaseType.STRING); } } }
/** * Set the parameter "inputArrayElement" of the model to an element of the input array. * * @param t The element value. * @exception IllegalActionException If the model does not have a settable attribute named * "inputArrayElement". */ private void _updateParameter(Token t) throws IllegalActionException { Attribute attribute = _model.getAttribute("inputArrayElement"); // Use the token directly rather than a string if possible. if (attribute instanceof Variable) { if (_debugging) { _debug("** Transferring input to parameter inputArrayElement."); } ((Variable) attribute).setToken(t); } else if (attribute instanceof Settable) { if (_debugging) { _debug("** Transferring input as string to inputArrayElement."); } ((Settable) attribute).setExpression(t.toString()); } else { throw new IllegalActionException( this, "The specified model does not have an inputArrayElement parameter."); } }
// ///////////////////////////////////////////////////////////////// // // private methods //// private void _setValue(Token value) throws IllegalActionException { Attribute variable = getModifiedVariable(); if (variable instanceof Variable) { ((Variable) variable).setToken(value); // NOTE: If we don't call validate(), then the // change will not propagate to dependents. ((Variable) variable).validate(); } else if (variable instanceof Settable) { ((Settable) variable).setExpression(value.toString()); // NOTE: If we don't call validate(), then the // change will not propagate to dependents. ((Settable) variable).validate(); } else { throw new IllegalActionException( SetVariable.this, "Cannot set the value of the variable " + "named: " + variableName.getExpression()); } }