mirror of
https://github.com/igniterealtime/Spark.git
synced 2026-08-18 11:10:02 +00:00
optimize ResourceUtils
This commit is contained in:
@ -27,6 +27,8 @@ import org.jivesoftware.spark.ui.ChatRoomButton;
|
||||
import org.jivesoftware.sparkimpl.plugin.emoticons.Emoticon;
|
||||
import org.jivesoftware.sparkimpl.plugin.emoticons.EmoticonManager;
|
||||
|
||||
import static org.jivesoftware.spark.util.ResourceUtils.stripMnemonic;
|
||||
|
||||
public class ButtonFactory {
|
||||
|
||||
private static final ButtonFactory instance = new ButtonFactory();
|
||||
@ -89,18 +91,13 @@ public class ButtonFactory {
|
||||
|
||||
public RolloverButton createRegisterButton() {
|
||||
RolloverButton register = new RolloverButton(SparkRes.getImageIcon(SparkRes.Icon.PEOPLE_IMAGE));
|
||||
register.setToolTipText(Res.getString("button.register").replace("&", ""));
|
||||
register.setToolTipText(stripMnemonic(Res.getString("button.register")));
|
||||
return register;
|
||||
}
|
||||
|
||||
public RolloverButton createAlwaysOnTop(boolean isAlwaysOnTopActive) {
|
||||
RolloverButton alwaysOnTopItem = new RolloverButton();
|
||||
if (isAlwaysOnTopActive) {
|
||||
alwaysOnTopItem.setIcon(SparkRes.getImageIcon(SparkRes.Icon.FRAME_ALWAYS_ON_TOP_ACTIVE));
|
||||
} else {
|
||||
alwaysOnTopItem.setIcon(SparkRes.getImageIcon(SparkRes.Icon.FRAME_ALWAYS_ON_TOP_DEACTIVE));
|
||||
}
|
||||
|
||||
alwaysOnTopItem.setIcon(SparkRes.getImageIcon(isAlwaysOnTopActive ? SparkRes.Icon.FRAME_ALWAYS_ON_TOP_ACTIVE : SparkRes.Icon.FRAME_ALWAYS_ON_TOP_DEACTIVE));
|
||||
alwaysOnTopItem.setToolTipText(Res.getString("menuitem.always.on.top"));
|
||||
return alwaysOnTopItem;
|
||||
|
||||
|
||||
@ -55,7 +55,6 @@ public final class ResourceUtils {
|
||||
*/
|
||||
public static void resLabel(JLabel label, Component labelFor, String labelText) {
|
||||
label.setText(stripMnemonic(labelText));
|
||||
|
||||
if (Spark.isWindows()) {
|
||||
label.setDisplayedMnemonic(getMnemonicKeyCode(labelText));
|
||||
}
|
||||
@ -69,14 +68,13 @@ public final class ResourceUtils {
|
||||
* <p/>
|
||||
* This method sets the text and mnemonic.
|
||||
*
|
||||
* @param button The button on which to set the text and mnemonoic
|
||||
* @param button The button on which to set the text and mnemonic
|
||||
* @param labelText the text which contains the displayed text and mnemonic
|
||||
* @see AbstractButton#setText(String)
|
||||
* @see AbstractButton#setMnemonic(int)
|
||||
*/
|
||||
public static void resButton(AbstractButton button, String labelText) {
|
||||
button.setText(stripMnemonic(labelText));
|
||||
|
||||
if (Spark.isWindows()) {
|
||||
button.setMnemonic(getMnemonicKeyCode(labelText));
|
||||
}
|
||||
@ -96,31 +94,29 @@ public final class ResourceUtils {
|
||||
*/
|
||||
public static void resButton(RolloverButton button, String labelText) {
|
||||
button.setText(stripMnemonic(labelText));
|
||||
|
||||
if (Spark.isWindows()) {
|
||||
button.setMnemonic(getMnemonicKeyCode(labelText));
|
||||
}
|
||||
}
|
||||
|
||||
public static String stripMnemonic(String label) {
|
||||
String text;
|
||||
int index = label.indexOf("&");
|
||||
if (index != -1) {
|
||||
text = label.substring(0, index);
|
||||
if (label.length() > index) {
|
||||
text = text + label.substring(index + 1);
|
||||
return text;
|
||||
}
|
||||
if (index == -1) {
|
||||
return label;
|
||||
}
|
||||
if (label.length() - 1 > index) {
|
||||
return label.substring(0, index) + label.substring(index + 1);
|
||||
} else {
|
||||
return label.substring(0, index);
|
||||
}
|
||||
return label;
|
||||
}
|
||||
|
||||
public static int getMnemonicKeyCode(String mnemonic) {
|
||||
private static int getMnemonicKeyCode(String mnemonic) {
|
||||
int mindex = mnemonic.indexOf("&");
|
||||
if (mindex > -1) {
|
||||
return mnemonic.toUpperCase().charAt(mindex + 1);
|
||||
if (mindex == -1) {
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
return Character.toUpperCase(mnemonic.charAt(mindex + 1));
|
||||
}
|
||||
|
||||
private ResourceUtils() {
|
||||
|
||||
Reference in New Issue
Block a user