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);
  }
  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;
  }
Esempio n. 3
0
 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);
 }
Esempio n. 4
0
 private void setVisualizationViewer(VisualizationViewer vviewer) {
   //			vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
   vv = vviewer;
   // vv.setPickSupport(new edu.uci.ics.jung.visualization.picking.ShapePickSupport(vv));
   vv.setPreferredSize(new Dimension(350, 350));
   //			vv.getRenderContext().setVertexLabelTransformer(vertexLabelTransformer);
   vv.setGraphMouse(gm);
   vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
   splitPanelLeft.setRightComponent(new GraphZoomScrollPane(vv));
 }
Esempio n. 5
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);
  }
 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);
 }
 /** @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);
 }
  /** @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);
  }
  @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);
  }
  /**
   * ***************************************** 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);
  }