]> gitweb.fperrin.net Git - Dictionary.git/blob - src/com/hughes/android/dictionary/engine/TextEntry.java
About dialog, added pictures, multi word search.
[Dictionary.git] / src / com / hughes / android / dictionary / engine / TextEntry.java
1 // Copyright 2011 Google Inc. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package com.hughes.android.dictionary.engine;
16
17 import java.io.IOException;
18 import java.io.PrintStream;
19 import java.io.RandomAccessFile;
20 import java.util.List;
21 import java.util.regex.Pattern;
22
23 import com.hughes.util.raf.RAFSerializable;
24 import com.hughes.util.raf.RAFSerializer;
25 import com.ibm.icu.text.Transliterator;
26
27 public class TextEntry extends AbstractEntry implements RAFSerializable<TextEntry> {
28   
29   final String text;
30   
31   public TextEntry(final Dictionary dictionary, final RandomAccessFile raf) throws IOException {
32     super(dictionary, raf);
33     text = raf.readUTF();
34     throw new RuntimeException();
35   }
36   @Override
37   public void write(RandomAccessFile raf) throws IOException {
38     super.write(raf);
39     raf.writeUTF(text);
40   }
41   
42   static final class Serializer implements RAFSerializer<TextEntry> {
43     
44     final Dictionary dictionary;
45     
46     Serializer(Dictionary dictionary) {
47       this.dictionary = dictionary;
48     }
49
50     @Override
51     public TextEntry read(RandomAccessFile raf) throws IOException {
52       return new TextEntry(dictionary, raf);
53     }
54
55     @Override
56     public void write(RandomAccessFile raf, TextEntry t) throws IOException {
57       t.write(raf);
58     }
59   };
60
61   
62   @Override
63   public int addToDictionary(final Dictionary dictionary) {
64     dictionary.textEntries.add(this);
65     return dictionary.textEntries.size() - 1;
66   }
67
68   public static class Row extends RowBase {
69     
70     Row(final RandomAccessFile raf, final int thisRowIndex,
71         final Index index) throws IOException {
72       super(raf, thisRowIndex, index);
73     }
74     
75     public TextEntry getEntry() {
76       return index.dict.textEntries.get(referenceIndex);
77     }
78     
79     @Override
80     public void print(PrintStream out) {
81       out.println("  " + getEntry().text);
82     }
83
84     @Override
85     public String getRawText(boolean compact) {
86       return getEntry().text;
87     }
88     
89     @Override
90     public RowMatchType matches(final List<String> searchTokens, final Pattern orderedMatchPattern, Transliterator normalizer, boolean swapPairEntries) {
91       return null;
92     }
93   }
94
95
96
97 }