Package diva.graph

Examples of diva.graph.GraphModel


     * amount decreases linearly with the SPARSENESS value.
     *
     * @see #setSparseness(double)
     */
    protected void initGrid() {
        GraphModel model = getLayoutTarget().getGraphModel();
        int nodeCount = model.getNodeCount(_graph);

        if (nodeCount > 0) {
            Rectangle2D dim = getLayoutTarget().getViewport(_graph);
            double aspect = dim.getHeight() / dim.getWidth();
            double gh = Math.sqrt(nodeCount * aspect) * _sparseness;

            //debug("aspect=" + aspect);
            //debug("gh=" + gh);
            // Fix the number of vertical nodes.
            _gh = (int) Math.ceil(gh);

            // Infer the number of horizontal nodes.
            _gw = nodeCount / _gh;

            while ((_gh * _gw) < nodeCount) {
                _gw++;
            }

            _grid = new Object[_gw][_gh];

            Iterator nodes = model.nodes(_graph);

            for (int x = 0; x < _gw; x++) {
                for (int y = 0; y < _gh; y++) {
                    if (!nodes.hasNext()) {
                        break;
View Full Code Here


     *                 TEE_PENALTY * num_tee(g)
     * </pre>
     */
    protected double nodeCost(Object node) {
        LayoutTarget target = getLayoutTarget();
        GraphModel model = target.getGraphModel();

        if (node == null) {
            return 0;
        }

        int cost = 0;

        for (Iterator i = model.inEdges(node); i.hasNext();) {
            cost += edgeCost(i.next());
        }

        for (Iterator i = model.outEdges(node); i.hasNext();) {
            cost += edgeCost(i.next());
        }

        double teeCost = numTees(_graph) * TEE_PENALTY;
        cost += teeCost;
View Full Code Here

     * Return the number of crossings between this edge and other
     * edges in the graph.
     */
    protected final int numCrossings(Object inEdge, Object composite) {
        int num = 0;
        GraphModel model = getLayoutTarget().getGraphModel();
        Object inTail = model.getTail(inEdge);
        Object inHead = model.getHead(inEdge);

        inHead = _getParentInGraph(inHead);
        inTail = _getParentInGraph(inTail);

        if ((inHead == null) || (inTail == null)) {
            return 0;
        }

        int[] inTailPt = getXY(inTail);
        int[] inHeadPt = getXY(inHead);

        for (Iterator i = model.nodes(composite); i.hasNext();) {
            Object node = i.next();

            for (Iterator j = model.outEdges(node); j.hasNext();) {
                Object edge = j.next();
                Object tail = model.getTail(edge);
                Object head = model.getHead(edge);

                if ((tail == null) || (head == null) || (tail == inTail)
                        || (tail == inHead) || (head == inTail)
                        || (head == inHead)) {
                    //these cannot cross
View Full Code Here

     * in the graph.  For now, simply test to see if the lines are
     * horizontal or vertical and overlap with each other.
     */
    protected final int numOverlaps(Object inEdge, Object composite) {
        int num = 0;
        GraphModel model = getLayoutTarget().getGraphModel();
        Object inTail = model.getTail(inEdge);
        Object inHead = model.getHead(inEdge);

        inHead = _getParentInGraph(inHead);
        inTail = _getParentInGraph(inTail);

        if ((inHead == null) || (inTail == null)) {
            return 0;
        }

        int[] inTailPt = getXY(inTail);
        int[] inHeadPt = getXY(inHead);

        for (int which = 0; which < 2; which++) {
            if (inTailPt[which] == inHeadPt[which]) {
                for (Iterator i = model.nodes(composite); i.hasNext();) {
                    Object node = i.next();

                    for (Iterator j = model.outEdges(node); j.hasNext();) {
                        Object edge = j.next();
                        Object tail = model.getTail(edge);
                        Object head = model.getHead(edge);
                        head = _getParentInGraph(head);
                        tail = _getParentInGraph(tail);

                        if ((head != null) && (tail != null)) {
                            int[] tailPt = getXY(tail);
View Full Code Here

    // Unfortunately, the head and/or tail of the edge may not
    // be directly contained in the graph.  In this case, we need to
    // figure out which of their parents IS in the graph and calculate the
    // cost of that instead.
    private Object _getParentInGraph(Object node) {
        GraphModel model = getLayoutTarget().getGraphModel();

        while ((node != null) && !model.containsNode(_graph, node)) {
            Object parent = model.getParent(node);

            if (model.isNode(parent)) {
                node = parent;
            } else {
                node = null;
            }
        }
View Full Code Here

     */
    public void actionPerformed(ActionEvent e) {
        JGraph jgraph = (JGraph) e.getSource();
        GraphPane graphPane = jgraph.getGraphPane();
        GraphController controller = graphPane.getGraphController();
        GraphModel graphModel = controller.getGraphModel();
        SelectionModel model = controller.getSelectionModel();
        Object[] selection = model.getSelectionAsArray();
        Object[] userObjects = new Object[selection.length];

        // First remove the selection.
        for (int i = 0; i < selection.length; i++) {
            userObjects[i] = ((Figure) selection[i]).getUserObject();
            model.removeSelection(selection[i]);
        }

        // Remove all the edges first, since if we remove the nodes first,
        // then removing the nodes might remove some of the edges.
        for (int i = 0; i < userObjects.length; i++) {
            Object userObject = userObjects[i];

            if (graphModel.isEdge(userObject)) {
                controller.removeEdge(userObject);
            }
        }

        for (int i = 0; i < selection.length; i++) {
            Object userObject = userObjects[i];

            if (graphModel.isNode(userObject)) {
                controller.removeNode(userObject);
            }
        }
    }
View Full Code Here

    /** Layout the graph again.
     */
    protected void _doLayout(GraphModel graph, GraphPane gp) {
        // Do the layout
        try {
            final GraphModel layoutGraph = graph;
            final GraphController gc = gp.getGraphController();
            final GraphPane pane = gp;
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    // Layout is a bit stupid
                    LayoutTarget target = new BasicLayoutTarget(gc);
                    LevelLayout staticLayout = new LevelLayout(target);
                    staticLayout.setOrientation(LevelLayout.HORIZONTAL);
                    staticLayout.layout(layoutGraph.getRoot());
                    pane.repaint();
                }
            });
        } catch (Exception e) {
            System.out.println(e);
View Full Code Here

     */
    public void paste() {
        Clipboard clipboard = java.awt.Toolkit.getDefaultToolkit()
                .getSystemClipboard();
        Transferable transferable = clipboard.getContents(this);
        GraphModel model = _getGraphModel();

        if (transferable == null) {
            return;
        }

        try {
            NamedObj container = (NamedObj) model.getRoot();
            StringBuffer moml = new StringBuffer();

            // The pasted version will have the names generated by the
            // uniqueName() method of the container, to ensure that they
            // do not collide with objects already in the container.
View Full Code Here

    /** Redo the last undone change on the model.
     *  @see #undo()
     */
    public void redo() {
        GraphModel model = _getGraphModel();

        try {
            NamedObj toplevel = (NamedObj) model.getRoot();
            RedoChangeRequest change = new RedoChangeRequest(this, toplevel);
            toplevel.requestChange(change);
        } catch (Exception ex) {
            MessageHandler.error("Redo failed", ex);
        }
View Full Code Here

    /** Undo the last undoable change on the model.
     *  @see #redo()
     */
    public void undo() {
        GraphModel model = _getGraphModel();

        try {
            NamedObj toplevel = (NamedObj) model.getRoot();
            UndoChangeRequest change = new UndoChangeRequest(this, toplevel);
            toplevel.requestChange(change);
        } catch (Exception ex) {
            MessageHandler.error("Undo failed", ex);
        }
View Full Code Here

TOP

Related Classes of diva.graph.GraphModel

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.