1 10 11 package org.enhydra.jawe; 12 13 import org.jgraph.JGraph; 14 import org.jgraph.graph.*; 15 import org.jgraph.event.*; 16 import java.awt.event.ComponentListener ; 17 import java.awt.event.ComponentEvent ; 18 import java.util.Observer ; 19 import java.util.Observable ; 20 import javax.swing.JPanel ; 21 import javax.swing.BorderFactory ; 22 import java.awt.*; 23 24 public class JaWEOverviewPanel extends JPanel implements ComponentListener , 25 GraphModelListener, Observer { 26 protected ProcessGraph graph; 27 28 public JaWEOverviewPanel(JGraph g) { 29 GraphLayoutCache view = new ViewRedirector(g, g.getGraphLayoutCache()); 30 graph = new ProcessGraph(g.getModel(), view); 31 graph.setAntiAliased(true); 32 setBorder(BorderFactory.createEtchedBorder()); 33 graph.getModel().addGraphModelListener(this); 34 graph.setEnabled(false); 35 g.addComponentListener(this); 36 g.getGraphLayoutCache().addObserver(this); 37 setLayout(new BorderLayout()); 38 add(graph, BorderLayout.CENTER); 39 } 40 41 public JGraph getGraph () { 42 return graph; 43 } 44 45 49 public void update(Observable o, Object arg) { 50 componentResized(null); 51 } 52 53 57 public void graphChanged(GraphModelEvent e) { 58 componentResized(null); 59 } 60 61 65 public void componentResized(ComponentEvent e) { 66 Rectangle r = null; 67 if(AbstractCellView.getBounds(graph.getGraphLayoutCache().getRoots())!=null) { 68 r = AbstractCellView.getBounds(graph.getGraphLayoutCache().getRoots()).getBounds(); 69 } 70 double scale = 0.5; 71 if (r != null) { 72 Dimension d = new Dimension(r.x+r.width, r.y+r.height); 73 Dimension s = getSize(); 74 double sx = s.getWidth()*0.95/d.getWidth(); 75 double sy = s.getHeight()*0.95/d.getHeight(); 76 scale = Math.min(Math.max(Math.min(sx, sy), 0.05), 0.5); 77 } 78 graph.setScale(scale); 79 repaint(); 80 } 81 82 public void componentShown(ComponentEvent e) { 83 componentResized(e); 84 } 85 86 public void componentHidden(ComponentEvent e) { } 87 88 public void componentMoved(ComponentEvent e) { } 89 90 94 public class ViewRedirector extends GraphLayoutCache { 95 96 protected GraphLayoutCache realView; 97 98 public ViewRedirector(JGraph graph, GraphLayoutCache realView) { 99 super(graph); this.realView = realView; 101 setModel(graph.getModel()); 102 } 103 104 public CellView[] getRoots() { 105 return realView.getRoots(); 106 } 107 108 public CellView getMapping(Object cell, boolean create) { 109 if (realView != null) 110 return realView.getMapping(cell, create); 111 return null; 112 } 113 114 public void putMapping(Object cell, CellView view) { 115 if (realView != null) 116 realView.putMapping(cell, view); 117 } 118 119 } 120 121 } 122 123 124 | Popular Tags |