001: package Language.Editor;
002:
003: import Schmortopf.Utility.SortableTable.*;
004: import Language.*;
005:
006: import java.util.*;
007: import java.awt.event.*;
008: import javax.swing.event.*;
009:
010: /** used to display sentences for editing
011: */
012: public class SentencesTableModel extends FineGrainTableModel implements
013: ChangeListener {
014: final static int COLUMN_SENTENCE = 0;
015: final static int COLUMN_TRANSLATION = 1;
016: final static int COLUMN_SOURCEFILE = 2;
017: final static int COLUMN_SOURCELINE = 3;
018:
019: final Vector sentences = new Vector();
020: SentenceDictionary actualDic;
021:
022: boolean editable = true;
023:
024: public SentencesTableModel() {
025:
026: } // Constructor
027:
028: public void setDictionary(SentenceDictionary dic, boolean editable) {
029: this .editable = editable;
030: if (actualDic != null)
031: actualDic.removeChangeListener(this );
032:
033: actualDic = dic;
034: sentences.removeAllElements();
035: //
036: Vector v = dic.getAllSentences();
037: for (int i = 0; i < v.size(); i++) {
038: sentences.addElement(v.elementAt(i));
039: }
040:
041: this .fireTableDataChanged();
042:
043: dic.addChangeListener(this );
044:
045: }
046:
047: // called when actualDic changed
048: public void stateChanged(ChangeEvent e) {
049: fireTableDataChanged();
050: }
051:
052: public String getColumnName(int col) {
053: if (col == COLUMN_SENTENCE)
054: return "English";
055: if (col == COLUMN_TRANSLATION)
056: return "Translation";
057: if (col == COLUMN_SOURCEFILE)
058: return "Found in source";
059: return "?";
060: }
061:
062: public Sentence getSentenceAt(int pos) {
063: return (Sentence) sentences.elementAt(pos);
064: }
065:
066: public int getColumnCount() {
067: return 3;
068: }
069:
070: public int getRowCount() {
071: return sentences.size();
072: }
073:
074: public boolean isCellEditable(int rowIndex, int columnIndex) {
075: return false;
076: }
077:
078: public Object getValueAt(int row, int col) {
079: Sentence s = (Sentence) sentences.elementAt(row);
080:
081: if (col == COLUMN_SENTENCE) {
082: return s.getSentence();
083: } else if (col == COLUMN_TRANSLATION) {
084: return s.getTranslation();
085: } else if (col == COLUMN_SOURCEFILE) {
086: int line = s.getLinePosition();
087: String loc = s.getLocationClass();
088: if (loc.equals(""))
089: return "";
090: return loc + " : " + (line == -1 ? "?" : "" + line);
091: } else if (col == COLUMN_SOURCELINE) {
092: return "" + s.getLinePosition();
093: }
094: return "?";
095: }
096:
097: public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
098: // not editable
099: }
100:
101: public Class getColumnClass(int column) {
102: Object obj = getValueAt(0, column);
103: return obj.getClass();
104: }
105:
106: public int compareForColumnSort(int pos1, int pos2, int col) {
107: Sentence s1 = (Sentence) sentences.elementAt(pos1);
108: Sentence s2 = (Sentence) sentences.elementAt(pos2);
109:
110: if (col == COLUMN_SENTENCE) {
111: return s1.getSentence().compareToIgnoreCase(
112: s2.getSentence());
113: } else if (col == COLUMN_TRANSLATION) {
114: return s1.getTranslation().compareToIgnoreCase(
115: s2.getTranslation());
116: } else if (col == COLUMN_SOURCEFILE) {
117: return s1.getLocationClass().compareToIgnoreCase(
118: s2.getLocationClass());
119: } else if (col == COLUMN_SOURCELINE) {
120: int l1 = s1.getLinePosition();
121: int l2 = s2.getLinePosition();
122: if (l1 == l2)
123: return 0;
124: if (l1 < l2)
125: return -1;
126: return 1;
127: }
128: return 0;
129: }
130:
131: public boolean hitForTextSearch(int row, String txt) {
132: String upt = txt.toUpperCase();
133: Sentence s = (Sentence) sentences.elementAt(row);
134:
135: if (s.getSentence().toUpperCase().indexOf(upt) != -1)
136: return true;
137: if (s.getTranslation().toUpperCase().indexOf(upt) != -1)
138: return true;
139:
140: return false;
141: }
142:
143: } // SentencesTableModel
|