fork(9) download
  1. package org.jgrapht.demo;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Dimension;
  5. import java.awt.Rectangle;
  6.  
  7. import java.util.HashMap;
  8. import java.util.Map;
  9.  
  10. import javax.swing.JApplet;
  11. import javax.swing.JFrame;
  12.  
  13. import org.jgraph.JGraph;
  14. import org.jgraph.graph.DefaultGraphCell;
  15. import org.jgraph.graph.GraphConstants;
  16.  
  17. import org.jgrapht.ListenableGraph;
  18. import org.jgrapht.ext.JGraphModelAdapter;
  19. import org.jgrapht.graph.ListenableDirectedGraph;
  20. import org.jgrapht.graph.DefaultEdge;
  21.  
  22. /**
  23.  * A demo applet that shows how to use JGraph to visualize JGraphT graphs.
  24.  *
  25.  * @author Barak Naveh
  26.  *
  27.  * @since Aug 3, 2003
  28.  */
  29. public class JGraphAdapterDemo extends JApplet {
  30. private static final Color DEFAULT_BG_COLOR = Color.decode( "#FAFBFF" );
  31. private static final Dimension DEFAULT_SIZE = new Dimension( 530, 320 );
  32.  
  33. //
  34. private JGraphModelAdapter m_jgAdapter;
  35.  
  36. /**
  37.   * @see java.applet.Applet#init().
  38.   */
  39. public void init( ) {
  40. // create a JGraphT graph
  41. ListenableGraph g = new ListenableDirectedGraph( DefaultEdge.class );
  42.  
  43. // create a visualization using JGraph, via an adapter
  44. m_jgAdapter = new JGraphModelAdapter( g );
  45.  
  46. JGraph jgraph = new JGraph( m_jgAdapter );
  47.  
  48. adjustDisplaySettings( jgraph );
  49. getContentPane( ).add( jgraph );
  50. resize( DEFAULT_SIZE );
  51.  
  52. // add some sample data (graph manipulated via JGraphT)
  53. g.addVertex( "v1" );
  54. g.addVertex( "v2" );
  55. g.addVertex( "v3" );
  56. g.addVertex( "v4" );
  57.  
  58. g.addEdge( "v1", "v2" );
  59. g.addEdge( "v2", "v3" );
  60. g.addEdge( "v3", "v1" );
  61. g.addEdge( "v4", "v3" );
  62.  
  63. // position vertices nicely within JGraph component
  64. positionVertexAt( "v1", 130, 40 );
  65. positionVertexAt( "v2", 60, 200 );
  66. positionVertexAt( "v3", 310, 230 );
  67. positionVertexAt( "v4", 380, 70 );
  68.  
  69. // that's all there is to it!...
  70. }
  71.  
  72.  
  73. private void adjustDisplaySettings( JGraph jg ) {
  74. jg.setPreferredSize( DEFAULT_SIZE );
  75.  
  76. Color c = DEFAULT_BG_COLOR;
  77. String colorStr = null;
  78.  
  79. try {
  80. colorStr = getParameter( "bgcolor" );
  81. }
  82. catch( Exception e ) {}
  83.  
  84. if( colorStr != null ) {
  85. c = Color.decode( colorStr );
  86. }
  87.  
  88. jg.setBackground( c );
  89. }
  90.  
  91.  
  92. private void positionVertexAt( Object vertex, int x, int y ) {
  93. DefaultGraphCell cell = m_jgAdapter.getVertexCell( vertex );
  94. Map attr = cell.getAttributes( );
  95. Rectangle b = GraphConstants.getBounds( attr );
  96.  
  97. GraphConstants.setBounds( attr, new Rectangle( x, y, b.width, b.height ) );
  98.  
  99. Map cellAttr = new HashMap( );
  100. cellAttr.put( cell, attr );
  101. m_jgAdapter.edit( cellAttr, null, null, null, null );
  102. }
  103. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:29: error: class JGraphAdapterDemo is public, should be declared in a file named JGraphAdapterDemo.java
public class JGraphAdapterDemo extends JApplet {
       ^
Main.java:13: error: package org.jgraph does not exist
import org.jgraph.JGraph;
                 ^
Main.java:14: error: package org.jgraph.graph does not exist
import org.jgraph.graph.DefaultGraphCell;
                       ^
Main.java:15: error: package org.jgraph.graph does not exist
import org.jgraph.graph.GraphConstants;
                       ^
Main.java:17: error: cannot find symbol
import org.jgrapht.ListenableGraph;
                  ^
  symbol:   class ListenableGraph
  location: package org.jgrapht
Main.java:18: error: package org.jgrapht.ext does not exist
import org.jgrapht.ext.JGraphModelAdapter;
                      ^
Main.java:19: error: package org.jgrapht.graph does not exist
import org.jgrapht.graph.ListenableDirectedGraph;
                        ^
Main.java:20: error: package org.jgrapht.graph does not exist
import org.jgrapht.graph.DefaultEdge;
                        ^
Main.java:34: error: cannot find symbol
    private JGraphModelAdapter m_jgAdapter;
            ^
  symbol:   class JGraphModelAdapter
  location: class JGraphAdapterDemo
Main.java:73: error: cannot find symbol
    private void adjustDisplaySettings( JGraph jg ) {
                                        ^
  symbol:   class JGraph
  location: class JGraphAdapterDemo
Main.java:41: error: cannot find symbol
        ListenableGraph g = new ListenableDirectedGraph( DefaultEdge.class );
        ^
  symbol:   class ListenableGraph
  location: class JGraphAdapterDemo
Main.java:41: error: cannot find symbol
        ListenableGraph g = new ListenableDirectedGraph( DefaultEdge.class );
                                ^
  symbol:   class ListenableDirectedGraph
  location: class JGraphAdapterDemo
Main.java:41: error: cannot find symbol
        ListenableGraph g = new ListenableDirectedGraph( DefaultEdge.class );
                                                         ^
  symbol:   class DefaultEdge
  location: class JGraphAdapterDemo
Main.java:44: error: cannot find symbol
        m_jgAdapter = new JGraphModelAdapter( g );
                          ^
  symbol:   class JGraphModelAdapter
  location: class JGraphAdapterDemo
Main.java:46: error: cannot find symbol
        JGraph jgraph = new JGraph( m_jgAdapter );
        ^
  symbol:   class JGraph
  location: class JGraphAdapterDemo
Main.java:46: error: cannot find symbol
        JGraph jgraph = new JGraph( m_jgAdapter );
                            ^
  symbol:   class JGraph
  location: class JGraphAdapterDemo
Main.java:93: error: cannot find symbol
        DefaultGraphCell cell = m_jgAdapter.getVertexCell( vertex );
        ^
  symbol:   class DefaultGraphCell
  location: class JGraphAdapterDemo
Main.java:95: error: cannot find symbol
        Rectangle        b    = GraphConstants.getBounds( attr );
                                ^
  symbol:   variable GraphConstants
  location: class JGraphAdapterDemo
Main.java:97: error: cannot find symbol
        GraphConstants.setBounds( attr, new Rectangle( x, y, b.width, b.height ) );
        ^
  symbol:   variable GraphConstants
  location: class JGraphAdapterDemo
19 errors
stdout
Standard output is empty