public VisualizationViewer<String, Edge> generateGraphView() {

    Transformer<String, Paint> vertexColor =
        new Transformer<String, Paint>() {
          public Paint transform(String licenseTerm) {
            if (licenseTerm.contains("May")) return Color.GREEN;
            if (licenseTerm.contains("Must")) return Color.ORANGE;
            if (licenseTerm.equals("LimitedLiability")
                || licenseTerm.equals("ProvideWithoutWarranty")) return Color.CYAN;
            return Color.YELLOW;
          }
        };

    Layout<String, Edge> layout = new CircleLayout<String, Edge>(this.licenseGraph);
    layout.setSize(new Dimension(1024, 768));
    VisualizationViewer<String, Edge> vv = new VisualizationViewer<String, Edge>(layout);
    vv.setPreferredSize(new Dimension(1024, 768));

    vv.getRenderContext().setVertexFillPaintTransformer(vertexColor);
    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<String>());
    vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller<Edge>());

    AbstractModalGraphMouse gm = new DefaultModalGraphMouse<String, Edge>();
    vv.setGraphMouse(gm);

    popupMenu = new LicenseTermPopupMenu<>(licenseModel);
    gm.add(popupMenu);

    return vv;
  }
  public void displayLicenseGraph() {

    Transformer<String, Paint> vertexColor =
        new Transformer<String, Paint>() {
          public Paint transform(String licenseTerm) {
            if (licenseTerm.contains("May")) return Color.GREEN;
            if (licenseTerm.contains("Must")) return Color.ORANGE;
            if (licenseTerm.equals("LimitedLiability")
                || licenseTerm.equals("ProvideWithoutWarranty")) return Color.CYAN;
            return Color.YELLOW;
          }
        };

    Layout<String, Edge> layout = new CircleLayout<String, Edge>(this.licenseGraph);
    layout.setSize(new Dimension(1024, 768));
    VisualizationViewer<String, Edge> vv = new VisualizationViewer<String, Edge>(layout);
    vv.setPreferredSize(new Dimension(1024, 768));

    vv.getRenderContext().setVertexFillPaintTransformer(vertexColor);
    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<String>());
    vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller<Edge>());

    AbstractModalGraphMouse gm = new DefaultModalGraphMouse<String, Edge>();
    vv.setGraphMouse(gm);

    LicenseTermPopupMenu<String, Edge> popupMenu = new LicenseTermPopupMenu<>(licenseModel);
    gm.add(popupMenu);

    JFrame frame = new JFrame("Interactive Graph View 1");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(vv);

    frame.pack();
    frame.setVisible(true);
  }
  /**
   * This will reload all positions of all vertices in the layout's graph. It will not reload if the
   * used layout type does not match the saved one. (the position of x/y in a circle is not valid
   * for x/y in a tree).
   *
   * @param layout
   * @param type
   * @param properties
   * @param category
   */
  private static void reloadAllVerticesPositions(
      final Layout<DatabaseObject, Relation> layout,
      final LayoutType type,
      final ConnectionProperties properties,
      final AttributeMapSet category) {
    final Collection<DatabaseObject> vertices = layout.getGraph().getVertices();
    if (vertices.isEmpty()) {
      return;
    }

    for (final DatabaseObject object : vertices) {
      // If special positions contained in properties' attributes map, use them.
      if (properties != null) {
        final ConnectionAttributesMap attributes = properties.getAttributesMap(category, object);
        final int newPosX = attributes.getPositionX();
        final int newPosY = attributes.getPositionY();
        final String oldLayout = attributes.getLayout();

        // Is this the same layout?
        if (oldLayout.isEmpty() || oldLayout.equalsIgnoreCase(type.toString())) {
          // Are this valid number values?
          if ((newPosX > 0) && (newPosY > 0)) {
            layout.setLocation(object, new Point2D.Double(newPosX, newPosY));
          }
        }
      }
    }
  }
Example #4
0
  /** @param args the command line arguments */
  public static void main(String[] args) {
    JFrame frame = new JFrame("Editing and Mouse Menu Demo");
    SparseMultigraph<GraphElements.MyVertex, GraphElements.MyEdge> g =
        new SparseMultigraph<GraphElements.MyVertex, GraphElements.MyEdge>();
    // Layout<V, E>, VisualizationViewer<V,E>
    //        Map<GraphElements.MyVertex,Point2D> vertexLocations = new
    // HashMap<GraphElements.MyVertex, Point2D>();
    Layout<GraphElements.MyVertex, GraphElements.MyEdge> layout = new StaticLayout(g);
    layout.setSize(new Dimension(300, 300));
    VisualizationViewer<GraphElements.MyVertex, GraphElements.MyEdge> vv =
        new VisualizationViewer<GraphElements.MyVertex, GraphElements.MyEdge>(layout);
    vv.setPreferredSize(new Dimension(350, 350));
    // Show vertex and edge labels
    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
    vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller());
    // Create a graph mouse and add it to the visualization viewer
    EditingModalGraphMouse gm =
        new EditingModalGraphMouse(
            vv.getRenderContext(),
            GraphElements.MyVertexFactory.getInstance(),
            GraphElements.MyEdgeFactory.getInstance());
    // Set some defaults for the Edges...
    GraphElements.MyEdgeFactory.setDefaultCapacity(192.0);
    GraphElements.MyEdgeFactory.setDefaultWeight(5.0);
    // Trying out our new popup menu mouse plugin...
    PopupVertexEdgeMenuMousePlugin myPlugin = new PopupVertexEdgeMenuMousePlugin();
    // Add some popup menus for the edges and vertices to our mouse plugin.
    JPopupMenu edgeMenu = new MyMouseMenus.EdgeMenu(frame);
    JPopupMenu vertexMenu = new MyMouseMenus.VertexMenu();
    myPlugin.setEdgePopup(edgeMenu);
    myPlugin.setVertexPopup(vertexMenu);
    gm.remove(gm.getPopupEditingPlugin()); // Removes the existing popup editing plugin

    gm.add(myPlugin); // Add our new plugin to the mouse

    vv.setGraphMouse(gm);

    // JFrame frame = new JFrame("Editing and Mouse Menu Demo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(vv);

    // Let's add a menu for changing mouse modes
    JMenuBar menuBar = new JMenuBar();
    JMenu modeMenu = gm.getModeMenu();
    modeMenu.setText("Mouse Mode");
    modeMenu.setIcon(null); // I'm using this in a main menu
    modeMenu.setPreferredSize(new Dimension(80, 20)); // Change the size so I can see the text

    menuBar.add(modeMenu);
    frame.setJMenuBar(menuBar);
    gm.setMode(ModalGraphMouse.Mode.EDITING); // Start off in editing mode
    frame.pack();
    frame.setVisible(true);
  }
Example #5
0
 protected Collection<E> getFilteredEdges(Layout<V, E> layout) {
   if (edgesAreFiltered()) {
     Collection<E> unfiltered = layout.getGraph().getEdges();
     Collection<E> filtered = new LinkedHashSet<E>();
     for (E e : unfiltered) {
       if (isEdgeRendered(Context.<Graph<V, E>, E>getInstance(layout.getGraph(), e))) {
         filtered.add(e);
       }
     }
     return filtered;
   } else {
     return layout.getGraph().getEdges();
   }
 }
Example #6
0
 protected Collection<V> getFilteredVertices(Layout<V, E> layout) {
   if (verticesAreFiltered()) {
     Collection<V> unfiltered = layout.getGraph().getVertices();
     Collection<V> filtered = new LinkedHashSet<V>();
     for (V v : unfiltered) {
       if (isVertexRendered(Context.<Graph<V, E>, V>getInstance(layout.getGraph(), v))) {
         filtered.add(v);
       }
     }
     return filtered;
   } else {
     return layout.getGraph().getVertices();
   }
 }
  @Override
  public void update() {
    if (enabled) {
      try {
        final Layout<V, E> layout =
            (Layout<V, E>) layoutClass.getConstructor(Graph.class).newInstance(graph);
        if (this.size == null) {
          double border = PADDING * 2 * parent.getScale();
          layout.setSize(
              new Dimension(
                  (int) parent.getWidth() - PADDING * 2, (int) parent.getHeight() - PADDING * 2));
        } else {
          layout.setSize(size);
        }

        List<PNode> nodes = new ArrayList<PNode>();
        List<Point2D> targetPositions = new ArrayList<Point2D>();
        for (V n : graph.getVertices()) {
          nodes.add(n);
          Point2D pos = layout.transform(n);

          pos.setLocation(pos.getX() + parent.getX(), pos.getY() + parent.getY());

          targetPositions.add(pos);
        }

        PActivity a =
            new PMultipleNodeTranlate(
                duration,
                ANIMATION_DEFAULT_STEP_RATE,
                System.currentTimeMillis(),
                nodes,
                targetPositions);
        parent.getRoot().addActivity(a);

      } catch (InstantiationException e) {
        e.printStackTrace();
      } catch (IllegalAccessException e) {
        e.printStackTrace();
      } catch (IllegalArgumentException e) {
        e.printStackTrace();
      } catch (SecurityException e) {
        e.printStackTrace();
      } catch (InvocationTargetException e) {
        e.printStackTrace();
      } catch (NoSuchMethodException e) {
        e.printStackTrace();
      }
    }
  }
 public FSMBuildVisualizer() {
   super("Model Visualizer");
   graph = new DirectedSparseMultigraph<>();
   graph.addVertex(current);
   //    Layout<FSMTransition, String> layout = new CircleLayout<FSMTransition, String>(graph);
   layout = new KKLayout<>(graph);
   layout.setSize(new Dimension(800, 600)); // sets the initial size of the space
   vv = new VisualizationViewer<>(layout);
   vv.setPreferredSize(new Dimension(800, 600)); // Sets the viewing area size
   vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
   vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller());
   vv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);
   VertexLabelAsShapeRenderer<String, StepCounter> vlasr =
       new VertexLabelAsShapeRenderer<>(vv.getRenderContext());
   //    vv.getRenderContext().setVertexShapeTransformer(vlasr);
   vv.getRenderContext().setVertexShapeTransformer(new EllipseVertexTransformer());
   //    vv.getRenderContext().setVertexLabelRenderer(new
   // TransitionVertextLabelRenderer(Color.GREEN));
   DefaultModalGraphMouse gm = new DefaultModalGraphMouse();
   vv.addKeyListener(gm.getModeKeyListener());
   gm.setMode(ModalGraphMouse.Mode.TRANSFORMING);
   vv.setGraphMouse(gm);
   getContentPane().add(vv);
   setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   setSize(1024, 768);
   pack();
   setVisible(true);
 }
 private void visualize(UndirectedSparseGraph<String, Integer> coOccurenceGraph) {
   Layout<String, String> layout = new FRLayout(coOccurenceGraph);
   layout.setSize(new Dimension(300, 300));
   VisualizationViewer<String, String> vv = new VisualizationViewer<String, String>(layout);
   vv.setPreferredSize(new Dimension(350, 350));
   // Show vertex and edge labels
   vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
   vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller());
   // Create a graph mouse and add it to the visualization component
   DefaultModalGraphMouse gm = new DefaultModalGraphMouse();
   vv.setGraphMouse(gm);
   JFrame frame = new JFrame("Co-Occurrence");
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   frame.getContentPane().add(vv);
   frame.pack();
   frame.setVisible(true);
 }
Example #10
0
  /**
   * Returns the vertex, if any, whose shape contains (x, y). If (x,y) is contained in more than one
   * vertex's shape, returns the vertex whose center is closest to the pick point.
   *
   * @param layout the layout instance that records the positions for all vertices
   * @param x the x coordinate of the pick point
   * @param y the y coordinate of the pick point
   * @return the vertex whose shape contains (x,y), and whose center is closest to the pick point
   */
  public V getVertex(Layout<V, E> layout, double x, double y) {

    V closest = null;
    double minDistance = Double.MAX_VALUE;
    Point2D ip =
        vv.getRenderContext()
            .getMultiLayerTransformer()
            .inverseTransform(Layer.VIEW, new Point2D.Double(x, y));
    x = ip.getX();
    y = ip.getY();

    while (true) {
      try {
        for (V v : getFilteredVertices(layout)) {

          Shape shape = vv.getRenderContext().getVertexShapeTransformer().apply(v);
          // get the vertex location
          Point2D p = layout.apply(v);
          if (p == null) continue;
          // transform the vertex location to screen coords
          p = vv.getRenderContext().getMultiLayerTransformer().transform(Layer.LAYOUT, p);

          double ox = x - p.getX();
          double oy = y - p.getY();

          if (shape.contains(ox, oy)) {

            if (style == Style.LOWEST) {
              // return the first match
              return v;
            } else if (style == Style.HIGHEST) {
              // will return the last match
              closest = v;
            } else {

              // return the vertex closest to the
              // center of a vertex shape
              Rectangle2D bounds = shape.getBounds2D();
              double dx = bounds.getCenterX() - ox;
              double dy = bounds.getCenterY() - oy;
              double dist = dx * dx + dy * dy;
              if (dist < minDistance) {
                minDistance = dist;
                closest = v;
              }
            }
          }
        }
        break;
      } catch (ConcurrentModificationException cme) {
      }
    }
    return closest;
  }
Example #11
0
    /**
     * Changes the size of the underlying Layout.
     *
     * @param size The new size for the layout.
     */
    private void setSize(Dimension size) {
      ObservableCachingLayout<V, E> observableLayout = (ObservableCachingLayout) getGraphLayout();
      Layout<V, E> tmpLayout = observableLayout;
      while (!AbstractLayout.class.isAssignableFrom(tmpLayout.getClass()))
        tmpLayout = ((LayoutDecorator<V, E>) tmpLayout).getDelegate();
      AbstractLayout<V, E> layout = (AbstractLayout<V, E>) tmpLayout;

      // the first time the graph is resized, re-initialize the layout to make sure it gets
      // the right size.  Any other time, just scale it. The first resize should be when the
      // graph is made visible and laid out.
      // this is kind of a hack; there may be a better way to handle this.
      // I tried listening for componentShown, but it didn't work properly.
      if (layoutInitialized < 1) {
        layout.getSize().setSize(size);
        layout.initialize();
        layoutInitialized++;
        return;
      }

      // change the size of the layout without triggering the automatic resizing.
      double wScale = size.getWidth() / layout.getSize().getWidth();
      double hScale = size.getHeight() / layout.getSize().getHeight();
      double scale = Math.min(wScale, hScale);
      layout.getSize().setSize(size);
      Collection<V> vertices = new Vector(getVertices());
      synchronized (graph) {
        for (V v : vertices) {
          double x =
              layout.getX(v)
                  * scale; // Math.min( size.getWidth( ) - 10, Math.max( 10, layout.getX( v ) *
                           // scale ));
          double y =
              layout.getY(v)
                  * scale; // Math.min( size.getHeight( ) - 10, Math.max( 10, layout.getY( v ) *
                           // scale ));
          layout.setLocation(v, new Point2D.Double(x, y));
        }
      }
      // alert the ObservableLayout that things have changed.
      observableLayout.fireStateChanged();
    }
Example #12
0
  /**
   * Retrieves the shape template for <code>e</code> and transforms it according to the positions of
   * its endpoints in <code>layout</code>.
   *
   * @param layout the <code>Layout</code> which specifies <code>e</code>'s endpoints' positions
   * @param e the edge whose shape is to be returned
   * @return the transformed shape
   */
  private Shape getTransformedEdgeShape(Layout<V, E> layout, E e) {
    Pair<V> pair = layout.getGraph().getEndpoints(e);
    V v1 = pair.getFirst();
    V v2 = pair.getSecond();
    boolean isLoop = v1.equals(v2);
    Point2D p1 =
        vv.getRenderContext().getMultiLayerTransformer().transform(Layer.LAYOUT, layout.apply(v1));
    Point2D p2 =
        vv.getRenderContext().getMultiLayerTransformer().transform(Layer.LAYOUT, layout.apply(v2));
    if (p1 == null || p2 == null) return null;
    float x1 = (float) p1.getX();
    float y1 = (float) p1.getY();
    float x2 = (float) p2.getX();
    float y2 = (float) p2.getY();

    // translate the edge to the starting vertex
    AffineTransform xform = AffineTransform.getTranslateInstance(x1, y1);

    Shape edgeShape = vv.getRenderContext().getEdgeShapeTransformer().apply(e);
    if (isLoop) {
      // make the loops proportional to the size of the vertex
      Shape s2 = vv.getRenderContext().getVertexShapeTransformer().apply(v2);
      Rectangle2D s2Bounds = s2.getBounds2D();
      xform.scale(s2Bounds.getWidth(), s2Bounds.getHeight());
      // move the loop so that the nadir is centered in the vertex
      xform.translate(0, -edgeShape.getBounds2D().getHeight() / 2);
    } else {
      float dx = x2 - x1;
      float dy = y2 - y1;
      // rotate the edge to the angle between the vertices
      double theta = Math.atan2(dy, dx);
      xform.rotate(theta);
      // stretch the edge to span the distance between the vertices
      float dist = (float) Math.sqrt(dx * dx + dy * dy);
      xform.scale(dist, 1.0f);
    }

    // transform the edge to its location and dimensions
    edgeShape = xform.createTransformedShape(edgeShape);
    return edgeShape;
  }
 /** @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 a graph mouse and add it to the visualization component
   DefaultModalGraphMouse gm = new DefaultModalGraphMouse();
   gm.setMode(ModalGraphMouse.Mode.TRANSFORMING);
   vv.setGraphMouse(gm);
   // Add the mouses mode key listener to work it needs to be added to the visualization component
   vv.addKeyListener(gm.getModeKeyListener());
   JFrame frame = new JFrame("Interactive Graph View 2");
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   frame.getContentPane().add(vv);
   frame.pack();
   frame.setVisible(true);
 }
  // method for flow graph visualization
  public static void visualizeGraph(int[][] matrix, int N, int k) {
    Graph<Integer, String> graph = new DirectedSparseGraph<Integer, String>();

    for (int i = 0; i < matrix.length; i++) {
      graph.addVertex((Integer) i);
    }

    for (int i = 0; i < matrix.length; i++) {
      for (int j = 0; j < matrix[i].length; j++) {
        // only select edge that has flow bigger than 0
        if (matrix[i][j] > 0) {
          graph.addEdge(i + "->" + j, i, j, EdgeType.DIRECTED);
        }
      }
    }

    Layout<Integer, String> layout = new CircleLayout<Integer, String>(graph);
    layout.setSize(new Dimension(800, 800));

    BasicVisualizationServer<Integer, String> vv =
        new BasicVisualizationServer<Integer, String>(layout);
    Transformer<Integer, Paint> vertexPaint =
        new Transformer<Integer, Paint>() {
          public Paint transform(Integer i) {
            return Color.YELLOW;
          }
        };

    vv.setPreferredSize(new Dimension(800, 800));
    vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<Integer>());
    vv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);

    JFrame frame = new JFrame("Network Visualization - N = " + N + ", k = " + k);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(vv);
    frame.pack();
    frame.setVisible(true);
  }
  /** @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);
  }
Example #16
0
 private void addEdge(String step) {
   String edge = current + "->" + step;
   if (!edges.containsKey(edge)) {
     //      System.out.println("EDGE+" + edge);
     if (!vertices.contains(step)) {
       //        System.out.println("VERTEX+" + t);
       graph.addVertex(step);
       vertices.add(step);
     }
     StepCounter counter = new StepCounter();
     edges.put(edge, counter);
     graph.addEdge(counter, current, step);
     vv.repaint();
   } else {
     edges.get(edge).increment();
   }
   layout.reset();
 }
Example #17
0
  /**
   * Returns the vertices whose layout coordinates are contained in <code>Shape</code>. The shape is
   * in screen coordinates, and the graph vertices are transformed to screen coordinates before they
   * are tested for inclusion.
   *
   * @return the <code>Collection</code> of vertices whose <code>layout</code> coordinates are
   *     contained in <code>shape</code>.
   */
  public Collection<V> getVertices(Layout<V, E> layout, Shape shape) {
    Set<V> pickedVertices = new HashSet<V>();

    // remove the view transform from the rectangle
    shape = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(Layer.VIEW, shape);

    while (true) {
      try {
        for (V v : getFilteredVertices(layout)) {
          Point2D p = layout.apply(v);
          if (p == null) continue;

          p = vv.getRenderContext().getMultiLayerTransformer().transform(Layer.LAYOUT, p);
          if (shape.contains(p)) {
            pickedVertices.add(v);
          }
        }
        break;
      } catch (ConcurrentModificationException cme) {
      }
    }
    return pickedVertices;
  }
  /**
   * ***************************************** 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);
  }
  @Override
  public void labelEdge(RenderContext<V, E> rc, Layout<V, E> layout, E e, String label) {
    if (label == null || label.length() == 0) {
      return;
    }

    Graph<V, E> graph = layout.getGraph();
    // don't draw edge if either incident vertex is not drawn
    Pair<V> endpoints = graph.getEndpoints(e);
    V v1 = endpoints.getFirst();
    V v2 = endpoints.getSecond();
    if (!rc.getVertexIncludePredicate().evaluate(Context.<Graph<V, E>, V>getInstance(graph, v1))
        || !rc.getVertexIncludePredicate()
            .evaluate(Context.<Graph<V, E>, V>getInstance(graph, v2))) {
      return;
    }

    Point2D p1 = layout.transform(v1);
    Point2D p2 = layout.transform(v2);
    p1 = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, p1);
    p2 = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, p2);
    float x1 = (float) p1.getX();
    float y1 = (float) p1.getY();
    float x2 = (float) p2.getX();
    float y2 = (float) p2.getY();

    GraphicsDecorator g = rc.getGraphicsContext();
    float distX = x2 - x1;
    float distY = y2 - y1;
    double totalLength = Math.sqrt(distX * distX + distY * distY);

    double closeness =
        rc.getEdgeLabelClosenessTransformer()
            .transform(Context.<Graph<V, E>, E>getInstance(graph, e))
            .doubleValue();

    int posX = (int) (x1 + (closeness) * distX);
    int posY = (int) (y1 + (closeness) * distY);

    int xDisplacement = 0;
    int yDisplacement = 0;

    /*
     * BUG 1: change X and Y in distXXX xDisplacement = (int) (rc.getLabelOffset() * (distY /
     * totalLength)); yDisplacement = (int) (rc.getLabelOffset() * (-distX / totalLength));
     */

    xDisplacement = (int) (rc.getLabelOffset() * (distX / totalLength));
    yDisplacement = (int) (rc.getLabelOffset() * (-distY / totalLength));

    // BUG 2
    /*
     * Component component = prepareRenderer(rc, rc.getEdgeLabelRenderer(), label,
     * rc.getPickedEdgeState().isPicked(e), e); Dimension d = component.getPreferredSize();
     * Shape edgeShape = rc.getEdgeShapeTransformer().transform(Context.<Graph<V, E>, E>
     * getInstance(graph, e)); double parallelOffset = 1;
     *
     * parallelOffset -= rc.getParallelEdgeIndexFunction().getIndex(graph, e);
     *
     * if (edgeShape instanceof Ellipse2D) { parallelOffset +=
     * edgeShape.getBounds().getHeight(); parallelOffset = -parallelOffset; }
     *
     * parallelOffset *= d.height;
     */

    AffineTransform old = g.getTransform();
    AffineTransform xform = new AffineTransform(old);
    xform.translate(posX + xDisplacement, posY + yDisplacement);

    // BUG 3
    /*
     * double dx = x2 - x1; double dy = y2 - y1; if
     * (rc.getEdgeLabelRenderer().isRotateEdgeLabels()) { double theta = Math.atan2(dy, dx); if
     * (dx < 0) { theta += Math.PI; } xform.rotate(theta); } if (dx < 0) { parallelOffset =
     * -parallelOffset; }
     */

    double parallelOffset = 0.0d;
    Component component =
        prepareRenderer(
            rc, rc.getEdgeLabelRenderer(), label, rc.getPickedEdgeState().isPicked(e), e);
    Dimension d = component.getPreferredSize();
    xform.translate(-d.width / 2.0d, -(d.height / 2.0d - parallelOffset));
    g.setTransform(xform);
    g.draw(component, rc.getRendererPane(), 0, 0, d.width, d.height, true);
    g.setTransform(old);
  }
  public static void main(String[] args) {

    File tweetFile;

    if (args.length > 0) {
      tweetFile = new File(args[0]);
    } else {
      tweetFile =
          new File(
              "C:\\Users\\IBM_ADMIN\\Desktop\\Twitter\\TwitterDataAnalytics\\TwitterDataAnalytics\\owssad.json");
    }

    DirectedGraph<UserNode, RetweetEdge> retweetGraph =
        TweetFileToGraph.getRetweetNetwork(tweetFile);

    /*
     * Converts a node to its string representation
     */
    Transformer<UserNode, String> stringer =
        new Transformer<UserNode, String>() {
          public String transform(UserNode n) {
            return n.toString();
          }
        };

    /*
     * Calculate the centrality
     */
    // calculate the betweenness centrality
    //		final InDegreeScorer<UserNode> centralityScore = new InDegreeScorer<UserNode>(retweetGraph);
    //		final BetweennessCentrality<UserNode, RetweetEdge> centralityScore = new
    // BetweennessCentrality<UserNode, RetweetEdge>(retweetGraph);
    //		final PageRank<UserNode, RetweetEdge> centralityScore = new PageRank<UserNode,
    // RetweetEdge>(retweetGraph, 0.85);
    final EigenvectorCentrality<UserNode, RetweetEdge> centralityScore =
        new EigenvectorCentrality<UserNode, RetweetEdge>(retweetGraph);
    centralityScore.evaluate();

    double centralityMax = 0.0f;
    for (UserNode node : retweetGraph.getVertices()) {
      centralityMax = Math.max(centralityMax, centralityScore.getVertexScore(node));
    }
    final double centralityMaxFinal = centralityMax;

    /*
     * Sizes a node by some centrality measure
     */
    Transformer<UserNode, Shape> shaper =
        new Transformer<UserNode, Shape>() {
          public Shape transform(UserNode n) {
            System.out.println(
                "User: "******" Cent: "
                    + centralityScore.getVertexScore(n)
                    + " Max: "
                    + centralityMaxFinal);
            double radius = 50 * (centralityScore.getVertexScore(n)) / centralityMaxFinal;
            radius = Math.max(radius, 5.0f);
            float fRadius = (float) radius;
            return new Ellipse2D.Float(-fRadius / 2, -fRadius / 2, fRadius, fRadius);
          }
        };

    Layout<UserNode, RetweetEdge> layout = new KKLayout<UserNode, RetweetEdge>(retweetGraph);
    layout.setSize(new Dimension(500, 500));

    BasicVisualizationServer<UserNode, RetweetEdge> vv =
        new BasicVisualizationServer<UserNode, RetweetEdge>(layout);
    vv.setPreferredSize(new Dimension(550, 550));
    vv.getRenderContext().setVertexLabelTransformer(stringer);
    vv.getRenderContext().setVertexShapeTransformer(shaper);

    JFrame jframe = new JFrame("Simple Graph View");
    jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jframe.getContentPane().add(vv);
    jframe.pack();
    jframe.setVisible(true);
  }
  @SuppressWarnings({"unchecked", "rawtypes"})
  public static void main(String[] args) {

    final EditingGraphViewer sgv = new EditingGraphViewer();

    // Layout<V, E>, VisualizationViewer<V,E>
    final Layout<Integer, String> layout = new StaticLayout<Integer, String>(g);
    layout.setSize(new Dimension(300, 300));
    final VisualizationViewer<Integer, String> vv =
        new VisualizationViewer<Integer, String>(layout);
    vv.setBackground(Color.white);
    vv.setPreferredSize(new Dimension(350, 350));

    Transformer<Integer, Paint> vertexPaint =
        new Transformer<Integer, Paint>() {
          public Paint transform(Integer i) {
            return (Paint) Color.WHITE;
          }
        };
    vv.getRenderContext()
        .setVertexFillPaintTransformer((Transformer<Integer, java.awt.Paint>) vertexPaint);

    // Show vertex and edge labels
    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<Integer>());
    vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller<String>());

    // Create a graph mouse and add it to the visualization viewer
    // Our Vertices are going to be Integer objects so we need an Integer factory
    EditingModalGraphMouse gm =
        new EditingModalGraphMouse(vv.getRenderContext(), sgv.vertexFactory, sgv.edgeFactory);
    vv.setGraphMouse(gm);

    JFrame frame = new JFrame("Editing Graph");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(vv);

    // ===========================================================================
    // Menu for changing mouse modes

    JMenuBar menuBar = new JMenuBar();
    JMenu modeMenu = gm.getModeMenu();
    modeMenu.setText("Mode");
    modeMenu.setIcon(null);
    modeMenu.setPreferredSize(new Dimension(80, 20));
    menuBar.add(modeMenu);

    // ---------------------------------------------------------------------------
    // Menu Item to compute Centrality Measures

    JMenu centrality = new JMenu("Centrality");
    JMenuItem execB = new JMenuItem("Betweenness C.");
    execB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            Betweenness.compute(g);
          }
        });
    centrality.add(execB);

    JMenuItem execC = new JMenuItem("Closeness C");
    execC.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            Closeness.compute(g);
          }
        });
    centrality.add(execC);

    menuBar.add(centrality);

    // ---------------------------------------------------------------------------
    // Menu Item to change Vertices Color
    colorArray.add(2);

    JMenu selColor = new JMenu("NodeColor");

    JMenuItem selBlack = new JMenuItem("black");
    selBlack.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {

            colorArray.add(1);
            int v = g.getVertexCount();
            for (int j = 0; j < nodeArray.size(); j++) v = v - nodeArray.get(j);
            int vC = g.getVertexCount();
            nodeArray.add(v);
            SelectColor.choiceColor(1, vv, nodeArray, colorArray, vC);
          }
        });
    selColor.add(selBlack);

    JMenuItem selGray = new JMenuItem("gray");
    selGray.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {

            colorArray.add(0);
            int v = g.getVertexCount();
            for (int j = 0; j < nodeArray.size(); j++) v = v - nodeArray.get(j);
            nodeArray.add(v);
            int vC = g.getVertexCount();
            SelectColor.choiceColor(0, vv, nodeArray, colorArray, vC);
          }
        });
    selColor.add(selGray);

    JMenuItem selWhite = new JMenuItem("white");
    selWhite.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {

            colorArray.add(2);
            int v = g.getVertexCount();
            for (int j = 0; j < nodeArray.size(); j++) v = v - nodeArray.get(j);
            nodeArray.add(v);
            int vC = g.getVertexCount();
            SelectColor.choiceColor(2, vv, nodeArray, colorArray, vC);
          }
        });
    selColor.add(selWhite);

    JMenuItem selYellow = new JMenuItem("yellow");
    selYellow.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {

            colorArray.add(3);
            int v = g.getVertexCount();
            for (int j = 0; j < nodeArray.size(); j++) v = v - nodeArray.get(j);
            nodeArray.add(v);
            int vC = g.getVertexCount();
            SelectColor.choiceColor(3, vv, nodeArray, colorArray, vC);
          }
        });
    selColor.add(selYellow);

    menuBar.add(selColor);

    // ------------------------------------------------------------------------------------
    // MenuItem to save the graph as jpeg ,or eps, or to save code generation graph

    JMenu saveImg = new JMenu("Save");

    JMenuItem saveJPG = new JMenuItem("Save as jpeg");
    saveJPG.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {

            Save.saveJpeg(vv);
          }
        });

    saveImg.add(saveJPG);

    JMenuItem saveEPS = new JMenuItem("Save as eps");
    saveEPS.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {

            Save.saveEps(vv);
          }
        });

    saveImg.add(saveEPS);

    JMenuItem saveCode = new JMenuItem("Save Graph Code");
    saveCode.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {

            Save.saveCode(g, colorArray, nodeArray);
          }
        });

    saveImg.add(saveCode);

    menuBar.add(saveImg);

    // -------------------------------------------------------------------------------------

    frame.setJMenuBar(menuBar);
    gm.setMode(ModalGraphMouse.Mode.EDITING); // Start off in editing mode

    frame.pack();
    frame.setVisible(true);
  }
  public HecataeusNodePolicies(
      final VisualizationViewer<VisualNode, VisualEdge> vv, final VisualNode node) {
    this.setSize(500, 500);
    this.setTitle("Policies for: " + node.getName());
    this.setModal(true);
    setLocationRelativeTo(vv);
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    this.node = node;
    this.vv = vv;

    // get current graph
    Layout<VisualNode, VisualEdge> ll = vv.getGraphLayout();
    graph = (VisualGraph) ll.getGraph();

    jTabbedPane = new JTabbedPane();

    // tab for edit existing policies
    view = new JScrollPane();
    jTextArea = new JTextArea();
    jTextArea.setEditable(false);

    view.setViewportView((Component) jTextArea);
    jTabbedPane.addTab(" View ", view);

    // tab for add policy
    add = new JPanel();
    jTabbedPane.addTab(" Add ", add);
    GridBagLayout gridbag = new GridBagLayout();
    HecataeusGridBagConstraints constraints = new HecataeusGridBagConstraints();
    add.setLayout(gridbag);

    // label for top level node
    constraints.reset(0, 0, 1, 1, 0, 40);
    constraints.fill = GridBagConstraints.NONE;
    constraints.anchor = GridBagConstraints.EAST;
    JLabel labelNode = new JLabel("Choose a top level node: ", JLabel.LEFT);
    gridbag.setConstraints(labelNode, constraints);
    add.add(labelNode);

    // combo box for top level node
    comboBoxEventNodeParent = new JComboBox();
    constraints.reset(1, 0, 1, 1, 0, 0);
    constraints.fill = GridBagConstraints.HORIZONTAL;
    gridbag.setConstraints(comboBoxEventNodeParent, constraints);
    comboBoxEventNodeParent.addItem(null);
    // fill comboBox for Node selection
    for (VisualNode parentNode : graph.getVertices()) {
      if (parentNode.getType().getCategory() == NodeCategory.MODULE) {
        comboBoxEventNodeParent.addItem(parentNode);
      }
    }
    // add action listener to fill childcombo
    comboBoxEventNodeParent.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // get key for parent node
            VisualNode parentNode = (VisualNode) comboBoxEventNodeParent.getSelectedItem();
            // reset child combo
            comboBoxEventNodeChild.removeAllItems();
            if (parentNode != null) {
              // get descendant nodes
              List<VisualNode> subGraph = graph.getModule(parentNode);
              for (VisualNode childNode : subGraph) {
                // filter only these nodes that are adjacent to node assigned the policy
                // including the node itself
                if ((node.equals(childNode))) {
                  comboBoxEventNodeChild.addItem(childNode);
                } else {
                  for (VisualEdge outEdge : node.getOutEdges()) {
                    if ((node.equals(childNode)) || (outEdge.getToNode().equals(childNode)))
                      comboBoxEventNodeChild.addItem(childNode);
                  }
                }
              }
            }
          }
        });
    add.add(comboBoxEventNodeParent);

    // label for low level node
    constraints.reset(0, 1, 1, 1, 0, 40);
    constraints.fill = GridBagConstraints.NONE;
    constraints.anchor = GridBagConstraints.EAST;
    labelNode = new JLabel("Set the event node: ", JLabel.LEFT);
    gridbag.setConstraints(labelNode, constraints);
    add.add(labelNode);

    // combo box for low level node
    constraints.reset(1, 1, 1, 1, 0, 0);
    constraints.fill = GridBagConstraints.HORIZONTAL;
    comboBoxEventNodeChild = new JComboBox();
    gridbag.setConstraints(comboBoxEventNodeChild, constraints);
    // add action listener to fill event types
    comboBoxEventNodeChild.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            VisualNode eventNode = (VisualNode) comboBoxEventNodeChild.getSelectedItem();
            // reset event combo
            comboBoxEventType.removeAllItems();
            if (eventNode != null) {
              // fill appropriate event types
              for (EventType eventType : EventType.values(eventNode.getType())) {
                comboBoxEventType.addItem(eventType);
              }
            }
          }
        });
    add.add(comboBoxEventNodeChild);

    // label for event type
    constraints.reset(0, 2, 1, 1, 0, 40);
    constraints.fill = GridBagConstraints.NONE;
    constraints.anchor = GridBagConstraints.EAST;
    JLabel labelEventType = new JLabel("Set the event type: ", JLabel.LEFT);
    gridbag.setConstraints(labelEventType, constraints);
    add.add(labelEventType);

    // combo box fox event type
    constraints.reset(1, 2, 1, 1, 90, 0);
    constraints.fill = GridBagConstraints.NONE;
    constraints.anchor = GridBagConstraints.WEST;
    comboBoxEventType = new JComboBox();
    gridbag.setConstraints(comboBoxEventType, constraints);
    add.add(comboBoxEventType);

    // label for policy type
    constraints.reset(0, 3, 1, 1, 0, 0);
    constraints.fill = GridBagConstraints.NONE;
    constraints.anchor = GridBagConstraints.EAST;
    JLabel labelPolicyType = new JLabel("Set the policy type: ", JLabel.LEFT);
    gridbag.setConstraints(labelPolicyType, constraints);
    add.add(labelPolicyType);

    // combo box for policy type
    constraints.reset(1, 3, 1, 1, 0, 0);
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.anchor = GridBagConstraints.WEST;
    comboBoxPolicyType = new JComboBox();
    gridbag.setConstraints(comboBoxPolicyType, constraints);
    add.add(comboBoxPolicyType);

    // OK button
    constraints.reset(0, 4, 2, 1, 0, 20);
    constraints.fill = GridBagConstraints.NONE;
    constraints.anchor = GridBagConstraints.WEST;
    okAddButton = new JButton("Add Policy");
    gridbag.setConstraints(okAddButton, constraints);
    add.add(okAddButton);
    okAddButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // get informations from comboBoxes
            // get event type
            EventType eventType = (EventType) comboBoxEventType.getSelectedItem();
            // get policy type
            PolicyType policyType = (PolicyType) comboBoxPolicyType.getSelectedItem();
            // get event node
            VisualNode eventNode = (VisualNode) comboBoxEventNodeChild.getSelectedItem();
            if (eventNode != null) {
              // create and add selected policy
              EvolutionPolicy<VisualNode> newPolicy =
                  new EvolutionPolicy<VisualNode>(eventType, policyType);
              EvolutionPolicies policies = node.getPolicies();
              if (policies.get(eventType) != null) {
                if (JOptionPane.showConfirmDialog(
                        null,
                        "This policy already exists! Do you want to replace it?",
                        "Warning Message",
                        JOptionPane.YES_NO_OPTION)
                    == JOptionPane.YES_OPTION) {
                  node.addPolicy(newPolicy);
                }
              } else {
                node.addPolicy(newPolicy);
              }
              vv.repaint();
              initialize();
            }
          } // end actionPerformed
        }); // end actionListener

    // Cancel button
    constraints.reset(1, 4, 2, 1, 0, 20);
    constraints.fill = GridBagConstraints.NONE;
    constraints.anchor = GridBagConstraints.CENTER;
    JButton cancelAddButton = new JButton("Cancel");
    gridbag.setConstraints(cancelAddButton, constraints);
    cancelAddButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            dispose();
          }
        });
    add.add(cancelAddButton);

    // tab for remove policy
    remove = new JPanel();
    jTabbedPane.addTab(" Remove ", remove);
    remove.setLayout(gridbag);

    // label for remove policy
    constraints.reset(0, 0, 1, 1, 10, 40);
    constraints.fill = GridBagConstraints.NONE;
    constraints.anchor = GridBagConstraints.EAST;
    JLabel labelPolicy = new JLabel("Choose policy to remove: ", JLabel.LEFT);
    gridbag.setConstraints(labelPolicy, constraints);
    remove.add(labelPolicy);

    // combo box fox policy
    constraints.reset(1, 0, 1, 1, 90, 20);
    constraints.fill = GridBagConstraints.NONE;
    constraints.anchor = GridBagConstraints.WEST;
    comboBoxPolicies = new JComboBox();
    gridbag.setConstraints(comboBoxPolicies, constraints);
    remove.add(comboBoxPolicies);

    // OK button
    constraints.reset(0, 2, 2, 1, 0, 20);
    constraints.fill = GridBagConstraints.NONE;
    constraints.anchor = GridBagConstraints.WEST;
    okRemoveButton = new JButton("Remove policy");
    gridbag.setConstraints(okRemoveButton, constraints);
    remove.add(okRemoveButton);
    okRemoveButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            EvolutionPolicy<VisualNode> policyToRemove =
                (EvolutionPolicy<VisualNode>) comboBoxPolicies.getSelectedItem();
            // get  node
            node.removePolicy(policyToRemove);
            vv.repaint();
            initialize();
          }
        });

    // Cancel button
    constraints.reset(1, 2, 2, 1, 0, 20);
    constraints.fill = GridBagConstraints.NONE;
    constraints.anchor = GridBagConstraints.CENTER;
    JButton cancelRemoveButton = new JButton("Cancel");
    gridbag.setConstraints(cancelRemoveButton, constraints);
    cancelRemoveButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            dispose();
          }
        });
    remove.add(cancelRemoveButton);

    initialize();
    setContentPane(jTabbedPane);
    setVisible(true);
  } // end constructor
  /**
   * This method implements the building of the chosen layout with chosen parameters
   *
   * @return The built layout
   * @throws BadLayoutException If the chosen layout doesn't exist (invalid code was provided)
   */
  public Layout<NodeDescriptor, EdgeDescriptor> build() throws BadLayoutException {
    Layout<NodeDescriptor, EdgeDescriptor> layout;

    String layoutCode = layoutEntry.getCode();
    if (layoutCode.equals(Layouts.LAYOUT_ISOM.getCode())) {
      layout = new TitaniumISOMLayout<NodeDescriptor, EdgeDescriptor>(g);
      ((TitaniumISOMLayout<NodeDescriptor, EdgeDescriptor>) layout)
          .setMaxIterations(
              Activator.getDefault()
                  .getPreferenceStore()
                  .getInt(PreferenceConstants.NO_ITERATIONS));
    } else if (layoutCode.equals(Layouts.LAYOUT_KK.getCode())) {
      layout = new KKLayout<NodeDescriptor, EdgeDescriptor>(g);
      ((KKLayout<NodeDescriptor, EdgeDescriptor>) layout)
          .setMaxIterations(
              Activator.getDefault()
                  .getPreferenceStore()
                  .getInt(PreferenceConstants.NO_ITERATIONS));
    } else if (layoutCode.equals(Layouts.LAYOUT_FR.getCode())) {
      layout = new FRLayout<NodeDescriptor, EdgeDescriptor>(g);
      ((FRLayout<NodeDescriptor, EdgeDescriptor>) layout).setAttractionMultiplier(0.6);
      ((FRLayout<NodeDescriptor, EdgeDescriptor>) layout).setRepulsionMultiplier(0.8);
      ((FRLayout<NodeDescriptor, EdgeDescriptor>) layout)
          .setMaxIterations(
              Activator.getDefault()
                  .getPreferenceStore()
                  .getInt(PreferenceConstants.NO_ITERATIONS));
    } else if (layoutCode.equals(Layouts.LAYOUT_SPRING.getCode())) {
      layout = new SpringLayout<NodeDescriptor, EdgeDescriptor>(g);
    } else if (layoutCode.equals(Layouts.LAYOUT_CIRCLE.getCode())) {
      layout = new CircleLayout<NodeDescriptor, EdgeDescriptor>(g);
    } else if (layoutCode.equals(Layouts.LAYOUT_RTDAG.getCode())) {
      layout = new ReverseDAGLayout<NodeDescriptor, EdgeDescriptor>(g, size);
    } else if (layoutCode.equals(Layouts.LAYOUT_TDAG.getCode())) {
      layout = new TitaniumDAGLayout<NodeDescriptor, EdgeDescriptor>(g, size);
    } else if (layoutCode.equals(Layouts.METRIC_LAYOUT_CODE)) {
      if (!(layoutEntry instanceof MetricsLayoutEntry)) {
        throw new IllegalStateException("A metric must be chosen before using metric layout!");
      }
      layout =
          new MetricLayout<EdgeDescriptor>(g, size, ((MetricsLayoutEntry) layoutEntry).getMetric());
    } else if (layoutCode.equals(Layouts.S_LAYOUT_CLUSTER)) {
      if (clusters == null) {
        throw new IllegalStateException("A clustering must be set before using cluster layout!");
      }
      ClusterTransformer trf =
          new ClusterTransformer(new FRLayout<NodeDescriptor, EdgeDescriptor>(g), clusters, size);
      layout = new StaticLayout<NodeDescriptor, EdgeDescriptor>(g, trf);
    } else if ("STATIC".equals(layoutCode)) {
      if (pointTransformer == null) {
        throw new IllegalStateException(
            "A point transformer must be set before using static layout!");
      }
      layout = new StaticLayout<NodeDescriptor, EdgeDescriptor>(g, pointTransformer);
    } else {
      throw new BadLayoutException(
          "There is no such layout! (Layout=" + layoutCode + ")", ErrorType.NOT_EXISITING_LAYOUT);
    }
    layout.setSize(size);

    return layout;
  }
Example #24
0
 /**
  * Sets a new Layout for the graph.
  *
  * @param layout The Layout instance to use for the new Graph Layout.
  */
 public void setGraphLayout(Layout<V, E> layout) {
   super.setGraphLayout(layout);
   layout.initialize();
   this.graph = (UndirectedSparseGraph<V, E>) this.getGraphLayout().getGraph();
 }