Package ptolemy.kernel.util

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


        removeQueryListener(this);

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

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

        _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

                        .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

                        .iterator();
                StringBuffer buffer = new StringBuffer("<group>\n");
                final List parametersReset = new LinkedList();

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

                    if (isVisible(_object, parameter)) {
                        String newValue = parameter.getExpression();
                        String defaultValue = parameter.getDefaultExpression();

                        if ((defaultValue != null)
                                && !newValue.equals(defaultValue)) {
                            buffer.append("<property name=\"");
                            buffer.append(((NamedObj) parameter)
                                    .getName(_object));
                            buffer.append("\" value=\"");
                            buffer.append(StringUtilities
                                    .escapeForXML(defaultValue));
                            buffer.append("\"/>\n");
                            parametersReset.add(parameter);
                        }
                    }
                }

                buffer.append("</group>\n");

                // If there are changes, then issue a change request.
                // Use a MoMLChangeRequest so undo works... I.e., you can undo a cancel
                // of a previous change.
                if (parametersReset.size() > 0) {
                    MoMLChangeRequest request = new MoMLChangeRequest(this, // originator
                            _object, // context
                            buffer.toString(), // MoML code
                            null) { // base
                        protected void _execute() throws Exception {
                            super._execute();

                            // Reset the derived level, which has the side
                            // effect of marking the object not overridden.
                            Iterator parameters = parametersReset.iterator();

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

                                if (isVisible(_object, parameter)) {
                                    int derivedLevel = ((NamedObj) parameter)
                                            .getDerivedLevel();
View Full Code Here

                            String outputExpression = writer
                                    .printParseTree(parseTree);
                            parameter.setExpression(outputExpression);
                        }
                    } catch (ClassCastException ex) {
                        Settable parameter = (Settable) actor
                                .getAttribute(parameterName);
                        ParseTreeFreeVariableCollector collector = new ParseTreeFreeVariableCollector();
                        Set expressionVariables = collector
                                .collectFreeVariables(parseTree);
                        Set scopeVariables = _scope.identifierSet();
                        List<String> excludedVariables = new LinkedList<String>();
                        for (Object variable : expressionVariables) {
                            if (variable instanceof String) {
                                if (!scopeVariables.contains(variable)) {
                                    excludedVariables.add((String) variable);
                                }
                            }
                        }
                        ParseTreeSpecializer specializer = new ParseTreeSpecializer();
                        parseTree = specializer.specialize(parseTree,
                                excludedVariables, _scope);
                        ParseTreeWriter writer = new ParseTreeWriter();
                        String outputExpression = writer
                                .printParseTree(parseTree);
                        parameter.setExpression(outputExpression);
                    }
                }
            } catch (Exception ex) {
                throw new PtalonRuntimeException("Trouble making connections",
                        ex);
View Full Code Here

         @param row The row number.
         *  @param col The column number.
         *  @see javax.swing.table.TableModel#getValueAt(int, int)
         */
        public Object getValueAt(int row, int col) {
            Settable parameter = (Settable) _parameters.get(row);
            if (ColumnNames.COL_NAME.equals(getColumnName(col))) {
                return parameter.getDisplayName();
            } else if (ColumnNames.COL_EXPRESSION.equals(getColumnName(col))) {
                return parameter.getExpression();
            } else {
                return parameter.getValueAsString();
            }
        }
View Full Code Here

                Object value, boolean isSelected, boolean hasFocus, int row,
                int col) {
            setOpaque(true);
            setText((String) value);
            // The color depends on the properties of the parameter.
            Settable parameter = (Settable) _parameters.get(row);
            if (parameter.getVisibility() == Settable.EXPERT) {
                setBackground(_EXPERT_COLOR);
            } else if (parameter.getVisibility() == Settable.NONE) {
                setBackground(_INVISIBLE_COLOR);
            } else {
                setBackground(Color.WHITE);
            }
            return this;
View Full Code Here

        NamedObj object = getContainer();
        PtolemyQuery query = new PtolemyQuery(object);
        query.setTextWidth(25);

        if (object instanceof Settable) {
            Settable parameter = (Settable) object;
            _oldExpression = parameter.getExpression();
            query.addStyledEntry(parameter);
            return query;
        } else {
            return new JLabel(object.getName()
                    + " is not a settable attribute!");
View Full Code Here

                }
            }

            if (isAttributeTypeEnabled() || isAttributeValueEnabled()) {
                if (attribute instanceof Settable) {
                    Settable settable = (Settable) attribute;
                    String expression = settable.getExpression();
                    VariableScope scope = new VariableScope(object);
                    try {
                        ASTPtRootNode tree = _TYPE_PARSER
                                .generateParseTree(expression);
                        Token token = _TYPE_EVALUATOR.evaluateParseTree(tree,
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.