001: /* ====================================================================
002: * The QueryForm License, Version 1.1
003: *
004: * Copyright (c) 1998 - 2003 David F. Glasser. All rights
005: * reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions
009: * are met:
010: *
011: * 1. Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: *
014: * 2. Redistributions in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * 3. The end-user documentation included with the redistribution,
020: * if any, must include the following acknowledgment:
021: * "This product includes software developed by
022: * David F. Glasser."
023: * Alternately, this acknowledgment may appear in the software itself,
024: * if and wherever such third-party acknowledgments normally appear.
025: *
026: * 4. The names "QueryForm" and "David F. Glasser" must
027: * not be used to endorse or promote products derived from this
028: * software without prior written permission. For written
029: * permission, please contact dglasser@pobox.com.
030: *
031: * 5. Products derived from this software may not be called "QueryForm",
032: * nor may "QueryForm" appear in their name, without prior written
033: * permission of David F. Glasser.
034: *
035: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
036: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
037: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
038: * DISCLAIMED. IN NO EVENT SHALL DAVID F. GLASSER, THE APACHE SOFTWARE
039: * FOUNDATION OR ITS CONTRIBUTORS, OR ANY AUTHORS OR DISTRIBUTORS
040: * OF THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: * ====================================================================
049: *
050: * This product includes software developed by the
051: * Apache Software Foundation (http://www.apache.org/).
052: *
053: * ====================================================================
054: *
055: * $Source: /cvsroot/qform/qform/src/org/glasser/swing/XInternalFrame.java,v $
056: * $Revision: 1.2 $
057: * $Author: dglasser $
058: * $Date: 2003/05/29 00:43:45 $
059: *
060: * --------------------------------------------------------------------
061: */
062: package org.glasser.swing;
063:
064: import javax.swing.*;
065: import javax.swing.event.*;
066: import java.awt.event.*;
067: import java.awt.*;
068:
069: public class XInternalFrame extends JInternalFrame implements
070: ActionListener {
071:
072: private final JMenuItem menuItem = new JMenuItem();
073:
074: private ImageIcon selectedIcon = null;
075:
076: private ImageIcon deselectedIcon = null;
077:
078: public static boolean debug = System
079: .getProperty("XInternalFrame.debug") != null
080: || System.getProperty("DEBUG") != null;
081:
082: private class Listener implements InternalFrameListener {
083: /**
084: * Invoked when an internal frame is activated.
085: * @see javax.swing.JInternalFrame#setSelected
086: */
087: public void internalFrameActivated(InternalFrameEvent e) {
088:
089: menuItem.setIcon(selectedIcon);
090: }
091:
092: /**
093: * Invoked when a internal frame has been opened.
094: * @see javax.swing.JInternalFrame#show
095: */
096: public void internalFrameOpened(InternalFrameEvent e) {
097: }
098:
099: /**
100: * Invoked when an internal frame is in the process of being closed.
101: * The close operation can be overridden at this point.
102: * @see javax.swing.JInternalFrame#setDefaultCloseOperation
103: */
104: public void internalFrameClosing(InternalFrameEvent e) {
105: if (debug)
106: System.out.println("TRC: " + getClass().getName()
107: + ".internalFrameClosing()");
108: }
109:
110: /**
111: * Invoked when an internal frame is de-activated.
112: * @see javax.swing.JInternalFrame#setSelected
113: */
114: public void internalFrameDeactivated(InternalFrameEvent e) {
115:
116: menuItem.setIcon(deselectedIcon);
117:
118: }
119:
120: /**
121: * Invoked when an internal frame has been closed.
122: * @see javax.swing.JInternalFrame#setClosed
123: */
124: public void internalFrameClosed(InternalFrameEvent e) {
125: if (debug)
126: System.out.println("TRC: " + getClass().getName()
127: + ".internalFrameClosed()");
128: Container c = menuItem.getParent();
129: if (c != null)
130: c.remove(menuItem);
131: menuItem.removeActionListener(XInternalFrame.this );
132: }
133:
134: /**
135: * Invoked when an internal frame is iconified.
136: * @see javax.swing.JInternalFrame#setIcon
137: */
138: public void internalFrameIconified(InternalFrameEvent e) {
139: }
140:
141: /**
142: * Invoked when an internal frame is de-iconified.
143: * @see javax.swing.JInternalFrame#setIcon
144: */
145: public void internalFrameDeiconified(InternalFrameEvent e) {
146: }
147:
148: }
149:
150: {
151: menuItem.addActionListener(this );
152: selectedIcon = GUIHelper
153: .getImageIconFromClasspath("org/glasser/swing/images/Play16.gif");
154: deselectedIcon = GUIHelper
155: .getImageIconFromClasspath("org/glasser/swing/images/Clear16.gif");
156: addInternalFrameListener(new Listener());
157:
158: }
159:
160: public XInternalFrame() {
161: super ();
162: }
163:
164: public XInternalFrame(String title, boolean resizable) {
165: super (title, resizable);
166: menuItem.setText(title);
167: }
168:
169: public XInternalFrame(String title, boolean resizable,
170: boolean closable) {
171: super (title, resizable, closable);
172: menuItem.setText(title);
173: }
174:
175: public XInternalFrame(String title, boolean resizable,
176: boolean closable, boolean maximizable) {
177: super (title, resizable, closable, maximizable);
178: menuItem.setText(title);
179: }
180:
181: public XInternalFrame(String title, boolean resizable,
182: boolean closable, boolean maximizable, boolean iconifiable) {
183: super (title, resizable, closable, maximizable, iconifiable);
184: menuItem.setText(title);
185: }
186:
187: public void actionPerformed(ActionEvent e) {
188:
189: if (e.getSource() == menuItem) {
190:
191: try {
192: if (this .isIcon()) {
193: this .setIcon(false);
194: }
195:
196: JDesktopPane dp = this .getDesktopPane();
197:
198: if (dp != null) {
199: DesktopManager dm = dp.getDesktopManager();
200: if (dm != null)
201: dm.activateFrame(this );
202: setSelected(true);
203: menuItem.setIcon(selectedIcon);
204: }
205: } catch (Exception ex) {
206: ex.printStackTrace();
207: }
208: }
209: }
210:
211: public JMenuItem getMenuItem() {
212: return menuItem;
213: }
214:
215: public JViewport getViewport() {
216: Container parent = super .getParent();
217: while (parent != null) {
218: if (parent instanceof JViewport)
219: return (JViewport) parent;
220: parent = parent.getParent();
221: }
222:
223: return null;
224:
225: }
226:
227: public void finalize() {
228: if (debug) {
229: System.out.println("XInternalFrame.finalize(): "
230: + getTitle());
231: }
232: }
233:
234: }
|