1 19 20 package org.openide.awt; 21 22 import java.awt.event.KeyEvent ; 23 import javax.swing.JButton ; 24 import org.netbeans.junit.NbTestCase; 25 import org.openide.util.Utilities; 26 27 30 public class MnemonicsTest extends NbTestCase { 31 32 public MnemonicsTest(String name) { 33 super(name); 34 } 35 36 38 39 public void testMnemonicAfterParens() throws Exception { 40 JButton b = new JButton (); 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 } 53 54 public void testMnemonicHTML() throws Exception { 55 JButton b = new JButton (); 56 Mnemonics.setLocalizedText(b, "<html><b>R&D</b> department"); 57 assertEquals("<html><b>R&D</b> department", b.getText()); 58 assertEquals(0, b.getMnemonic()); 59 assertEquals(-1, b.getDisplayedMnemonicIndex()); 60 Mnemonics.setLocalizedText(b, "<html><b>R&D</b> departmen&t"); 61 assertEquals("<html><b>R&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 & &Wesson"); 70 assertEquals("<html>Smith & <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 |