001    /**
002     * 
003     */
004    package edu.wwu.tobikley.acgc.ui;
005    
006    import java.awt.BorderLayout;
007    import java.awt.Color;
008    import java.awt.Dimension;
009    
010    import javax.swing.JPanel;
011    import javax.swing.JFrame;
012    
013    import edu.uci.ics.jung.graph.ArchetypeVertex;
014    import edu.uci.ics.jung.graph.Graph;
015    import edu.uci.ics.jung.graph.decorators.DefaultToolTipFunction;
016    import edu.uci.ics.jung.graph.decorators.EdgeShape;
017    import edu.uci.ics.jung.graph.decorators.VertexStringer;
018    import edu.uci.ics.jung.visualization.AbstractLayout;
019    //import edu.uci.ics.jung.visualization.DefaultSettableVertexLocationFunction;
020    import edu.uci.ics.jung.visualization.FRLayout;
021    import edu.uci.ics.jung.visualization.GraphZoomScrollPane;
022    import edu.uci.ics.jung.visualization.PluggableRenderer;
023    import edu.uci.ics.jung.visualization.ShapePickSupport;
024    import edu.uci.ics.jung.visualization.VisualizationViewer;
025    
026    /**
027     * GraphViewer for GUI.
028     * 
029     * @version 1.0
030     * @author  Tobias Kley
031     */
032    public class GraphViewer extends JFrame {
033    
034            private static final long serialVersionUID = 1L;
035    
036            private JPanel jContentPane = null;
037        
038            private Graph graph;
039            private AbstractLayout layout;
040            private VisualizationViewer vv;
041            //private DefaultSettableVertexLocationFunction vertexLocations;  //  @jve:decl-index=0:
042    
043        /**
044             * This is the default constructor
045             */
046            public GraphViewer(Graph graph) {
047                    super();
048                    this.graph = graph;
049                    initialize();
050            }
051    
052            /**
053             * This method initializes this
054             * 
055             * @return void
056             */
057            private void initialize() {
058                    this.setSize(300, 200);
059                    this.setContentPane(getJContentPane());
060                    this.setTitle("Graph Viewer");
061                    this.setExtendedState(MAXIMIZED_BOTH);
062            }
063    
064            /**
065             * This method initializes jContentPane
066             * 
067             * @return javax.swing.JPanel
068             */
069            private JPanel getJContentPane() {
070                    if (jContentPane == null) {
071                            jContentPane = new JPanel();
072                            jContentPane.setLayout(new BorderLayout());
073                            
074                    jContentPane.add(getGraphPane());
075                    }
076                    return jContentPane;
077            }
078    
079        public GraphZoomScrollPane getGraphPane() {
080            
081            // allows the precise setting of initial vertex locations
082            //vertexLocations = new DefaultSettableVertexLocationFunction();
083    
084            PluggableRenderer pr = new PluggableRenderer();
085            this.layout = new FRLayout(graph);
086            layout.initialize(new Dimension(600,600));
087            
088            vv =  new VisualizationViewer(layout, pr);
089            vv.setBackground(Color.white);
090            vv.setPickSupport(new ShapePickSupport());
091            pr.setEdgeShapeFunction(new EdgeShape.QuadCurve());
092            pr.setVertexStringer(new VertexStringer() {
093    
094                public String getLabel(ArchetypeVertex v) {
095                    return v.toString();
096                }});
097    
098            vv.setToolTipFunction(new DefaultToolTipFunction());
099            
100            //Container content = getContentPane();
101            final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
102    
103     /*       final EditingModalGraphMouse graphMouse = new EditingModalGraphMouse();
104            
105            // the EditingGraphMouse will pass mouse event coordinates to the
106            // vertexLocations function to set the locations of the vertices as
107            // they are created
108            graphMouse.setVertexLocations(vertexLocations);
109            vv.setGraphMouse(graphMouse);
110            graphMouse.add(new EditingPopupGraphMousePlugin(vertexLocations));
111            graphMouse.setMode(ModalGraphMouse.Mode.EDITING);
112            
113            final ScalingControl scaler = new CrossoverScalingControl();
114            JButton plus = new JButton("+");
115            plus.addActionListener(new ActionListener() {
116                public void actionPerformed(ActionEvent e) {
117                    scaler.scale(vv, 1.1f, vv.getCenter());
118                }
119            });
120            JButton minus = new JButton("-");
121            minus.addActionListener(new ActionListener() {
122                public void actionPerformed(ActionEvent e) {
123                    scaler.scale(vv, 1/1.1f, vv.getCenter());
124                }
125            });
126    
127            JPanel controls = new JPanel();
128            controls.add(plus);
129            controls.add(minus);
130            JComboBox modeBox = graphMouse.getModeComboBox();
131            controls.add(modeBox);
132            content.add(controls, BorderLayout.SOUTH); */
133            
134            return panel;
135        }
136            
137    }