Source code: com/eireneh/bible/view/awt/beans/Display.java
1
2 package com.eireneh.bible.view.awt.beans;
3
4 import java.util.*;
5 import java.awt.*;
6 import java.awt.event.*;
7
8 import com.eireneh.util.*;
9 import com.eireneh.bible.passage.*;
10 import com.eireneh.bible.book.*;
11
12 /**
13 * An AWT Bible display pane.
14 * TODO: Re-write this using Tasks
15 *
16 * <table border='1' cellPadding='3' cellSpacing='0' width="100%">
17 * <tr><td bgColor='white'class='TableRowColor'><font size='-7'>
18 * Distribution Licence:<br />
19 * Project B is free software; you can redistribute it
20 * and/or modify it under the terms of the GNU General Public License,
21 * version 2 as published by the Free Software Foundation.<br />
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 * General Public License for more details.<br />
26 * The License is available on the internet
27 * <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, by writing to
28 * <i>Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
29 * MA 02111-1307, USA</i>, Or locally at the Licence link below.<br />
30 * The copyright to this program is held by it's authors.
31 * </font></td></tr></table>
32 * @see <a href='http://www.eireneh.com/servlets/Web'>Project B Home</a>
33 * @see docs.Licence
34 * @author Joe Walker
35 * @version D9.I9.T6
36 */
37 public class Display extends Panel
38 {
39 /**
40 * Create a basic swing display
41 */
42 public Display()
43 {
44 jbInit();
45 }
46
47 /**
48 * Initialize the gui components
49 */
50 private void jbInit()
51 {
52 cbo_type.addItem("View");
53 cbo_type.addItem("Match");
54 cbo_type.addItem("Search");
55 cbo_type.addItem("Help");
56
57 btn_go.setLabel("GO");
58 btn_go.addActionListener(new ActionListener()
59 {
60 public void actionPerformed(ActionEvent ev)
61 {
62 view();
63 }
64 });
65 txt_query.addKeyListener(new KeyAdapter()
66 {
67 public void keyTyped(KeyEvent ev)
68 {
69 if (ev.getKeyCode() == KeyEvent.VK_ENTER)
70 view();
71 }
72 });
73
74 pnl_top.setLayout(new BorderLayout());
75 pnl_top.add(cbo_type, BorderLayout.WEST);
76 pnl_top.add(txt_query, BorderLayout.CENTER);
77 pnl_top.add(btn_go, BorderLayout.EAST);
78
79 txt_results.setEditable(false);
80 scr_results.add(txt_results, null);
81
82 this.setLayout(new BorderLayout());
83 this.add(scr_results, BorderLayout.CENTER);
84 this.add(pnl_top, BorderLayout.NORTH);
85 }
86
87 /**
88 * When someone clicks on the GO button
89 */
90 public void view()
91 {
92 String input = txt_query.getText();
93
94 String next_type = OPTIONS[QUERY_PASSAGE];
95 String next_input = DEFAULT_PASSAGE;
96 Passage ref = null;
97 Passage remainder = null;
98 //String error = null;
99 String results = "";
100
101 try
102 {
103 Bible version = Bibles.getDefaultBible();
104
105 switch (cbo_type.getSelectedIndex())
106 {
107 case QUERY_PASSAGE:
108 case QUERY_FAST_PASS:
109 ref = PassageFactory.createPassage(input);
110 remainder = ref.trimVerses(VERSES_MAX);
111 next_input = remainder == null ? ref.getName() : remainder.getName();
112 Enumeration en = ref.rangeElements();
113 while (en.hasMoreElements())
114 {
115 VerseRange range = (VerseRange) en.nextElement();
116 results += range.toString();
117 results += " ";
118 results += version.getText(range);
119 results += "\n";
120 }
121 break;
122
123 case QUERY_MATCH:
124 // To Do
125 break;
126
127 case QUERY_SEARCH:
128 // To Do
129 break;
130
131 case QUERY_HELP:
132 txt_results.setText(HELP_MSG);
133 break;
134 }
135 }
136 catch (Exception ex)
137 {
138 log.log(Level.INFO, "Failure", ex);
139 txt_results.setText(ex.getMessage());
140 }
141 }
142
143 /** The top panel */
144 protected Panel pnl_top = new Panel();
145
146 /** The query chooser */
147 protected Choice cbo_type = new Choice();
148
149 /** The query entry box */
150 protected TextField txt_query = new TextField();
151
152 /** The GO button */
153 protected Button btn_go = new Button();
154
155 /** The results */
156 protected TextArea txt_results = new TextArea();
157
158 /** The results scroller */
159 protected ScrollPane scr_results = new ScrollPane();
160
161 /** The log stream */
162 protected static Logger log = Logger.getLogger("bible.view");
163
164 /** The default Passage to view */
165 private static final String DEFAULT_PASSAGE = "Gen 1:1-5";
166
167 /** The Available options */
168 private static final String OPTIONS[] =
169 {
170 "View Passage",
171 "Best Match Search",
172 "Power Search",
173 "Quick Passage",
174 "Help",
175 };
176
177 /** Query of type passage - must match the index below */
178 private static final int QUERY_PASSAGE = 0;
179
180 /** Query of type best match - must match the index below */
181 private static final int QUERY_MATCH = 1;
182
183 /** Query of type search - must match the index below */
184 private static final int QUERY_SEARCH = 2;
185
186 /** Query of type search - must match the index below */
187 private static final int QUERY_FAST_PASS = 3;
188
189 /** Query of type help - must match the index below */
190 private static final int QUERY_HELP = 4;
191
192 /** The maximum number of verses to fetch at a time */
193 private static final int VERSES_MAX = 35;
194
195 /** The Help string */
196 protected static final String HELP_MSG =
197 "Welcome: There are 3 different types of query you can execute on this server.\n " +
198 "View Passage: Selecting this option and then entering a passage\n" +
199 "description will enable you to see the Biblical text of the specified verses.\n " +
200 "The parser is quite advanced, so the following will work: 'gen 1', 'Jude 2',\n "+
201 "'MAT 1:3,4,7-8,5-6'\n\n" +
202 "Best Match Search: This attempts to find a passage the matches that text that\n "+
203 "you entered. Note the implementation of this is mediocre right now. There are\n "+
204 "several tweaks in the pipeline that will make this much better. So expect slow\n "+
205 "and imperfect matches. God willing it will get better.\n\n" +
206 "Power Search: This allows you to search for a word or words. You can use a\n "+
207 "searches syntax like the OnLine Bible e.g. 'aaron & moses' searches for Aaron\n "+
208 "and Moses, and 'aaron | moses' finds verses with Aaron or Moses.\n\n" +
209 "Quick Passage: This is similar to 'View Passage'\n "+
210 "with the emphasis here on speed. View Passage provides customizable views, linkingv "+
211 "technology, and so on. Quick Passage just gives you the text.\n\n" +
212 "Help: Gets back to this message.\n\n" +
213 "The Config screen allows you to select a Bible view style.\n "+
214 "(Amongst other stuff like the current version, and the web page style)\n "+
215 "This option shows off the power of using XSL as a template language. At the timev "+
216 "of writing there are 2 styles. 'Oxford' looks like my old AV, uses ¶ marks to\n "+
217 "denote new paragraphs, uses a serifed font. 'Modern' uses different fonts and\n "+
218 "colours, includes a small graphic (which adds nothing other than proof that we "+
219 "can do graphics) and even links - Try clicking on the verse numbers.\n";
220 }