Guest User

Jscrollbar in graphstream

a guest
May 30th, 2013
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.54 KB | None | 0 0
  1. import java.awt.BorderLayout;
  2. import java.awt.Dimension;
  3.  
  4. import javax.swing.JButton;
  5. import javax.swing.JFrame;
  6. import javax.swing.JLabel;
  7. import javax.swing.JPanel;
  8. import javax.swing.JScrollPane;
  9.  
  10. import org.graphstream.graph.Graph;
  11. import org.graphstream.graph.Node;
  12. import org.graphstream.graph.implementations.SingleGraph;
  13. import org.graphstream.ui.swingViewer.GraphRenderer;
  14. import org.graphstream.ui.swingViewer.View;
  15. import org.graphstream.ui.swingViewer.Viewer;
  16. import org.graphstream.ui.swingViewer.ViewerListener;
  17. import org.graphstream.ui.swingViewer.ViewerPipe;
  18. import org.graphstream.ui.swingViewer.util.Camera;
  19. import org.graphstream.ui.swingViewer.util.DefaultCamera;
  20.  
  21. public class Clicks extends JFrame implements ViewerListener {
  22.    
  23.     protected boolean loop = true;
  24.     private JLabel label = new JLabel("bla");
  25.     private Graph graph;
  26.  
  27.     public static void main(String args[]) {
  28.         new Clicks();
  29.     }
  30.    
  31.     public Clicks() {
  32.         setSize(new Dimension(800, 600));
  33.        
  34.         // We do as usual to display a graph. This
  35.         // connect the graph outputs to the viewer.
  36.         // The viewer is a sink of the graph.
  37.         graph = new SingleGraph("Clicks");
  38.         graph.setStrict(false);
  39.         Node n2 = graph.addNode("gs");
  40.         Node n3 = graph.addNode("gs2");
  41.         graph.addEdge("t", n2, n3);
  42.        
  43.         Viewer viewer = new Viewer(graph, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
  44.         //Viewer viewer = graph.display();
  45.        
  46.         View view = viewer.addDefaultView(false);
  47.         viewer.enableAutoLayout();
  48.        
  49.         view.setMinimumSize(new Dimension(600, 600));
  50.         view.setPreferredSize(new Dimension(600, 600));
  51.  
  52.         Camera cam = view.getCamera();
  53.        
  54.         this.getContentPane().setLayout(new BorderLayout());
  55.         JScrollPane jsp = new JScrollPane(view);
  56.        
  57.        
  58.        
  59.         this.getContentPane().add(jsp, BorderLayout.CENTER);
  60.         /*
  61.         this.getContentPane().add(viewer.addView(
  62.                 String.format("defaultView_%d", (long) (Math.random() * 10000)),
  63.                 renderer, false), BorderLayout.CENTER);
  64.                 */
  65.         this.getContentPane().add(label, BorderLayout.SOUTH);
  66.        
  67.         // The default action when closing the view is to quit
  68.         // the program.
  69.         viewer.setCloseFramePolicy(Viewer.CloseFramePolicy.HIDE_ONLY);
  70.        
  71.         // We connect back the viewer to the graph,
  72.         // the graph becomes a sink for the viewer.
  73.         // We also install us as a viewer listener to
  74.         // intercept the graphic events.
  75.         ViewerPipe fromViewer = new BlockingViewerPipe(viewer);
  76.         fromViewer.addViewerListener(this);
  77.         fromViewer.addSink(graph);
  78.  
  79.         this.setVisible(true);
  80.        
  81.        
  82.         // Then we need a loop to wait for events.
  83.         // In this loop we will need to call the
  84.         // pump() method to copy back events that have
  85.         // already occurred in the viewer thread inside
  86.         // our thread.
  87.        
  88.        
  89.        
  90.         while(loop) {
  91.             fromViewer.pump();
  92.             System.out.println("Pumping....."+Math.random());
  93.         }
  94.        
  95.     }
  96.  
  97.     public void viewClosed(String id) {
  98.         loop = false;
  99.     }
  100.  
  101.     public void buttonPushed(String id) {
  102.         label.setText(id);
  103.         Node n = graph.addNode("Node: "+(int)(Math.random()*100));
  104.         graph.addEdge(n.getId(), n, graph.getNode(0));
  105.     }
  106.  
  107.     public void buttonReleased(String id) {
  108.         System.out.println("Button released on node "+id);
  109.     }
  110. }
Add Comment
Please, Sign In to add comment