public GraphVisualisation(rndalg.Graph graphToShow, Vector<Vertex> cut) { super(); Graph displayed = new Graph(false); displayed.addColumn("id", String.class); displayed.addColumn("isCut", Boolean.class); this.makeGraph(displayed, graphToShow, cut); this.addGraph("graph", displayed); LabelRenderer r = new LabelRenderer("id"); r.setRoundedCorner(10, 10); r.setHorizontalPadding(5); r.setVerticalPadding(2); this.setRendererFactory(new DefaultRendererFactory(r)); ActionList layoutActions = new ActionList(Activity.INFINITY); ForceDirectedLayout layout = new ForceDirectedLayout("graph"); layoutActions.add(layout); layoutActions.add(new RepaintAction()); // black text ColorAction textCA = new ColorAction("graph.nodes", VisualItem.TEXTCOLOR, ColorLib.rgb(0, 0, 0)); // black edges // ColorAction edgeCA = new ColorAction("graph.edges", VisualItem.STROKECOLOR, // ColorLib.rgb(0,0,0)); // edges ColorAction edgeCA = new ColorAction( "graph.edges", ExpressionParser.predicate("isCut = false"), VisualItem.STROKECOLOR, ColorLib.rgb(0, 0, 0)); ColorAction edgeCutCA = new ColorAction( "graph.edges", ExpressionParser.predicate("isCut = true"), VisualItem.STROKECOLOR, ColorLib.rgb(255, 0, 0)); // concatenate the color actions ActionList colorActions = new ActionList(); colorActions.add(textCA); colorActions.add(edgeCA); colorActions.add(edgeCutCA); this.putAction("draw", colorActions); this.putAction("layout", layoutActions); this.runAfter("draw", "layout"); this.run("draw"); }
/** * 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 DataMountain(Table t) { super(new Visualization()); m_vis.addTable("data", t); LabelRenderer nodeRenderer = new LabelRenderer(null, "image"); nodeRenderer.setTextField(null); nodeRenderer.setVerticalAlignment(Constants.BOTTOM); nodeRenderer.setHorizontalPadding(0); nodeRenderer.setVerticalPadding(0); nodeRenderer.setMaxImageDimensions(100, 100); m_vis.setRendererFactory(new DefaultRendererFactory(nodeRenderer)); ActionList init = new ActionList(); init.add(new RandomLayout()); init.add(new DataMountainSizeAction()); m_vis.putAction("init", init); ActionList update = new ActionList(); update.add(new DataMountainSizeAction()); update.add( new ColorAction("data", VisualItem.STROKECOLOR) { public int getColor(VisualItem item) { return ColorLib.rgb((item.isHover() ? 255 : 0), 0, 0); } }); update.add(new RepaintAction()); m_vis.putAction("update", update); // we run this to make sure the forces are stabilized ActionList preforce = new ActionList(1000); preforce.add(new DataMountainForceLayout(true)); m_vis.putAction("preforce", preforce); // this will cause docs to move out of the way when dragging final ForceDirectedLayout fl = new DataMountainForceLayout(false); ActivityListener fReset = new ActivityAdapter() { public void activityCancelled(Activity a) { fl.reset(); } }; ActionList forces = new ActionList(Activity.INFINITY); forces.add(fl); forces.add(update); forces.addActivityListener(fReset); m_vis.putAction("forces", forces); setSize(640, 450); setDamageRedraw(false); // disable due to Java2D image clipping errors setBorder(BorderFactory.createEmptyBorder(30, 20, 5, 20)); setItemSorter(new DataMountainSorter()); addControlListener(new DataMountainControl()); // pre-load images, otherwise they will be loaded asynchronously nodeRenderer.getImageFactory().preloadImages(m_vis.items(), "image"); // initialize and present the interface m_vis.run("init"); m_vis.runAfter("preforce", "update"); m_vis.run("preforce"); }