Ignore:
Timestamp:
08/17/12 08:52:45 (12 years ago)
Author:
pharms
Message:
  • adapted to new coding style in quest
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/quest-misc/src/main/java/de/ugoe/cs/tasktree/keyboardmaps/VirtualKeySynonyms.java

    r447 r558  
    1 //------------------------------------------------------------------------------------------------- 
    21// Module    : $RCSfile: VirtualKeySynonyms.java,v $ 
    32// Version   : $Revision: 0.0 $  $Author: pharms $  $Date: 12.07.2012 $ 
     
    54// Creation  : 2012 by pharms 
    65// Copyright : Patrick Harms, 2012 
    7 //------------------------------------------------------------------------------------------------- 
     6 
    87package de.ugoe.cs.tasktree.keyboardmaps; 
    98 
     
    1413import java.util.logging.Logger; 
    1514 
    16 //------------------------------------------------------------------------------------------------- 
    1715/** 
    1816 * TODO comment 
     
    2119 * @author 2012, last modified by $Author: pharms$ 
    2220 */ 
    23 //------------------------------------------------------------------------------------------------- 
    24 class VirtualKeySynonyms 
    25 { 
    26   /** */ 
    27   private static Logger LOG = Logger.getLogger(KeyboardMap.class.getName()); 
     21class VirtualKeySynonyms { 
     22     
     23    /** */ 
     24    private static Logger LOG = Logger.getLogger(KeyboardMap.class.getName()); 
    2825 
    29   /** */ 
    30   private Map<Integer, List<VirtualKey>> mSynonyms = new HashMap<Integer, List<VirtualKey>>(); 
    31    
    32   /** */ 
    33   private Map<VirtualKey, Integer> mKeyIds = new HashMap<VirtualKey, Integer>(); 
     26    /** */ 
     27    private Map<Integer, List<VirtualKey>> synonyms = new HashMap<Integer, List<VirtualKey>>(); 
    3428 
    35   //----------------------------------------------------------------------------------------------- 
    36   /** 
    37    * TODO: comment 
    38    * 
    39    * @param keyId 
    40    * @param virtualKey 
    41    */ 
    42   //----------------------------------------------------------------------------------------------- 
    43   public void add(int keyId, VirtualKey virtualKey) 
    44   { 
    45     List<VirtualKey> synonyms = mSynonyms.get(keyId); 
    46      
    47     if (synonyms == null) 
    48     { 
    49       synonyms = new ArrayList<VirtualKey>(); 
    50       mSynonyms.put(keyId, synonyms); 
     29    /** */ 
     30    private Map<VirtualKey, Integer> keyIds = new HashMap<VirtualKey, Integer>(); 
     31 
     32    /** 
     33     * TODO: comment 
     34     *  
     35     * @param keyId 
     36     * @param virtualKey 
     37     */ 
     38    public void add(int keyId, VirtualKey virtualKey) { 
     39        List<VirtualKey> synonymList = synonyms.get(keyId); 
     40 
     41        if (synonymList == null) { 
     42            synonymList = new ArrayList<VirtualKey>(); 
     43            synonyms.put(keyId, synonymList); 
     44        } 
     45 
     46        if (!synonymList.contains(virtualKey)) { 
     47            // ensure that the latest determined virtual keys are considered first 
     48            synonymList.add(0, virtualKey); 
     49        } 
     50 
     51        Integer existingKeyId = keyIds.get(virtualKey); 
     52 
     53        if ((existingKeyId != null) && (existingKeyId != keyId)) { 
     54            LOG.finest("virtual key " + virtualKey + 
     55                       " is mapped to more than one key id (current is " + existingKeyId + 
     56                       ", new is " + keyId + "). New key id will be used (" + keyId + ")."); 
     57        } 
     58 
     59        keyIds.put(virtualKey, keyId); 
    5160    } 
    52      
    53     if (!synonyms.contains(virtualKey)) 
    54     { 
    55       // ensure that the latest determined virtual keys are considered first 
    56       synonyms.add(0, virtualKey); 
    57     } 
    58      
    59     Integer existingKeyId = mKeyIds.get(virtualKey); 
    60      
    61     if ((existingKeyId != null) && (existingKeyId != keyId)) 
    62     { 
    63       LOG.finest("virtual key " + virtualKey + " is mapped to more than one key id (current is " + 
    64                  existingKeyId + ", new is " + keyId + "). New key id will be used (" + keyId + 
    65                  ")."); 
    66     } 
    67      
    68     mKeyIds.put(virtualKey, keyId); 
    69   } 
    7061 
    71   //----------------------------------------------------------------------------------------------- 
    72   /** 
     62    /** 
    7363   * 
    7464   */ 
    75   //----------------------------------------------------------------------------------------------- 
    76   public boolean containsKey(int keyId) 
    77   { 
    78     return mSynonyms.containsKey(keyId); 
    79   } 
     65    public boolean containsKey(int keyId) { 
     66        return synonyms.containsKey(keyId); 
     67    } 
    8068 
    81   //----------------------------------------------------------------------------------------------- 
    82   /** 
    83    * TODO: comment 
    84    * 
    85    * @param keyId 
    86    * @return 
    87    */ 
    88   //----------------------------------------------------------------------------------------------- 
    89   public VirtualKey[] getVirtualKeySynonyms(int keyId) 
    90   { 
    91     List<VirtualKey> virtualKeys = mSynonyms.get(keyId); 
    92     if (virtualKeys != null) 
    93     { 
    94       return virtualKeys.toArray(new VirtualKey[virtualKeys.size()]); 
     69    /** 
     70     * TODO: comment 
     71     *  
     72     * @param keyId 
     73     * @return 
     74     */ 
     75    public VirtualKey[] getVirtualKeySynonyms(int keyId) { 
     76        List<VirtualKey> virtualKeys = synonyms.get(keyId); 
     77        if (virtualKeys != null) { 
     78            return virtualKeys.toArray(new VirtualKey[virtualKeys.size()]); 
     79        } 
     80        else { 
     81            LOG.warning("no virtual key define for key id " + keyId); 
     82            return null; 
     83        } 
    9584    } 
    96     else 
    97     { 
    98       LOG.warning("no virtual key define for key id " + keyId); 
    99       return null; 
    100     } 
    101   } 
    102    
     85 
    10386} 
Note: See TracChangeset for help on using the changeset viewer.