KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > jawe > actions > ShowOverview


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

10
11 package org.enhydra.jawe.actions;
12
13 import org.enhydra.jawe.*;
14 import org.enhydra.jawe.xml.*;
15 import org.enhydra.jawe.xml.elements.*;
16 import org.enhydra.jawe.xml.panels.*;
17
18 import java.awt.event.*;
19 import java.awt.*;
20 import javax.swing.*;
21 import java.util.*;
22
23 /**
24  * Action that shows overview of current graph.
25  */

26 public class ShowOverview extends ActionBase {
27    
28    private JDialog overviewDlg;
29    private JaWEOverviewPanel overviewPanel;
30    
31    
32    public ShowOverview (ProcessEditor pe) {
33       super(pe);
34    }
35    
36    public void actionPerformed(ActionEvent e) {
37       if(overviewDlg == null) {
38          // Create a dialog containing an instance of
39
// LibraryPanel.
40
String JavaDoc title;
41          try {
42             title = ResourceManager.getLanguageDependentString("OverviewKey");
43          } catch (MissingResourceException mre) {
44             title="Overview";
45          }
46          Window w=editor.getWindow();
47          if (w instanceof JFrame) {
48             overviewDlg = new JDialog((JFrame)w,title,false);
49          }
50          else {
51             overviewDlg = new JDialog((JDialog)w,title,false);
52          }
53          Container fContentPane = overviewDlg.getContentPane();
54          
55          fContentPane.setLayout(new BorderLayout());
56          overviewPanel = new JaWEOverviewPanel(editor.getGraph());
57          fContentPane.add(overviewPanel);
58          overviewDlg.setSize(new Dimension(180,180));
59          overviewDlg.setLocationRelativeTo(w);
60          
61          //Harald Meister: adjust the overview if window is resized
62
overviewDlg.addComponentListener(new ComponentListener(){
63                   public void componentShown(ComponentEvent evt){}
64                   public void componentHidden(ComponentEvent evt){}
65                   public void componentMoved(ComponentEvent evt){}
66                   public void componentResized(ComponentEvent evt){
67                      overviewPanel.componentResized(null);
68                   }
69                });
70          overviewPanel.getGraph().addMouseListener(new OverviewMouseListener());
71          //Harald Meister
72

73       }
74       overviewDlg.show();
75       overviewPanel.componentResized(null);
76    }
77    
78    //Harald Meister: scrolls to the point in the original graph when clicked in the overview
79
//TODO: does not correctly scroll if the original graph is zoomed...
80
class OverviewMouseListener extends MouseAdapter{
81       public void mouseClicked(MouseEvent evt){
82          AbstractGraph origGraph = editor.getGraph();
83          Rectangle origVis = origGraph.getVisibleRect();
84          Dimension ovDdim = overviewPanel.getGraph().getPreferredSize();
85          double mul = origGraph.getWidth()/ovDdim.getWidth();
86          int x = evt.getX();
87          int y = evt.getY();
88          double halfH = origVis.getHeight()/2;
89          double halfW = origVis.getWidth()/2;
90          double oldMiddleX = origVis.getX() + halfW;
91          double oldMiddleY = origVis.getY() + halfH;
92          double newMiddleX = x*mul;
93          double newMiddleY = y*mul;
94          origVis.translate((int)(newMiddleX-oldMiddleX),(int)(newMiddleY-oldMiddleY));
95          origGraph.scrollRectToVisible(origVis);
96       }
97    }
98    //Harald Meister
99

100 }
101
Popular Tags