1 package org.unicode.cldr.draft.keyboard; 2 3 import static com.google.common.base.Preconditions.checkNotNull; 4 5 /** 6 * Enum which represents the corresponding position of a key using the ISO layout convention where 7 * rows are identified by letters and columns are identified by numbers. For example, "D01" 8 * corresponds to the Q key on a US keyboard. For the purposes of this enum, we depict an ISO 9 * layout position by a one-letter row identifier followed by a two digit column number (like "B03", 10 * "E12" or "C00"). 11 * 12 * <p> 13 * It is important to note that the physical placement of the keys is not encoded in this enum, 14 * rather what is important is their logical placement using the ISO convention. 15 * 16 * <p> 17 * We can also extend the ISO Layout convention by adding rows as we please (such as adding an F 18 * row) or adding columns (going beyond 13 or before 0, in which case we would introduce negative 19 * column numbers). This extension can be used to map almost any key to the convention for our 20 * purposes. 21 * 22 * <p> 23 * More information about the ISO layout positions can be found in the <a 24 * href="https://docs.google.com/document/d/1XSFyUKFGJr3lTv1mmoL4Pmk3RTJJapwYZ63pAkiIYvg/edit">LDML 25 * XML Keyboard Specification</a> 26 */ 27 public enum IsoLayoutPosition { 28 /* Row 1 */ 29 E00('E', 0, "`"), E01('E', 1, "1"), E02('E', 2, "2"), E03('E', 3, "3"), E04('E', 4, "4"), E05('E', 5, "5"), E06('E', 6, "6"), E07('E', 7, "7"), E08('E', 8, 30 "8"), E09('E', 9, "9"), E10('E', 10, "0"), E11('E', 11, "-"), E12('E', 12, "="), E13('E', 13, "(key to right of =)"), // Additional key in 106 keyboards (like Japanese 31 // keyboards) 32 33 /* Row 2 */ 34 D01('D', 1, "Q"), D02('D', 2, "W"), D03('D', 3, "E"), D04('D', 4, "R"), D05('D', 5, "T"), D06('D', 6, "Y"), D07('D', 7, "U"), D08('D', 8, "I"), D09('D', 9, 35 "O"), D10('D', 10, "P"), D11('D', 11, "["), D12('D', 12, "]"), D13('D', 13, "\\"), 36 37 /* Row 3 */ 38 C01('C', 1, "A"), C02('C', 2, "S"), C03('C', 3, "D"), C04('C', 4, "F"), C05('C', 5, "G"), C06('C', 6, "H"), C07('C', 7, "J"), C08('C', 8, "K"), C09('C', 9, 39 "L"), C10('C', 10, ";"), C11('C', 11, "'"), C12('C', 12, "(key to right of ')"), // Additional key in 102+ layouts, typically is present 40 // when D13 is not 41 42 /* Row 4 */ 43 B00('B', 0, "(key to left of Z)"), // Additional key in 102 and 103 keyboards (like European 44 // keyboards) 45 B01('B', 1, "Z"), B02('B', 2, "X"), B03('B', 3, "C"), B04('B', 4, "V"), B05('B', 5, "B"), B06('B', 6, "N"), B07('B', 7, "M"), B08('B', 8, ","), B09('B', 9, 46 "."), B10('B', 10, "/"), B11('B', 11, "(key to right of /)"), B12('B', 12, "(2 keys to right of /)"), // Additional key for Android 47 48 /* Row 5 */ 49 A01('A', 1, "(2 keys to left of space)"), // Additional key for Android 50 A02('A', 2, "(key to left of space)"), // Additional key for Android 51 A03('A', 3, "space"), A04('A', 4, "(key to right of space)"), // Additional key for Android 52 A05('A', 5, "(2 keys to right of space)"), // Additional key for Android 53 A06('A', 6, "(3 keys to right of space)"), // Additional key for Android 54 A07('A', 7, "(4 keys to right of space)"); // Additional key for Android 55 56 private final char row; 57 private final int column; 58 private final String englishKeyName; 59 60 private IsoLayoutPosition(char row, int column, String englishKeyName) { 61 this.row = row; 62 this.column = column; 63 this.englishKeyName = checkNotNull(englishKeyName); 64 } 65 66 public char row() { 67 return row; 68 } 69 70 public int column() { 71 return column; 72 } 73 74 /** 75 * Get the label that would be on the key on a US keyboard. This is for convenience and 76 * readability purposes only. If the key does not appear on a US keyboard, it returns a 77 * description of the position relative to the closest US keyboard key. 78 */ 79 public String englishKeyName() { 80 return englishKeyName; 81 } 82 83 /** 84 * Returns the enum member for a given row and column. Throws an illegal argument exception if 85 * the element does not exist. 86 * 87 * @param row the layout row, is an upper-case character between A and E (inclusive) 88 * @param column the layout column, is an integer between 0 and 13 (inclusive), not all rows 89 * contain elements for all 14 columns 90 */ 91 public static IsoLayoutPosition forPosition(char row, int column) { 92 for (IsoLayoutPosition position : values()) { 93 if (position.row == row && position.column == column) { 94 return position; 95 } 96 } 97 throw new IllegalArgumentException("Missing ISO Position for " + row + ":" + column); 98 } 99 }