View Javadoc

1   /*
2   * The contents of this file are subject to the BT "ZEUS" Open Source 
3   * Licence (L77741), Version 1.0 (the "Licence"); you may not use this file 
4   * except in compliance with the Licence. You may obtain a copy of the Licence
5   * from $ZEUS_INSTALL/licence.html or alternatively from
6   * http://www.labs.bt.com/projects/agents/zeus/licence.htm
7   * 
8   * Except as stated in Clause 7 of the Licence, software distributed under the
9   * Licence is distributed WITHOUT WARRANTY OF ANY KIND, either express or 
10  * implied. See the Licence for the specific language governing rights and 
11  * limitations under the Licence.
12  * 
13  * The Original Code is within the package zeus.*.
14  * The Initial Developer of the Original Code is British Telecommunications
15  * public limited company, whose registered office is at 81 Newgate Street, 
16  * London, EC1A 7AJ, England. Portions created by British Telecommunications 
17  * public limited company are Copyright 1996-9. All Rights Reserved.
18  * 
19  * THIS NOTICE MUST BE INCLUDED ON ANY COPY OF THIS FILE
20  */
21  
22  
23  
24  package zeus.gui.graph;
25  
26  import java.awt.*;
27  import javax.swing.*;
28  import java.util.*;
29  
30  public class MovePanel extends SelectPanel{
31      protected Cursor lastCursor;
32  
33      public MovePanel() {
34         super();
35      }
36      public MovePanel(Dimension d) {
37         super(d);
38      }
39      public MovePanel(int w, int h) {
40         super(w,h);
41      }
42  
43      public void anchor(Point p) {
44         super.anchor(p);
45  
46         // Moving
47         if ( regionSelected && region.contains(anchor.x,anchor.y) ) {
48            JFrame f = (JFrame)SwingUtilities.getRoot(this);
49            lastCursor = f.getCursor();
50            f.setCursor(new Cursor(Cursor.MOVE_CURSOR));
51         }
52      }
53      public void stretch(Point p) {
54         super.stretch(p);
55  
56         Graphics g = this.getGraphics();
57         if ( g != null && regionSelected ) {
58            g.setXORMode(this.getBackground());
59  
60            drawRegion(g);
61            region.translate(stretched.x-last.x,stretched.y-last.y);
62            drawRegion(g);
63         }
64      }
65      public void end(Point p) {
66         boolean prior = regionSelected; // hack since the super.end() method
67                                         // determines the new state of
68                                         // regionSelected
69         super.end(p);
70  
71         Graphics g = this.getGraphics();
72         if ( g != null && prior ) {
73            g.setXORMode(this.getBackground());
74            drawRegion(g);
75            region.translate(stretched.x-last.x,stretched.y-last.y);
76            moveItems();
77            drawRegion(g);
78  
79            // reset cursor -- end of move
80            JFrame f = (JFrame)SwingUtilities.getRoot(this);
81            f.setCursor(lastCursor);
82         }
83      }
84  
85      protected void moveItems() {
86         for(int i = 0; i < items.size(); i++ ) {
87            Component comp = (Component)items.elementAt(i);
88            Point p = comp.getLocation();
89            comp.setLocation(p.x + end.x-anchor.x, p.y + end.y-anchor.y);
90        }
91     }
92  }