KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > webdocwf > util > loader > wizard > SampleDesktopMgr


1
2 package org.webdocwf.util.loader.wizard;
3
4 import javax.swing.*;
5 import java.awt.*;
6
7 public class SampleDesktopMgr extends DefaultDesktopManager {
8
9   // This is called anytime a frame is moved. This
10
// implementation keeps the frame from leaving the desktop.
11
public void dragFrame(JComponent f, int x, int y) {
12     if (f instanceof JInternalFrame) { // Deal only w/internal frames
13
JInternalFrame frame = (JInternalFrame)f;
14       JDesktopPane desk = frame.getDesktopPane();
15       Dimension d = desk.getSize();
16
17       // Nothing all that fancy below, just figuring out how to adjust
18
// to keep the frame on the desktop.
19
if (x < 0) { // too far left?
20
x = 0; // flush against the left side
21
}
22       else {
23         if (x + frame.getWidth() > d.width) { // too far right?
24
x = d.width - frame.getWidth(); // flush against right side
25
}
26       }
27       if (y < 0) { // too high?
28
y=0; // flush against the top
29
}
30       else {
31         if (y + frame.getHeight() > d.height) { // too low?
32
y = d.height - frame.getHeight(); // flush against the bottom
33
}
34       }
35     }
36
37     // Pass along the (possibly cropped) values to the normal drag handler.
38
super.dragFrame(f, x, y);
39   }
40 }
41
Popular Tags