Package ptolemy.kernel

Examples of ptolemy.kernel.CompositeEntity


            output.send(0, new IntToken(_count++));
        } else {
            ChangeRequest request = new ChangeRequest(this,
                    "Find a destination") {
                protected void _execute() throws IllegalActionException {
                    CompositeEntity container = (CompositeEntity) getContainer();
                    List entityList = container.entityList();
                    Iterator entities = entityList.iterator();

                    while (entities.hasNext()) {
                        Entity entity = (Entity) entities.next();
                        Iterator ports = entity.portList().iterator();

                        while (ports.hasNext()) {
                            Port port = (Port) ports.next();

                            if (port instanceof IOPort
                                    && ((IOPort) port).isInput()
                                    && (((IOPort) port).getWidth() == 0)) {
                                container.connect(output, (IOPort) port);
                                return;
                            }
                        }
                    }
                }
View Full Code Here


    public Figure createBackgroundFigure() {
        Figure result = null;
        Nameable container = getContainer();

        if (container instanceof CompositeEntity) {
            CompositeEntity myContainer = ((CompositeEntity) container);
            ComponentEntity entity = null;
            Iterator entities = myContainer.entityList().iterator();

            while (entities.hasNext()) {
                entity = (ComponentEntity) entities.next();
            }

            try {
                if (entity != null) {
                    // Look for an icon within the entity.
                    EditorIcon icon = null;
                    Iterator icons = entity.attributeList(EditorIcon.class)
                            .iterator();

                    while (icons.hasNext()) {
                        icon = (EditorIcon) icons.next();
                    }

                    if (icon != null) {
                        result = icon.createBackgroundFigure();
                    } else {
                        // If there is no icon, then maybe there is an
                        // _iconDescription attribute.
                        SingletonConfigurableAttribute description = (SingletonConfigurableAttribute) entity
                                .getAttribute("_iconDescription",
                                        SingletonConfigurableAttribute.class);

                        if (description != null) {
                            // Look for an icon description in my container.
                            SingletonConfigurableAttribute myDescription = (SingletonConfigurableAttribute) myContainer
                                    .getAttribute(
                                            "_iconDescription",
                                            SingletonConfigurableAttribute.class);

                            if (myDescription != null) {
                                // Save my original description, in case I go
                                // back to having nothing inside.
                                if (_originalDescription == null) {
                                    _originalDescription = myDescription
                                            .getConfigureText();
                                }

                                myDescription.configure(null, null, description
                                        .getConfigureText());
                            }
                        }
                    }
                } else {
                    // Restore the original description if we don't have
                    // one now.
                    if ((result == null) && (_originalDescription != null)) {
                        // Restore the original icon description.
                        // Look for an icon description in my container.
                        SingletonConfigurableAttribute myDescription = (SingletonConfigurableAttribute) myContainer
                                .getAttribute("_iconDescription",
                                        SingletonConfigurableAttribute.class);

                        if (myDescription != null) {
                            myDescription.configure(null, null,
View Full Code Here

            final StringBuffer failmoml = new StringBuffer();
            moml.append("<group>\n");
            failmoml.append("<group>\n");

            // Make the request in the context of the container.
            final CompositeEntity container = (CompositeEntity) getPtolemyModel();

            String relationName = "";

            // Flag specifying whether we have actually created any MoML.
            boolean appendedMoML = false;

            try {
                // create moml to unlink any existing.
                appendedMoML = _unlinkMoML(container, moml, linkHead, linkTail,
                        linkRelation);

                // create moml to make the new links.
                relationName = _linkMoML(container, moml, failmoml,
                        (NamedObj) newLinkHead, linkTail);

                // FIXME: Above can return an empty name, so the following
                // test is not quite right.
                appendedMoML = appendedMoML || (relationName != null);
            } catch (Exception ex) {
                // The link is bad... remove it.
                _linkSet.remove(link);
                link.setHead(null);
                link.setTail(null);
                dispatchGraphEvent(new GraphEvent(ActorGraphModel.this,
                        GraphEvent.STRUCTURE_CHANGED, getRoot()));
            }

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

            final String relationNameToAdd = relationName;
            final boolean nonEmptyMoML = appendedMoML;

            // Here the source IS the graph model, because we need to
            // handle the event dispatch specially:  An event is only
            // dispatched if both the head and the tail are attached.
            // This rather obnoxious hack is here because edge creation
            // is tricky and we can't rerender the edge while we are dragging
            // it.
            MoMLChangeRequest request = new MoMLChangeRequest(
                    ActorGraphModel.this, container, moml.toString()) {
                protected void _execute() throws Exception {
                    // If nonEmptyMoML is false, then the MoML code is empty.
                    // Do not execute it, as this will put spurious empty
                    // junk on the undo stack.
                    if (nonEmptyMoML) {
                        super._execute();
                    }

                    link.setHead(newLinkHead);

                    if (relationNameToAdd != null) {
                        ComponentRelation relation = container
                                .getRelation(relationNameToAdd);

                        if (relation == null) {
                            throw new InternalErrorException(
                                    "Tried to find relation with name "
                                            + relationNameToAdd
                                            + " in context " + container);
                        }

                        link.setRelation(relation);
                    } else {
                        link.setRelation(null);
                    }
                }
            };

            // Handle what happens if the mutation fails.
            request.addChangeListener(new LinkChangeListener(link, container,
                    failmoml));

            request.setUndoable(true);
            container.requestChange(request);
        }
View Full Code Here

            moml.append("<group>\n");
            failmoml.append("<group>\n");

            // Make the request in the context of the container.
            // JDK1.2.2 fails to compile the next line.
            final CompositeEntity container = (CompositeEntity) getPtolemyModel();

            String relationName = "";

            // Flag specifying whether we have actually created any MoML.
            boolean appendedMoML = false;

            try {
                // create moml to unlink any existing.
                appendedMoML = _unlinkMoML(container, moml, linkHead, linkTail,
                        linkRelation);

                // create moml to make the new links.
                relationName = _linkMoML(container, moml, failmoml, linkHead,
                        (NamedObj) newLinkTail);

                appendedMoML = appendedMoML || (relationName != null);
            } catch (Exception ex) {
                // The link is bad... remove it.
                _linkSet.remove(link);
                link.setHead(null);
                link.setTail(null);
                dispatchGraphEvent(new GraphEvent(ActorGraphModel.this,
                        GraphEvent.STRUCTURE_CHANGED, getRoot()));
            }

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

            final String relationNameToAdd = relationName;
            final boolean nonEmptyMoML = appendedMoML;

            // Here the source IS the graph model, because we need to
            // handle the event dispatch specially:  An event is only
            // dispatched if both the head and the tail are attached.
            // This rather obnoxious hack is here because edge creation
            // is tricky and we can't rerender the edge while we are dragging
            // it.
            MoMLChangeRequest request = new MoMLChangeRequest(
                    ActorGraphModel.this, container, moml.toString()) {
                protected void _execute() throws Exception {
                    // If nonEmptyMoML is false, then the MoML code is empty.
                    // Do not execute it, as this will put spurious empty
                    // junk on the undo stack.
                    if (nonEmptyMoML) {
                        super._execute();
                    }

                    link.setTail(newLinkTail);

                    if (relationNameToAdd != null) {
                        ComponentRelation relation = container
                                .getRelation(relationNameToAdd);

                        if (relation == null) {
                            throw new InternalErrorException(
                                    "Tried to find relation with name "
                                            + relationNameToAdd
                                            + " in context " + container);
                        }

                        link.setRelation(relation);
                    } else {
                        link.setRelation(null);
                    }
                }
            };

            // Handle what happens if the mutation fails.
            request.addChangeListener(new LinkChangeListener(link, container,
                    failmoml));

            request.setUndoable(true);
            container.requestChange(request);
        }
View Full Code Here

     */
    protected CompositeEntity _createDefaultLibrary(Workspace workspace) {
        Configuration configuration = getConfiguration();

        if (configuration != null) {
            CompositeEntity result = (CompositeEntity) configuration
                    .getEntity("icon editor library");

            if (result == null) {
                // Create a default library by directly reading the
                // default XML description.
View Full Code Here

        _getRightComponent().requestFocus();
    }

    public void copy() {
        if (!getFrameController().isTableActive()) {
            CompositeEntity model = getFrameController().getActiveModel();
            if (model instanceof Pattern || GTTools.isInPattern(model)) {
                _setOrClearPatternObjectAttributes(model, true,
                        _getSelectionSet());
                super.copy();
                _setOrClearPatternObjectAttributes(model, false,
View Full Code Here

    public void paste() {
        if (!getFrameController().isTableActive()) {
            super.paste();

            CompositeEntity model = getFrameController().getActiveModel();
            if (model instanceof Pattern || GTTools.isInPattern(model)) {
                // FIXME: modify only newly created entities and relations.
                _setOrClearPatternObjectAttributes(model, false, null);
            } else {
                _refreshTable();
View Full Code Here

            LibraryAttribute gtLibrary) {
        if (gtLibrary != null) {
            try {
                Configuration configuration =
                    (Configuration) tableau.toplevel();
                CompositeEntity actorLibrary = (CompositeEntity) configuration
                        .getEntity("actor library");
                CompositeEntity library = gtLibrary.getLibrary();
                for (Object entityObject : actorLibrary.entityList()) {
                    try {
                        ComponentEntity libraryEntity =
                            (ComponentEntity) entityObject;
                        ComponentEntity entity = (ComponentEntity) libraryEntity
                                .clone(library.workspace());
                        entity.setContainer(library);
                    } catch (Exception e) {
                        // Ignore this entity in the actor library because we
                        // don't know how to import it.
                    }
View Full Code Here

            // A linked list containing all the actors.
            LinkedList allActorList = new LinkedList();

            // Container of the Director (Composite Actor that holds
            // the model).
            CompositeEntity container = (CompositeEntity) getContainer();

            // Populate it.
            for (Iterator entities = container.deepEntityList().iterator(); entities
                    .hasNext();) {
                ComponentEntity entity = (ComponentEntity) entities.next();

                // Fill allActorList with the list of things that we
                // can schedule.
View Full Code Here

                            + "<" + objectType + " name=\"" + object.getName()
                            + "\" class=\"" + deferredClass + "\"/>\n"
                            + "</entity>";
                    _reflectionParser.reset();

                    CompositeEntity toplevel;

                    try {
                        toplevel = (CompositeEntity) _reflectionParser
                                .parse(source);
                    } catch (Exception ex) {
                        throw new InternalErrorException("Attempt "
                                + "to create an instance of " + deferredClass
                                + " failed because "
                                + "it does not have a Workspace "
                                + "constructor.  Original error:\n"
                                + ex.getMessage());
                    }

                    if (object instanceof Attribute) {
                        deferredObject = toplevel
                                .getAttribute(object.getName());
                    } else if (object instanceof Port) {
                        deferredObject = toplevel.getPort(object.getName());
                    } else {
                        deferredObject = toplevel.getEntity(object.getName());
                    }

                    //       System.out.println("class without workspace = " +
                    //         deferredClass);
                }
View Full Code Here

TOP

Related Classes of ptolemy.kernel.CompositeEntity

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.