Exemplo n.º 1
0
  /**
   * Create a new, empty FisheyeMenu.
   *
   * @see #addMenuItem(String, javax.swing.Action)
   */
  public FisheyeMenu() {
    super(new Visualization());
    m_vis.addTable(ITEMS, m_items);

    // set up the renderer to use
    LabelRenderer renderer = new LabelRenderer(LABEL);
    renderer.setHorizontalPadding(0);
    renderer.setVerticalPadding(1);
    renderer.setHorizontalAlignment(Constants.LEFT);
    m_vis.setRendererFactory(new DefaultRendererFactory(renderer));

    // set up this display
    setSize(100, 470);
    setHighQuality(true);
    setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 5));
    addControlListener(
        new ControlAdapter() {
          // dispatch an action event to the menu item
          public void itemClicked(VisualItem item, MouseEvent e) {
            ActionListener al = (ActionListener) item.get(ACTION);
            al.actionPerformed(
                new ActionEvent(item, e.getID(), "click", e.getWhen(), e.getModifiers()));
          }
        });

    // text color function
    // items with the mouse over printed in red, otherwise black
    ColorAction colors = new ColorAction(ITEMS, VisualItem.TEXTCOLOR);
    colors.setDefaultColor(ColorLib.gray(0));
    colors.add("hover()", ColorLib.rgb(255, 0, 0));

    // initial layout and coloring
    ActionList init = new ActionList();
    init.add(new VerticalLineLayout(m_maxHeight));
    init.add(colors);
    init.add(new RepaintAction());
    m_vis.putAction("init", init);

    // fisheye distortion based on the current anchor location
    ActionList distort = new ActionList();
    Distortion feye = new FisheyeDistortion(0, m_scale);
    distort.add(feye);
    distort.add(colors);
    distort.add(new RepaintAction());
    m_vis.putAction("distort", distort);

    // update the distortion anchor position to be the current
    // location of the mouse pointer
    addControlListener(new AnchorUpdateControl(feye, "distort"));
  }
Exemplo n.º 2
0
  public trial(int st, String n) {

    // setup a visualisation
    super(new Visualization());

    System.out.println(st + "  " + n);

    // generate a graph
    initGraph(n, st);

    //  standard labelRenderer for the given label
    LabelRenderer nodeRenderer = new LabelRenderer(LABEL);
    // rendererFactory for the visualization items
    DefaultRendererFactory rendererFactory = new DefaultRendererFactory();
    // set the labelRenderer
    rendererFactory.setDefaultRenderer(nodeRenderer);
    m_vis.setRendererFactory(rendererFactory);

    // Color Actions
    ColorAction nodeText = new ColorAction(NODES, VisualItem.TEXTCOLOR);
    nodeText.setDefaultColor(ColorLib.gray(0));
    ColorAction nodeStroke = new ColorAction(NODES, VisualItem.STROKECOLOR);
    nodeStroke.setDefaultColor(ColorLib.gray(100));
    ColorAction nodeFill = new ColorAction(NODES, VisualItem.FILLCOLOR);
    nodeFill.setDefaultColor(ColorLib.gray(255));
    ColorAction edgeStrokes = new ColorAction(EDGES, VisualItem.STROKECOLOR);
    edgeStrokes.setDefaultColor(ColorLib.gray(100));

    // ColorAction fill = new ColorAction(NODES, VisualItem.FILLCOLOR,
    ColorLib.rgb(200, 200, 255);
    // fill.add(VisualItem.FIXED, ColorLib.rgb(255,100,100));
    // fill.add(VisualItem.HIGHLIGHT, ColorLib.rgb(255,200,125));

    // bundle the color actions
    ActionList draw = new ActionList();
    //    draw.add(fill);
    draw.add(new ColorAction(NODES, VisualItem.STROKECOLOR, 0));
    draw.add(new ColorAction(NODES, VisualItem.TEXTCOLOR, ColorLib.rgb(0, 0, 0)));
    draw.add(new ColorAction(EDGES, VisualItem.FILLCOLOR, ColorLib.gray(200)));
    draw.add(new ColorAction(EDGES, VisualItem.STROKECOLOR, ColorLib.gray(200)));
    draw.add(nodeText);
    draw.add(nodeStroke);
    draw.add(nodeFill);
    draw.add(edgeStrokes);

    ActionList animate = new ActionList(Activity.INFINITY);
    //   animate.add(fill);
    animate.add(new RepaintAction());

    m_nodeRenderer = new LabelRenderer(m_label);

    m_nodeRenderer.setRenderType(AbstractShapeRenderer.RENDER_TYPE_FILL);
    m_nodeRenderer.setHorizontalAlignment(Constants.LEFT);
    m_nodeRenderer.setRoundedCorner(8, 8);
    m_edgeRenderer = new EdgeRenderer(Constants.EDGE_TYPE_CURVE);

    DefaultRendererFactory rf = new DefaultRendererFactory(m_nodeRenderer);
    m_vis.setRendererFactory(rf);

    // DataSizeAction
    DataSizeAction nodeDataSizeAction = new DataSizeAction(NODES, SIZE);
    draw.add(nodeDataSizeAction);
    m_vis.putAction("draw", draw);
    m_vis.putAction("layout", animate);

    m_vis.runAfter("draw", "layout");

    // create the layout action for the graph
    NodeLinkTreeLayout treeLayout = new NodeLinkTreeLayout(GRAPH, m_orientation, 80, 5, 10);
    treeLayout.setLayoutAnchor(new Point2D.Double(250, -150));
    m_vis.putAction("treeLayout", treeLayout);
    m_vis.addFocusGroup("selected");

    CollapsedSubtreeLayout subLayout = new CollapsedSubtreeLayout(GRAPH, m_orientation);
    m_vis.putAction("subLayout", subLayout);

    m_vis.run("treeLayout");
    m_vis.run("draw");

    pan(250, 250);
    setHighQuality(true);
    addControlListener(new ZoomControl());
    addControlListener(new PanControl());
    addControlListener(new DragControl(true));
    addControlListener(new NodeClicked());
    addControlListener(new FocusControl());

    registerKeyboardAction(
        new OrientAction(Constants.ORIENT_LEFT_RIGHT),
        "left-to-right",
        KeyStroke.getKeyStroke("ctrl 1"),
        WHEN_FOCUSED);
    registerKeyboardAction(
        new OrientAction(Constants.ORIENT_TOP_BOTTOM),
        "top-to-bottom",
        KeyStroke.getKeyStroke("ctrl 2"),
        WHEN_FOCUSED);
    registerKeyboardAction(
        new OrientAction(Constants.ORIENT_RIGHT_LEFT),
        "right-to-left",
        KeyStroke.getKeyStroke("ctrl 3"),
        WHEN_FOCUSED);
    registerKeyboardAction(
        new OrientAction(Constants.ORIENT_BOTTOM_TOP),
        "bottom-to-top",
        KeyStroke.getKeyStroke("ctrl 4"),
        WHEN_FOCUSED);
    TupleSet search = new PrefixSearchTupleSet();
    m_vis.addFocusGroup(Visualization.SEARCH_ITEMS, search);
    search.addTupleSetListener(
        new TupleSetListener() {
          public void tupleSetChanged(TupleSet t, Tuple[] add, Tuple[] rem) {
            m_vis.cancel("animatePaint");
            m_vis.run("fullPaint");
            m_vis.run("animatePaint");
          }
        });
  }
Exemplo n.º 3
0
  public AggregateDemo() {
    // initialize display and data
    super(new Visualization());
    initDataGroups();

    // set up the renderers
    // draw the nodes as basic shapes
    Renderer nodeR = new ShapeRenderer(20);
    // draw aggregates as polygons with curved edges
    Renderer polyR = new PolygonRenderer(Constants.POLY_TYPE_CURVE);
    ((PolygonRenderer) polyR).setCurveSlack(0.15f);

    // modification to try drawing edges to aggregates
    Renderer edgeR =
        new EdgeRenderer() {
          @Override
          protected Shape getRawShape(VisualItem item) {
            EdgeItem edge = (EdgeItem) item;
            VisualItem item1 = edge.getSourceItem();
            VisualItem item2 = edge.getTargetItem();
            item2 = (AggregateItem) at.getAggregates(item2).next();

            int type = m_edgeType;

            getAlignedPoint(m_tmpPoints[0], item1.getBounds(), m_xAlign1, m_yAlign1);
            getAlignedPoint(m_tmpPoints[1], item2.getBounds(), m_xAlign2, m_yAlign2);
            m_curWidth = (float) (m_width * getLineWidth(item));

            // create the arrow head, if needed
            EdgeItem e = (EdgeItem) item;
            if (e.isDirected() && m_edgeArrow != Constants.EDGE_ARROW_NONE) {
              // get starting and ending edge endpoints
              boolean forward = (m_edgeArrow == Constants.EDGE_ARROW_FORWARD);
              Point2D start = null, end = null;
              start = m_tmpPoints[forward ? 0 : 1];
              end = m_tmpPoints[forward ? 1 : 0];

              // compute the intersection with the target bounding box
              VisualItem dest = forward ? e.getTargetItem() : e.getSourceItem();
              int i =
                  GraphicsLib.intersectLineRectangle(start, end, dest.getBounds(), m_isctPoints);
              if (i > 0) end = m_isctPoints[0];

              // create the arrow head shape
              AffineTransform at = getArrowTrans(start, end, m_curWidth);
              m_curArrow = at.createTransformedShape(m_arrowHead);

              // update the endpoints for the edge shape
              // need to bias this by arrow head size
              Point2D lineEnd = m_tmpPoints[forward ? 1 : 0];
              lineEnd.setLocation(0, -m_arrowHeight);
              at.transform(lineEnd, lineEnd);
            } else {
              m_curArrow = null;
            }

            // create the edge shape
            Shape shape = null;
            double n1x = m_tmpPoints[0].getX();
            double n1y = m_tmpPoints[0].getY();
            double n2x = m_tmpPoints[1].getX();
            double n2y = m_tmpPoints[1].getY();
            switch (type) {
              case Constants.EDGE_TYPE_LINE:
                m_line.setLine(n1x, n1y, n2x, n2y);
                shape = m_line;
                break;
              case Constants.EDGE_TYPE_CURVE:
                getCurveControlPoints(edge, m_ctrlPoints, n1x, n1y, n2x, n2y);
                m_cubic.setCurve(
                    n1x,
                    n1y,
                    m_ctrlPoints[0].getX(),
                    m_ctrlPoints[0].getY(),
                    m_ctrlPoints[1].getX(),
                    m_ctrlPoints[1].getY(),
                    n2x,
                    n2y);
                shape = m_cubic;
                break;
              default:
                throw new IllegalStateException("Unknown edge type");
            }

            // return the edge shape
            return shape;
          }
        };

    DefaultRendererFactory drf = new DefaultRendererFactory(nodeR, edgeR);
    drf.add("ingroup('aggregates')", polyR);
    m_vis.setRendererFactory(drf);

    // set up the visual operators
    // first set up all the color actions
    ColorAction nStroke = new ColorAction(NODES, VisualItem.STROKECOLOR);
    nStroke.setDefaultColor(ColorLib.gray(100));
    nStroke.add("_hover", ColorLib.gray(50));

    ColorAction nFill = new ColorAction(NODES, VisualItem.FILLCOLOR);
    nFill.setDefaultColor(ColorLib.gray(255));
    nFill.add("_hover", ColorLib.gray(200));

    ColorAction nEdges = new ColorAction(EDGES, VisualItem.STROKECOLOR);
    nEdges.setDefaultColor(ColorLib.gray(100));

    ColorAction aStroke = new ColorAction(AGGR, VisualItem.STROKECOLOR);
    aStroke.setDefaultColor(ColorLib.gray(200));
    aStroke.add("_hover", ColorLib.rgb(255, 100, 100));

    int[] palette =
        new int[] {
          ColorLib.rgba(255, 200, 200, 255),
          ColorLib.rgba(200, 255, 200, 255),
          ColorLib.rgba(200, 200, 255, 255)
        };
    ColorAction aFill =
        new DataColorAction(AGGR, "id", Constants.NOMINAL, VisualItem.FILLCOLOR, palette);

    // bundle the color actions
    ActionList colors = new ActionList();
    colors.add(nStroke);
    colors.add(nFill);
    colors.add(nEdges);
    colors.add(aStroke);
    colors.add(aFill);

    // now create the main layout routine
    ActionList layout = new ActionList(Activity.INFINITY);
    layout.add(colors);
    layout.add(new ForceDirectedLayout(GRAPH, true));
    layout.add(new AggregateLayout(AGGR));
    layout.add(new RepaintAction());
    m_vis.putAction("layout", layout);

    // set up the display
    setSize(500, 500);
    pan(250, 250);
    setHighQuality(true);
    addControlListener(new AggregateDragControl());
    addControlListener(new ZoomControl());
    addControlListener(new PanControl());

    // set things running
    m_vis.run("layout");
  }