javax.swing.AbstractButton#setDisplayedMnemonicIndex ( )源码实例Demo

下面列出了javax.swing.AbstractButton#setDisplayedMnemonicIndex ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: azure-devops-intellij   文件: ProxySettingsForm.java
/**
 * @noinspection ALL
 */
private void $$$loadButtonText$$$(AbstractButton component, String text) {
    StringBuffer result = new StringBuffer();
    boolean haveMnemonic = false;
    char mnemonic = '\0';
    int mnemonicIndex = -1;
    for (int i = 0; i < text.length(); i++) {
        if (text.charAt(i) == '&') {
            i++;
            if (i == text.length()) break;
            if (!haveMnemonic && text.charAt(i) != '&') {
                haveMnemonic = true;
                mnemonic = text.charAt(i);
                mnemonicIndex = result.length();
            }
        }
        result.append(text.charAt(i));
    }
    component.setText(result.toString());
    if (haveMnemonic) {
        component.setMnemonic(mnemonic);
        component.setDisplayedMnemonicIndex(mnemonicIndex);
    }
}
 
源代码2 项目: azure-devops-intellij   文件: ApplyLabelForm.java
/**
 * @noinspection ALL
 */
private void $$$loadButtonText$$$(AbstractButton component, String text) {
    StringBuffer result = new StringBuffer();
    boolean haveMnemonic = false;
    char mnemonic = '\0';
    int mnemonicIndex = -1;
    for (int i = 0; i < text.length(); i++) {
        if (text.charAt(i) == '&') {
            i++;
            if (i == text.length()) break;
            if (!haveMnemonic && text.charAt(i) != '&') {
                haveMnemonic = true;
                mnemonic = text.charAt(i);
                mnemonicIndex = result.length();
            }
        }
        result.append(text.charAt(i));
    }
    component.setText(result.toString());
    if (haveMnemonic) {
        component.setMnemonic(mnemonic);
        component.setDisplayedMnemonicIndex(mnemonicIndex);
    }
}
 
源代码3 项目: azure-devops-intellij   文件: LockItemsForm.java
/**
 * @noinspection ALL
 */
private void $$$loadButtonText$$$(AbstractButton component, String text) {
    StringBuffer result = new StringBuffer();
    boolean haveMnemonic = false;
    char mnemonic = '\0';
    int mnemonicIndex = -1;
    for (int i = 0; i < text.length(); i++) {
        if (text.charAt(i) == '&') {
            i++;
            if (i == text.length()) break;
            if (!haveMnemonic && text.charAt(i) != '&') {
                haveMnemonic = true;
                mnemonic = text.charAt(i);
                mnemonicIndex = result.length();
            }
        }
        result.append(text.charAt(i));
    }
    component.setText(result.toString());
    if (haveMnemonic) {
        component.setMnemonic(mnemonic);
        component.setDisplayedMnemonicIndex(mnemonicIndex);
    }
}
 
/**
 * @noinspection ALL
 */
private void $$$loadButtonText$$$(AbstractButton component, String text) {
    StringBuffer result = new StringBuffer();
    boolean haveMnemonic = false;
    char mnemonic = '\0';
    int mnemonicIndex = -1;
    for (int i = 0; i < text.length(); i++) {
        if (text.charAt(i) == '&') {
            i++;
            if (i == text.length()) break;
            if (!haveMnemonic && text.charAt(i) != '&') {
                haveMnemonic = true;
                mnemonic = text.charAt(i);
                mnemonicIndex = result.length();
            }
        }
        result.append(text.charAt(i));
    }
    component.setText(result.toString());
    if (haveMnemonic) {
        component.setMnemonic(mnemonic);
        component.setDisplayedMnemonicIndex(mnemonicIndex);
    }
}
 
/**
 * @noinspection ALL
 */
private void $$$loadButtonText$$$(AbstractButton component, String text) {
    StringBuffer result = new StringBuffer();
    boolean haveMnemonic = false;
    char mnemonic = '\0';
    int mnemonicIndex = -1;
    for (int i = 0; i < text.length(); i++) {
        if (text.charAt(i) == '&') {
            i++;
            if (i == text.length()) break;
            if (!haveMnemonic && text.charAt(i) != '&') {
                haveMnemonic = true;
                mnemonic = text.charAt(i);
                mnemonicIndex = result.length();
            }
        }
        result.append(text.charAt(i));
    }
    component.setText(result.toString());
    if (haveMnemonic) {
        component.setMnemonic(mnemonic);
        component.setDisplayedMnemonicIndex(mnemonicIndex);
    }
}
 
源代码6 项目: azure-devops-intellij   文件: CreateBranchForm.java
/**
 * @noinspection ALL
 */
private void $$$loadButtonText$$$(AbstractButton component, String text) {
    StringBuffer result = new StringBuffer();
    boolean haveMnemonic = false;
    char mnemonic = '\0';
    int mnemonicIndex = -1;
    for (int i = 0; i < text.length(); i++) {
        if (text.charAt(i) == '&') {
            i++;
            if (i == text.length()) break;
            if (!haveMnemonic && text.charAt(i) != '&') {
                haveMnemonic = true;
                mnemonic = text.charAt(i);
                mnemonicIndex = result.length();
            }
        }
        result.append(text.charAt(i));
    }
    component.setText(result.toString());
    if (haveMnemonic) {
        component.setMnemonic(mnemonic);
        component.setDisplayedMnemonicIndex(mnemonicIndex);
    }
}
 
源代码7 项目: azure-devops-intellij   文件: CreateBranchForm.java
/**
 * @noinspection ALL
 */
private void $$$loadButtonText$$$(AbstractButton component, String text) {
    StringBuffer result = new StringBuffer();
    boolean haveMnemonic = false;
    char mnemonic = '\0';
    int mnemonicIndex = -1;
    for (int i = 0; i < text.length(); i++) {
        if (text.charAt(i) == '&') {
            i++;
            if (i == text.length()) break;
            if (!haveMnemonic && text.charAt(i) != '&') {
                haveMnemonic = true;
                mnemonic = text.charAt(i);
                mnemonicIndex = result.length();
            }
        }
        result.append(text.charAt(i));
    }
    component.setText(result.toString());
    if (haveMnemonic) {
        component.setMnemonic(mnemonic);
        component.setDisplayedMnemonicIndex(mnemonicIndex);
    }
}
 
/**
 * @noinspection ALL
 */
private void $$$loadButtonText$$$(AbstractButton component, String text) {
    StringBuffer result = new StringBuffer();
    boolean haveMnemonic = false;
    char mnemonic = '\0';
    int mnemonicIndex = -1;
    for (int i = 0; i < text.length(); i++) {
        if (text.charAt(i) == '&') {
            i++;
            if (i == text.length()) break;
            if (!haveMnemonic && text.charAt(i) != '&') {
                haveMnemonic = true;
                mnemonic = text.charAt(i);
                mnemonicIndex = result.length();
            }
        }
        result.append(text.charAt(i));
    }
    component.setText(result.toString());
    if (haveMnemonic) {
        component.setMnemonic(mnemonic);
        component.setDisplayedMnemonicIndex(mnemonicIndex);
    }
}
 
源代码9 项目: wpcleaner   文件: Utilities.java
/**
 * Apply a shortcut to a button.
 * 
 * @param button Button.
 * @param shortcut Shortcut.
 * @param message Related message.
 */
private static void setShortcut(
    AbstractButton button,
    ShortcutProperties shortcut,
    String message) {
  if ((shortcut == null) || (shortcut.useMnemonic())) {
    int mnemonic = getMnemonic(message);
    if ((mnemonic == -1) && (shortcut != null)) {
      mnemonic = shortcut.getKey();
    }
    if (mnemonic != -1) {
      button.setMnemonic(mnemonic);
    }
  } else if (shortcut.getEnabled()) {
    String actionName = "action_" + shortcut.getName();
    InputMap inputMap = button.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMap.put(KeyStroke.getKeyStroke(shortcut.getKey(), shortcut.getModifiers()), actionName);
    button.getActionMap().put(actionName, new ActionClick(button));
    if (message != null) {
      int index = message.indexOf(shortcut.getKey());
      if ((index >= 0) && (index < button.getText().length())) {
        button.setDisplayedMnemonicIndex(index);
      }
    }
  }
}
 
源代码10 项目: FancyBing   文件: GuiUtil.java
/** Parse text that has the mnemonic marked with a preceding'&amp;'
    (like in Qt) and set the text and mnemonic of the button. */
public static void setTextAndMnemonic(AbstractButton button, String text)
{
    int pos = text.indexOf('&');
    text = text.replace("&", "");
    button.setText(text);
    if (pos >= 0 && pos < text.length())
    {
        String mnemonic = text.substring(pos, pos + 1).toUpperCase();
        KeyStroke keyStroke = KeyStroke.getKeyStroke(mnemonic);
        int code = keyStroke.getKeyCode();
        button.setMnemonic(code);
        button.setDisplayedMnemonicIndex(pos);
    }
}
 
源代码11 项目: netbeans   文件: Mnemonics.java
/**
 * Wrapper for the
 * <code>AbstractButton.setMnemonicIndex</code> or
 * <code>JLabel.setDisplayedMnemonicIndex</code> method.
 * @param item AbstractButton/JLabel or subclasses
 * @param index Index of the Character to underline under JDK1.4
 * @param latinCode Latin Character Keycode to underline under JDK1.3
 */
private static void setMnemonicIndex(Object item, int index) {
    if (item instanceof AbstractButton) {
        AbstractButton b = (AbstractButton) item;
        b.putClientProperty(PROP_DISPLAYED_MNEMONIC_INDEX, index);
        b.removePropertyChangeListener(PROP_DISPLAYED_MNEMONIC_INDEX, MNEMONIC_INDEX_LISTENER);
        b.setDisplayedMnemonicIndex(index);
        b.addPropertyChangeListener(PROP_DISPLAYED_MNEMONIC_INDEX, MNEMONIC_INDEX_LISTENER);
    } else if (item instanceof JLabel) {
        ((JLabel) item).setDisplayedMnemonicIndex(index);
    }
}
 
源代码12 项目: netbeans   文件: Mnemonics.java
public void propertyChange(PropertyChangeEvent evt) {
    AbstractButton b = (AbstractButton) evt.getSource();
    if (b.getDisplayedMnemonicIndex() == -1) {
        Integer mnemonic = (Integer) b.getClientProperty(PROP_MNEMONIC);
        Integer index = (Integer) b.getClientProperty(PROP_DISPLAYED_MNEMONIC_INDEX);
        if (mnemonic != null && index != null && Utilities.compareObjects(b.getText(), b.getClientProperty(PROP_TEXT))) {
            b.setMnemonic(mnemonic);
            b.setDisplayedMnemonicIndex(index);
        }
    }
}
 
源代码13 项目: visualvm   文件: Utils.java
/**
 * Actual setter of the text & mnemonics for the AbstractButton or
 * their subclasses. We must copy necessary code from org.openide.awt.Mnemonics
 * because org.openide.awt module is not available yet when this code is called.
 * @param item AbstractButton
 * @param text new label
 */
static void setLocalizedText (AbstractButton button, String text) {
    if (text == null) {
        button.setText(null);
        return;
    }

    int i = findMnemonicAmpersand(text);

    if (i < 0) {
        // no '&' - don't set the mnemonic
        button.setText(text);
        button.setMnemonic(0);
    } else {
        button.setText(text.substring(0, i) + text.substring(i + 1));

        if (Utilities.isMac()) {
            // there shall be no mnemonics on macosx.
            //#55864
            return;
        }

        char ch = text.charAt(i + 1);

        // it's latin character or arabic digit,
        // setting it as mnemonics
        button.setMnemonic(ch);

        // If it's something like "Save &As", we need to set another
        // mnemonic index (at least under 1.4 or later)
        // see #29676
        button.setDisplayedMnemonicIndex(i);
    }
}
 
源代码14 项目: keystore-explorer   文件: PlatformUtil.java
/**
 * Set mnemonic on button in a platform dependant manner.
 *
 * @param button
 *            Button
 * @param mnemonic
 *            Mnemonic
 * @param index
 *            Index of string to underline
 */
public static void setMnemonic(AbstractButton button, char mnemonic, int index) {
	/*
	 * Only set mnemonic if not using macOS - they are not recommended by
	 * the style guidelines there and clash with established commands
	 */
	if (!OperatingSystem.isMacOs()) {
		button.setMnemonic(mnemonic);

		if (index >= 0) {
			button.setDisplayedMnemonicIndex(index);
		}
	}
}
 
private void $$$loadButtonText$$$( AbstractButton component, String text )
{
    StringBuffer result = new StringBuffer();
    boolean haveMnemonic = false;
    char mnemonic = '\0';
    int mnemonicIndex = -1;
    for( int i = 0; i < text.length(); i++ )
    {
        if( text.charAt( i ) == '&' )
        {
            i++;
            if( i == text.length() )
            {
                break;
            }
            if( !haveMnemonic && text.charAt( i ) != '&' )
            {
                haveMnemonic = true;
                mnemonic = text.charAt( i );
                mnemonicIndex = result.length();
            }
        }
        result.append( text.charAt( i ) );
    }
    component.setText( result.toString() );
    if( haveMnemonic )
    {
        component.setMnemonic( mnemonic );
        component.setDisplayedMnemonicIndex( mnemonicIndex );
    }
}
 
源代码16 项目: spotbugs   文件: AnnotatedString.java
/**
 * Localise the given AbstractButton, setting the text and optionally
 * mnemonic Note that AbstractButton includes menus and menu items.
 *
 * @param button
 *            The button to localise
 * @param key
 *            The key to look up in resource bundle
 * @param defaultString
 *            default String to use if key not found
 * @param setMnemonic
 *            whether or not to set the mnemonic. According to Sun's
 *            guidelines, default/cancel buttons should not have mnemonics
 *            but instead should use Return/Escape
 */
public static void localiseButton(AbstractButton button, String key, String defaultString, boolean setMnemonic) {
    AnnotatedString as = new AnnotatedString(L10N.getLocalString(key, defaultString));
    button.setText(as.toString());
    int mnemonic;
    if (setMnemonic && (mnemonic = as.getMnemonic()) != KeyEvent.VK_UNDEFINED) {
        button.setMnemonic(mnemonic);
        button.setDisplayedMnemonicIndex(as.getMnemonicIndex());
    }
}