KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > util > datatransfer > ExTransferableTest


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 package org.openide.util.datatransfer;
20
21 import java.awt.AWTEvent JavaDoc;
22 import java.awt.Component JavaDoc;
23 import java.awt.Dialog JavaDoc;
24 import java.awt.Graphics JavaDoc;
25 import java.awt.Toolkit JavaDoc;
26 import java.awt.datatransfer.DataFlavor JavaDoc;
27 import java.awt.event.AWTEventListener JavaDoc;
28 import java.awt.event.ActionEvent JavaDoc;
29 import java.awt.event.ActionListener JavaDoc;
30 import java.util.ArrayList JavaDoc;
31 import java.util.Arrays JavaDoc;
32 import java.util.EventListener JavaDoc;
33 import java.util.HashSet JavaDoc;
34 import java.util.List JavaDoc;
35 import javax.swing.JPanel JavaDoc;
36 import javax.swing.SwingUtilities JavaDoc;
37 import javax.swing.Timer JavaDoc;
38 import junit.textui.TestRunner;
39 import org.openide.util.Utilities;
40 import org.netbeans.junit.NbTestCase;
41 import org.netbeans.junit.NbTestSuite;
42 import org.openide.util.AsyncGUIJob;
43
44 /**
45  *
46  * @author Jaroslav Tulach
47  */

48 public class ExTransferableTest extends NbTestCase {
49     /** Creates a new instance of UtilProgressCursorTest */
50     public ExTransferableTest (String JavaDoc testName) {
51         super(testName);
52     }
53
54     public static void main(java.lang.String JavaDoc[] args) {
55         TestRunner.run(new NbTestSuite(ExTransferableTest.class));
56     }
57
58     public void testExTranferableKeepsOrderOfInsertedDataFlavors () throws Exception JavaDoc {
59         HashSet JavaDoc set = new HashSet JavaDoc ();
60         set.add (DataFlavor.stringFlavor);
61         set.add (DataFlavor.imageFlavor);
62         
63         DataFlavor JavaDoc[] arr = (DataFlavor JavaDoc[])set.toArray (new DataFlavor JavaDoc[2]);
64         
65         ExTransferable t = ExTransferable.create (ExTransferable.EMPTY);
66         // now insert the DataFlavor but in oposite order than is
67
// according to their hashCodes
68
t.put (new Sin (arr[1]));
69         t.put (new Sin (arr[0]));
70         
71         
72         List JavaDoc res = Arrays.asList (t.getTransferDataFlavors ());
73
74         assertEquals ("First inserted is first", 0, res.indexOf (arr[1]));
75         assertEquals ("Second inserted is second", 1, res.indexOf (arr[0]));
76     }
77
78     private static final class Sin extends ExTransferable.Single {
79         public Sin (DataFlavor JavaDoc f) {
80             super (f);
81         }
82         
83         protected Object JavaDoc getData () {
84             return null;
85         }
86     } // end of Sin
87
}
88
Popular Tags