Java tutorial
/* * Church Software * * Package : com.plugin.UI.Windows * Filename: BiblePeopleSearchResultsDialog.java * Author : Felix Chandrakumar <i@fc.id.au> * Website : www.churchsw.org * * PUBLIC DOMAIN * * As the Word of God says, * * Freely you have received, freely give. - (Mat 10:8). For all things are from Jesus Christ, * by Jesus Christ, and for Jesus Christ. - (Romans 11:36) * * Free means completely free! Church Software has no restrictions at all. The source code, * binary and everything that is not licensed by others but included in Church Software bundle * is released to public domain and you can modify anything to fit your church needs. Public * domain simply means everyone can use it without any restrictions. * * WHY PUBLIC DOMAIN? * * The manifestation of the Spirit is given to each one for the profit of all: for to one is * given the word of wisdom through the Spirit, to another the word of knowledge through the * same Spirit, to another faith by the same Spirit, to another gifts of healings by the same * Spirit, to another the working of miracles, to another prophecy, to another discerning of * spirits, to another different kinds of tongues, to another the interpretation of tongues. * But one and the same Spirit works all these things, distributing to each one individually * as He wills. - 1 Co 12:7-11 * * Woe unto them! for they have gone in the way of Cain, and ran greedily after the error of * Balaam for reward, and perished in the rebellion of Korah. - Jud 1:11 * * Jesus Christ gives word of knowledge through Holy Spirit for the profit of all. I dont * want to run greedily after the error of Balaam for reward. Balaam is a prophet of God who * went greedily to Balak. Unfortunately, many christian organizations, churches, bands, song * writers, musicians etc market the gifts of Holy Spirit, doing the same error of Balam for * reward. My Bible says, Woe to them and I don't want to be a part of them. */ package com.plugin.UI.Windows; import java.awt.Frame; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.util.ArrayList; import javax.swing.JDialog; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.WindowConstants; import javax.swing.table.DefaultTableModel; import org.apache.commons.codec.language.Soundex; import org.apache.log4j.Logger; import com.church.db.BiblePerson; import com.church.gateway.Global; import com.plugin.UI.Windows.BibleStudy.BibleGenealogy; /** * The Class BiblePeopleSearchResultsDialog. */ public class BiblePeopleSearchResultsDialog extends JDialog { /** The term. */ String term = null; /** The table. */ JTable table = null; /** The tm. */ DefaultTableModel tm = null; /** The log. */ Logger log = Logger.getLogger(this.getClass()); /** * Instantiates a new bible people search results dialog. * * @param owner the owner * @param _term the _term */ public BiblePeopleSearchResultsDialog(Frame owner, String _term) { super(owner); try { initialize(_term); term = _term; } catch (Exception e) { // TODO Auto-generated catch block log.error(e, e); } } /** * Initialize. * * @param _term the _term * * @throws Exception the exception */ private void initialize(String _term) throws Exception { ArrayList<String[]> arr = new ArrayList<String[]>(); for (BiblePerson bp : Global.biblePersons) { if (isSoundexCalc(bp.getName().toUpperCase(), _term)) { String[] arrin = new String[5]; arrin[0] = String.valueOf(bp.getName_id()); arrin[1] = bp.getName(); arrin[2] = bp.getFather(); arrin[3] = bp.getMother(); arrin[4] = bp.getBible_ref(); arr.add(arrin); } } String[][] arr3 = new String[arr.size()][5]; for (int i = 0; i < arr.size(); i++) arr3[i] = arr.get(i); String columns[] = new String[] { "ID", "Name", "Father", "Mother", "Reference" }; tm = new DefaultTableModel(arr3, columns) { public boolean isCellEditable(int row, int column) { return false; } }; table = new JTable(tm); table.addMouseListener(new MouseListener() { public void mouseClicked(MouseEvent e) { int member_id = Integer.parseInt((String) tm.getValueAt(table.getSelectedRow(), 0)); BibleGenealogy.setSelectMember(member_id); if (e.getClickCount() == 2) { new BiblePersonDialog(Global._jMainFrame, member_id); } } public void mouseEntered(MouseEvent e) { // TODO Auto-generated method stub } public void mouseExited(MouseEvent e) { // TODO Auto-generated method stub } public void mousePressed(MouseEvent e) { // TODO Auto-generated method stub } public void mouseReleased(MouseEvent e) { // TODO Auto-generated method stub } }); JScrollPane jsp = new JScrollPane(table); jsp.setSize(640, 260); this.getContentPane().add(jsp); this.pack(); this.setTitle("Bible People Search Results - " + _term); this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); this.setLocationRelativeTo(null); this.setVisible(true); } /** * Checks if is soundex calc. * * @param str the str * @param _term the _term * * @return true, if is soundex calc */ private boolean isSoundexCalc(String str, String _term) { Soundex s = new Soundex(); try { if (s.difference(str, _term) == 4) return true; } catch (Exception e) { return false; } if (str.indexOf(" ") != -1) { String[] str2 = str.split("[ ]"); for (int i = 0; i < str2.length; i++) { try { if (s.difference(str.split("[ ]")[i], _term) == 4) return true; } catch (Exception e) { return false; } } } return false; } } // @jve:decl-index=0:visual-constraint="10,10"