001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2003-2006, Geotools Project Managment Committee (PMC)
005: * (C) 2002, Institut de Recherche pour le Développement
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: package org.geotools.resources;
018:
019: // Events
020: import java.awt.Frame;
021: import java.awt.event.WindowListener;
022:
023: import javax.swing.JInternalFrame;
024: import javax.swing.event.InternalFrameEvent;
025: import javax.swing.event.InternalFrameListener;
026:
027: /**
028: * Wrap a {@link WindowListener} into an {@link InternalFrameListener}. This is used
029: * by {@link SwingUtilities} in order to have the same methods working seemless on both
030: * {@link Frame} and {@link JInternalFrame}.
031: *
032: * @since 2.0
033: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/metadata/src/main/java/org/geotools/resources/InternalWindowListener.java $
034: * @version $Id: InternalWindowListener.java 22443 2006-10-27 20:47:22Z desruisseaux $
035: * @author Martin Desruisseaux
036: */
037: final class InternalWindowListener implements InternalFrameListener {
038: /**
039: * The underlying {@link WindowListener}.
040: */
041: private final WindowListener listener;
042:
043: /**
044: * Wrap the specified {@link WindowListener} into an {@link InternalFrameListener}.
045: * If the specified object is already an {@link InternalFrameListener}, then it is
046: * returned as-is.
047: */
048: public static InternalFrameListener wrap(
049: final WindowListener listener) {
050: if (listener == null) {
051: return null;
052: }
053: if (listener instanceof InternalFrameListener) {
054: return (InternalFrameListener) listener;
055: }
056: return new InternalWindowListener(listener);
057: }
058:
059: /**
060: * Construct a new {@link InternalFrameListener}
061: * wrapping the specified {@link WindowListener}.
062: */
063: private InternalWindowListener(final WindowListener listener) {
064: this .listener = listener;
065: }
066:
067: /**
068: * Invoked when a internal frame has been opened.
069: */
070: public void internalFrameOpened(InternalFrameEvent event) {
071: listener.windowOpened(null);
072: }
073:
074: /**
075: * Invoked when an internal frame is in the process of being closed.
076: * The close operation can be overridden at this point.
077: */
078: public void internalFrameClosing(InternalFrameEvent event) {
079: listener.windowClosing(null);
080: }
081:
082: /**
083: * Invoked when an internal frame has been closed.
084: */
085: public void internalFrameClosed(InternalFrameEvent event) {
086: listener.windowClosed(null);
087: }
088:
089: /**
090: * Invoked when an internal frame is iconified.
091: */
092: public void internalFrameIconified(InternalFrameEvent event) {
093: listener.windowIconified(null);
094: }
095:
096: /**
097: * Invoked when an internal frame is de-iconified.
098: */
099: public void internalFrameDeiconified(InternalFrameEvent event) {
100: listener.windowDeiconified(null);
101: }
102:
103: /**
104: * Invoked when an internal frame is activated.
105: */
106: public void internalFrameActivated(InternalFrameEvent event) {
107: listener.windowActivated(null);
108: }
109:
110: /**
111: * Invoked when an internal frame is de-activated.
112: */
113: public void internalFrameDeactivated(InternalFrameEvent event) {
114: listener.windowDeactivated(null);
115: }
116: }
|