src/share/classes/java/awt/event/MouseEvent.java
Print this page
@@ -31,10 +31,12 @@
import java.awt.Toolkit;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.awt.IllegalComponentStateException;
import java.awt.MouseInfo;
+import java.util.StringJoiner;
+
import sun.awt.SunToolkit;
/**
* An event which indicates that a mouse action occurred in a component.
* A mouse action is considered to occur in a particular component if and only
@@ -937,64 +939,53 @@
* keys and mouse buttons that were down during the event
* @see InputEvent#getModifiersExText(int)
* @since 1.4
*/
public static String getMouseModifiersText(int modifiers) {
- StringBuilder buf = new StringBuilder();
+ StringJoiner buf = new StringJoiner("+");
if ((modifiers & InputEvent.ALT_MASK) != 0) {
- buf.append(Toolkit.getProperty("AWT.alt", "Alt"));
- buf.append("+");
+ buf.add(Toolkit.getProperty("AWT.alt", "Alt"));
}
if ((modifiers & InputEvent.META_MASK) != 0) {
- buf.append(Toolkit.getProperty("AWT.meta", "Meta"));
- buf.append("+");
+ buf.add(Toolkit.getProperty("AWT.meta", "Meta"));
}
if ((modifiers & InputEvent.CTRL_MASK) != 0) {
- buf.append(Toolkit.getProperty("AWT.control", "Ctrl"));
- buf.append("+");
+ buf.add(Toolkit.getProperty("AWT.control", "Ctrl"));
}
if ((modifiers & InputEvent.SHIFT_MASK) != 0) {
- buf.append(Toolkit.getProperty("AWT.shift", "Shift"));
- buf.append("+");
+ buf.add(Toolkit.getProperty("AWT.shift", "Shift"));
}
if ((modifiers & InputEvent.ALT_GRAPH_MASK) != 0) {
- buf.append(Toolkit.getProperty("AWT.altGraph", "Alt Graph"));
- buf.append("+");
+ buf.add(Toolkit.getProperty("AWT.altGraph", "Alt Graph"));
}
if ((modifiers & InputEvent.BUTTON1_MASK) != 0) {
- buf.append(Toolkit.getProperty("AWT.button1", "Button1"));
- buf.append("+");
+ buf.add(Toolkit.getProperty("AWT.button1", "Button1"));
}
if ((modifiers & InputEvent.BUTTON2_MASK) != 0) {
- buf.append(Toolkit.getProperty("AWT.button2", "Button2"));
- buf.append("+");
+ buf.add(Toolkit.getProperty("AWT.button2", "Button2"));
}
if ((modifiers & InputEvent.BUTTON3_MASK) != 0) {
- buf.append(Toolkit.getProperty("AWT.button3", "Button3"));
- buf.append("+");
+ buf.add(Toolkit.getProperty("AWT.button3", "Button3"));
}
-
- int mask;
+ String result = buf.toString();
// TODO: add a toolkit field that holds a number of button on the mouse.
// As the method getMouseModifiersText() is static and obtain
// an integer as a parameter then we may not restrict this with the number
// of buttons installed on the mouse.
// It's a temporary solution. We need to somehow hold the number of buttons somewhere else.
+ buf = new StringJoiner("+");
+ buf.add(result);
for (int i = 1; i <= cachedNumberOfButtons; i++){
- mask = InputEvent.getMaskForButton(i);
+ int mask = InputEvent.getMaskForButton(i);
if ((modifiers & mask) != 0 &&
- buf.indexOf(Toolkit.getProperty("AWT.button"+i, "Button"+i)) == -1) //1,2,3 buttons may already be there; so don't duplicate it.
+ //1,2,3 buttons may already be there; so don't duplicate it.
+ !result.contains(Toolkit.getProperty("AWT.button" + i, "Button" + i)))
{
- buf.append(Toolkit.getProperty("AWT.button"+i, "Button"+i));
- buf.append("+");
+ buf.add(Toolkit.getProperty("AWT.button" + i, "Button" + i));
}
}
-
- if (buf.length() > 0) {
- buf.setLength(buf.length()-1); // remove trailing '+'
- }
return buf.toString();
}
/**
* Returns a parameter string identifying this event.