Mega Code Archive

 
Categories / Java / Event
 

Reads for modifiers and creates integer with required mask

import java.awt.event.KeyEvent; import java.util.NoSuchElementException; /*  * $Id: Utilities.java,v 1.11 2008/10/14 22:31:46 rah003 Exp $  *  * Copyright 2006 Sun Microsystems, Inc., 4150 Network Circle,  * Santa Clara, California 95054, U.S.A. All rights reserved.  *  * This library is free software; you can redistribute it and/or  * modify it under the terms of the GNU Lesser General Public  * License as published by the Free Software Foundation; either  * version 2.1 of the License, or (at your option) any later version.  *  * This library is distributed in the hope that it will be useful,  * but WITHOUT ANY WARRANTY; without even the implied warranty of  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  * Lesser General Public License for more details.  *  * You should have received a copy of the GNU Lesser General Public  * License along with this library; if not, write to the Free Software  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA  */ /**  * Contribution from NetBeans: Issue #319-swingx.  * <p>  *   * PENDING: need to reconcile with OS, JVM... added as-is because needed the  * shortcut handling to fix #  *   * @author apple  */ public class Utils {   private static final int CTRL_WILDCARD_MASK = 32768;   private static final int ALT_WILDCARD_MASK = CTRL_WILDCARD_MASK * 2;   /** Reads for modifiers and creates integer with required mask.   * @param s string with modifiers   * @return integer with mask   * @exception NoSuchElementException if some letter is not modifier   */   private static int readModifiers(String s) throws NoSuchElementException {       int m = 0;       for (int i = 0; i < s.length(); i++) {           switch (s.charAt(i)) {           case 'C':               m |= KeyEvent.CTRL_MASK;               break;           case 'A':               m |= KeyEvent.ALT_MASK;               break;           case 'M':               m |= KeyEvent.META_MASK;               break;           case 'S':               m |= KeyEvent.SHIFT_MASK;               break;           case 'D':               m |= CTRL_WILDCARD_MASK;               break;           case 'O':               m |= ALT_WILDCARD_MASK;               break;           default:               throw new NoSuchElementException(s);           }       }       return m;   }    }