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