01: /*
02: * Copyright (C) 2004 NNL Technology AB
03: * Visit www.infonode.net for information about InfoNode(R)
04: * products and how to contact NNL Technology AB.
05: *
06: * This program is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU General Public License
08: * as published by the Free Software Foundation; either version 2
09: * of the License, or (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU General Public License for more details.
15: *
16: * You should have received a copy of the GNU General Public License
17: * along with this program; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
19: * MA 02111-1307, USA.
20: */
21:
22: // $Id: CloseOthersWindowAction.java,v 1.2 2005/05/20 14:48:12 johan Exp $
23: package net.infonode.docking.action;
24:
25: import net.infonode.docking.AbstractTabWindow;
26: import net.infonode.docking.DockingWindow;
27: import net.infonode.docking.OperationAbortedException;
28: import net.infonode.docking.internalutil.InternalDockingUtil;
29: import net.infonode.gui.icon.button.CloseIcon;
30:
31: import javax.swing.*;
32: import java.io.ObjectStreamException;
33:
34: /**
35: * Closes all tabs (with abort possibility) except the one belonging to the window the action is performed upon in
36: * the AbstractTabWindow parent of the window.
37: *
38: * @author $Author: johan $
39: * @version $Revision: 1.2 $
40: * @since IDW 1.4.0
41: */
42: public class CloseOthersWindowAction extends DockingWindowAction {
43: private static final long serialVersionUID = 1;
44:
45: /**
46: * The only instance of this class
47: */
48: public static final CloseOthersWindowAction INSTANCE = new CloseOthersWindowAction();
49:
50: private static final Icon icon = new CloseIcon(
51: InternalDockingUtil.DEFAULT_BUTTON_ICON_SIZE);
52:
53: private CloseOthersWindowAction() {
54: }
55:
56: public Icon getIcon() {
57: return icon;
58: }
59:
60: public String getName() {
61: return "Close Others";
62: }
63:
64: public boolean isPerformable(DockingWindow window) {
65: return window.getWindowParent() instanceof AbstractTabWindow;
66: }
67:
68: public void perform(DockingWindow window) {
69: if (isPerformable(window)) {
70: AbstractTabWindow tw = (AbstractTabWindow) window
71: .getWindowParent();
72:
73: for (int i = 0; i < tw.getChildWindowCount();) {
74: if (tw.getChildWindow(i) != window
75: && tw.getChildWindow(i).isClosable()) {
76: try {
77: tw.getChildWindow(i).closeWithAbort();
78: } catch (OperationAbortedException e) {
79: i++;
80: }
81: } else
82: i++;
83: }
84: }
85: }
86:
87: protected Object readResolve() throws ObjectStreamException {
88: return INSTANCE;
89: }
90:
91: }
|