private void init(Graph<? extends Object, ? extends Object>[] graph_array, double[][][] matrix) { // super("DendrogramView View"); Graph<String, Number> g = (Graph<String, Number>) graph_array[0]; SparseDoubleMatrix2D matrixArray = GraphMatrixOperations.graphToSparseMatrix((Graph<String, Number>) graph_array[0]); /* * matrix=new double[g.getVertexCount()][g.getVertexCount()]; for(int * i=0; i<matrix.length; i++){ matrix[i][i]=0; for(int j=i+1; * j<matrix[i].length; j++) if(g.isNeighbor(String.valueOf(i), * String.valueOf(j))){ matrix[i][j]=1; matrix[j][i]=1; } else{ * matrix[i][j]=0; matrix[j][i]=0; } } */ graph = new DelegateForest<String, Number>(); Collection<String> c = g.getVertices(); // create a simple graph for the demo // graph = new DelegateForest<String,Integer>(); String labels[] = new String[matrix[0].length]; for (int i = 0; i < labels.length; i++) { labels[i] = String.valueOf(i); } mlc = new MultiLevelConcor(labels, matrix); initTree(); treeLayout = new TreeLayout<String, Number>(graph); radialLayout = new BalloonLayout<String, Number>(graph); radialLayout.setSize(new Dimension(600, 600)); vv = new VisualizationViewer<String, Number>(treeLayout, new Dimension(600, 600)); vv.setBackground(Color.white); nfc = new NodeFillColor<String>(vv.getPickedVertexState()); vv.getRenderContext().setVertexFillPaintTransformer(nfc); /* * nh = new NodeHighlight<String>(vv.getPickedVertexState()); nh.ID = 2; * nh.node_no = graph.getVertexCount(); nh.node_count = nh.node_no; * nh.synchroFlag = syncFlag; * vv.getRenderContext().setVertexFillPaintTransformer(nh); */ vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line()); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller()); // add a listener for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller()); vv.getRenderContext().setArrowFillPaintTransformer(new ConstantTransformer(Color.lightGray)); rings = new Rings(radialLayout); // Container content = getContentPane(); // final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); // content.add(panel); final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse(); vv.setGraphMouse(graphMouse); JComboBox modeBox = graphMouse.getModeComboBox(); modeBox.addItemListener(graphMouse.getModeListener()); graphMouse.setMode(ModalGraphMouse.Mode.TRANSFORMING); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); radial = new JToggleButton("Balloon"); radial.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { LayoutTransition<String, Number> lt = new LayoutTransition<String, Number>(vv, treeLayout, radialLayout); Animator animator = new Animator(lt); animator.start(); vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.addPreRenderPaintable(rings); } else { LayoutTransition<String, Number> lt = new LayoutTransition<String, Number>(vv, radialLayout, treeLayout); Animator animator = new Animator(lt); animator.start(); vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.removePreRenderPaintable(rings); } vv.repaint(); } }); JPanel scaleGrid = new JPanel(new GridLayout(1, 0)); scaleGrid.setBorder(BorderFactory.createTitledBorder("Zoom")); JPanel controls = new JPanel(); scaleGrid.add(plus); scaleGrid.add(minus); controls.add(radial); controls.add(scaleGrid); controls.add(modeBox); int max = (int) Math.round(Math.log(matrix[0].length) / Math.log(2)); levelControl = new JSlider(JSlider.HORIZONTAL, 1, max, 1); levelControl.setMajorTickSpacing(1); levelControl.setMinorTickSpacing(1); levelControl.setPaintTicks(true); levelControl.addChangeListener(this); levelControl.setPaintLabels(true); Hashtable<Integer, JLabel> ht = new Hashtable<Integer, JLabel>(); for (int i = 1; i <= max; i++) { ht.put(new Integer(i), new JLabel(String.valueOf(i))); } levelControl.setLabelTable(ht); controls.add(levelControl); setBackground(Color.WHITE); setLayout(new BorderLayout()); this.add(vv, BorderLayout.CENTER); this.add(controls, BorderLayout.NORTH); // content.add(controls, BorderLayout.SOUTH); // Dimension preferredSize = new Dimension(600,600); // setSize(preferredSize); // setLocation(600,0); // setVisible(true); // Thread t = new Thread(this); // t.start(); vv.addMouseListener(this); }
public SetupGraphPane() { // create a simple graph for the demo graph = new SparseMultigraph<Number, Number>(); this.layout = new StaticLayout<Number, Number>(graph, new Dimension(600, 600)); vv = new VisualizationViewer<Number, Number>(layout); vv.setBackground(Color.white); vv.getRenderContext() .setVertexLabelTransformer( MapTransformer.<Number, String>getInstance( LazyMap.<Number, String>decorate( new HashMap<Number, String>(), new ToStringLabeller<Number>()))); vv.getRenderContext() .setEdgeLabelTransformer( MapTransformer.<Number, String>getInstance( LazyMap.<Number, String>decorate( new HashMap<Number, String>(), new ToStringLabeller<Number>()))); vv.setVertexToolTipTransformer(vv.getRenderContext().getVertexLabelTransformer()); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); add(panel); Factory<Number> vertexFactory = new VertexFactory(); Factory<Number> edgeFactory = new EdgeFactory(); final EditingModalGraphMouse<Number, Number> graphMouse = new EditingModalGraphMouse<Number, Number>( vv.getRenderContext(), vertexFactory, edgeFactory); // the EditingGraphMouse will pass mouse event coordinates to the // vertexLocations function to set the locations of the vertices as // they are created // graphMouse.setVertexLocations(vertexLocations); vv.setGraphMouse(graphMouse); vv.addKeyListener(graphMouse.getModeKeyListener()); graphMouse.setMode(ModalGraphMouse.Mode.EDITING); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); // JButton help = new JButton("Help"); // help.addActionListener(new ActionListener() { // // public void actionPerformed(ActionEvent e) { // JOptionPane.showMessageDialog(vv, instructions); // }}); AnnotationControls<Number, Number> annotationControls = new AnnotationControls<Number, Number>(graphMouse.getAnnotatingPlugin()); JPanel controls = new JPanel(); controls.add(plus); controls.add(minus); JComboBox modeBox = graphMouse.getModeComboBox(); controls.add(modeBox); controls.add(annotationControls.getAnnotationsToolBar()); // controls.add(help); add(controls, BorderLayout.SOUTH); }
public SearchTreeFrame(DelegateForest<MetaVariable, ConstraintNetwork> graph) { this.graph = graph; treeLayout = new TreeLayout<MetaVariable, ConstraintNetwork>(graph); radialLayout = new RadialTreeLayout<MetaVariable, ConstraintNetwork>(graph); radialLayout.setSize(new Dimension(600, 600)); vv = new VisualizationViewer<MetaVariable, ConstraintNetwork>( treeLayout, new Dimension(600, 600)); vv.setBackground(Color.white); vv.getRenderContext() .setEdgeShapeTransformer(new EdgeShape.Line<MetaVariable, ConstraintNetwork>()); vv.getRenderContext() .setVertexLabelTransformer( new Transformer<MetaVariable, String>() { @Override public String transform(MetaVariable arg0) { return arg0.toString(); } }); vv.setVertexToolTipTransformer( new Transformer<MetaVariable, String>() { @Override public String transform(MetaVariable arg0) { return arg0.toString(); } }); // vv.getRenderContext().setArrowFillPaintTransformer(new ConstantTransformer(Color.lightGray)); vv.getRenderContext() .setArrowFillPaintTransformer( new Transformer<ConstraintNetwork, Paint>() { @Override public Paint transform(ConstraintNetwork arg0) { return Color.lightGray; } }); // System.out.println(graph.getVertices()); rings = new Rings(); Container content = getContentPane(); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); content.add(panel); final DefaultModalGraphMouse<?, ?> graphMouse = new DefaultModalGraphMouse<Object, Object>(); vv.setGraphMouse(graphMouse); JComboBox modeBox = graphMouse.getModeComboBox(); modeBox.addItemListener(graphMouse.getModeListener()); graphMouse.setMode(Mode.TRANSFORMING); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JToggleButton radial = new JToggleButton("Radial"); radial.addItemListener( new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { LayoutTransition<MetaVariable, ConstraintNetwork> lt = new LayoutTransition<MetaVariable, ConstraintNetwork>( vv, treeLayout, radialLayout); Animator animator = new Animator(lt); animator.start(); vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.addPreRenderPaintable(rings); } else { LayoutTransition<MetaVariable, ConstraintNetwork> lt = new LayoutTransition<MetaVariable, ConstraintNetwork>( vv, radialLayout, treeLayout); Animator animator = new Animator(lt); animator.start(); vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.removePreRenderPaintable(rings); } vv.repaint(); } }); JPanel scaleGrid = new JPanel(new GridLayout(1, 0)); scaleGrid.setBorder(BorderFactory.createTitledBorder("Zoom")); JPanel controls = new JPanel(); scaleGrid.add(plus); scaleGrid.add(minus); controls.add(radial); controls.add(scaleGrid); controls.add(modeBox); content.add(controls, BorderLayout.SOUTH); }
/** * ***************************************** This method is used to create the visualizer based on * the layout selected by the User. ****************************************** */ @SuppressWarnings("unchecked") private void Visualizer() { // Setting the Layout size layout.setSize(new Dimension(1350, 650)); // Creating the Visualizer VisualizationViewer<String, String> visualizer = new VisualizationViewer<String, String>(layout); visualizer.setPreferredSize(new Dimension(1400, 700)); // Creating a hash-map to store Icons Map<String, Icon> iconsMap = new HashMap<String, Icon>(); for (int i = 0; i < GraphPlotter.uCombinedList.length; i++) { String tempString = "images//UsersProfilePics//" + GraphPlotter.uCombinedList[i] + ".jpg"; try { Icon icon = new ImageIcon(tempString); iconsMap.put(GraphPlotter.uCombinedList[i], icon); } catch (Exception ex) { System.out.println("Error: Problem in creating a Hash-Map for Icons"); } } // Creating a transformer for Painting Nodes @SuppressWarnings("unused") Transformer<String, Paint> NodePaint = new Transformer<String, Paint>() { public Paint transform(String i) { return Color.GREEN; } }; // Creating local Icon Transformer final myVertexIconTransformer<String> vertexIconTransformer = new myVertexIconTransformer<String>(); // Setting Hash-Map for Icon on Transformer vertexIconTransformer.setIconMap(iconsMap); // A tool-tip Transformer, this will display tweets text on mouse-over. visualizer.setVertexToolTipTransformer(new ToolTipView()); // Setting Visualizer's Renderer properties visualizer.getRenderContext().setVertexIconTransformer(vertexIconTransformer); // visualizer.getRenderContext().setVertexFillPaintTransformer(NodePaint); visualizer.getRenderContext().setVertexLabelTransformer(new ToStringLabeller()); visualizer.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller()); // PluggableGraphMouse properties PluggableGraphMouse graphMouse = new PluggableGraphMouse(); graphMouse.add(new PickingGraphMousePlugin()); // Picking Mode is active graphMouse.add(new RotatingGraphMousePlugin()); // Rotating Graph mode is active graphMouse.add(new ShearingGraphMousePlugin()); // shearing Graph mode is active graphMouse.add(new LabelEditingGraphMousePlugin()); // Label Editing mode is active graphMouse.add( new TranslatingGraphMousePlugin( MouseEvent.BUTTON1_MASK)); // Translating Graph mode is active graphMouse.add( new ScalingGraphMousePlugin( new CrossoverScalingControl(), 0, 1.1f, 0.9f)); // Scaling Graph mode is active. // Setting GraphMouse on Visualizer visualizer.setGraphMouse(graphMouse); // Creating a JFrame to hold the Visualizer JFrame frame = new JFrame("Social Network Visualizer"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(visualizer); frame.pack(); frame.setVisible(true); }
public GraphEditorDemo() { // create a simple graph for the demo graph = new SparseMultigraph<Sommet, Number>(); Transformer<Sommet, Paint> vertexPaint = new Transformer<Sommet, Paint>() { private final Color vert = Color.GREEN; private final Color bleu = Color.BLUE; private final Color rouge = Color.RED; public Paint transform(Sommet s) { if (s.isColoriee()) { return rouge; } else { if (s.proprietaire == 0) { return vert; } else { return bleu; } } } }; this.layout = new StaticLayout<Sommet, Number>(graph, new Dimension(600, 600)); vv = new VisualizationViewer<Sommet, Number>(layout); vv.setBackground(Color.white); vv.getRenderContext() .setVertexLabelTransformer( MapTransformer.<Sommet, String>getInstance( LazyMap.<Sommet, String>decorate( new HashMap<Sommet, String>(), new ToStringLabeller<Sommet>()))); vv.getRenderContext() .setEdgeLabelTransformer( MapTransformer.<Number, String>getInstance( LazyMap.<Number, String>decorate( new HashMap<Number, String>(), new ToStringLabeller<Number>()))); vv.setVertexToolTipTransformer(vv.getRenderContext().getVertexLabelTransformer()); vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint); Container content = getContentPane(); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); content.add(panel); Factory<Sommet> vertexFactory = new VertexFactory(); Factory<Number> edgeFactory = new EdgeFactory(); final EditingModalGraphMouse<Sommet, Number> graphMouse = new EditingModalGraphMouse<Sommet, Number>( vv.getRenderContext(), vertexFactory, edgeFactory); // the EditingGraphMouse will pass mouse event coordinates to the // vertexLocations function to set the locations of the vertices as // they are created // graphMouse.setVertexLocations(vertexLocations); vv.setGraphMouse(graphMouse); vv.addKeyListener(graphMouse.getModeKeyListener()); graphMouse.setMode(ModalGraphMouse.Mode.CREATION); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JToggleButton jtb = new JToggleButton("Joueur 1"); jtb.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent ev) { if (ev.getStateChange() == ItemEvent.SELECTED) { joueurcourant = 1; } else if (ev.getStateChange() == ItemEvent.DESELECTED) { joueurcourant = 0; } } }); JToggleButton jtf = new JToggleButton("Final"); jtf.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent ev) { if (ev.getStateChange() == ItemEvent.SELECTED) { etatfinal = true; } else if (ev.getStateChange() == ItemEvent.DESELECTED) { etatfinal = false; } } }); JButton att = new JButton("Attracteur Accessibilité"); minus.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { ArrayList<Sommet> vertices = (ArrayList<Sommet>) graph.getVertices(); ArrayList<Sommet> finaux = new ArrayList<Sommet>(); for (Sommet s : vertices) { if (s.isFinal) finaux.add(s); } colorierAttracteur(finaux, graph.getVertexCount()); } }); AnnotationControls<Sommet, Number> annotationControls = new AnnotationControls<Sommet, Number>(graphMouse.getAnnotatingPlugin()); JPanel controls = new JPanel(); controls.add(plus); controls.add(minus); JComboBox modeBox = graphMouse.getModeComboBox(); controls.add(modeBox); controls.add(jtb); controls.add(jtf); controls.add(att); // controls.add(annotationControls.getAnnotationsToolBar()); content.add(controls, BorderLayout.SOUTH); }