Home | History | Annotate | Download | only in keyboard
      1 package org.unicode.cldr.draft.keyboard;
      2 
      3 import static com.google.common.base.Preconditions.checkNotNull;
      4 
      5 import com.google.common.base.MoreObjects;
      6 import com.google.common.base.Objects;
      7 
      8 /**
      9  * Describes various platform dependent settings that are pertinent to the keyboard use.
     10  */
     11 public final class KeyboardSettings {
     12     private final FallbackSetting fallbackSetting;
     13     private final TransformFailureSetting transformFailureSetting;
     14     private final TransformPartialSetting transformPartialSetting;
     15 
     16     private KeyboardSettings(FallbackSetting fallbackSetting,
     17         TransformFailureSetting transformFailureSetting,
     18         TransformPartialSetting transformPartialSetting) {
     19         this.fallbackSetting = checkNotNull(fallbackSetting);
     20         this.transformFailureSetting = checkNotNull(transformFailureSetting);
     21         this.transformPartialSetting = checkNotNull(transformPartialSetting);
     22     }
     23 
     24     /** Creates a keyboard settings object from the given options. */
     25     public static KeyboardSettings of(FallbackSetting fallbackSetting,
     26         TransformFailureSetting transformFailureSetting,
     27         TransformPartialSetting transformPartialSetting) {
     28         return new KeyboardSettings(fallbackSetting, transformFailureSetting, transformPartialSetting);
     29     }
     30 
     31     public FallbackSetting fallbackSetting() {
     32         return fallbackSetting;
     33     }
     34 
     35     public TransformFailureSetting transformFailureSetting() {
     36         return transformFailureSetting;
     37     }
     38 
     39     public TransformPartialSetting transformPartialSetting() {
     40         return transformPartialSetting;
     41     }
     42 
     43     @Override
     44     public String toString() {
     45         return MoreObjects.toStringHelper(this)
     46             .add("fallbackSetting", fallbackSetting)
     47             .add("transformFailureSetting", transformFailureSetting)
     48             .add("transformPartialSetting", transformPartialSetting)
     49             .toString();
     50     }
     51 
     52     @Override
     53     public boolean equals(Object o) {
     54         if (o == this) {
     55             return true;
     56         }
     57         if (o instanceof KeyboardSettings) {
     58             KeyboardSettings other = (KeyboardSettings) o;
     59             return Objects.equal(fallbackSetting, other.fallbackSetting)
     60                 && Objects.equal(transformFailureSetting, other.transformFailureSetting)
     61                 && Objects.equal(transformPartialSetting, other.transformPartialSetting);
     62         }
     63         return false;
     64     }
     65 
     66     @Override
     67     public int hashCode() {
     68         return Objects.hashCode(fallbackSetting, transformFailureSetting, transformPartialSetting);
     69     }
     70 
     71     /**
     72      * Describes the behavior of the system when a key press fails. It specifies what happens if there
     73      * is no mapping for a particular key for the given set of modifier keys. This setting is
     74      * completely platform dependent. NONE indicates the setting does not apply to the platform.
     75      */
     76     public enum FallbackSetting {
     77         BASE, OMIT, NONE;
     78 
     79         @Override
     80         public String toString() {
     81             return name().toLowerCase();
     82         }
     83     }
     84 
     85     /**
     86      * Describes the behavior of the system when a transform fails. For example it specifies what
     87      * happens if a dead-key is pressed and the following key cannot be combined. This setting is
     88      * completely platform dependent. NONE indicates the setting does not apply to the platform.
     89      */
     90     public enum TransformFailureSetting {
     91         EMIT, OMIT, NONE;
     92 
     93         @Override
     94         public String toString() {
     95             return name().toLowerCase();
     96         }
     97     }
     98 
     99     /**
    100      * Describes the behavior of the system while a transform is in progress. It specifies whether the
    101      * pressed keys are displayed or not. This setting is completely platform dependent. NONE
    102      * indicates the setting does not apply to the platform.
    103      */
    104     public enum TransformPartialSetting {
    105         HIDE, SHOW, NONE;
    106 
    107         @Override
    108         public String toString() {
    109             return name().toLowerCase();
    110         }
    111     }
    112 }
    113