Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/eireneh/bible/book/swing/ComparePane.java


1   
2   package com.eireneh.bible.book.swing;
3   
4   import java.io.*;
5   import java.awt.*;
6   import java.awt.event.*;
7   
8   import javax.swing.*;
9   import javax.swing.text.*;
10  import javax.swing.border.*;
11  
12  import com.eireneh.util.*;
13  import com.eireneh.swing.*;
14  import com.eireneh.bible.passage.*;
15  import com.eireneh.bible.book.*;
16  
17  /**
18   * A ComparePane allows you to compare 2 differing version of the Bible
19   * verse, by verse.
20   *
21   * <table border='1' cellPadding='3' cellSpacing='0' width="100%">
22   * <tr><td bgColor='white'class='TableRowColor'><font size='-7'>
23   * Distribution Licence:<br />
24   * Project B is free software; you can redistribute it
25   * and/or modify it under the terms of the GNU General Public License,
26   * version 2 as published by the Free Software Foundation.<br />
27   * This program is distributed in the hope that it will be useful,
28   * but WITHOUT ANY WARRANTY; without even the implied warranty of
29   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30   * General Public License for more details.<br />
31   * The License is available on the internet
32   * <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, by writing to
33   * <i>Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
34   * MA 02111-1307, USA</i>, Or locally at the Licence link below.<br />
35   * The copyright to this program is held by it's authors.
36   * </font></td></tr></table>
37   * @see <a href='http://www.eireneh.com/servlets/Web'>Project B Home</a>
38   * @see docs.Licence
39   * @author Joe Walker
40   */
41  public class ComparePane extends EirPanel
42  {
43      /**
44       * Basic Constructor
45       */
46      public ComparePane()
47      {
48          jbInit();
49      }
50  
51      /**
52       * Generate the GUI
53       */
54      private void jbInit()
55      {
56          cbo_bible1.setModel(mdl_bibles1);
57          cbo_bible2.setModel(mdl_bibles2);
58          pnl_bibles.setLayout(new BoxLayout(pnl_bibles, BoxLayout.Y_AXIS));
59          pnl_bibles.setAlignmentX((float) 0.5);
60          pnl_bibles.setBorder(new TitledBorder("Bibles To Compare"));
61          btn_go.addActionListener(new ActionListener()
62          {
63              public void actionPerformed(ActionEvent ev) { compare(); }
64          });
65          pnl_bibles.add(cbo_bible1, null);
66          pnl_bibles.add(Box.createVerticalStrut(5), null);
67          pnl_bibles.add(cbo_bible2, null);
68  
69          txt_verses.setText(PassageFactory.getWholeBiblePassage().toString());
70          lbl_verses.setText("Verses: ");
71          lbl_verses.setDisplayedMnemonic('V');
72          lbl_verses.setLabelFor(txt_verses);
73          pnl_verses.setLayout(new BorderLayout());
74          pnl_verses.add(lbl_verses, BorderLayout.WEST);
75          pnl_verses.add(txt_verses, BorderLayout.CENTER);
76          txt_words.setToolTipText("[empty] - test no words; * - test all words, text - test all words starting with 'text'");
77          lbl_words.setText("Words:  ");
78          lbl_words.setDisplayedMnemonic('W');
79          lbl_words.setLabelFor(txt_words);
80          pnl_words.setLayout(new BorderLayout());
81          pnl_words.add(lbl_words, BorderLayout.WEST);
82          pnl_words.add(txt_words, BorderLayout.CENTER);
83          pnl_using.setBorder(new TitledBorder("Compare Using"));
84          pnl_using.setLayout(new BoxLayout(pnl_using, BoxLayout.Y_AXIS));
85          pnl_using.add(pnl_verses, null);
86          pnl_using.add(pnl_words, null);
87  
88          btn_go.setMnemonic('C');
89          btn_go.setText("Compare");
90          pnl_buttons.setLayout(new FlowLayout(FlowLayout.RIGHT));
91          pnl_buttons.add(btn_go, null);
92  
93          box_top = Box.createVerticalBox();
94          box_top.add(pnl_bibles, null);
95          box_top.add(pnl_using, null);
96          box_top.add(pnl_buttons, null);
97  
98          this.setLayout(new BorderLayout());
99          this.add(box_top, BorderLayout.NORTH);
100     }
101 
102     /**
103      * Show this Panel in a new dialog
104      */
105     public void showInDialog(Component parent)
106     {
107         showInDialog(parent, "Bible Compare", false);
108     }
109 
110     /**
111      * Actually preform the comparison.
112      */
113     private void compare()
114     {
115         Bible bible1 = mdl_bibles1.getSelectedBible();
116         Bible bible2 = mdl_bibles2.getSelectedBible();
117 
118         if (bible1.equals(bible2))
119         {
120             if (JOptionPane.showConfirmDialog(this,
121                 "You are attempting to compare 2 Bibles that are identical.\n"+
122                 "Do you want to continue?",
123                 "Compare Identical Bibles?",
124                 JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION)
125             {
126                 return;
127             }
128         }
129 
130         Version version1 = bible1.getVersion();
131         Version version2 = bible2.getVersion();
132 
133         if (!version1.equals(version2))
134         {
135             if (JOptionPane.showConfirmDialog(this,
136                 "You are attempting to compare 2 Bibles that are of different versions.\n"+
137                 bible1.getName()+" is a "+version1+"\n"+
138                 bible2.getName()+" is a "+version2+"\n"+
139                 "Do you want to continue?",
140                 "Compare Differing Versions?",
141                 JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION)
142             {
143                 return;
144             }
145         }
146 
147         try
148         {
149             String words = txt_words.getText();
150             String ref_text = txt_verses.getText();
151             Passage ref = PassageFactory.createPassage(ref_text);
152 
153             words =words.trim();
154             if (words.equals("*")) words = "";
155             if (words.equals(""))  words = null;
156 
157             Verifier ver = new Verifier();
158             ver.setBible1(bible1);
159             ver.setBible2(bible2);
160 
161             CompareResultsPane results = new CompareResultsPane(ver);
162             results.setCheckText(words);
163             results.setCheckPassages(ref);
164             results.showInFrame(GuiUtil.getFrame(this));
165             results.startStop();
166         }
167         catch (NoSuchVerseException ex)
168         {
169             Reporter.informUser(this, ex);
170         }
171     }
172 
173     /** The first Bible selection combo */
174     private BiblesComboBoxModel mdl_bibles1 = new BiblesComboBoxModel();
175 
176     /** The second Bible selection combo */
177     private BiblesComboBoxModel mdl_bibles2 = new BiblesComboBoxModel();
178 
179     /* GUI Components */
180     private Box box_top;
181     private JPanel pnl_bibles = new JPanel();
182     private JPanel pnl_using = new JPanel();
183     private JPanel pnl_verses = new JPanel();
184     private JLabel lbl_verses = new JLabel();
185     private JTextField txt_verses = new JTextField();
186     private JPanel pnl_words = new JPanel();
187     private JLabel lbl_words = new JLabel();
188     private JTextField txt_words = new JTextField();
189     private JComboBox cbo_bible1 = new JComboBox();
190     private JComboBox cbo_bible2 = new JComboBox();
191     private JPanel pnl_buttons = new JPanel();
192     private JButton btn_go = new JButton();
193 }