package kiyut.alkitab.options;

import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import kiyut.alkitab.api.TransformerHints;
import kiyut.alkitab.util.SwordUtilities;
import kiyut.swing.combo.SeparatorComboBox;
import org.crosswire.jsword.book.Book;
import org.crosswire.jsword.book.BookFilters;
import org.crosswire.jsword.book.Books;

/**
 *
 */
public class BookViewerOptionsPane extends AbstractOptionsPane {
    protected ResourceBundle bundle = ResourceBundle.getBundle(this.getClass().getName());    
    
    /** Creates new BookViewerOptionsPane */
    public BookViewerOptionsPane() {
        initComponents();
        initCustom();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        parallelBookLimitComboBox = new javax.swing.JComboBox();
        versesPerTabComboBox = new javax.swing.JComboBox();
        searchLimitComboBox = new javax.swing.JComboBox();
        fontPanel = new javax.swing.JPanel();
        fontComboBox =  new SeparatorComboBox();
        fontSizeComboBox = new javax.swing.JComboBox();
        fontBoldCheckBox = new javax.swing.JCheckBox();
        fontItalicCheckBox = new javax.swing.JCheckBox();
        jLabel8 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        defaultBibleComboBox = new javax.swing.JComboBox();
        defaultDictionaryComboBox = new javax.swing.JComboBox();
        defaultDailyDevotionsComboBox = new javax.swing.JComboBox();
        jPanel3 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        noVNumCheckBox = new javax.swing.JCheckBox();
        verseNumbersPane = new javax.swing.JPanel();
        vNumRadioButton = new javax.swing.JRadioButton();
        cvNumRadioButton = new javax.swing.JRadioButton();
        bcvNumRadioButton = new javax.swing.JRadioButton();
        tinyVNumCheckBox = new javax.swing.JCheckBox();
        vLineCheckBox = new javax.swing.JCheckBox();
        headingsCheckBox = new javax.swing.JCheckBox();
        notesCheckBox = new javax.swing.JCheckBox();
        strongsCheckBox = new javax.swing.JCheckBox();
        morphCheckBox = new javax.swing.JCheckBox();
        xRefCheckBox = new javax.swing.JCheckBox();
        jPanel5 = new javax.swing.JPanel();
        jPanel8 = new javax.swing.JPanel();
        jLabel10 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jLabel11 = new javax.swing.JLabel();
        jPanel6 = new javax.swing.JPanel();
        jTextField1 = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jPanel7 = new javax.swing.JPanel();
        jToolBar1 = new javax.swing.JToolBar();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();

        setLayout(new java.awt.BorderLayout());

        jPanel1.setBorder(javax.swing.BorderFactory.createEmptyBorder(12, 12, 12, 18));
        jPanel1.setLayout(new java.awt.GridBagLayout());

        jLabel1.setText(bundle.getString("CTL_ParallelLimit.Text")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 12);
        jPanel1.add(jLabel1, gridBagConstraints);

        jLabel2.setText(bundle.getString("CTL_VerseLimit.Text")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 12);
        jPanel1.add(jLabel2, gridBagConstraints);

        jLabel3.setText(bundle.getString("CTL_SearchLimit.Text")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 12);
        jPanel1.add(jLabel3, gridBagConstraints);

        jLabel4.setText(bundle.getString("CTL_Font.Text")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(8, 0, 0, 12);
        jPanel1.add(jLabel4, gridBagConstraints);

        parallelBookLimitComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "2", "3", "4", "5", "6", "7", "8", "9", "10" }));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
        jPanel1.add(parallelBookLimitComboBox, gridBagConstraints);

        versesPerTabComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "25", "50", "75", "100" }));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
        jPanel1.add(versesPerTabComboBox, gridBagConstraints);

        searchLimitComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "unlimited", "10", "20", "30", "40", "50", "75", "100", "125", "150", "175", "200" }));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.ipadx = 20;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
        jPanel1.add(searchLimitComboBox, gridBagConstraints);

        fontPanel.setLayout(new java.awt.GridBagLayout());
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.ipadx = 20;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 0.5;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 3);
        fontPanel.add(fontComboBox, gridBagConstraints);

        fontSizeComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "8", "9", "10", "11", "12", "13", "14", "16", "18", "20", "22", "24", "26", "28" }));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        fontPanel.add(fontSizeComboBox, gridBagConstraints);

        fontBoldCheckBox.setText(bundle.getString("CTL_FontBold.Tex")); // NOI18N
        fontBoldCheckBox.setToolTipText(bundle.getString("CTL_FontBold.Tex")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(3, 0, 0, 0);
        fontPanel.add(fontBoldCheckBox, gridBagConstraints);

        fontItalicCheckBox.setText(bundle.getString("CTL_FontItalic.Text")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        fontPanel.add(fontItalicCheckBox, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
        jPanel1.add(fontPanel, gridBagConstraints);

        jLabel8.setText(bundle.getString("CTL_DefaultBook.Text")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(20, 0, 0, 0);
        jPanel1.add(jLabel8, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(20, 0, 0, 0);
        jPanel1.add(jSeparator1, gridBagConstraints);

        jLabel5.setText(bundle.getString("CTL_DefaultBible.Text")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 12);
        jPanel1.add(jLabel5, gridBagConstraints);

        jLabel6.setText(bundle.getString("CTL_DefaultDictionary.Text")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(6, 12, 0, 12);
        jPanel1.add(jLabel6, gridBagConstraints);

        jLabel7.setText(bundle.getString("CTL_DefaultDailyDevotions.Text")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(6, 12, 0, 12);
        jPanel1.add(jLabel7, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 0);
        jPanel1.add(defaultBibleComboBox, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
        jPanel1.add(defaultDictionaryComboBox, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
        jPanel1.add(defaultDailyDevotionsComboBox, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 8;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        jPanel1.add(jPanel3, gridBagConstraints);

        jTabbedPane1.addTab(bundle.getString("CTL_GeneralCategory.Text"), jPanel1); // NOI18N

        jPanel2.setBorder(javax.swing.BorderFactory.createEmptyBorder(12, 12, 12, 12));
        jPanel2.setLayout(new java.awt.GridBagLayout());

        noVNumCheckBox.setText(bundle.getString("CTL_NoVNum.Text")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 0);
        jPanel2.add(noVNumCheckBox, gridBagConstraints);

        verseNumbersPane.setLayout(new java.awt.GridBagLayout());

        vNumRadioButton.setText(bundle.getString("CTL_VNum.Text")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        verseNumbersPane.add(vNumRadioButton, gridBagConstraints);

        cvNumRadioButton.setText(bundle.getString("CTL_CVNum.Text")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
        verseNumbersPane.add(cvNumRadioButton, gridBagConstraints);

        bcvNumRadioButton.setText(bundle.getString("CTL_BCVNum.Text")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
        verseNumbersPane.add(bcvNumRadioButton, gridBagConstraints);

        tinyVNumCheckBox.setText(bundle.getString("CTL_TinyVNum.Text")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
        verseNumbersPane.add(tinyVNumCheckBox, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(6, 40, 6, 0);
        jPanel2.add(verseNumbersPane, gridBagConstraints);

        vLineCheckBox.setText(bundle.getString("CTL_VLine.Text")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(6, 12, 0, 0);
        jPanel2.add(vLineCheckBox, gridBagConstraints);

        headingsCheckBox.setText(bundle.getString("CTL_Headings.Text")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(6, 12, 0, 0);
        jPanel2.add(headingsCheckBox, gridBagConstraints);

        notesCheckBox.setText(bundle.getString("CTL_Notes.Text")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(6, 12, 0, 0);
        jPanel2.add(notesCheckBox, gridBagConstraints);

        strongsCheckBox.setText(bundle.getString("CTL_Strongs.Text")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(6, 12, 0, 0);
        jPanel2.add(strongsCheckBox, gridBagConstraints);

        morphCheckBox.setText(bundle.getString("CTL_Morph.Text")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(6, 12, 0, 0);
        jPanel2.add(morphCheckBox, gridBagConstraints);

        xRefCheckBox.setText(bundle.getString("CTL_XRef.Text")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(6, 12, 0, 0);
        jPanel2.add(xRefCheckBox, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 8;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        jPanel2.add(jPanel5, gridBagConstraints);

        jTabbedPane1.addTab(bundle.getString("CTL_ViewerCategory.Text"), jPanel2); // NOI18N

        jPanel8.setBorder(javax.swing.BorderFactory.createEmptyBorder(12, 12, 12, 12));
        jPanel8.setLayout(new java.awt.GridBagLayout());

        jLabel10.setText(bundle.getString("CTL_BookPath.Text")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(14, 0, 0, 12);
        jPanel8.add(jLabel10, gridBagConstraints);

        jList1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane1.setViewportView(jList1);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 0);
        jPanel8.add(jScrollPane1, gridBagConstraints);

        jLabel11.setText(bundle.getString("CTL_DownloadPath.Text")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 12);
        jPanel8.add(jLabel11, gridBagConstraints);

        jPanel6.setLayout(new java.awt.GridBagLayout());
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 1.0;
        jPanel6.add(jTextField1, gridBagConstraints);

        jButton1.setText(bundle.getString("CTL_DownloadPathBrowse.Text")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.insets = new java.awt.Insets(0, 3, 0, 0);
        jPanel6.add(jButton1, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
        jPanel8.add(jPanel6, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        jPanel8.add(jPanel7, gridBagConstraints);

        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/kiyut/alkitab/swing/plus.png"))); // NOI18N
        jButton2.setFocusable(false);
        jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton2);

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/kiyut/alkitab/swing/minus.png"))); // NOI18N
        jButton3.setFocusable(false);
        jButton3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton3.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton3);

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/kiyut/alkitab/swing/up.png"))); // NOI18N
        jButton4.setFocusable(false);
        jButton4.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton4.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton4);

        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/kiyut/alkitab/swing/down.png"))); // NOI18N
        jButton5.setFocusable(false);
        jButton5.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton5.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton5);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanel8.add(jToolBar1, gridBagConstraints);

        jTabbedPane1.addTab(bundle.getString("CTL_PathCategory.Text"), jPanel8); // NOI18N

        add(jTabbedPane1, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JRadioButton bcvNumRadioButton;
    private javax.swing.JRadioButton cvNumRadioButton;
    private javax.swing.JComboBox defaultBibleComboBox;
    private javax.swing.JComboBox defaultDailyDevotionsComboBox;
    private javax.swing.JComboBox defaultDictionaryComboBox;
    private javax.swing.JCheckBox fontBoldCheckBox;
    private javax.swing.JComboBox fontComboBox;
    private javax.swing.JCheckBox fontItalicCheckBox;
    private javax.swing.JPanel fontPanel;
    private javax.swing.JComboBox fontSizeComboBox;
    private javax.swing.JCheckBox headingsCheckBox;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JList jList1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JCheckBox morphCheckBox;
    private javax.swing.JCheckBox noVNumCheckBox;
    private javax.swing.JCheckBox notesCheckBox;
    private javax.swing.JComboBox parallelBookLimitComboBox;
    private javax.swing.JComboBox searchLimitComboBox;
    private javax.swing.JCheckBox strongsCheckBox;
    private javax.swing.JCheckBox tinyVNumCheckBox;
    private javax.swing.JCheckBox vLineCheckBox;
    private javax.swing.JRadioButton vNumRadioButton;
    private javax.swing.JPanel verseNumbersPane;
    private javax.swing.JComboBox versesPerTabComboBox;
    private javax.swing.JCheckBox xRefCheckBox;
    // End of variables declaration//GEN-END:variables

    private void initCustom() {
        fontComboBox.setModel(new DefaultComboBoxModel());
        defaultBibleComboBox.setModel(new DefaultComboBoxModel());
        defaultDictionaryComboBox.setModel(new DefaultComboBoxModel());
        defaultDailyDevotionsComboBox.setModel(new DefaultComboBoxModel());
        
        noVNumCheckBox.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                boolean sel = noVNumCheckBox.isSelected();
                for (int i=0; i<verseNumbersPane.getComponentCount(); i++) {
                    verseNumbersPane.getComponent(i).setEnabled(!sel);
                }
            }
        });
        
        refreshAvailableFonts();
        refreshDefaultBooks();
    }
    
    @Override
    public void refreshOptions() {
        ////////////////////////
        // BookViewerOptions
        
        BookViewerOptions viewerOpts = BookViewerOptions.getInstance();
        
        parallelBookLimitComboBox.setSelectedItem(Integer.toString(viewerOpts.getParallelBookLimit()));
        versesPerTabComboBox.setSelectedItem(Integer.toString(viewerOpts.getVersesPerTab()));
        searchLimitComboBox.setSelectedItem(Integer.toString(viewerOpts.getSearchLimit()));
        
        String name = viewerOpts.getDefaultBible();
        if (name != null) {
            int index = indexOfDefaultBooks(defaultBibleComboBox.getModel(), name);
            if (index >= 0) {
                defaultBibleComboBox.setSelectedIndex(index);
            }
        }
        name = viewerOpts.getDefaultDictionary();
        if (name != null) {
            int index = indexOfDefaultBooks(defaultDictionaryComboBox.getModel(), name);
            if (index >= 0) {
                defaultDictionaryComboBox.setSelectedIndex(index);
            }
        }
        name = viewerOpts.getDefaultDailyDevotions();
        if (name != null) {
            int index = indexOfDefaultBooks(defaultDailyDevotionsComboBox.getModel(), name);
            if (index >= 0) {
                defaultDailyDevotionsComboBox.setSelectedIndex(index);
            }
        }
        
        
        ////////////////////////
        // TransformerHintsOptions
        
        TransformerHints<TransformerHints.Key,Object> hints = TransformerHintsOptions.getInstance().getTransformerHints();
        Object hintsVal;
        
        hintsVal = hints.get(TransformerHints.NO_VERSE_NUMBERS);
        noVNumCheckBox.setSelected(((Boolean)hintsVal).booleanValue());
        hintsVal = hints.get(TransformerHints.VERSE_NUMBERS);
        boolean vNum = ((Boolean)hintsVal).booleanValue();
        hintsVal = hints.get(TransformerHints.CHAPTER_VERSE_NUMBERS);
        boolean cvNum = ((Boolean)hintsVal).booleanValue();
        
        if (vNum) {
            vNumRadioButton.setSelected(true);
        } else {
            if (cvNum) {
                cvNumRadioButton.setSelected(true);
            } else {
                bcvNumRadioButton.setSelected(true);
            }
        }
        
        hintsVal = hints.get(TransformerHints.TINY_VERSE_NUMBERS);
        tinyVNumCheckBox.setSelected(((Boolean)hintsVal).booleanValue());
        hintsVal = hints.get(TransformerHints.START_VERSE_ON_NEWLINE);
        vLineCheckBox.setSelected(((Boolean)hintsVal).booleanValue());
        hintsVal = hints.get(TransformerHints.HEADINGS);
        headingsCheckBox.setSelected(((Boolean)hintsVal).booleanValue());
        hintsVal = hints.get(TransformerHints.NOTES);
        notesCheckBox.setSelected(((Boolean)hintsVal).booleanValue());
        hintsVal = hints.get(TransformerHints.STRONGS_NUMBERS);
        strongsCheckBox.setSelected(((Boolean)hintsVal).booleanValue());
        hintsVal = hints.get(TransformerHints.MORPH);
        morphCheckBox.setSelected(((Boolean)hintsVal).booleanValue());
        hintsVal = hints.get(TransformerHints.XREF);
        xRefCheckBox.setSelected(((Boolean)hintsVal).booleanValue());

        
        String fontDef = hints.get(TransformerHints.FONT).toString();
        String[] fontDefs = fontDef.split(",");
        if (fontDefs.length < 3) {
            // invalid font definitions, set default; serif,0,14
            fontComboBox.setSelectedIndex(0);
            fontSizeComboBox.setSelectedItem(Integer.toString(14));
            fontBoldCheckBox.setSelected(false);
            fontItalicCheckBox.setSelected(false);
        } else {
            fontComboBox.setSelectedItem(fontDefs[0]);
            fontSizeComboBox.setSelectedItem(fontDefs[2]);
            try {
                int style = Integer.valueOf(fontDefs[1]);
                if (style == Font.PLAIN) {
                    fontBoldCheckBox.setSelected(false);
                    fontItalicCheckBox.setSelected(false);
                } else {
                    fontBoldCheckBox.setSelected((style & Font.BOLD) != 0);
                    fontItalicCheckBox.setSelected((style & Font.ITALIC) != 0);
                }
            } catch (Exception ex) {
                Logger logger = Logger.getLogger(this.getClass().getName());
                logger.log(Level.WARNING, ex.getMessage(),ex );
            }
        }
    }

    @Override
    public void applyChanges() {
        BookViewerOptions viewerOpts = BookViewerOptions.getInstance();
        viewerOpts.setParallelBookLimit(Integer.parseInt(parallelBookLimitComboBox.getSelectedItem().toString()));
        viewerOpts.setVersesPerTab(Integer.parseInt(versesPerTabComboBox.getSelectedItem().toString()));
        if (searchLimitComboBox.getSelectedIndex() == 0) {
            // unlimited
            viewerOpts.setSearchLimit(0);
        } else {
            viewerOpts.setSearchLimit(Integer.parseInt(searchLimitComboBox.getSelectedItem().toString()));
        }
        
        
        String initials = null;
        if (defaultBibleComboBox.getSelectedIndex() > 0) {
            initials = defaultBibleComboBox.getSelectedItem().toString();
            initials = initials.substring(0,initials.indexOf('-') - 1);
            //System.out.println(initials + "TEST");
            viewerOpts.setDefaultBible(initials);
        } else {
            viewerOpts.setDefaultBible(null);
        }
        
        if (defaultDictionaryComboBox.getSelectedIndex() > 0) {
            initials = defaultDictionaryComboBox.getSelectedItem().toString();
            initials = initials.substring(0,initials.indexOf('-') - 1);
            viewerOpts.setDefaultDictionary(initials);
        } else {
            viewerOpts.setDefaultDictionary(null);
        }
        
        if (defaultDailyDevotionsComboBox.getSelectedIndex() > 0) {
            initials = defaultDailyDevotionsComboBox.getSelectedItem().toString();
            initials = initials.substring(0,initials.indexOf('-') - 1);
            viewerOpts.setDefaultDailyDevotions(initials);
        } else {
            viewerOpts.setDefaultDailyDevotions(null);
        }
        
        
        viewerOpts.save();
        
        
        TransformerHints<TransformerHints.Key,Object> hints = TransformerHintsOptions.getInstance().getTransformerHints();
        hints.put(TransformerHints.NO_VERSE_NUMBERS, noVNumCheckBox.isSelected());
        hints.put(TransformerHints.VERSE_NUMBERS, vNumRadioButton.isSelected());
        hints.put(TransformerHints.CHAPTER_VERSE_NUMBERS, cvNumRadioButton.isSelected());
        hints.put(TransformerHints.BOOK_CHAPTER_VERSE_NUMBERS, bcvNumRadioButton.isSelected());
        hints.put(TransformerHints.TINY_VERSE_NUMBERS, tinyVNumCheckBox.isSelected());
        hints.put(TransformerHints.START_VERSE_ON_NEWLINE, vLineCheckBox.isSelected());
        hints.put(TransformerHints.HEADINGS, headingsCheckBox.isSelected());
        hints.put(TransformerHints.NOTES, notesCheckBox.isSelected());
        hints.put(TransformerHints.STRONGS_NUMBERS, strongsCheckBox.isSelected());
        hints.put(TransformerHints.MORPH, morphCheckBox.isSelected());
        hints.put(TransformerHints.XREF, xRefCheckBox.isSelected());
        
        int style = Font.PLAIN;
        style = fontBoldCheckBox.isSelected() ? style | Font.BOLD : style;
        style = fontItalicCheckBox.isSelected() ? style | Font.ITALIC : style;
        String fontDefs = fontComboBox.getSelectedItem().toString() + "," + style + "," + fontSizeComboBox.getSelectedItem().toString();
        hints.put(TransformerHints.FONT, fontDefs);
        //System.out.println(fontDefs + "   TEST ONLY");
        
        TransformerHintsOptions.getInstance().save();
    }
    
    
    
    protected void refreshAvailableFonts() {
        DefaultComboBoxModel model = (DefaultComboBoxModel)fontComboBox.getModel();
        model.removeAllElements();
        
        // add generic font family
        model.addElement("serif");
        model.addElement("sans-serif");
        model.addElement("monospace");
        model.addElement("cursive");
        model.addElement("fantasy");
        model.addElement(SeparatorComboBox.DEFAULT_SEPARATOR);
        
        String fontList[] = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
        for ( int i = 0; i < fontList.length; i++ ) {
            model.addElement(fontList[i]);
        }
    }
    
    protected void refreshDefaultBooks() {
        Comparator<Book> comparator = SwordUtilities.getBookInitialsComparator();
        DefaultComboBoxModel model;
        
        List<Book> bibles = new ArrayList<Book>();
        bibles.addAll(Books.installed().getBooks(BookFilters.getOnlyBibles()));
        Collections.sort(bibles, comparator);
        model = (DefaultComboBoxModel)defaultBibleComboBox.getModel();
        model.removeAllElements();
        model.addElement("None");
        for (int i=0; i<bibles.size(); i++) {
            model.addElement(bibles.get(i).getInitials() + " - " + bibles.get(i).getName());
        }
        
        List<Book> dictionaries = new ArrayList<Book>();
        dictionaries.addAll(Books.installed().getBooks(BookFilters.getDictionaries()));
        Collections.sort(dictionaries, comparator);
        model = (DefaultComboBoxModel)defaultDictionaryComboBox.getModel();
        model.removeAllElements();
        model.addElement("None");
        for (int i=0; i<dictionaries.size(); i++) {
            model.addElement(dictionaries.get(i).getInitials() + " - " + dictionaries.get(i).getName());
        }
        
        List<Book> dailies = new ArrayList<Book>();
        dailies.addAll(Books.installed().getBooks(BookFilters.getDailyDevotionals()));
        Collections.sort(dailies, comparator);
        model = (DefaultComboBoxModel)defaultDailyDevotionsComboBox.getModel();
        model.removeAllElements();
        model.addElement("None");
        for (int i=0; i<dailies.size(); i++) {
            model.addElement(dailies.get(i).getInitials() + " - " + dailies.get(i).getName());
        }
    }
    
    private int indexOfDefaultBooks(ComboBoxModel model, String search) {
        int index = -1;
        
        for (int i=0; i<model.getSize();i++) {
            Object obj = model.getElementAt(i);
            if ((obj == null)) { continue; }
            if (!(obj instanceof String)) { continue; }
            if (obj.toString().startsWith(search)) {
                index = i;
                break;
            }
        }
        
        return index;
    }
}
