Search in sources :

Example 1 with NodeItem

use of prefuse.visual.NodeItem in project qi4j-sdk by Qi4j.

the class StackedGraphDisplay method setSelectedValue.

@Override
public void setSelectedValue(Object object) {
    if (object == null) {
        return;
    }
    NodeItem item = null;
    Iterator iter = m_vis.items(GRAPH_NODES);
    while (iter.hasNext()) {
        NodeItem tItem = (NodeItem) iter.next();
        Object tObj = tItem.get(USER_OBJECT);
        if (tObj.equals(object)) {
            item = tItem;
            break;
        }
    }
    if (item != null) {
        int depth = item.getDepth();
        boolean relayout = false;
        if (depth > stackedLayout.getZoom()) {
            stackedLayout.zoom(depth);
            relayout = true;
        }
        TupleSet ts = m_vis.getFocusGroup(Visualization.FOCUS_ITEMS);
        ts.setTuple(item);
        if (relayout) {
            run();
        } else {
            m_vis.run(AUTO_PAN_ACTION);
        }
    }
}
Also used : TupleSet(prefuse.data.tuple.TupleSet) NodeItem(prefuse.visual.NodeItem) Iterator(java.util.Iterator)

Example 2 with NodeItem

use of prefuse.visual.NodeItem in project qi4j-sdk by Qi4j.

the class StackedLayout method run.

@Override
public void run(double frac) {
    // setup
    NodeItem root = getLayoutRoot();
    layout(root, 0, 0);
    Rectangle2D bounds = root.getBounds();
    Display display = this.getVisualization().getDisplay(0);
    Dimension size = new Dimension((int) bounds.getWidth(), (int) bounds.getHeight());
    display.setSize(size);
    if (!display.isValid()) {
        display.validate();
    }
}
Also used : NodeItem(prefuse.visual.NodeItem) Rectangle2D(java.awt.geom.Rectangle2D) Dimension(java.awt.Dimension) Display(prefuse.Display)

Example 3 with NodeItem

use of prefuse.visual.NodeItem in project qi4j-sdk by Qi4j.

the class StackedLayout method arrangeChildHorizontally.

private void arrangeChildHorizontally(NodeItem parent) {
    double maxH = 0;
    for (int i = 0; i < parent.getChildCount(); i++) {
        NodeItem node = (NodeItem) parent.getChild(i);
        Rectangle2D bounds = node.getBounds();
        maxH = Math.max(maxH, bounds.getHeight());
    }
    for (int i = 0; i < parent.getChildCount(); i++) {
        NodeItem node = (NodeItem) parent.getChild(i);
        Rectangle2D bounds = node.getBounds();
        node.setBounds(bounds.getX(), bounds.getY(), bounds.getWidth(), maxH);
    }
}
Also used : NodeItem(prefuse.visual.NodeItem) Rectangle2D(java.awt.geom.Rectangle2D)

Example 4 with NodeItem

use of prefuse.visual.NodeItem in project qi4j-sdk by Qi4j.

the class StackedLayout method layout.

private void layout(NodeItem node, double x, double y) {
    Dimension minSize = getItemMinSize(node, null);
    node.setBounds(x, y, minSize.width, minSize.height);
    int depth = node.getDepth();
    if (depth > zoom) {
        //System.out.println("depth: " +  depth + "  zoom: " + zoom);
        node.setBounds(x, y, 0, 0);
        node.setVisible(false);
    } else {
        node.setVisible(true);
    }
    double cx = x + INSET;
    double cy = y + minSize.height;
    Area area = new Area(node.getBounds());
    boolean hasChild = false;
    for (int i = 0; i < node.getChildCount(); i++) {
        hasChild = true;
        NodeItem child = (NodeItem) node.getChild(i);
        layout(child, cx, cy);
        area.add(new Area(child.getBounds()));
        // shifting location calculation
        Rectangle2D nodeRect = child.getBounds();
        if (depth == 0) {
            // layer
            cy = cy + (INSET * 2) + nodeRect.getHeight();
        }
        if (depth == 1) {
            // module
            cx = cx + INSET + nodeRect.getWidth();
        } else if (depth == 2) {
            // type container
            cx = cx + INSET + nodeRect.getWidth();
        } else if (depth == 3) {
            // type
            cy = cy + INSET + nodeRect.getHeight();
        }
    }
    Rectangle2D bounds = area.getBounds2D();
    if (hasChild && depth <= zoom) {
        bounds.setRect(x, y, bounds.getWidth() + INSET, bounds.getHeight() + INSET);
    }
    node.setBounds(x, y, bounds.getWidth(), bounds.getHeight());
    //int depth = parent.getDepth();
    if (depth == 0) {
        arrangeChildVertically(node);
    } else if (depth == 1) {
        arrangeChildHorizontally(node);
    } else if (depth == 2) {
        arrangeChildHorizontally(node);
    } else if (depth == 3) {
        arrangeChildVertically(node);
    }
}
Also used : Area(java.awt.geom.Area) NodeItem(prefuse.visual.NodeItem) Rectangle2D(java.awt.geom.Rectangle2D) Dimension(java.awt.Dimension)

Example 5 with NodeItem

use of prefuse.visual.NodeItem in project qi4j-sdk by Qi4j.

the class StackedLayout method arrangeChildVertically.

private void arrangeChildVertically(NodeItem parent) {
    double maxW = 0;
    for (int i = 0; i < parent.getChildCount(); i++) {
        NodeItem node = (NodeItem) parent.getChild(i);
        Rectangle2D bounds = node.getBounds();
        maxW = Math.max(maxW, bounds.getWidth());
    }
    for (int i = 0; i < parent.getChildCount(); i++) {
        NodeItem node = (NodeItem) parent.getChild(i);
        Rectangle2D bounds = node.getBounds();
        node.setBounds(bounds.getX(), bounds.getY(), maxW, bounds.getHeight());
    }
}
Also used : NodeItem(prefuse.visual.NodeItem) Rectangle2D(java.awt.geom.Rectangle2D)

Aggregations

NodeItem (prefuse.visual.NodeItem)5 Rectangle2D (java.awt.geom.Rectangle2D)4 Dimension (java.awt.Dimension)2 Area (java.awt.geom.Area)1 Iterator (java.util.Iterator)1 Display (prefuse.Display)1 TupleSet (prefuse.data.tuple.TupleSet)1