KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > awt > MnemonicsTest


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 org.openide.awt;
21
22 import java.awt.event.KeyEvent JavaDoc;
23 import javax.swing.JButton JavaDoc;
24 import org.netbeans.junit.NbTestCase;
25 import org.openide.util.Utilities;
26
27 /** Test use of mnemonics.
28  * @author Jesse Glick
29  */

30 public class MnemonicsTest extends NbTestCase {
31
32     public MnemonicsTest(String JavaDoc name) {
33         super(name);
34     }
35
36     // XXX testSetLocalizedText, testFindMnemonicAmpersand
37

38     /** @see #31093 */
39     public void testMnemonicAfterParens() throws Exception JavaDoc {
40         JButton JavaDoc b = new JButton JavaDoc();
41         Mnemonics.setLocalizedText(b, "Execute (&Force Reload)");
42         assertEquals("Execute (Force Reload)", b.getText());
43         if (Utilities.getOperatingSystem() == Utilities.OS_MAC) {
44             assertEquals(0, b.getMnemonic());
45             assertEquals(-1, b.getDisplayedMnemonicIndex());
46         } else {
47             assertEquals(KeyEvent.VK_F, b.getMnemonic());
48             assertEquals(9, b.getDisplayedMnemonicIndex());
49         }
50         assertEquals("Execute (Force Reload)", Actions.cutAmpersand("Execute (&Force Reload)"));
51         // XXX test that actual Japanese mnemonics work as expected...
52
}
53     
54     public void testMnemonicHTML() throws Exception JavaDoc {
55         JButton JavaDoc b = new JButton JavaDoc();
56         Mnemonics.setLocalizedText(b, "<html><b>R&amp;D</b> department");
57         assertEquals("<html><b>R&amp;D</b> department", b.getText());
58         assertEquals(0, b.getMnemonic());
59         assertEquals(-1, b.getDisplayedMnemonicIndex());
60         Mnemonics.setLocalizedText(b, "<html><b>R&amp;D</b> departmen&t");
61         assertEquals("<html><b>R&amp;D</b> departmen<u>t</u>", b.getText());
62         if (Utilities.getOperatingSystem() == Utilities.OS_MAC) {
63             assertEquals(0, b.getMnemonic());
64             assertEquals(-1, b.getDisplayedMnemonicIndex());
65         } else {
66             assertEquals(KeyEvent.VK_T, b.getMnemonic());
67         }
68         
69         Mnemonics.setLocalizedText(b, "<html>Smith &amp; &Wesson");
70         assertEquals("<html>Smith &amp; <u>W</u>esson", b.getText());
71         if (Utilities.getOperatingSystem() == Utilities.OS_MAC) {
72             assertEquals(0, b.getMnemonic());
73             assertEquals(-1, b.getDisplayedMnemonicIndex());
74         } else {
75             assertEquals(KeyEvent.VK_W, b.getMnemonic());
76         }
77         Mnemonics.setLocalizedText(b, "<html>&Advanced Mode <em>(experimental)</em></html>");
78         assertEquals("<html><u>A</u>dvanced Mode <em>(experimental)</em></html>", b.getText());
79         if (Utilities.getOperatingSystem() == Utilities.OS_MAC) {
80             assertEquals(0, b.getMnemonic());
81             assertEquals(-1, b.getDisplayedMnemonicIndex());
82         } else {
83             assertEquals(KeyEvent.VK_A, b.getMnemonic());
84             assertEquals('A', b.getText().charAt(b.getDisplayedMnemonicIndex()));
85         }
86     }
87     
88 }
89
Popular Tags