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

Print this page

        

*** 31,40 **** --- 31,42 ---- 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,1000 **** * 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(); if ((modifiers & InputEvent.ALT_MASK) != 0) { ! buf.append(Toolkit.getProperty("AWT.alt", "Alt")); ! buf.append("+"); } if ((modifiers & InputEvent.META_MASK) != 0) { ! buf.append(Toolkit.getProperty("AWT.meta", "Meta")); ! buf.append("+"); } if ((modifiers & InputEvent.CTRL_MASK) != 0) { ! buf.append(Toolkit.getProperty("AWT.control", "Ctrl")); ! buf.append("+"); } if ((modifiers & InputEvent.SHIFT_MASK) != 0) { ! buf.append(Toolkit.getProperty("AWT.shift", "Shift")); ! buf.append("+"); } if ((modifiers & InputEvent.ALT_GRAPH_MASK) != 0) { ! buf.append(Toolkit.getProperty("AWT.altGraph", "Alt Graph")); ! buf.append("+"); } if ((modifiers & InputEvent.BUTTON1_MASK) != 0) { ! buf.append(Toolkit.getProperty("AWT.button1", "Button1")); ! buf.append("+"); } if ((modifiers & InputEvent.BUTTON2_MASK) != 0) { ! buf.append(Toolkit.getProperty("AWT.button2", "Button2")); ! buf.append("+"); } if ((modifiers & InputEvent.BUTTON3_MASK) != 0) { ! buf.append(Toolkit.getProperty("AWT.button3", "Button3")); ! buf.append("+"); } ! ! int mask; // 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. for (int i = 1; i <= cachedNumberOfButtons; i++){ ! 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. { ! buf.append(Toolkit.getProperty("AWT.button"+i, "Button"+i)); ! buf.append("+"); } } - - if (buf.length() > 0) { - buf.setLength(buf.length()-1); // remove trailing '+' - } return buf.toString(); } /** * Returns a parameter string identifying this event. --- 939,991 ---- * keys and mouse buttons that were down during the event * @see InputEvent#getModifiersExText(int) * @since 1.4 */ public static String getMouseModifiersText(int modifiers) { ! StringJoiner buf = new StringJoiner("+"); if ((modifiers & InputEvent.ALT_MASK) != 0) { ! buf.add(Toolkit.getProperty("AWT.alt", "Alt")); } if ((modifiers & InputEvent.META_MASK) != 0) { ! buf.add(Toolkit.getProperty("AWT.meta", "Meta")); } if ((modifiers & InputEvent.CTRL_MASK) != 0) { ! buf.add(Toolkit.getProperty("AWT.control", "Ctrl")); } if ((modifiers & InputEvent.SHIFT_MASK) != 0) { ! buf.add(Toolkit.getProperty("AWT.shift", "Shift")); } if ((modifiers & InputEvent.ALT_GRAPH_MASK) != 0) { ! buf.add(Toolkit.getProperty("AWT.altGraph", "Alt Graph")); } if ((modifiers & InputEvent.BUTTON1_MASK) != 0) { ! buf.add(Toolkit.getProperty("AWT.button1", "Button1")); } if ((modifiers & InputEvent.BUTTON2_MASK) != 0) { ! buf.add(Toolkit.getProperty("AWT.button2", "Button2")); } if ((modifiers & InputEvent.BUTTON3_MASK) != 0) { ! buf.add(Toolkit.getProperty("AWT.button3", "Button3")); } ! 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++){ ! int mask = InputEvent.getMaskForButton(i); if ((modifiers & mask) != 0 && ! //1,2,3 buttons may already be there; so don't duplicate it. ! !result.contains(Toolkit.getProperty("AWT.button" + i, "Button" + i))) { ! buf.add(Toolkit.getProperty("AWT.button" + i, "Button" + i)); } } return buf.toString(); } /** * Returns a parameter string identifying this event.