/** * 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")); }
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"); }