001: package net.sourceforge.squirrel_sql.fw.gui.action;
002:
003: /*
004: * Copyright (C) 2001-2003 Colin Bell
005: * colbell@users.sourceforge.net
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021: import java.awt.Dimension;
022: import java.awt.event.ActionEvent;
023:
024: import javax.swing.JDesktopPane;
025: import javax.swing.JInternalFrame;
026:
027: import net.sourceforge.squirrel_sql.fw.gui.CascadeInternalFramePositioner;
028: import net.sourceforge.squirrel_sql.fw.gui.GUIUtils;
029: import net.sourceforge.squirrel_sql.fw.util.StringManager;
030: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
031:
032: /**
033: * This class will cascade all internal frames owned by a
034: * <CODE>JDesktopPane</CODE>.
035: *
036: * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
037: */
038: public class CascadeInternalFramesAction extends BaseAction implements
039: IHasJDesktopPane {
040: /** Internationalized strings for this class. */
041: private static final StringManager s_stringMgr = StringManagerFactory
042: .getStringManager(CascadeInternalFramesAction.class);
043:
044: /**
045: * The <CODE>JDesktopPane</CODE> that owns the internal frames to be
046: * cascaded.
047: */
048: private JDesktopPane _desktop;
049:
050: /**
051: * Default constructor.
052: */
053: public CascadeInternalFramesAction() {
054: this (null);
055: }
056:
057: /**
058: * Constructor specifying the <CODE>JDesktopPane</CODE> that owns the
059: * internal frames to be cascaded.
060: *
061: * @param desktop the <CODE>JDesktopPane</CODE> that owns the
062: * internal frames to be cascaded.
063: */
064: public CascadeInternalFramesAction(JDesktopPane desktop) {
065: super (s_stringMgr
066: .getString("CascadeInternalFramesAction.title"));
067: setJDesktopPane(desktop);
068: }
069:
070: /**
071: * Set the <CODE>JDesktopPane</CODE> that owns the internal frames to be
072: * tiled.
073: *
074: * @param desktop the <CODE>JDesktopPane</CODE> that owns the
075: * internal frames to be tiled.
076: */
077: public void setJDesktopPane(JDesktopPane value) {
078: _desktop = value;
079: }
080:
081: /**
082: * Cascade the internal frames.
083: *
084: * @param evt Specifies the event being proceessed.
085: */
086: public void actionPerformed(ActionEvent evt) {
087: if (_desktop != null) {
088: Dimension cs = null; // Size to set child windows to.
089: CascadeInternalFramePositioner pos = new CascadeInternalFramePositioner();
090: JInternalFrame[] children = GUIUtils
091: .getOpenNonToolWindows(_desktop.getAllFrames());
092: for (int i = children.length - 1; i >= 0; --i) {
093: JInternalFrame child = children[i];
094: if (cs == null && child.getParent() != null) {
095: cs = child.getParent().getSize();
096: // Cast to int required as Dimension::setSize(double,double)
097: // doesn't appear to do anything in JDK1.2.2.
098: cs.setSize((int) (cs.width * 0.8d),
099: (int) (cs.height * 0.8d));
100: }
101: if (cs != null) {
102: child.setSize(cs);
103: pos.positionInternalFrame(child);
104: }
105: }
106: }
107: }
108: }
|