]> gitweb.fperrin.net Git - Dictionary.git/blob - src/com/hughes/android/dictionary/engine/TextEntry.java
Switching to WebView!
[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
21 import com.hughes.util.raf.RAFSerializable;
22 import com.hughes.util.raf.RAFSerializer;
23
24 public class TextEntry extends AbstractEntry implements RAFSerializable<TextEntry> {
25   
26   final String text;
27   
28   public TextEntry(final Dictionary dictionary, final RandomAccessFile raf) throws IOException {
29     super(dictionary, raf);
30     text = raf.readUTF();
31   }
32   @Override
33   public void write(RandomAccessFile raf) throws IOException {
34     super.write(raf);
35     raf.writeUTF(text);
36   }
37   
38   static final class Serializer implements RAFSerializer<TextEntry> {
39     
40     final Dictionary dictionary;
41     
42     Serializer(Dictionary dictionary) {
43       this.dictionary = dictionary;
44     }
45
46     @Override
47     public TextEntry read(RandomAccessFile raf) throws IOException {
48       return new TextEntry(dictionary, raf);
49     }
50
51     @Override
52     public void write(RandomAccessFile raf, TextEntry t) throws IOException {
53       t.write(raf);
54     }
55   };
56
57   
58   @Override
59   public int addToDictionary(final Dictionary dictionary) {
60     dictionary.textEntries.add(this);
61     return dictionary.textEntries.size() - 1;
62   }
63
64   public static class Row extends RowBase {
65     
66     Row(final RandomAccessFile raf, final int thisRowIndex,
67         final Index index) throws IOException {
68       super(raf, thisRowIndex, index);
69     }
70     
71     public TextEntry getEntry() {
72       return index.dict.textEntries.get(referenceIndex);
73     }
74     
75     @Override
76     public void print(PrintStream out) {
77       out.println("  " + getEntry().text);
78     }
79
80     @Override
81     public String getRawText(boolean compact) {
82       return getEntry().text;
83     }
84   }
85
86
87
88 }