01: package net.sourceforge.squirrel_sql.fw.gui;
02:
03: /*
04: * Copyright (C) 2001-2003 Colin Bell
05: * colbell@users.sourceforge.net
06: *
07: * This library is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation; either
10: * version 2.1 of the License, or (at your option) any later version.
11: *
12: * This library is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this library; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20: */
21: import java.awt.*;
22: import java.beans.PropertyVetoException;
23:
24: import javax.swing.JInternalFrame;
25:
26: /**
27: * This class will position an internal frame slightly below and to the
28: * right of the internal frame that it previously positioned.
29: */
30: public class CascadeInternalFramePositioner implements
31: IInternalFramePositioner {
32: private int _x = INITIAL_POS;
33: private int _y = INITIAL_POS;
34:
35: private static final int MOVE = 20;
36: private static final int INITIAL_POS = 5;
37:
38: public CascadeInternalFramePositioner() {
39: super ();
40: }
41:
42: public void positionInternalFrame(JInternalFrame child) {
43: if (child == null) {
44: throw new IllegalArgumentException(
45: "null JInternalFrame passed");
46: }
47:
48: boolean toInitialPos = false;
49:
50: if (!child.isClosed()) {
51: if (child.getParent() != null) {
52: Dimension childSize = child.getSize();
53:
54: if (0 == childSize.width || 0 == childSize.height) {
55: toInitialPos = true;
56: } else {
57: Rectangle parentBounds = child.getParent()
58: .getBounds();
59: if (_x + MOVE + childSize.width >= parentBounds.width) {
60: _x = INITIAL_POS;
61: }
62: if (_y + MOVE + childSize.height >= parentBounds.height) {
63: _y = INITIAL_POS;
64: }
65: }
66: }
67: if (child.isIcon()) {
68: try {
69: child.setIcon(false);
70: } catch (PropertyVetoException ignore) {
71: // Ignore.
72: }
73: } else if (child.isMaximum()) {
74: try {
75: child.setMaximum(false);
76: } catch (PropertyVetoException ignore) {
77: // Ignore.
78: }
79: }
80:
81: if (toInitialPos) {
82: child.setBounds(INITIAL_POS, INITIAL_POS, child
83: .getWidth(), child.getHeight());
84: } else {
85: child.setBounds(_x, _y, child.getWidth(), child
86: .getHeight());
87: _x += MOVE;
88: _y += MOVE;
89: }
90: }
91: }
92: }
|