public void testMnemonic() throws Exception { JPanel panel = (JPanel) getInstrumentedRootComponent("TestMnemonics.form", "BindingTest"); JLabel label = (JLabel) panel.getComponent(0); assertEquals("Mnemonic", label.getText()); assertEquals('M', label.getDisplayedMnemonic()); assertEquals(3, label.getDisplayedMnemonicIndex()); }
protected void paintEnabledText(JLabel l, Graphics g, String s, int textX, int textY) { int mnemIndex = -1; if (JTattooUtilities.getJavaVersion() >= 1.4) { mnemIndex = l.getDisplayedMnemonicIndex(); } else { mnemIndex = JTattooUtilities.findDisplayedMnemonicIndex(l.getText(), l.getDisplayedMnemonic()); } g.setColor(l.getForeground()); JTattooUtilities.drawStringUnderlineCharAt(l, g, s, mnemIndex, textX, textY); }
protected void paintDisabledText(JLabel l, Graphics g, String s, int textX, int textY) { int mnemIndex = -1; if (JTattooUtilities.getJavaVersion() >= 1.4) { mnemIndex = l.getDisplayedMnemonicIndex(); } else { mnemIndex = JTattooUtilities.findDisplayedMnemonicIndex(l.getText(), l.getDisplayedMnemonic()); } g.setColor(Color.white); JTattooUtilities.drawStringUnderlineCharAt(l, g, s, mnemIndex, textX + 1, textY + 1); g.setColor(AbstractLookAndFeel.getDisabledForegroundColor()); JTattooUtilities.drawStringUnderlineCharAt(l, g, s, mnemIndex, textX, textY); }
private static boolean hasMnemonic(final Container container, final int keyCode) { if (container == null) return false; final Component[] components = container.getComponents(); for (Component component : components) { if (component instanceof AbstractButton) { final AbstractButton button = (AbstractButton) component; if (button instanceof JBOptionButton) { if (((JBOptionButton) button).isOkToProcessDefaultMnemonics()) return true; } else { if (button.getMnemonic() == keyCode) return true; } } if (component instanceof JLabel) { final JLabel label = (JLabel) component; if (label.getDisplayedMnemonic() == keyCode) return true; } if (component instanceof Container) { if (hasMnemonic((Container) component, keyCode)) return true; } } return false; }
protected void paintDisabledText(JLabel l, Graphics g, String s, int textX, int textY) { int accChar = l.getDisplayedMnemonic(); g.setColor(l.getBackground()); drawString(g, s, accChar, textX, textY); }
private static Object[] create() { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); frame.setVisible(true); // show color chooser JColorChooser chooser = new JColorChooser(); JDialog dialog = JColorChooser.createDialog(frame, null, false, chooser, null, null); dialog.setVisible(true); // process all values List<Object> list = new ArrayList<Object>(KEYS.length); Component component = getC(getC(dialog.getLayeredPane(), 0), 1); AbstractButton ok = (AbstractButton) getC(component, 0); AbstractButton cancel = (AbstractButton) getC(component, 1); AbstractButton reset = (AbstractButton) getC(component, 2); list.add(ok.getText()); list.add(cancel.getText()); list.add(reset.getText()); list.add(Integer.valueOf(reset.getMnemonic())); for (int i = 0; i < 5; i++) { AbstractColorChooserPanel panel = (AbstractColorChooserPanel) getC(getC(getC(chooser, 0), i), 0); list.add(panel.getDisplayName()); list.add(Integer.valueOf(panel.getMnemonic())); if (i == 0) { JLabel label = (JLabel) getC(getC(panel, 0), 1); JPanel upper = (JPanel) getC(getC(getC(panel, 0), 0), 0); JPanel lower = (JPanel) getC(getC(getC(panel, 0), 2), 0); addSize(list, upper, 1, 1, 31, 9); list.add(label.getText()); addSize(list, lower, 1, 1, 5, 7); } else { Component container = getC(panel, 0); for (int j = 0; j < 3; j++) { AbstractButton button = (AbstractButton) getC(container, j); list.add(button.getText()); } JLabel label = (JLabel) getC(container, 3); list.add(label.getText()); if (i == 4) { label = (JLabel) getC(container, 4); list.add(label.getText()); } if (i == 3) { label = (JLabel) getC(panel, 1); list.add(label.getText()); list.add(Integer.valueOf(label.getDisplayedMnemonic())); } } } // close dialog dialog.setVisible(false); dialog.dispose(); // close frame frame.setVisible(false); frame.dispose(); return list.toArray(); }