/* * Test method for 'prefuse.Visualization.removeGroup(String)' */ @Test public void testRemoveGroup() { m_vis.removeGroup("g"); Assert.assertEquals(null, m_vis.getGroup("g")); Assert.assertEquals(null, m_vis.getGroup("g.nodes")); Assert.assertEquals(null, m_vis.getGroup("g.edges")); Assert.assertEquals(null, m_vis.getSourceData("g")); Assert.assertEquals(null, m_vis.getSourceData("g.nodes")); Assert.assertEquals(null, m_vis.getSourceData("g.edges")); Assert.assertEquals(false, m_vis.getFocusGroup("_focus_").containsTuple(m_n0)); }
public JPanel demo(Graph g, final String label) { // create a new radial tree view final PhysioMapRadialGraphView gview = new PhysioMapRadialGraphView(settings, g, label, semsimmodel); Visualization vis = gview.getVisualization(); // create a search panel for the tree map SearchQueryBinding sq = new SearchQueryBinding( (Table) vis.getGroup(treeNodes), label, (SearchTupleSet) vis.getGroup(Visualization.SEARCH_ITEMS)); JSearchPanel search = sq.createSearchPanel(); search.setShowResultCount(true); search.setBorder(BorderFactory.createEmptyBorder(5, 5, 4, 0)); search.setFont(FontLib.getFont("Verdana", Font.PLAIN, 11)); final JTextArea title = new JTextArea(); title.setPreferredSize(new Dimension(450, 500)); title.setMaximumSize(new Dimension(450, 500)); title.setMinimumSize(new Dimension(450, 500)); title.setAlignmentY(CENTER_ALIGNMENT); title.setLineWrap(true); title.setWrapStyleWord(true); title.setBorder(BorderFactory.createEmptyBorder(3, 0, 0, 0)); title.setFont(FontLib.getFont("Verdana", Font.PLAIN, 11)); gview.addControlListener( new ControlAdapter() { public void itemEntered(VisualItem item, MouseEvent e) {} public void itemExited(VisualItem item, MouseEvent e) { title.setText(null); } }); Box searchbox = new Box(BoxLayout.X_AXIS); searchbox.add(Box.createHorizontalStrut(10)); searchbox.add(search); searchbox.add(Box.createHorizontalStrut(3)); JPanel panel = new JPanel(new BorderLayout()); panel.add(searchbox, BorderLayout.NORTH); panel.add(gview, BorderLayout.CENTER); panel.add(Box.createGlue(), BorderLayout.SOUTH); Color BACKGROUND = Color.WHITE; Color FOREGROUND = Color.DARK_GRAY; UILib.setColor(panel, BACKGROUND, FOREGROUND); return panel; }
public void mouseClicked(MouseEvent e) { if (!(e.getSource().getClass().getName()).equalsIgnoreCase("VisualItem") && !UILib.isButtonPressed(e, button1)) { if (gv.getDisplay().getCursor().getType() == (Cursor.DEFAULT_CURSOR)) { // release all focus and neighbour highlight TupleSet ts = vis.getGroup(Visualization.FOCUS_ITEMS); if (gv.getRecStatus() == 2 && gv.fromIndirect && (ts.getTupleCount() == 0) && !gv.fromAll) gv.showDirectGraph(); ts.clear(); vis.removeGroup("depthEdge"); gv.releaseSearchFocus(); } } if (UILib.isButtonPressed(e, button1) && e.getClickCount() == 1) { if (gv.getDisplay().getCursor().getName().equals("zoom")) admin.toggleZoom(); else if (gv.getDisplay().getCursor().getName().equals("zoomout")) admin.toggleZoomOut(); else if (gv.getDisplay().getCursor().getName().equals("zoomin")) admin.toggleZoomIn(); else if (gv.getDisplay().getCursor().getName().equals("zoomout1")) admin.toggleZoomOut1(); else if (gv.getDisplay().getCursor().getName().equals("zoomin1")) admin.toggleZoomIn1(); else if (gv.getDisplay().getCursor().getName().equals("pan")) admin.togglePan(); } }
/* * Test method for 'prefuse.Visualization.reset()' */ @Test public void testReset() { m_vis.reset(); Assert.assertEquals(null, m_vis.getGroup("t")); Assert.assertEquals(null, m_vis.getSourceData("t")); Assert.assertEquals(null, m_vis.getGroup("g")); Assert.assertEquals(null, m_vis.getGroup("g.nodes")); Assert.assertEquals(null, m_vis.getGroup("g.edges")); Assert.assertEquals(null, m_vis.getSourceData("g")); Assert.assertEquals(null, m_vis.getSourceData("g.nodes")); Assert.assertEquals(null, m_vis.getSourceData("g.edges")); Assert.assertEquals(0, m_vis.size("t")); Assert.assertEquals(0, m_vis.size("g")); Assert.assertEquals(0, m_vis.size("g.nodes")); Assert.assertEquals(0, m_vis.size("g.edges")); Assert.assertEquals(0, m_vis.getFocusGroup("_focus_").getTupleCount()); Assert.assertEquals(false, m_vis.items().hasNext()); }
public static JComponent demo(Graph g, String label) { // create a new, empty visualization for our data final Visualization vis = new Visualization(); VisualGraph vg = vis.addGraph(graph, g); vis.setValue(edges, null, VisualItem.INTERACTIVE, Boolean.FALSE); int[] palette = new int[] { ColorLib.rgb(77, 175, 74), ColorLib.rgb(55, 126, 184), ColorLib.rgb(228, 26, 28), ColorLib.rgb(152, 78, 163), ColorLib.rgb(255, 127, 0) }; int[] shape_palette = new int[] {Constants.SHAPE_ELLIPSE, Constants.SHAPE_RECTANGLE, Constants.SHAPE_TRIANGLE_UP}; TupleSet focusGroup = vis.getGroup(Visualization.FOCUS_ITEMS); focusGroup.addTupleSetListener( new TupleSetListener() { public void tupleSetChanged(TupleSet ts, Tuple[] add, Tuple[] rem) { for (int i = 0; i < rem.length; ++i) ((VisualItem) rem[i]).setFixed(false); for (int i = 0; i < add.length; ++i) { ((VisualItem) add[i]).setFixed(false); ((VisualItem) add[i]).setFixed(true); } vis.run("draw"); } }); // set up the renderers /* ShapeRenderer s = new ShapeRenderer(); s.rectangle(0, 0, 30, 30); vis.setRendererFactory(new DefaultRendererFactory(s));*/ MyRenderer tr = new MyRenderer(label); // MyRenderer tr = new MyRenderer(label); DefaultRendererFactory d = new DefaultRendererFactory(tr); EdgeRenderer MyEdgeRenderer = new EdgeRenderer(); d.add(new InGroupPredicate(edges), MyEdgeRenderer); vis.setRendererFactory(d); // -- set up the actions ---------------------------------------------- int maxhops = 1024, hops = 1024; final GraphDistanceFilter filter = new GraphDistanceFilter(graph, hops); ActionList draw = new ActionList(); draw.add(filter); // draw.add(new ColorAction(nodes, VisualItem.FILLCOLOR, ColorLib.rgb(180,180,255))); 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(100))); draw.add(new ColorAction(edges, VisualItem.STROKECOLOR, ColorLib.gray(170))); draw.add(new DataShapeAction(nodes, "type", shape_palette)); DataColorAction fill = new DataColorAction( "graph.nodes", "type", Constants.NOMINAL, VisualItem.FILLCOLOR, palette); // use black for node text ColorAction text = new ColorAction("graph.nodes", VisualItem.TEXTCOLOR, ColorLib.gray(0)); // use light grey for edges ColorAction edges = new ColorAction("graph.edges", VisualItem.STROKECOLOR, ColorLib.gray(200)); // create an action list containing all color assignments ActionList color = new ActionList(); color.add(fill); color.add(text); color.add(edges); // ColorAction fill = new ColorAction(nodes, // VisualItem.FILLCOLOR, ColorLib.rgb(200,200,255)); fill.add("_fixed", ColorLib.rgb(255, 100, 100)); fill.add("_highlight", ColorLib.rgb(255, 200, 125)); // Instead have to use GridLayout here - how do i create ForceDirectedLayout fdl = new ForceDirectedLayout(graph); // GridLayout fdl = new GridLayout(graph); ForceSimulator fsim = fdl.getForceSimulator(); fsim.getForces()[0].setParameter(0, -5f); ActionList animate = new ActionList(Activity.INFINITY); // ActionList animate = new ActionList(vis); animate.add(fdl); animate.add(fill); animate.add(new RepaintAction()); // finally, we register our ActionList with the Visualization. // we can later execute our Actions by invoking a method on our // Visualization, using the name we've chosen below. vis.putAction("draw", draw); vis.putAction("layout", animate); vis.runAfter("draw", "layout"); vis.putAction("color", color); // vis.putAction("layout", layout); // -------------------------------------------------------------------- // STEP 4: set up a display to show the visualization Display display = new Display(vis); display.setSize(2000, 2000); display.setForeground(Color.GRAY); display.setBackground(Color.WHITE); // main display controls display.addControlListener(new FocusControl(1)); display.addControlListener(new DragControl()); display.addControlListener(new PanControl()); display.addControlListener(new ZoomControl()); display.addControlListener(new WheelZoomControl()); display.addControlListener(new ZoomToFitControl()); display.addControlListener(new NeighborHighlightControl()); display.setForeground(Color.GRAY); display.setBackground(Color.WHITE); // -------------------------------------------------------------------- // STEP 5: launching the visualization // create a panel for editing force values final JForcePanel fpanel = new JForcePanel(fsim); final JValueSlider slider = new JValueSlider("Distance", 0, maxhops, hops); slider.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { filter.setDistance(slider.getValue().intValue()); vis.run("draw"); } }); slider.setBackground(Color.WHITE); slider.setPreferredSize(new Dimension(300, 30)); slider.setMaximumSize(new Dimension(300, 30)); Box cf = new Box(BoxLayout.Y_AXIS); cf.add(slider); cf.setBorder(BorderFactory.createTitledBorder("Connectivity Filter")); fpanel.add(cf); fpanel.add(Box.createVerticalGlue()); // create a new JSplitPane to present the interface JSplitPane split = new JSplitPane(); split.setLeftComponent(display); split.setRightComponent(fpanel); split.setOneTouchExpandable(true); split.setContinuousLayout(false); split.setDividerLocation(530); split.setDividerLocation(800); // position and fix the default focus node NodeItem focus = (NodeItem) vg.getNode(0); PrefuseLib.setX(focus, null, 400); PrefuseLib.setY(focus, null, 250); focusGroup.setTuple(focus); // now we run our action list and return return split; }