📄 sampledictionary.java
字号:
import java.util.*;import com.sun.tdc.toolkit.api.Dictionary;public class SampleDictionary implements Dictionary { Hashtable dict; static String[] keys = { "file", "open", "new", "save", "exit" }; static String[][] vals = { {"Fichier"}, {"Ouvrir"}, {"Nouveau"}, {"Sauver"}, {"Quitter"} }; public SampleDictionary() { dict = new Hashtable(); for (int i = 0; i < keys.length; i++) { dict.put(keys[i], vals[i]); } } /** * Gets the source locale. It defines the source language. */ public Locale getSource() { return Locale.ENGLISH; } /** * Gets the target locale. It defines the meanings' language. */ public Locale getTarget() { return Locale.FRENCH; } /** * Tests if this dictionary has no keys (meanings). */ public boolean isEmpty() { return dict.isEmpty(); } /** * Gets an enumeration of the meanings in this dictionary. */ public Enumeration elements() { Vector v = new Vector(); for (Enumeration e = dict.elements() ; e.hasMoreElements() ;) { String[] val = (String[])e.nextElement(); for (int i = 0; i < val.length; i++) { v.addElement(val[i]); } } return v.elements(); } /** * Gets an enumeration of the keys in this dictionary. */ public Enumeration keys() { return dict.keys(); } /** * Gets the meanings to which the key is mapped in this dictionary. */ public String[] get(String key) { return (String[])dict.get(key); } /** * Gets one of the meanings with the index. * @return null, if no key available; the first meaning, if index is less than zero; * the last meaning, if the index is greater than or equal to the meaning count; empty string, * if no meaning is available. */ public String select(String key, int index) { String[] val = (String[])get(key); if (val == null) return null; if (index < 0) { index = 0; } else if (index >= val.length) { index = val.length - 1; } return val[index]; } /** * Maps the specified key to the specified meaning in this dictionary. * Only valid string(not null and not blank) can be used as key. * Only valid string(not null and not blank) can be used as meanings. * @return the meanings successfully mapped. */ public String[] put(String key, String[] meanings) { dict.put(key, meanings); return meanings; } /** * Gets the number of meanings to which the key is mapped in this dictionary. * @return -1 if no key found. */ public int getMeaningCount(String key) { String[] val = (String[])get(key); return val == null ? -1:val.length; } /** * Appends the specified key to the specified meaning in this dictionary. * Only valid string(not null and not blank) can be used as key. * Only valid string(not null and not blank) can be used as meaning. * @return the meaning appended. */ public String append(String key, String meaning) { String[] val = (String[])get(key); if (val == null) { String[] tmp = {meaning}; dict.put(key, tmp); } else { String[] newVal = new String[val.length + 1]; System.arraycopy(val, 0, newVal, 0, val.length); newVal[val.length] = meaning; dict.put(key, newVal); } return meaning; } /** * Removes the key (and all its meanings) from this dictionary. * @return the meanings of the key removed. */ public String[] remove(String key) { return (String[])dict.remove(key); } /** * Removes the meaning of the key from this dictionary. * @return the meaning removed. */ public String remove(String key, String meaning) { String[] val = remove(key); if (val != null) { Vector v = new Vector(); for (int i = 0; i < val.length; i++) { if (! val[i].equals(meaning)) { v.addElement(val[i]); } } String[] tmp = new String[v.size()]; v.copyInto(tmp); dict.put(key, tmp); if (val.length == v.size()) { meaning = null; } return meaning; } else { return null; } } /** * Number of keys in this dictionary. */ public int size() { return dict.size(); } /** * Sets case sensitive lookup or not, if this dictionary supports. */ public void setCaseSensitive(boolean caseSense) { return; } /** * Whether to use case sensitive lookup or not, if this dictionary supports. * @return true, case sensitive. */ public boolean isCaseSensitive() { return true; } /** * Gets the dictionary's information, eg. name, description, etc. */ public Properties getDictionaryInfo() { return new Properties(); } /** * Gets the dictionary's name. */ public String getName() { return "En-Fr"; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -