Example #1
0
    public void paint(Graphics g) {
      g.setColor(Color.gray);

      Graphics2D g2d = (Graphics2D) g;

      Ellipse2D ellipse = new Ellipse2D.Double();
      for (String v : layout.getGraph().getVertices()) {
        Double radius = layout.getRadii().get(v);
        if (radius == null) {
          continue;
        }
        Point2D p = layout.transform(v);
        ellipse.setFrame(-radius, -radius, 2 * radius, 2 * radius);
        AffineTransform at = AffineTransform.getTranslateInstance(p.getX(), p.getY());
        Shape shape = at.createTransformedShape(ellipse);

        MutableTransformer viewTransformer =
            vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW);

        if (viewTransformer instanceof MutableTransformerDecorator) {
          shape = vv.getRenderContext().getMultiLayerTransformer().transform(shape);
        } else {
          shape = vv.getRenderContext().getMultiLayerTransformer().transform(Layer.LAYOUT, shape);
        }

        g2d.draw(shape);
      }
    }
Example #2
0
 @Override
 public void stateChanged(ChangeEvent e) {
   int level = levelControl.getValue();
   if (level != current_level) {
     createTree(level);
     current_level = level;
     if (!radial.isSelected()) {
       TreeLayout<String, Number> tl2 = treeLayout;
       radialLayout = new BalloonLayout<String, Number>(graph);
       radialLayout.setSize(new Dimension(1200, 1200));
       rings = new Rings(radialLayout);
       treeLayout = new TreeLayout<String, Number>(graph);
       LayoutTransition<String, Number> lt =
           new LayoutTransition<String, Number>(vv, tl2, treeLayout);
       Animator animator = new Animator(lt);
       animator.start();
     } else {
       BalloonLayout<String, Number> r2 = radialLayout;
       radialLayout = new BalloonLayout<String, Number>(graph);
       radialLayout.setSize(new Dimension(1200, 1200));
       treeLayout = new TreeLayout<String, Number>(graph);
       vv.getRenderContext().getMultiLayerTransformer().setToIdentity();
       vv.removePreRenderPaintable(rings);
       rings = new Rings(radialLayout);
       LayoutTransition<String, Number> lt =
           new LayoutTransition<String, Number>(vv, r2, radialLayout);
       Animator animator = new Animator(lt);
       animator.start();
       vv.getRenderContext().getMultiLayerTransformer().setToIdentity();
       vv.addPreRenderPaintable(rings);
     }
     // vv.getRenderContext().getMultiLayerTransformer().setToIdentity();
   }
 }
Example #3
0
  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);
  }