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): Alexandre Iline.
025: *
026: * The Original Software is the Jemmy library.
027: * The Initial Developer of the Original Software is Alexandre Iline.
028: * 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: *
043: * $Id: DefaultInternalFrameDriver.java,v 1.7 2007/10/05 11:37:31 jskrivanek Exp $ $Revision: 1.7 $ $Date: 2007/10/05 11:37:31 $
044: *
045: */
046:
047: package org.netbeans.jemmy.drivers.windows;
048:
049: import java.awt.Component;
050: import java.awt.Container;
051: import java.awt.Dimension;
052: import java.awt.Toolkit;
053: import java.awt.Window;
054:
055: import java.awt.event.WindowEvent;
056:
057: import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
058:
059: import org.netbeans.jemmy.ComponentChooser;
060: import org.netbeans.jemmy.ComponentSearcher;
061:
062: import org.netbeans.jemmy.operators.ComponentOperator;
063: import org.netbeans.jemmy.operators.JButtonOperator;
064: import org.netbeans.jemmy.operators.JInternalFrameOperator;
065:
066: import org.netbeans.jemmy.drivers.FrameDriver;
067: import org.netbeans.jemmy.drivers.InternalFrameDriver;
068: import org.netbeans.jemmy.drivers.LightSupportiveDriver;
069: import org.netbeans.jemmy.drivers.WindowDriver;
070:
071: import org.netbeans.jemmy.drivers.input.EventDriver;
072:
073: public class DefaultInternalFrameDriver extends LightSupportiveDriver
074: implements WindowDriver, FrameDriver, InternalFrameDriver {
075: public DefaultInternalFrameDriver() {
076: super (
077: new String[] { "org.netbeans.jemmy.operators.JInternalFrameOperator" });
078: }
079:
080: public void activate(ComponentOperator oper) {
081: checkSupported(oper);
082: ((JInternalFrameOperator) oper).moveToFront();
083: ((JInternalFrameOperator) oper).getTitleOperator().clickMouse();
084: }
085:
086: public void close(ComponentOperator oper) {
087: checkSupported(oper);
088: ((JInternalFrameOperator) oper).moveToFront();
089: ((JButtonOperator) ((JInternalFrameOperator) oper)
090: .getCloseButton()).push();
091: }
092:
093: public void move(ComponentOperator oper, int x, int y) {
094: checkSupported(oper);
095: ComponentOperator titleOperator = ((JInternalFrameOperator) oper)
096: .getTitleOperator();
097: titleOperator.dragNDrop(titleOperator.getCenterY(),
098: titleOperator.getCenterY(), x
099: - ((JInternalFrameOperator) oper).getX()
100: + titleOperator.getCenterY(), y
101: - ((JInternalFrameOperator) oper).getY()
102: + titleOperator.getCenterY());
103: }
104:
105: public void resize(ComponentOperator oper, int width, int height) {
106: checkSupported(oper);
107: ((JInternalFrameOperator) oper).dragNDrop(
108: ((JInternalFrameOperator) oper).getWidth() - 1,
109: ((JInternalFrameOperator) oper).getHeight() - 1,
110: width - 1, height - 1);
111: }
112:
113: public void iconify(ComponentOperator oper) {
114: checkSupported(oper);
115: ((JButtonOperator) ((JInternalFrameOperator) oper)
116: .getMinimizeButton()).clickMouse();
117: }
118:
119: public void deiconify(ComponentOperator oper) {
120: checkSupported(oper);
121: ((JInternalFrameOperator) oper).getIconOperator().pushButton();
122: }
123:
124: public void maximize(ComponentOperator oper) {
125: checkSupported(oper);
126: if (!((JInternalFrameOperator) oper).isMaximum()) {
127: if (!((JInternalFrameOperator) oper).isSelected()) {
128: activate(oper);
129: }
130: ((JInternalFrameOperator) oper).getMaximizeButton().push();
131: }
132: }
133:
134: public void demaximize(ComponentOperator oper) {
135: checkSupported(oper);
136: if (((JInternalFrameOperator) oper).isMaximum()) {
137: if (!((JInternalFrameOperator) oper).isSelected()) {
138: activate(oper);
139: }
140: ((JInternalFrameOperator) oper).getMaximizeButton().push();
141: }
142: }
143:
144: public Component getTitlePane(ComponentOperator operator) {
145: ComponentSearcher cs = new ComponentSearcher(
146: (Container) operator.getSource());
147: cs.setOutput(operator.getOutput().createErrorOutput());
148: return (cs.findComponent(new ComponentChooser() {
149: public boolean checkComponent(Component comp) {
150: if (System.getProperty("java.version")
151: .startsWith("1.2")) {
152: return (comp.getClass().getName()
153: .endsWith("InternalFrameTitlePane"));
154: } else {
155: return (comp instanceof BasicInternalFrameTitlePane);
156: }
157: }
158:
159: public String getDescription() {
160: return ("Title pane");
161: }
162: }));
163: }
164: }
|