KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gui > propertyeditors > utilities > CoreSupport


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package gui.propertyeditors.utilities;
21
22 import java.io.PrintStream JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.awt.Component JavaDoc;
25 import javax.swing.JDialog JavaDoc;
26 import org.netbeans.jellytools.JellyTestCase;
27
28 import org.netbeans.jemmy.ComponentSearcher;
29 import org.netbeans.jemmy.JemmyException;
30 import org.netbeans.jemmy.operators.JDialogOperator;
31
32 import org.netbeans.junit.NbTestCase;
33
34 // ide imports
35
import org.openide.filesystems.FileObject;
36 import org.openide.filesystems.FileStateInvalidException;
37 import org.openide.filesystems.Repository;
38
39 /** Utilities for core tests. From this class extends supports for each testsuite.
40  *
41  * @author Marian.Mirilovic@Sun.Com
42  * @version
43  */

44
45 public class CoreSupport {
46     
47     /** Creates new utilities */
48     public CoreSupport() {
49     }
50     
51     /**
52      * Find path to the Sample Project.
53      *
54      * @return path to the Sample Project
55      * @param testCase
56      */

57     public static String JavaDoc getSampleProjectPath(JellyTestCase testCase) {
58         return new java.io.File JavaDoc(testCase.getDataDir(),"SampleProject").getPath();
59     }
60     
61     
62     /**
63      * Find file system name.
64      *
65      * @param exc
66      * @param err
67      */

68 /* public static String getFS(String _package, String fileName, String fileExtension){
69         FileObject f = findFileObject(_package, fileName, fileExtension);
70         
71         if(f==null)
72             throw new JemmyException("Unable find file " + fileName + "." + fileExtension + " in package " + _package);
73         
74         String fs;
75         try{
76             fs = f.getFileSystem().getSystemName();
77         }catch(FileStateInvalidException exc){
78             throw new JemmyException("FileStateInvalidException during attempt get filesystem name for " + fileName + "." + fileExtension + " in package " + _package);
79         }
80         
81         // hack for Win NT/2K , where in FileObject is bad file separator !!!
82         char fileSeparator = System.getProperty("file.separator").charAt(0);
83         String fsName = fs.replace('/',fileSeparator).replace('\\',fileSeparator);
84         //String path = fsName+ ", " + _package + ", " + fileName;
85         
86         return fsName;
87     }
88     
89     
90     public static String getPath(String packageName, String fileName, String fileExtension, String delim){
91         String FS_Name = getFS(packageName, fileName, fileExtension);
92         return FS_Name + delim + packageName.replace('.',delim.charAt(0)) + delim + fileName;
93     }
94     
95     public static String getSystemPath(String packageName, String fileName, String fileExtension){
96         String fileSeparator = System.getProperty("file.separator");
97         return getPath(packageName, fileName, fileExtension, fileSeparator)+ "." + fileExtension;
98     }
99 */

100     public static void writeExc(Exception JavaDoc exc, PrintStream JavaDoc err) {
101         err.println("Test ERROR: ");
102         exc.printStackTrace(err);
103     }
104     
105     /**
106      *
107      * @param testCase
108      */

109     public static void makeIDEScreenshot(NbTestCase testCase) {
110         try{
111             testCase.getWorkDir();
112             org.netbeans.jemmy.util.PNGEncoder.captureScreen(testCase.getWorkDirPath()+System.getProperty("file.separator")+"IDEscreenshot.png");
113         }catch(Exception JavaDoc ioexc){
114             testCase.log("Impossible make IDE screenshot!!! \n" + ioexc.toString());
115         }
116     }
117     
118     /**
119      *
120      * @param testCase
121      * @param component
122      */

123     public static void makeWindowScreenshot(NbTestCase testCase, Component JavaDoc component) {
124         try{
125             testCase.getWorkDir();
126             if(component != null)
127                 org.netbeans.jemmy.util.PNGEncoder.captureScreen(component,testCase.getWorkDirPath()+System.getProperty("file.separator")+"ComponentScreenshot.png");
128             else
129                 makeIDEScreenshot(testCase);
130         }catch(Exception JavaDoc ioexc){
131             testCase.log("Impossible make component screenshot!!! \n =========" +component.toString() + "\n ======== \n " + ioexc.toString());
132         }
133     }
134     
135     
136     public static void closeAllModal() {
137         JDialogOperator oper = null;
138         // find some JDialog
139
JDialog JavaDoc jDialog = JDialogOperator.findJDialog(ComponentSearcher.getTrueChooser(""));
140         // number of opened non-modal
141
int nonModal = 0;
142         // until any modal dialog is opened
143
while(jDialog!=null) {
144             oper = new JDialogOperator(jDialog);
145             if(oper.isModal()) {
146                 // close if modal
147
oper.close();
148             } else {
149                 // increment nonModal
150
nonModal++;
151             }
152             // use nonModal variable as index to skip opened non-modal dialogs
153
jDialog = JDialogOperator.findJDialog(ComponentSearcher.getTrueChooser(""), nonModal);
154         }
155     }
156
157 }
158
Popular Tags