Clover Coverage Report - FEST Swing 1.2
Coverage timestamp: Tue Jun 1 2010 15:19:25 PDT
../../../../img/srcFileCovDistChart7.png 95% of files have more coverage
35   111   16   4.38
16   50   0.46   8
8     2  
1    
 
  KeyStrokeMapping       Line # 27 35 0% 16 23 61% 0.6101695
 
No Tests
 
1    /*
2    * Created on Mar 26, 2008
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5    * in compliance with the License. You may obtain a copy of the License at
6    *
7    * http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software distributed under the License
10    * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11    * or implied. See the License for the specific language governing permissions and limitations under
12    * the License.
13    *
14    * Copyright @2008-2010 the original author or authors.
15    */
16    package org.fest.swing.keystroke;
17   
18    import static org.fest.util.Objects.HASH_CODE_PRIME;
19   
20    import javax.swing.KeyStroke;
21   
22    /**
23    * Understands a mapping between a character and a <code>{@link KeyStroke}</code>.
24    *
25    * @author Yvonne Wang
26    */
 
27    public class KeyStrokeMapping {
28   
29    private final char character;
30    private final KeyStroke keyStroke;
31   
32    /**
33    * Creates a new </code>{@link KeyStrokeMapping}</code>.
34    * @param character the character corresponding to the intended <code>KeyStroke</code>.
35    * @param keyCode the numeric key code for the intended <code>KeyStroke</code>.
36    * @param modifiers the set of modifiers for the intended <code>KeyStroke</code>.
37    * @return the created <code>KeyStrokeMapping</code>.
38    */
 
39  151687 toggle public static KeyStrokeMapping mapping(char character, int keyCode, int modifiers) {
40  151687 return new KeyStrokeMapping(character, keyCode, modifiers);
41    }
42   
43    /**
44    * Creates a new </code>{@link KeyStrokeMapping}</code>.
45    * @param character the character corresponding to the intended <code>KeyStroke</code>.
46    * @param keyCode the numeric key code for the intended <code>KeyStroke</code>.
47    * @param modifiers the set of modifiers for the intended <code>KeyStroke</code>.
48    */
 
49  151687 toggle public KeyStrokeMapping(char character, int keyCode, int modifiers) {
50  151687 this(character, KeyStroke.getKeyStroke(keyCode, modifiers));
51    }
52   
53    /**
54    * Creates a new </code>{@link KeyStrokeMapping}</code>.
55    * @param character the character corresponding to the given <code>KeyStroke</code>.
56    * @param keyStroke the <code>KeyStroke</code> corresponding to the given character.
57    */
 
58  151691 toggle public KeyStrokeMapping(char character, KeyStroke keyStroke) {
59  151691 this.character = character;
60  151691 this.keyStroke = keyStroke;
61    }
62   
63    /**
64    * Returns the character corresponding to this mapping's <code>{@link #keyStroke()}</code>.
65    * @return the character corresponding to this mapping's <code>KeyStroke</code>.
66    */
 
67  147406 toggle public char character() {
68  147406 return character;
69    }
70   
71    /**
72    * Returns the <code>{@link KeyStroke}</code> corresponding to this mapping's <code>{@link #character()}</code>.
73    * @return the <code>KeyStroke</code> corresponding to this mapping's character.
74    */
 
75  147406 toggle public KeyStroke keyStroke() {
76  147406 return keyStroke;
77    }
78   
79    /** @see Object#equals(Object) */
 
80  78 toggle @Override public boolean equals(Object o) {
81  78 if (this == o) return true;
82  78 if (o == null) return false;
83  78 if (!(o instanceof KeyStrokeMapping)) return false;
84  78 KeyStrokeMapping other = (KeyStrokeMapping) o;
85  57 if (character != other.character) return false;
86  21 if (keyStroke == null) return other.keyStroke == null;
87  21 if (other.keyStroke == null) return false;
88  21 if (keyStroke.getKeyCode() != other.keyStroke.getKeyCode()) return false;
89  21 return keyStroke.getModifiers() == other.keyStroke.getModifiers();
90    }
91   
92    /** @see Object#hashCode() */
 
93  0 toggle @Override public int hashCode() {
94  0 int prime = HASH_CODE_PRIME;
95  0 int result = 1;
96  0 result = prime * result + character;
97  0 if (keyStroke == null) return result;
98  0 result = prime * result + keyStroke.getKeyCode();
99  0 result = prime * result + keyStroke.getModifiers();
100  0 return result;
101    }
102   
103    /** @see Object#toString() */
 
104  1 toggle @Override public String toString() {
105  1 StringBuilder b = new StringBuilder();
106  1 b.append(getClass().getSimpleName()).append("[");
107  1 b.append("character='").append(character).append("',");
108  1 b.append("keyStroke=").append(keyStroke).append("]");
109  1 return b.toString();
110    }
111    }