diff options
| author | Paul Buetow <paul@buetow.org> | 2008-05-15 23:08:33 +0000 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2008-05-15 23:08:33 +0000 |
| commit | d4c1ddcc90c1e2e8660598fc36b3772d2bff6816 (patch) | |
| tree | 28a0afc255e42f92adbca0d102e785301bc43a58 /sources/utils/VSFrame.java | |
| parent | 61599471a5978c1521b9c89c044ac2ce9a88c398 (diff) | |
1 Moved the stuff to trunk!
Diffstat (limited to 'sources/utils/VSFrame.java')
| -rw-r--r-- | sources/utils/VSFrame.java | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/sources/utils/VSFrame.java b/sources/utils/VSFrame.java new file mode 100644 index 0000000..2725729 --- /dev/null +++ b/sources/utils/VSFrame.java @@ -0,0 +1,58 @@ +package utils; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.JFrame; + +public class VSFrame extends JFrame { + private final static int X_LOCATION_OFFSET = 40; + private final static int Y_LOCATION_OFFSET = 80; + private Component parent; + private boolean dispose; + + public VSFrame(String title, Component parent) { + super(title); + initialize(parent); + } + + public VSFrame(String title) { + super(title); + initialize(null); + } + + private void initialize(Component parent) { + this.parent = parent; + this.dispose = false; + + setLocation(); + } + + public void disposeWithParent() { + if (!dispose && parent != null && parent instanceof Window) { + Window window = (Window) parent; + window.addWindowListener(new WindowAdapter() { + public void windowClosed(WindowEvent we) { + VSFrame.this.dispose(); + } + }); + } + dispose = true; + } + + private void setLocation() { + int x = 0, y = 0; + + if (parent == null) { + final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + x = (int) (screenSize.width - getWidth()) / 2; + y = (int) (screenSize.height - getHeight()) / 2; + + } else { + final Point location = parent.getLocation(); + x = (int) location.getX() + X_LOCATION_OFFSET; + y = (int) location.getY() + Y_LOCATION_OFFSET; + } + + setLocation(x, y); + } +} |
