Package ptolemy.kernel.util

Examples of ptolemy.kernel.util.NamedObj


                            .getMenuShortcutKeyMask()));
            putValue(GUIUtilities.MNEMONIC_KEY, Integer.valueOf(KeyEvent.VK_B));
        }

        public void actionPerformed(ActionEvent e) {
            final NamedObj container = (NamedObj) _getGraphModel().getRoot();

            // Get the selection objects.
            // NOTE: The order in the model must be respected.
            HashSet namedObjSet = _getSelectionSet();
            final List elements = container.sortContainedObjects(namedObjSet);

            // Return if any is a derived object.
            if (_checkForImplied(elements)) {
                return;
            }

            // Issue a change request, since this requires write access.
            ChangeRequest request = new ChangeRequest(container, "Send to back") {
                protected void _execute() throws IllegalActionException {
                    MoveAction.move(elements, MoveAction.TO_FIRST, container);
                }
            };

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


                            .getMenuShortcutKeyMask()));
            putValue(GUIUtilities.MNEMONIC_KEY, Integer.valueOf(KeyEvent.VK_F));
        }

        public void actionPerformed(ActionEvent e) {
            final NamedObj container = (NamedObj) _getGraphModel().getRoot();

            // Get the selection objects.
            // NOTE: The order in the model must be respected.
            HashSet namedObjSet = _getSelectionSet();
            final List elements = container.sortContainedObjects(namedObjSet);

            // Return if any is a derived object.
            if (_checkForImplied(elements)) {
                return;
            }

            // Issue a change request, since this requires write access.
            ChangeRequest request = new ChangeRequest(container,
                    "Bring to front") {
                protected void _execute() throws IllegalActionException {
                    MoveAction.move(elements, MoveAction.TO_LAST, container);
                }
            };

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

         *  the container of the object with an icon.
         *  @param node The node.
         *  @return A valid MoML string.
         */
        public String getDeleteNodeMoML(Object node) {
            NamedObj deleteObj = ((Locatable) node).getContainer();
            String moml = "<deleteEntity name=\"" + deleteObj.getName()
                    + "\"/>\n";
            return moml;
        }
View Full Code Here

         @param eventSource The source of the event that will be dispatched,
         *   e.g. the view that made this call.
         *  @param node The node.
         */
        public void removeNode(final Object eventSource, Object node) {
            NamedObj deleteObj = ((Locatable) node).getContainer();

            if (!(deleteObj instanceof ComponentEntity)) {
                throw new InternalErrorException(
                        "Attempt to remove a node that is not an Entity. "
                                + "node = " + node);
            }

            // Make the request in the context of the container.
            NamedObj container = deleteObj.getContainer();
            ;

            String moml = "<deleteEntity name=\"" + deleteObj.getName()
                    + "\"/>\n";

            // Note: The source is NOT the graph model.
            MoMLChangeRequest request = new MoMLChangeRequest(this, container,
                    moml);
            request.setUndoable(true);
            container.requestChange(request);
        }
View Full Code Here

            // FIXME: Not sure why this is necessary, but it helps
            // when generating an applet for moml/demo/spectrum.xml
            filter.put("ptolemy.kernel.util.Location", null);
            MoMLParser.addMoMLFilter(filter);

            NamedObj toplevel = null;

            try {
                toplevel = parser.parse(null, modelURL);

                // FIXME: 1st arg of parse() could be $PTII as a URL.
                modelPathOrURL = modelURL.toExternalForm();
            } catch (FileNotFoundException ex) {
                try {
                    // Might be under Web Start, try it this way.
                    URL anotherURL = ClassUtilities
                            .jarURLEntryResource(modelPathOrURL);

                    if (anotherURL != null) {
                        toplevel = parser.parse(null, anotherURL);
                        modelPathOrURL = anotherURL.toExternalForm();
                    } else {
                        throw new Exception("1. Failed to find '"
                                + modelURL.toExternalForm() + "'\n"
                                + "2. Failed to find '" + modelPathOrURL + "'");
                    }
                } catch (Exception ex1) {
                    throw new IllegalActionException(this, ex1,
                            "Failed to parse '" + modelPathOrURL + "'"
                                    + " Tried loading as a resource, too!");
                }
            }

            Parameter modelPath;

            try {
                modelPath = (StringParameter) getAttribute("modelPath");
            } catch (ClassCastException ex) {
                throw new InternalErrorException(this, ex, "Failed to cast '"
                        + getAttribute("modelPath") + "' to a StringParameter");
            }

            modelPath.setExpression(modelPathOrURL);

            // Strip off the leading '.' and then sanitize.
            String modelNameValue = StringUtilities.sanitizeName(toplevel
                    .getFullName().substring(1));

            Parameter modelName = (StringParameter) getAttribute("modelName");
            modelName.setExpression(modelNameValue);
View Full Code Here

     */
    public void setContainer(NamedObj container) throws IllegalActionException,
            NameDuplicationException {
        if (container != getContainer()) {
            // May need to unregister as a piggyback with the previous container.
            NamedObj previousContainer = getContainer();
            if (previousContainer instanceof CompositeActor) {
                ((CompositeActor) previousContainer).removePiggyback(this);
            }
        }
        super.setContainer(container);
View Full Code Here

            if (selection[i] instanceof Figure) {
                Object userObject = ((Figure) selection[i]).getUserObject();

                if (graphModel.isEdge(userObject)
                        || graphModel.isNode(userObject)) {
                    NamedObj actual = (NamedObj) graphModel
                            .getSemanticObject(userObject);

                    if (actual != null) {
                        namedObjSet.add(actual);
                    } else {
                        // Special case, may need to handle by not going to
                        // MoML and which may not be undoable.
                        // FIXME: This is no way to handle it...
                        System.out
                                .println("Object with no semantic object , class: "
                                        + userObject.getClass().getName());
                    }
                }
            }
        }

        // Generate the MoML to carry out move.
        // Note that the location has already been set by the mouseMoved()
        // call, but we need to do this so that the undo is generated and
        // so that the change propagates.
        // The toplevel is the container being edited.
        final NamedObj toplevel = (NamedObj) graphModel.getRoot();

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

        Iterator elements = namedObjSet.iterator();

        while (elements.hasNext()) {
            NamedObj element = (NamedObj) elements.next();
            List locationList = element.attributeList(Locatable.class);

            if (locationList.isEmpty()) {
                // Nothing to do as there was no previous location
                // attribute (applies to "unseen" relations)
                continue;
            }

            // Set the new location attribute.
            Locatable locatable = (Locatable) locationList.get(0);

            // Give default values in case the previous locations value
            // has not yet been set
            double[] newLocation = new double[] { 0, 0 };

            if (locatable.getLocation() != null) {
                newLocation = locatable.getLocation();
            }

            // NOTE: we use the transform worked out for the drag to
            // set the original MoML location
            double[] oldLocation = new double[2];
            oldLocation[0] = newLocation[0] + transform[0];
            oldLocation[1] = newLocation[1] + transform[1];

            // Create the MoML, wrapping the new location attribute
            // in an element refering to the container
            String containingElementName = element.getElementName();
            String elementToMove = "<" + containingElementName + " name=\""
                    + element.getName() + "\" >\n";
            moml.append(elementToMove);
            undoMoml.append(elementToMove);

            // NOTE: use the moml info element name here in case the
            // location is a vertex
View Full Code Here

         @param edge The edge.
         *  @return A valid MoML string.
         */
        public String getDeleteEdgeMoML(Object edge) {
            final Link link = (Link) edge;
            NamedObj linkHead = (NamedObj) link.getHead();
            NamedObj linkTail = (NamedObj) link.getTail();
            Relation linkRelation = link.getRelation();

            // This moml is parsed to execute the change
            StringBuffer moml = new StringBuffer();

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

            // create moml to unlink any existing.
            try {
                _unlinkMoML(container, moml, linkHead, linkTail, linkRelation);
            } catch (Exception ex) {
View Full Code Here

                NamedObj linkHead, NamedObj linkTail, Relation relation)
                throws Exception {
            // If the link is already connected, then create a bit of MoML
            // to unlink the link.
            if ((linkHead != null) && (linkTail != null)) {
                NamedObj head = (NamedObj) getSemanticObject(linkHead);
                NamedObj tail = (NamedObj) getSemanticObject(linkTail);

                if (head instanceof ComponentPort
                        && tail instanceof ComponentPort) {
                    ComponentPort headPort = (ComponentPort) head;
                    ComponentPort tailPort = (ComponentPort) tail;

                    // Unlinking two ports with an anonymous relation.
                    moml.append("<unlink port=\"" + headPort.getName(container)
                            + "\" relation=\"" + relation.getName(container)
                            + "\"/>\n");
                    moml.append("<unlink port=\"" + tailPort.getName(container)
                            + "\" relation=\"" + relation.getName(container)
                            + "\"/>\n");
                    moml.append("<deleteRelation name=\""
                            + relation.getName(container) + "\"/>\n");
                } else if (head instanceof ComponentPort
                        && linkTail instanceof Vertex) {
                    // Unlinking a port from an existing relation.
                    moml.append("<unlink port=\"" + head.getName(container)
                            + "\" relation=\"" + tail.getName(container)
                            + "\"/>\n");
                } else if (tail instanceof ComponentPort
                        && linkHead instanceof Vertex) {
                    // Unlinking a port from an existing relation.
                    moml.append("<unlink port=\"" + tail.getName(container)
                            + "\" relation=\"" + head.getName(container)
                            + "\"/>\n");
                } else if (linkHead instanceof Vertex
                        && linkTail instanceof Vertex) {
                    moml.append("<unlink relation1=\""
                            + tail.getName(container) + "\" relation2=\""
                            + head.getName(container) + "\"/>\n");
                } else {
                    throw new RuntimeException("Unlink failed: " + "Head = "
                            + head + ", Tail = " + tail);
                }
View Full Code Here

         */
        private String _linkMoML(NamedObj container, StringBuffer moml,
                StringBuffer failmoml, NamedObj linkHead, NamedObj linkTail)
                throws Exception {
            if ((linkHead != null) && (linkTail != null)) {
                NamedObj head = (NamedObj) getSemanticObject(linkHead);
                NamedObj tail = (NamedObj) getSemanticObject(linkTail);

                if (head instanceof ComponentPort
                        && tail instanceof ComponentPort) {
                    ComponentPort headPort = (ComponentPort) head;
                    ComponentPort tailPort = (ComponentPort) tail;
                    NamedObj ptolemyModel = getPtolemyModel();

                    // Linking two ports with a new relation.
                    String relationName = ptolemyModel.uniqueName("relation");

                    // If the context is not the entity that we're editing,
                    // then we need to set the context correctly.
                    if (ptolemyModel != container) {
                        String contextString = "<entity name=\""
                                + ptolemyModel.getName(container) + "\">\n";
                        moml.append(contextString);
                        failmoml.append(contextString);
                    }

                    // Note that we use no class so that we use the container's
                    // factory method when this gets parsed
                    moml.append("<relation name=\"" + relationName + "\"/>\n");
                    moml.append("<link port=\""
                            + headPort.getName(ptolemyModel) + "\" relation=\""
                            + relationName + "\"/>\n");
                    moml.append("<link port=\""
                            + tailPort.getName(ptolemyModel) + "\" relation=\""
                            + relationName + "\"/>\n");

                    // Record moml so that we can blow away these
                    // links in case we can't create them
                    failmoml.append("<unlink port=\""
                            + headPort.getName(ptolemyModel) + "\" relation=\""
                            + relationName + "\"/>\n");
                    failmoml.append("<unlink port=\""
                            + tailPort.getName(ptolemyModel) + "\" relation=\""
                            + relationName + "\"/>\n");
                    failmoml.append("<deleteRelation name=\"" + relationName
                            + "\"/>\n");

                    // close the context
                    if (ptolemyModel != container) {
                        moml.append("</entity>");
                        failmoml.append("</entity>");
                    }

                    // Ugh this is ugly.
                    if (ptolemyModel != container) {
                        return ptolemyModel.getName(container) + "."
                                + relationName;
                    } else {
                        return relationName;
                    }
                } else if (head instanceof ComponentPort
View Full Code Here

TOP

Related Classes of ptolemy.kernel.util.NamedObj

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.