src/share/classes/java/awt/event/InputEvent.java

Print this page

        

@@ -28,10 +28,11 @@
 import java.awt.Event;
 import java.awt.Component;
 import java.awt.GraphicsEnvironment;
 import java.awt.Toolkit;
 import java.util.Arrays;
+import java.util.StringJoiner;
 
 import sun.awt.AWTAccessor;
 import sun.awt.AWTPermissions;
 import sun.util.logging.PlatformLogger;
 

@@ -510,41 +511,32 @@
      *         modifier keys and mouse buttons that were held down
      *         during the event.
      * @since 1.4
      */
     public static String getModifiersExText(int modifiers) {
-        StringBuilder buf = new StringBuilder();
+        StringJoiner buf = new StringJoiner("+");
         if ((modifiers & InputEvent.META_DOWN_MASK) != 0) {
-            buf.append(Toolkit.getProperty("AWT.meta", "Meta"));
-            buf.append("+");
+            buf.add(Toolkit.getProperty("AWT.meta", "Meta"));
         }
         if ((modifiers & InputEvent.CTRL_DOWN_MASK) != 0) {
-            buf.append(Toolkit.getProperty("AWT.control", "Ctrl"));
-            buf.append("+");
+            buf.add(Toolkit.getProperty("AWT.control", "Ctrl"));
         }
         if ((modifiers & InputEvent.ALT_DOWN_MASK) != 0) {
-            buf.append(Toolkit.getProperty("AWT.alt", "Alt"));
-            buf.append("+");
+            buf.add(Toolkit.getProperty("AWT.alt", "Alt"));
         }
         if ((modifiers & InputEvent.SHIFT_DOWN_MASK) != 0) {
-            buf.append(Toolkit.getProperty("AWT.shift", "Shift"));
-            buf.append("+");
+            buf.add(Toolkit.getProperty("AWT.shift", "Shift"));
         }
         if ((modifiers & InputEvent.ALT_GRAPH_DOWN_MASK) != 0) {
-            buf.append(Toolkit.getProperty("AWT.altGraph", "Alt Graph"));
-            buf.append("+");
+            buf.add(Toolkit.getProperty("AWT.altGraph", "Alt Graph"));
         }
 
         int buttonNumber = 1;
         for (int mask : InputEvent.BUTTON_DOWN_MASK){
             if ((modifiers & mask) != 0) {
-                buf.append(Toolkit.getProperty("AWT.button"+buttonNumber, "Button"+buttonNumber));
-                buf.append("+");
+                buf.add(Toolkit.getProperty("AWT.button" + buttonNumber, "Button" + buttonNumber));
             }
             buttonNumber++;
         }
-        if (buf.length() > 0) {
-            buf.setLength(buf.length()-1); // remove trailing '+'
-        }
         return buf.toString();
     }
 }