001: /*
002: * Copyright (C) 2004 NNL Technology AB
003: * Visit www.infonode.net for information about InfoNode(R)
004: * products and how to contact NNL Technology AB.
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
019: * MA 02111-1307, USA.
020: */
021:
022: // $Id: RestoreParentWithAbortWindowAction.java,v 1.3 2005/12/04 13:46:04 jesper Exp $
023: package net.infonode.docking.action;
024:
025: import net.infonode.docking.DockingWindow;
026: import net.infonode.docking.OperationAbortedException;
027: import net.infonode.docking.TabWindow;
028: import net.infonode.docking.internalutil.InternalDockingUtil;
029: import net.infonode.docking.util.DockingUtil;
030: import net.infonode.gui.icon.button.RestoreIcon;
031:
032: import javax.swing.*;
033: import java.io.ObjectStreamException;
034:
035: /**
036: * Restores a window using the {@link DockingWindow#restore()} method. If the parent window is a {@link TabWindow}
037: * which is maximized, it is restored. The action calls {@link net.infonode.docking.DockingWindow#restoreWithAbort()}.
038: *
039: * @author $Author: jesper $
040: * @version $Revision: 1.3 $
041: * @since IDW 1.4.0
042: */
043: public final class RestoreParentWithAbortWindowAction extends
044: DockingWindowAction {
045: private static final long serialVersionUID = 1;
046:
047: /**
048: * The only instance of this class.
049: */
050: public static final RestoreParentWithAbortWindowAction INSTANCE = new RestoreParentWithAbortWindowAction();
051:
052: private static final Icon icon = new RestoreIcon(
053: InternalDockingUtil.DEFAULT_BUTTON_ICON_SIZE);
054:
055: private RestoreParentWithAbortWindowAction() {
056: }
057:
058: public String getName() {
059: return "Restore";
060: }
061:
062: public boolean isPerformable(DockingWindow window) {
063: if (window.isMinimized() && window.isRestorable())
064: return true;
065: else {
066: TabWindow tabWindow = DockingUtil.getTabWindowFor(window);
067: return tabWindow != null && tabWindow.isMaximized()
068: && tabWindow.isRestorable();
069: }
070: }
071:
072: public void perform(DockingWindow window) {
073: if (window != null && window.isMinimized())
074: restore(window);
075: else {
076: TabWindow tabWindow = DockingUtil.getTabWindowFor(window);
077:
078: if (tabWindow != null && tabWindow.isMaximized())
079: restore(tabWindow);
080: }
081: }
082:
083: public Icon getIcon() {
084: return icon;
085: }
086:
087: private static void restore(DockingWindow window) {
088: try {
089: if (window != null && window.isRestorable())
090: window.restoreWithAbort();
091: } catch (OperationAbortedException e) {
092: // Ignore
093: }
094: }
095:
096: protected Object readResolve() throws ObjectStreamException {
097: return INSTANCE;
098: }
099:
100: }
|