/*
* Copyright (C) 2015-present, osfans
* waxaca@163.com https://github.com/osfans
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
package com.osfans.trime;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
/**
* Rime與OpenCC的Java實現
*
* @see Rime OpenCC
*/
public class Rime {
/** Rime編碼區 */
public static class RimeComposition {
int length;
int cursor_pos;
int sel_start;
int sel_end;
String preedit;
byte[] bytes;
public String getText() {
if (length == 0) return "";
bytes = preedit.getBytes();
return preedit;
}
public int getStart() {
if (length == 0) return 0;
return new String(bytes, 0, sel_start).length();
}
public int getEnd() {
if (length == 0) return 0;
return new String(bytes, 0, sel_end).length();
}
}
/** Rime候選項 */
public static class RimeCandidate {
String text;
String comment;
}
/** Rime候選區,包含多個{@link RimeCandidate 候選項} */
public static class RimeMenu {
int page_size;
int page_no;
boolean is_last_page;
int highlighted_candidate_index;
int num_candidates;
RimeCandidate[] candidates;
String select_keys;
}
/** Rime上屏的字符串 */
public static class RimeCommit {
int data_size;
// v0.9
String text;
}
/** Rime環境,包括 {@link RimeComposition 編碼區} 、{@link RimeMenu 候選區} */
public static class RimeContext {
int data_size;
// v0.9
RimeComposition composition;
RimeMenu menu;
// v0.9.2
String commit_text_preview;
String[] select_labels;
public int size() {
if (menu == null) return 0;
return menu.num_candidates;
}
public RimeCandidate[] getCandidates() {
return size() == 0 ? null : menu.candidates;
}
}
/** Rime狀態 */
public static class RimeStatus {
int data_size;
// v0.9
String schema_id;
String schema_name;
boolean is_disabled;
boolean is_composing;
boolean is_ascii_mode;
boolean is_full_shape;
boolean is_simplified;
boolean is_traditional;
boolean is_ascii_punct;
}
/** Rime方案 */
public static class RimeSchema {
private String kRightArrow = "→ ";
private String kRadioSelected = " ✓";
Map schema = new HashMap();
List