/** @param args the command line arguments */
  public static void main(String[] args) {
    InteractiveGraphView1 sgv = new InteractiveGraphView1(); // Creates the graph...
    // Layout<V, E>, VisualizationViewer<V,E>
    Layout<Integer, String> layout = new CircleLayout(sgv.g);
    layout.setSize(new Dimension(300, 300));
    VisualizationViewer<Integer, String> vv = new VisualizationViewer<Integer, String>(layout);
    vv.setPreferredSize(new Dimension(350, 350));
    // Show vertex and edge labels
    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
    vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller());

    // Create our "custom" mouse here. We start with a PluggableGraphMouse
    // Then add the plugins you desire.
    PluggableGraphMouse gm = new PluggableGraphMouse();
    gm.add(new TranslatingGraphMousePlugin(MouseEvent.BUTTON1_MASK));
    gm.add(new ScalingGraphMousePlugin(new CrossoverScalingControl(), 0, 1.1f, 0.9f));

    vv.setGraphMouse(gm);
    JFrame frame = new JFrame("Interactive Graph View 3");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(vv);
    frame.pack();
    frame.setVisible(true);
  }
  /**
   * ***************************************** 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);
  }
Beispiel #3
0
  /** Performs the necessary actions to set up the Graph. */
  protected void setup() {
    this.graph = (UndirectedSparseGraph<V, E>) this.getGraphLayout().getGraph();
    this.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<V>());
    //		this.getRenderContext( ).setEdgeLabelTransformer( new ToStringLabeller<E>( ));
    this.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);
    PluggableGraphMouse mouse =
        new PluggableGraphMouse() {
          public void mouseWheelMoved(MouseWheelEvent e) {
            scale((float) Math.pow(1.25, -e.getWheelRotation()), e.getPoint());
          }
        };
    mouse.add(new PickingGraphMousePlugin());
    mouse.add(new PickingGraphMousePlugin(-1, InputEvent.BUTTON1_MASK | InputEvent.CTRL_MASK));
    this.setGraphMouse(mouse);
    this.getPickedVertexState().addItemListener(this);
    this.getPickedEdgeState().addItemListener(this);
    this.addMouseListener(this);
    this.addComponentListener(new LayoutScaler());

    // set up coloring
    Transformer v =
        new Transformer<V, Paint>() {
          public Paint transform(V v) {
            if (getPickedVertexState().isPicked(v)) {
              return pickedVertexPaint;
            } else {
              if (commonNeighborIndicator && isCommonNeighbor(v)) {
                return commonNeighborPaint;
              } else {
                return vertexPaint;
              }
            }
          }
        };
    Transformer vo =
        new Transformer<V, Paint>() {
          public Paint transform(V v) {
            if (getPickedVertexState().isPicked(v)) {
              return pickedVertexOutline;
            } else {
              if (commonNeighborIndicator && isCommonNeighbor(v)) {
                return commonNeighborOutline;
              } else {
                return vertexOutline;
              }
            }
          }
        };

    this.getRenderContext().setVertexFillPaintTransformer(v);
    this.getRenderContext().setVertexDrawPaintTransformer(vo);

    Transformer e =
        new Transformer<E, Paint>() {
          public Paint transform(E e) {
            if (getPickedEdgeState().isPicked(e)) {
              return pickedEdgePaint;
            } else {
              return edgePaint;
            }
          }
        };
    this.getRenderContext().setEdgeDrawPaintTransformer(e);
    this.setPickedLabelColor(this.pickedLabelColor);
    this.commonNeighbors = new NeighborCollection<V, E>(this);
  }