KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > jawe > JaWEOverviewPanel


1 /* PEOverviewPanel.java
2  *
3  * Authors:
4  * Stefanovic Nenad chupo@iis.ns.ac.yu
5  * Bojanic Sasa sasaboy@neobee.net
6  * Puskas Vladimir vpuskas@eunet.yu
7  * Pilipovic Goran zboniek@uns.ac.yu
8  *
9  */

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 JavaDoc;
17 import java.awt.event.ComponentEvent JavaDoc;
18 import java.util.Observer JavaDoc;
19 import java.util.Observable JavaDoc;
20 import javax.swing.JPanel JavaDoc;
21 import javax.swing.BorderFactory JavaDoc;
22 import java.awt.*;
23
24 public class JaWEOverviewPanel extends JPanel JavaDoc implements ComponentListener JavaDoc,
25    GraphModelListener, Observer JavaDoc {
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    //
46
// Observer
47
//
48

49    public void update(Observable JavaDoc o, Object JavaDoc arg) {
50       componentResized(null);
51    }
52
53    //
54
// GraphModelListener
55
//
56

57    public void graphChanged(GraphModelEvent e) {
58       componentResized(null);
59    }
60
61    //
62
// Component Listener
63
//
64

65    public void componentResized(ComponentEvent JavaDoc 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 JavaDoc e) {
83       componentResized(e);
84    }
85
86    public void componentHidden(ComponentEvent JavaDoc e) { }
87
88    public void componentMoved(ComponentEvent JavaDoc e) { }
89
90    //
91
// View Redirector
92
//
93

94    public class ViewRedirector extends GraphLayoutCache {
95
96       protected GraphLayoutCache realView;
97
98       public ViewRedirector(JGraph graph, GraphLayoutCache realView) {
99          super(graph);//HM, JGraph3.4.1
100
this.realView = realView;
101          setModel(graph.getModel());
102       }
103
104       public CellView[] getRoots() {
105          return realView.getRoots();
106       }
107
108       public CellView getMapping(Object JavaDoc cell, boolean create) {
109          if (realView != null)
110             return realView.getMapping(cell, create);
111          return null;
112       }
113
114       public void putMapping(Object JavaDoc cell, CellView view) {
115          if (realView != null)
116             realView.putMapping(cell, view);
117          }
118
119    }
120
121 }
122
123 /* End of PEOverviewPanel.java */
124
Popular Tags