Пример #1
0
 @Override
 public void mousePressed(MouseEvent arg0) {
   // TODO Auto-generated method stub
   PickedState<String> ps = vv.getPickedVertexState();
   Set<String> ss = ps.getPicked();
   if (ss.size() == 1) {
     for (String s : ss) {
       nfc.kids.clear();
       ArrayList<String> kids = new ArrayList<String>();
       kids.add(s);
       for (int i = 0; i < kids.size(); i++) {
         includeKidNodes(kids.get(i), kids);
       }
       nfc.kids.addAll(kids);
       for (int i = kids.size() - 1; i >= 0; i--) {
         String id = kids.get(i);
         if (id.equals("Root") || id.startsWith("V")) {
           kids.remove(i);
         }
       }
       int[] selObj = new int[kids.size()];
       for (int i = 0; i < selObj.length; i++) {
         selObj[i] = Integer.parseInt(kids.get(i));
       }
       fireSelectionChanged(selObj);
       logger.info(Arrays.toString(selObj));
     }
   } else {
     nfc.kids.clear();
   }
 }
Пример #2
0
 @Override
 public void mouseReleased(MouseEvent arg0) {
   PickedState<String> ps = vv.getPickedVertexState();
   Set<String> selectedV = ps.getPicked();
   if (selectedV.isEmpty()) {
     return;
   }
   ArrayList<Integer> selNodes = new ArrayList<Integer>();
   Iterator<String> it = selectedV.iterator();
   while (it.hasNext()) {
     try {
       Integer I = Integer.parseInt(it.next());
       selNodes.add(I);
     } catch (Exception e) {
       continue;
     }
   }
   int[] selObjs = new int[selNodes.size()];
   for (int i = 0; i < selObjs.length; i++) {
     selObjs[i] = selNodes.get(i).intValue();
   }
   fireSelectionChanged(selObjs);
   logger.info(Arrays.toString(selObjs));
 }
Пример #3
0
  @Override
  /**
   * @modified by peifeng yin
   * @date Jan 13, 2011
   */
  public void selectionChanged(SelectionEvent e) {
    // TODO Auto-generated method stub

    int[] selObs = e.getSelection();
    // nh.selectedNodes.clear();
    if (selObs.length == 0) {
      return;
    }
    // else if(selObs.length==1)//include the selected node's children
    // selObs=includeChildren(selObs[0]);
    PickedState<String> ps = vv.getPickedVertexState();
    ps.clear();
    nfc.kids.clear();
    for (int obs : selObs) {
      if (obs < 0) {
        return;
      }
      ps.pick(String.valueOf(obs), true);
      /*
       * String name = dsa.getObservationName(obs);
       * System.out.println(DendrogramView.class.getName() +
       * " selection = " + obs + " " + name);
       * nh.selectedNodes.add(String.valueOf(obs));
       */
    }
    /*
     * if (!nh.selectedNodes.isEmpty()) { nh.passive = true; nh.node_count =
     * nh.node_no; this.vv.repaint(); }
     */
    vv.repaint();
  }
Пример #4
0
  private void initComponent() {
    // TODO Auto-generated method stub

    top = new JPanel();

    nodeGraph = new JPanel();
    FRLayout<String, String> graphLayout = new FRLayout<String, String>(graph);
    nodeGraphView = new VisualizationViewer<String, String>(graphLayout);

    // nodeGraphView.setBackground(new Color(228,247,186));
    // nodeGraphView.setBackground(new Color(178,204,255));
    nodeGraphView.setBackground(new Color(255, 216, 216));

    nodeGraphView
        .getRenderContext()
        .setEdgeDrawPaintTransformer(
            new PickableEdgePaintTransformer<String>(
                nodeGraphView.getPickedEdgeState(), Color.black, Color.GREEN));
    nodeGraphView
        .getRenderContext()
        .setVertexFillPaintTransformer(
            new PickableVertexPaintTransformer<String>(
                nodeGraphView.getPickedVertexState(),
                new Color(67, 116, 217),
                new Color(5, 0, 153)));
    final AbstractModalGraphMouse graphMouse = new DefaultModalGraphMouse();

    graphMouse.setMode(ModalGraphMouse.Mode.PICKING);
    nodeGraphView.setGraphMouse(graphMouse);

    nodeGraphProtocolFilter = new JPanel();
    nodeGraph.add(nodeGraphProtocolFilter);
    nodeGraph.add(nodeGraphView);

    nodeGraphInform = new JPanel();
    nodeGraphMap = new SatelliteVisualizationViewer<String, String>(nodeGraphView);
    // nodeGraphMap.getRenderContext().setEdgeDrawPaintTransformer(new
    // PickableEdgePaintTransformer<String>(nodeGraphMap.getPickedEdgeState(), Color.black,
    // Color.GREEN));
    nodeGraphMap
        .getRenderContext()
        .setVertexFillPaintTransformer(
            new PickableVertexPaintTransformer<String>(
                nodeGraphMap.getPickedVertexState(),
                new Color(67, 116, 217),
                new Color(5, 0, 153)));

    nodeTrafficTableModel = new NodeTrafficTableModel();
    TableColumnModel columnModel = new DefaultTableColumnModel();
    TableColumn column = new TableColumn(0);
    column.setHeaderValue("IP");
    columnModel.addColumn(column);

    column = new TableColumn(1);
    column.setHeaderValue("PORT");
    columnModel.addColumn(column);

    column = new TableColumn(2);
    column.setHeaderValue("PACKETS");
    columnModel.addColumn(column);

    column = new TableColumn(3);
    column.setHeaderValue("BYTES");
    columnModel.addColumn(column);

    column = new TableColumn(4);
    column.setHeaderValue("LEVEL");
    columnModel.addColumn(column);

    DefaultTableCellRenderer cellAlign = new DefaultTableCellRenderer();
    cellAlign.setHorizontalAlignment(JLabel.RIGHT);

    nodeTrafficTable = new JTable(nodeTrafficTableModel, columnModel);
    /*
       nodeTrafficTable.getColumn("IP").setCellRenderer(cellAlign);
       nodeTrafficTable.getColumn("IP").setPreferredWidth(90);
       nodeTrafficTable.getColumn("PORT").setCellRenderer(cellAlign);
       nodeTrafficTable.getColumn("PORT").setPreferredWidth(30);
       nodeTrafficTable.getColumn("PACKETS").setCellRenderer(cellAlign);
       nodeTrafficTable.getColumn("PACKETS").setPreferredWidth(60);
       nodeTrafficTable.getColumn("BYTES").setCellRenderer(cellAlign);
       nodeTrafficTable.getColumn("BYTES").setPreferredWidth(60);
       nodeTrafficTable.getColumn("LEVEL").setCellRenderer(cellAlign);
       nodeTrafficTable.getColumn("LEVEL").setPreferredWidth(5);
    */
    nodeGraphicTable = new JTable(nodeGraphicTableModel);

    nodeGraphProtocolView = new JScrollPane(nodeTrafficTable);
    // nodeGraphProtocolView.setLayout(new BorderLayout());
    // nodeGraphProtocolView.add(nodeTrafficTable);

    nodeGraphInform.add(nodeGraphMap);
    nodeGraphInform.add(nodeGraphProtocolView);

    top.add(nodeGraph);
    top.add(nodeGraphInform);
    this.add(top);

    trafficGraph = new ChartPanel(trafficChart);
    trafficGraph.setFocusable(false);
    trafficChart.getLegend().setPosition(RectangleEdge.LEFT);

    this.add(trafficGraph);

    graphVerticalSizeBt = new JButton("::::::::△▽::::::::");
    graphVerticalSizeBt.setFont(graphVerticalSizeBt.getFont().deriveFont(10.0f));
    graphVerticalSizeBt.addMouseMotionListener(new GraphVerticalSizeMotionListener());
    graphVerticalSizeBt.addActionListener(new GraphVerticalSizeMotionListener());
    this.add(graphVerticalSizeBt);

    graphHorizontalSizeBt = new JButton();
    graphHorizontalSizeBt.setEnabled(false);
    top.add(graphHorizontalSizeBt);
  }
Пример #5
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);
  }