Package ptolemy.kernel.util

Examples of ptolemy.kernel.util.Settable


        Iterator parameters = object.attributeList(Settable.class).iterator();
        boolean foundOne = false;

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

            if (Configurer.isVisible(object, parameter)) {
                foundOne = true;
                query.addStyledEntry(parameter);
            }
View Full Code Here


            // Count visible attributes
            Iterator parameters = attributeList.iterator();
            int count = 0;

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

                if (Configurer.isVisible(target, parameter)) {
                    count++;
                }
            }

            String[] attributeNames = new String[count];
            parameters = attributeList.iterator();

            int index = 0;

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

                if (Configurer.isVisible(target, parameter)) {
                    attributeNames[index++] = ((Attribute) parameter).getName();
                }
            }
View Full Code Here

                throw new RuntimeException(
                        "already created field for attribute" + attribute);
            }

            if (attribute instanceof Settable) {
                Settable settable = (Settable) attribute;

                if (debug) {
                    System.out.println("creating field for " + settable);
                }

                String fieldName = StringUtilities.sanitizeName(attribute
                        .getName(context));
                SootField field;

                // Create a field to contain the value of the attribute.
                if (settable instanceof Variable) {
                    Variable variable = (Variable) settable;
                    ptolemy.data.type.Type type = variable.getType();
                    Type tokenType = PtolemyUtilities
                            .getSootTypeForTokenType(type);

                    boolean isConstant = constantAnalysis.getConstVariables(
                            context).contains(attribute);

                    int modifier;

                    if (isConstant) {
                        modifier = Modifier.PUBLIC | Modifier.FINAL;
                    } else {
                        modifier = Modifier.PUBLIC;
                    }

                    field = new SootField(fieldName + "_CGToken", tokenType,
                            modifier);
                    theClass.addField(field);

                    if (isConstant) {
                        try {
                            field.addTag(new ValueTag(variable.getToken()));
                        } catch (Exception ex) {
                        }

                        field.addTag(new TypeTag(type));
                    }
                } else {
                    field = new SootField(fieldName + "_CGExpression",
                            stringType, Modifier.PUBLIC | Modifier.FINAL);
                    theClass.addField(field);

                    String expression = settable.getExpression();
                    field.addTag(new ValueTag(expression));
                }

                attributeToValueFieldMap.put(attribute, field);
            }
View Full Code Here

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

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

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

                    if (!showAllParameters
                            && !((NamedObj) settable).isOverridden()) {
                        continue;
                    }

                    if (!showAllParameters
                            && _isPropertySet((NamedObj) settable, "_hide")) {
                        continue;
                    }

                    String name = settable.getName();
                    String displayName = settable.getDisplayName();
                    parameters.append(displayName);

                    if (showAllParameters && !name.equals(displayName)) {
                        parameters.append(" (" + name + ")");
                    }

                    parameters.append(": ");
                    parameters.append(settable.getExpression());

                    if (settables.hasNext()) {
                        parameters.append("\n");
                    }
                }
View Full Code Here

            // 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

            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

        }

        // 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

            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

            }

            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

                            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

TOP

Related Classes of ptolemy.kernel.util.Settable

Copyright © 2018 www.massapicom. 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.