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

Print this page




  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.awt.event;
  27 
  28 import java.awt.Event;
  29 import java.awt.Component;
  30 import java.awt.GraphicsEnvironment;
  31 import java.awt.Toolkit;
  32 import java.util.Arrays;

  33 
  34 import sun.awt.AWTAccessor;
  35 import sun.awt.AWTPermissions;
  36 import sun.util.logging.PlatformLogger;
  37 
  38 /**
  39  * The root event class for all component-level input events.
  40  *
  41  * Input events are delivered to listeners before they are
  42  * processed normally by the source where they originated.
  43  * This allows listeners and component subclasses to "consume"
  44  * the event so that the source will not process them in their
  45  * default manner.  For example, consuming mousePressed events
  46  * on a Button component will prevent the Button from being
  47  * activated.
  48  *
  49  * @author Carl Quinn
  50  *
  51  * @see KeyEvent
  52  * @see KeyAdapter


 495      * mouse buttons, such as "Shift", "Button1", or "Ctrl+Shift".
 496      * These strings can be localized by changing the
 497      * <code>awt.properties</code> file.
 498      * <p>
 499      * Note that passing negative parameter is incorrect,
 500      * and will cause the returning an unspecified string.
 501      * Zero parameter means that no modifiers were passed and will
 502      * cause the returning an empty string.
 503      *
 504      * @return a String describing the extended modifier keys and
 505      * mouse buttons
 506      *
 507      * @param modifiers a modifier mask describing the extended
 508      *                modifier keys and mouse buttons for the event
 509      * @return a text description of the combination of extended
 510      *         modifier keys and mouse buttons that were held down
 511      *         during the event.
 512      * @since 1.4
 513      */
 514     public static String getModifiersExText(int modifiers) {
 515         StringBuilder buf = new StringBuilder();
 516         if ((modifiers & InputEvent.META_DOWN_MASK) != 0) {
 517             buf.append(Toolkit.getProperty("AWT.meta", "Meta"));
 518             buf.append("+");
 519         }
 520         if ((modifiers & InputEvent.CTRL_DOWN_MASK) != 0) {
 521             buf.append(Toolkit.getProperty("AWT.control", "Ctrl"));
 522             buf.append("+");
 523         }
 524         if ((modifiers & InputEvent.ALT_DOWN_MASK) != 0) {
 525             buf.append(Toolkit.getProperty("AWT.alt", "Alt"));
 526             buf.append("+");
 527         }
 528         if ((modifiers & InputEvent.SHIFT_DOWN_MASK) != 0) {
 529             buf.append(Toolkit.getProperty("AWT.shift", "Shift"));
 530             buf.append("+");
 531         }
 532         if ((modifiers & InputEvent.ALT_GRAPH_DOWN_MASK) != 0) {
 533             buf.append(Toolkit.getProperty("AWT.altGraph", "Alt Graph"));
 534             buf.append("+");
 535         }
 536 
 537         int buttonNumber = 1;
 538         for (int mask : InputEvent.BUTTON_DOWN_MASK){
 539             if ((modifiers & mask) != 0) {
 540                 buf.append(Toolkit.getProperty("AWT.button"+buttonNumber, "Button"+buttonNumber));
 541                 buf.append("+");
 542             }
 543             buttonNumber++;
 544         }
 545         if (buf.length() > 0) {
 546             buf.setLength(buf.length()-1); // remove trailing '+'
 547         }
 548         return buf.toString();
 549     }
 550 }


  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.awt.event;
  27 
  28 import java.awt.Event;
  29 import java.awt.Component;
  30 import java.awt.GraphicsEnvironment;
  31 import java.awt.Toolkit;
  32 import java.util.Arrays;
  33 import java.util.StringJoiner;
  34 
  35 import sun.awt.AWTAccessor;
  36 import sun.awt.AWTPermissions;
  37 import sun.util.logging.PlatformLogger;
  38 
  39 /**
  40  * The root event class for all component-level input events.
  41  *
  42  * Input events are delivered to listeners before they are
  43  * processed normally by the source where they originated.
  44  * This allows listeners and component subclasses to "consume"
  45  * the event so that the source will not process them in their
  46  * default manner.  For example, consuming mousePressed events
  47  * on a Button component will prevent the Button from being
  48  * activated.
  49  *
  50  * @author Carl Quinn
  51  *
  52  * @see KeyEvent
  53  * @see KeyAdapter


 496      * mouse buttons, such as "Shift", "Button1", or "Ctrl+Shift".
 497      * These strings can be localized by changing the
 498      * <code>awt.properties</code> file.
 499      * <p>
 500      * Note that passing negative parameter is incorrect,
 501      * and will cause the returning an unspecified string.
 502      * Zero parameter means that no modifiers were passed and will
 503      * cause the returning an empty string.
 504      *
 505      * @return a String describing the extended modifier keys and
 506      * mouse buttons
 507      *
 508      * @param modifiers a modifier mask describing the extended
 509      *                modifier keys and mouse buttons for the event
 510      * @return a text description of the combination of extended
 511      *         modifier keys and mouse buttons that were held down
 512      *         during the event.
 513      * @since 1.4
 514      */
 515     public static String getModifiersExText(int modifiers) {
 516         StringJoiner buf = new StringJoiner("+");
 517         if ((modifiers & InputEvent.META_DOWN_MASK) != 0) {
 518             buf.add(Toolkit.getProperty("AWT.meta", "Meta"));

 519         }
 520         if ((modifiers & InputEvent.CTRL_DOWN_MASK) != 0) {
 521             buf.add(Toolkit.getProperty("AWT.control", "Ctrl"));

 522         }
 523         if ((modifiers & InputEvent.ALT_DOWN_MASK) != 0) {
 524             buf.add(Toolkit.getProperty("AWT.alt", "Alt"));

 525         }
 526         if ((modifiers & InputEvent.SHIFT_DOWN_MASK) != 0) {
 527             buf.add(Toolkit.getProperty("AWT.shift", "Shift"));

 528         }
 529         if ((modifiers & InputEvent.ALT_GRAPH_DOWN_MASK) != 0) {
 530             buf.add(Toolkit.getProperty("AWT.altGraph", "Alt Graph"));

 531         }
 532 
 533         int buttonNumber = 1;
 534         for (int mask : InputEvent.BUTTON_DOWN_MASK){
 535             if ((modifiers & mask) != 0) {
 536                 buf.add(Toolkit.getProperty("AWT.button" + buttonNumber, "Button" + buttonNumber));

 537             }
 538             buttonNumber++;
 539         }



 540         return buf.toString();
 541     }
 542 }