001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.jellytools.actions;
043:
044: import org.netbeans.core.windows.WindowManagerImpl;
045: import org.netbeans.jellytools.Bundle;
046: import org.netbeans.jellytools.TopComponentOperator;
047: import org.netbeans.jellytools.nodes.Node;
048: import org.netbeans.jemmy.QueueTool;
049: import org.netbeans.jemmy.operators.ComponentOperator;
050:
051: /** Used to call "Restore Window" popup menu item, "Window|Restore Window" main menu item,
052: * shortcut or restore window by IDE API.
053: * @see Action
054: * @see org.netbeans.jellytools.TopComponentOperator
055: * @author Jiri.Skrivanek@sun.com
056: */
057: public class RestoreWindowAction extends Action {
058:
059: /** "Window" main menu item. */
060: private static final String windowItem = Bundle.getStringTrimmed(
061: "org.netbeans.core.Bundle", "Menu/Window");
062:
063: /** "Window|Restore Window" */
064: private static final String windowRestorePath = windowItem
065: + "|"
066: + Bundle.getStringTrimmed(
067: "org.netbeans.core.windows.actions.Bundle",
068: "CTL_UnmaximizeWindowAction");
069:
070: /** "Restore Window" */
071: private static final String popupPath = Bundle.getStringTrimmed(
072: "org.netbeans.core.windows.actions.Bundle",
073: "CTL_UnmaximizeWindowAction");
074:
075: /** Creates new instance of RestoreWindowAction. */
076: public RestoreWindowAction() {
077: // action MaximizeWindowAction is no called but it is used to get shortcut
078: super (windowRestorePath, popupPath,
079: "org.netbeans.core.windows.actions.MaximizeWindowAction");
080: }
081:
082: /** Performs popup action Restore Window on given component operator
083: * which is activated before the action. It only accepts TopComponentOperator
084: * as parameter.
085: * @param compOperator operator which should be activated and restored
086: */
087: public void performPopup(ComponentOperator compOperator) {
088: if (compOperator instanceof TopComponentOperator) {
089: performPopup((TopComponentOperator) compOperator);
090: } else {
091: throw new UnsupportedOperationException(
092: "RestoreWindowAction can only be called on TopComponentOperator.");
093: }
094: }
095:
096: /** Performs popup action Restore Window on given top component operator
097: * which is activated before the action.
098: * @param tco top component operator which should be activated and maximized
099: */
100: public void performPopup(TopComponentOperator tco) {
101: tco.pushMenuOnTab(popupPath);
102: }
103:
104: /** Restore active top component by IDE API.*/
105: public void performAPI() {
106: // run in dispatch thread
107: new QueueTool().invokeSmoothly(new Runnable() {
108: public void run() {
109: WindowManagerImpl.getInstance().switchMaximizedMode(
110: null);
111: }
112: });
113: }
114:
115: /** Throws UnsupportedOperationException because RestoreWindowAction doesn't have
116: * representation on nodes.
117: * @param nodes array of nodes
118: */
119: public void performAPI(Node[] nodes) {
120: throw new UnsupportedOperationException(
121: "RestoreWindowAction doesn't have popup representation on nodes.");
122: }
123:
124: /** Throws UnsupportedOperationException because RestoreWindowAction doesn't have
125: * representation on nodes.
126: * @param nodes array of nodes
127: */
128: public void performMenu(Node[] nodes) {
129: throw new UnsupportedOperationException(
130: "RestoreWindowAction doesn't have popup representation on nodes.");
131: }
132:
133: /** Throws UnsupportedOperationException because RestoreWindowAction doesn't have
134: * popup representation on nodes.
135: * @param nodes array of nodes
136: */
137: public void performPopup(Node[] nodes) {
138: throw new UnsupportedOperationException(
139: "RestoreWindowAction doesn't have popup representation on nodes.");
140: }
141:
142: /** Throws UnsupportedOperationException because RestoreWindowAction doesn't have
143: * representation on nodes.
144: * @param nodes array of nodes
145: */
146: public void performShortcut(Node[] nodes) {
147: throw new UnsupportedOperationException(
148: "RestoreWindowAction doesn't have popup representation on nodes.");
149: }
150: }
|