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.openide.awt;
043:
044: import java.awt.event.KeyEvent;
045: import javax.swing.JButton;
046: import org.netbeans.junit.NbTestCase;
047: import org.openide.util.Utilities;
048:
049: /** Test use of mnemonics.
050: * @author Jesse Glick
051: */
052: public class MnemonicsTest extends NbTestCase {
053:
054: public MnemonicsTest(String name) {
055: super (name);
056: }
057:
058: // XXX testSetLocalizedText, testFindMnemonicAmpersand
059:
060: /** @see #31093 */
061: public void testMnemonicAfterParens() throws Exception {
062: JButton b = new JButton();
063: Mnemonics.setLocalizedText(b, "Execute (&Force Reload)");
064: assertEquals("Execute (Force Reload)", b.getText());
065: if (Utilities.getOperatingSystem() == Utilities.OS_MAC) {
066: assertEquals(0, b.getMnemonic());
067: assertEquals(-1, b.getDisplayedMnemonicIndex());
068: } else {
069: assertEquals(KeyEvent.VK_F, b.getMnemonic());
070: assertEquals(9, b.getDisplayedMnemonicIndex());
071: }
072: assertEquals("Execute (Force Reload)", Actions
073: .cutAmpersand("Execute (&Force Reload)"));
074: // XXX test that actual Japanese mnemonics work as expected...
075: }
076:
077: public void testMnemonicHTML() throws Exception {
078: JButton b = new JButton();
079: Mnemonics
080: .setLocalizedText(b, "<html><b>R&D</b> department");
081: assertEquals("<html><b>R&D</b> department", b.getText());
082: assertEquals(0, b.getMnemonic());
083: assertEquals(-1, b.getDisplayedMnemonicIndex());
084: Mnemonics.setLocalizedText(b,
085: "<html><b>R&D</b> departmen&t");
086: assertEquals("<html><b>R&D</b> departmen<u>t</u>", b
087: .getText());
088: if (Utilities.getOperatingSystem() == Utilities.OS_MAC) {
089: assertEquals(0, b.getMnemonic());
090: assertEquals(-1, b.getDisplayedMnemonicIndex());
091: } else {
092: assertEquals(KeyEvent.VK_T, b.getMnemonic());
093: }
094:
095: Mnemonics.setLocalizedText(b, "<html>Smith & &Wesson");
096: assertEquals("<html>Smith & <u>W</u>esson", b.getText());
097: if (Utilities.getOperatingSystem() == Utilities.OS_MAC) {
098: assertEquals(0, b.getMnemonic());
099: assertEquals(-1, b.getDisplayedMnemonicIndex());
100: } else {
101: assertEquals(KeyEvent.VK_W, b.getMnemonic());
102: }
103: Mnemonics.setLocalizedText(b,
104: "<html>&Advanced Mode <em>(experimental)</em></html>");
105: assertEquals(
106: "<html><u>A</u>dvanced Mode <em>(experimental)</em></html>",
107: b.getText());
108: if (Utilities.getOperatingSystem() == Utilities.OS_MAC) {
109: assertEquals(0, b.getMnemonic());
110: assertEquals(-1, b.getDisplayedMnemonicIndex());
111: } else {
112: assertEquals(KeyEvent.VK_A, b.getMnemonic());
113: assertEquals('A', b.getText().charAt(
114: b.getDisplayedMnemonicIndex()));
115: }
116: }
117:
118: }
|