Examples of Settable


Examples of ptolemy.kernel.util.Settable

            // increase in complexity, because each validation of an
            // instance of SharedParameter causes validation of all
            // its shared instances. EAL 9/10/06.
            HashSet parametersValidated = new HashSet();
            while (parameters.hasNext()) {
                Settable param = (Settable) parameters.next();

                if (parametersValidated.contains(param)) {
                    continue;
                }

                // NOTE: We used to catch exceptions here and issue
                // a warning only, but this has the side effect of blocking
                // the mechanism in PtolemyQuery that carefully prompts
                // the user for corrected parameter values.
                try {
                    param.validate();

                    // Also validate derived objects.
                    Iterator derivedParams = ((NamedObj) param)
                            .getDerivedList().iterator();

                    while (derivedParams.hasNext()) {
                        Settable derivedParam = (Settable) derivedParams.next();
                        derivedParam.validate();
                        parametersValidated.add(derivedParam);
                    }

                    if (param instanceof SharedParameter) {
                        parametersValidated.addAll(((SharedParameter) param)
View Full Code Here

Examples of ptolemy.kernel.util.Settable

            if (previouslyExisted) {
                oldClassName = property.getClass().getName();

                if (property instanceof Settable) {
                    Settable settable = (Settable) property;
                    oldValue = settable.getExpression();
                }
            }

            if (!previouslyExisted
                    || ((newClass != null) && !newClass.isInstance(property))) {
                // The following will result in a
                // NameDuplicationException if there is a previous
                // property and it is not a singleton.
                try {
                    // No previously existing attribute with this name,
                    // or the class name of the previous entity doesn't
                    // match.
                    if (newClass == null) {
                        newClass = Attribute.class;
                    }

                    // An attribute is not usually a top-level element,
                    // but it might be (e.g. when editing icons).
                    if (_current == null) {
                        // If we want to be able to edit icons, we
                        // have to allow this.
                        // Invoke the constructor.
                        Object[] arguments = new Object[2];
                        arguments[0] = _workspace;
                        arguments[1] = propertyName;
                        property = _createInstance(newClass, arguments);
                        _toplevel = property;
                    } else {
                        // First check that there will be no name collision
                        // when this is propagated. Note that we need to
                        // include all derived objects, irrespective of whether
                        // they are locally changed.
                        List derivedList = _current.getDerivedList();
                        Iterator derivedObjects = derivedList.iterator();

                        while (derivedObjects.hasNext()) {
                            NamedObj derived = (NamedObj) derivedObjects.next();
                            Attribute other = derived
                                    .getAttribute(propertyName);

                            if ((other != null)
                                    && !(other instanceof Singleton)) {
                                throw new IllegalActionException(
                                        _current,
                                        "Cannot create attribute because a subclass or instance "
                                                + "contains an attribute with the same name: "
                                                + derived.getAttribute(
                                                        propertyName)
                                                        .getFullName());
                            }
                        }

                        // Invoke the constructor.
                        Object[] arguments = new Object[2];
                        arguments[0] = _current;
                        arguments[1] = propertyName;
                        property = _createInstance(newClass, arguments);

                        if (property instanceof ptolemy.actor.Director) {
                            _loadIconForClass(className, property);
                        }
                        // Check that the result is an instance of Attribute.
                        if (!(property instanceof Attribute)) {
                            // NOTE: Need to get rid of the object.
                            // Unfortunately, setContainer() is not defined,
                            // so we have to find the right class.
                            if (property instanceof ComponentEntity) {
                                ((ComponentEntity) property).setContainer(null);
                            } else if (property instanceof Port) {
                                ((Port) property).setContainer(null);
                            } else if (property instanceof ComponentRelation) {
                                ((ComponentRelation) property)
                                        .setContainer(null);
                            }

                            throw new XmlException("Property is not an "
                                    + "instance of Attribute. ",
                                    _currentExternalEntity(), _getLineNumber(),
                                    _getColumnNumber());
                        }

                        // Propagate.
                        property.propagateExistence();
                    }

                    if (value != null) {
                        if (property == null) {
                            throw new XmlException("Property does not exist: "
                                    + propertyName + "\n",
                                    _currentExternalEntity(), _getLineNumber(),
                                    _getColumnNumber());
                        }

                        if (!(property instanceof Settable)) {
                            throw new XmlException(
                                    "Property cannot be assigned a value: "
                                            + property.getFullName()
                                            + " (instance of "
                                            + property.getClass().toString()
                                            + ")\n", _currentExternalEntity(),
                                    _getLineNumber(), _getColumnNumber());
                        }

                        Settable settable = (Settable) property;
                        settable.setExpression(value);
                        _paramsToParse.add(property);

                        // Propagate. This has the side effect of marking
                        // the object overridden.
                        property.propagateValue();
                    }

                    createdNew = true;
                } catch (NameDuplicationException ex) {
                    // Ignore, so we can try to set the value.
                    // The createdNew variable will still be false.
                }
            }

            if (!createdNew) {
                // Previously existing property with this name,
                // whose class name exactly matches, or the class
                // name does not match, but a NameDuplicationException
                // was thrown (meaning the attribute was not
                // a singleton).
                // If value is null and the property already
                // exists, then there is nothing to do.
                if (value != null) {
                    if (!(property instanceof Settable)) {
                        throw new XmlException("Property is not an "
                                + "instance of Settable, "
                                + "so can't set the value.",
                                _currentExternalEntity(), _getLineNumber(),
                                _getColumnNumber());
                    }

                    Settable settable = (Settable) property;
                    //String previousValue = settable.getExpression();

                    // NOTE: It is not correct to do nothing even
                    // if the value is not changed.  If the value of
                    // of an instance parameter is explicitly set,
                    // and that value happens to be the same as the
                    // value in the base class, then it should keep
                    // that value even if the base class later changes.
                    // if (!value.equals(previousValue)) {
                    settable.setExpression(value);

                    // Propagate. This has the side effect of marking
                    // the object overridden.
                    property.propagateValue();
View Full Code Here

Examples of ptolemy.kernel.util.Settable

        }

        // validate all settable attributes.
        Iterator attributes = attributeList(Settable.class).iterator();
        while (attributes.hasNext()) {
            Settable attribute = (Settable) attributes.next();
            attribute.validate();
        }
        // preinitialize protected variables.
        _currentTime = getModelStartTime();
        _stopRequested = false;
        // preinitialize all the contained actors.
View Full Code Here

Examples of ptolemy.kernel.util.Settable

            StringBuffer buffer = new StringBuffer();
            Iterator settables = container.attributeList(Settable.class)
                    .iterator();

            while (settables.hasNext()) {
                Settable settable = (Settable) settables.next();

                if ((settable.getVisibility() != Settable.FULL)
                        && (settable.getVisibility() != Settable.NOT_EDITABLE)) {
                    continue;
                }

                String name = settable.getDisplayName();
                String value = settable.getExpression();
                String line = name + ": " + value;
                String truncated = line;

                try {
                    int width = ((IntToken) displayWidth.getToken()).intValue();
View Full Code Here

Examples of ptolemy.kernel.util.Settable

            }

            String name = change.getDescription();

            if (_attributes.containsKey(name)) {
                final Settable attribute = (Settable) (_attributes.get(name));

                // Make a record of the successful attribute value change
                // in case some future change fails and the user
                // chooses to revert.
                // Use the translated expression in case the attribute
View Full Code Here

Examples of ptolemy.kernel.util.Settable

                            nextQuote);
                }
            }

            final String entryName = tmpEntryName;
            final Settable attribute = (Settable) _attributes.get(entryName);

            // NOTE: Do this in the event thread, since this might be invoked
            // in whatever thread is processing mutations.
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    if (attribute != null) {
                        _query.addStyledEntry(attribute);
                    } else {
                        throw new InternalErrorException(
                                "Expected attribute attached to entry name: "
                                        + entryName);
                    }

                    _dialog = new ComponentDialog(JOptionPane
                            .getFrameForComponent(PtolemyQuery.this), "Error",
                            _query, null);

                    // The above returns only when the modal
                    // dialog is closing.  The following will
                    // force a new dialog to be created if the
                    // value is not valid.
                    _query._isOpenErrorWindow = false;

                    if (_dialog.buttonPressed().equals("Cancel")) {
                        if (_revertValue.containsKey(entryName)) {
                            String revertValue = (String) _revertValue
                                    .get(entryName);

                            // NOTE: Do not use setAndNotify() here because
                            // that checks whether the string entry has
                            // changed, and we want to force revert even
                            // if it appears to not have changed.
                            set(((NamedObj) attribute).getName(), revertValue);
                            changed(entryName);
                        }
                    } else {
                        // Force evaluation to check validity of
                        // the entry.  NOTE: Normally, we would
                        // not need to force evaluation because if
                        // the value has changed, then listeners
                        // are automatically notified.  However,
                        // if the value has not changed, then they
                        // are not notified.  Since the original
                        // value was invalid, it is not acceptable
                        // to skip notification in this case.  So
                        // we force it.
                        try {
                            attribute.validate();
                        } catch (IllegalActionException ex) {
                            change.setErrorReported(false);
                            changeFailed(change, ex);
                        }
                    }
View Full Code Here

Examples of ptolemy.kernel.util.Settable

     @param name The name of the entry that has changed.
     */
    public void changed(final String name) {
        // Check if the entry that changed is in the mapping.
        if (_attributes.containsKey(name)) {
            final Settable attribute = (Settable) (_attributes.get(name));

            if (attribute == null) {
                // No associated attribute.
                return;
            }

            ChangeRequest request;

            if (attribute instanceof PasswordAttribute) {
                // Passwords have to be handled specially because the password
                // is not represented in a string.
                request = new ChangeRequest(this, name) {
                    protected void _execute() throws IllegalActionException {
                        char[] password = getCharArrayValue(name);
                        ((PasswordAttribute) attribute).setPassword(password);
                        attribute.validate();

                        Iterator derived = ((PasswordAttribute) attribute)
                                .getDerivedList().iterator();

                        while (derived.hasNext()) {
                            PasswordAttribute derivedPassword = (PasswordAttribute) derived
                                    .next();
                            derivedPassword.setPassword(password);
                        }
                    }
                };
            } else if (attribute instanceof NamedObj) {
                // NOTE: We must use a MoMLChangeRequest so that changes
                // propagate to any objects that have been instantiating
                // using this one as a class.  This is only an issue if
                // attribute is a NamedObj.
                NamedObj castAttribute = (NamedObj) attribute;

                String stringValue = getStringValue(name);

                // If the attribute is a DoubleRangeParameter, then we
                // have to translate the integer value returned by the
                // JSlider into a double.
                if (attribute instanceof DoubleRangeParameter) {
                    try {
                        int newValue = Integer.parseInt(stringValue);
                        int precision = ((IntToken) ((DoubleRangeParameter) attribute).precision
                                .getToken()).intValue();
                        double max = ((DoubleToken) ((DoubleRangeParameter) attribute).max
                                .getToken()).doubleValue();
                        double min = ((DoubleToken) ((DoubleRangeParameter) attribute).min
                                .getToken()).doubleValue();
                        double newValueAsDouble = min
                                + (((max - min) * newValue) / precision);
                        stringValue = "" + newValueAsDouble;
                    } catch (IllegalActionException e) {
                        throw new InternalErrorException(e);
                    }
                }

                // The context for the MoML should be the first container
                // above this attribute in the hierarchy that defers its
                // MoML definition, or the immediate parent if there is none.
                NamedObj parent = castAttribute.getContainer();
                String moml = "<property name=\"" + castAttribute.getName()
                        + "\" value=\""
                        + StringUtilities.escapeForXML(stringValue) + "\"/>";
                request = new MoMLChangeRequest(this, // originator
                        parent, // context
                        moml, // MoML code
                        null) { // base
                    protected void _execute() throws Exception {
                        synchronized (PtolemyQuery.this) {
                            try {
                                _ignoreChangeNotifications = true;
                                super._execute();
                            } finally {
                                _ignoreChangeNotifications = false;
                            }
                        }
                    }
                };
            } else {
                // If the attribute is not a NamedObj, then we
                // set its value directly.
                request = new ChangeRequest(this, name) {
                    protected void _execute() throws IllegalActionException {
                        attribute.setExpression(getStringValue(name));

                        attribute.validate();

                        /* NOTE: Earlier version:
                         // Here, we need to handle instances of Variable
                         // specially.  This is too bad...
                         if (attribute instanceof Variable) {
View Full Code Here

Examples of ptolemy.kernel.util.Settable

        removeQueryListener(this);

        Iterator attributes = _attributes.values().iterator();

        while (attributes.hasNext()) {
            Settable attribute = (Settable) attributes.next();
            attribute.removeValueListener(this);
        }
    }
View Full Code Here

Examples of ptolemy.kernel.util.Settable

        _originalValues = new HashMap();

        Iterator parameters = _object.attributeList(Settable.class).iterator();

        while (parameters.hasNext()) {
            Settable parameter = (Settable) parameters.next();

            if (isVisible(_object, parameter)) {
                _originalValues.put(parameter, parameter.getExpression());
            }
        }

        boolean foundOne = false;
        Iterator editors = object.attributeList(EditorPaneFactory.class)
View Full Code Here

Examples of ptolemy.kernel.util.Settable

                        .iterator();
                boolean hasChanges = false;
                StringBuffer buffer = new StringBuffer("<group>\n");

                while (parameters.hasNext()) {
                    Settable parameter = (Settable) parameters.next();

                    if (isVisible(_object, parameter)) {
                        String newValue = parameter.getExpression();
                        String oldValue = (String) _originalValues
                                .get(parameter);

                        if (!newValue.equals(oldValue)) {
                            hasChanges = true;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.