abouttreesummaryrefslogcommitdiff
path: root/srcs/juloo.keyboard2/ExtraKeys.java
blob: 22187c1d24e3e6040bac70013e1ee816a13b9de4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package juloo.keyboard2;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

class ExtraKeys
{
  Map<String, List<KeyValue>> _keys_per_script;

  public ExtraKeys()
  {
    _keys_per_script = new HashMap<String, List<KeyValue>>();
  }

  public void add_keys_for_script(String script, List<KeyValue> kvs)
  {
    List<KeyValue> ks = _keys_per_script.get(script);
    if (ks == null) ks = new ArrayList<KeyValue>();
    ks.addAll(kvs);
    _keys_per_script.put(script, ks);
  }

  /** Add the keys that should be added to the keyboard into [dst]. [null] is
      a valid script. */
  public void compute(Set<KeyValue> dst, String script)
  {
    if (script == null)
    {
      for (String sc : _keys_per_script.keySet())
        get_keys_of_script(dst, sc);
    }
    else
    {
      get_keys_of_script(dst, null);
      get_keys_of_script(dst, script);
    }
  }

  void get_keys_of_script(Set<KeyValue> dst, String script)
  {
    List<KeyValue> ks = _keys_per_script.get(script);
    if (ks != null)
      dst.addAll(ks);
  }

  public static List<KeyValue> parse_extra_keys(String str)
  {
    List<KeyValue> dst = new ArrayList<KeyValue>();
    String[] ks = str.split("\\|");
    for (int i = 0; i < ks.length; i++)
      dst.add(KeyValue.getKeyByName(ks[i]));
    return dst;
  }
}