1 25 40 package org.jgrapht.experimental.touchgraph; 41 42 import com.touchgraph.graphlayout.*; 43 import com.touchgraph.graphlayout.interaction.*; 44 45 import java.awt.*; 46 47 import java.util.*; 48 49 import org.jgrapht.*; 50 51 52 58 public class TouchgraphPanel<V, E> 59 extends GLPanel 60 { 61 62 64 66 private static final long serialVersionUID = -7441058429719746032L; 67 68 70 private Color defaultBackColor = new Color(0x01, 0x11, 0x44); 71 private Color defaultBorderBackColor = new Color(0x02, 0x35, 0x81); 72 private Color defaultForeColor = 73 new Color((float) 0.95, (float) 0.85, (float) 0.55); 74 75 78 Graph<V, E> graph; 79 80 84 boolean selfReferencesAllowed = true; 85 86 88 90 91 public TouchgraphPanel(Graph<V, E> graph, boolean selfReferencesAllowed) 92 { 93 this.graph = graph; 94 this.selfReferencesAllowed = selfReferencesAllowed; 95 96 102 preinitialize(); 103 104 initialize(); } 106 107 109 115 public void preinitialize() 116 { 117 this.setBackground(defaultBorderBackColor); 118 this.setForeground(defaultForeColor); 119 scrollBarHash = new Hashtable(); 120 tgLensSet = new TGLensSet(); 121 tgPanel = new TGPanel(); 122 tgPanel.setBackColor(defaultBackColor); 123 hvScroll = new HVScroll(tgPanel, tgLensSet); 124 zoomScroll = new ZoomScroll(tgPanel); 125 hyperScroll = new HyperScroll(tgPanel); 126 rotateScroll = new RotateScroll(tgPanel); 127 localityScroll = new LocalityScroll(tgPanel); 128 } 129 130 133 public void initialize() 134 { 135 buildPanel(); 136 buildLens(); 137 tgPanel.setLensSet(tgLensSet); 138 addUIs(); 139 try { 140 if (this.graph == null) { 141 144 randomGraph(); 145 } else { 146 149 TouchgraphConverter<V, E> converter = 150 new TouchgraphConverter<V, E>(); 151 Node n = 152 (Node) converter.convertToTouchGraph( 153 this.graph, 154 tgPanel, 155 this.selfReferencesAllowed); 156 getHVScroll().slowScrollToCenter(n); 157 tgPanel.setLocale(n, Integer.MAX_VALUE); 158 } 159 } catch (TGException tge) { 160 System.err.println(tge.getMessage()); 161 tge.printStackTrace(System.err); 162 } 163 setVisible(true); 164 } 165 } 166 167 | Popular Tags |