package kiyut.alkitab.swing;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ResourceBundle;
import javax.swing.JOptionPane;
import kiyut.alkitab.api.TransformerHints;

/**
 *
 * 
 */
public class TransformerHintsPane extends javax.swing.JPanel {
    protected ResourceBundle bundle = ResourceBundle.getBundle(this.getClass().getName()); 
    
    protected TransformerHints<TransformerHints.Key,Object> transformerHints;

    /** Creates new form TransformerHintsPane */
    public TransformerHintsPane() {
        this(null);
    }
    
    public TransformerHintsPane(TransformerHints<TransformerHints.Key,Object> transformerHints) {
        initComponents();
        initCustom();
        if (transformerHints != null) {
            setTransformerHints(transformerHints);
        }
    }

    /** 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.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        verseButtonGroup = new javax.swing.ButtonGroup();
        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();

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

        noVNumCheckBox.setText(bundle.getString("CTL_NoVNum.Text")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        add(noVNumCheckBox, gridBagConstraints);

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

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

        verseButtonGroup.add(cvNumRadioButton);
        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(3, 0, 0, 0);
        verseNumbersPane.add(cvNumRadioButton, gridBagConstraints);

        verseButtonGroup.add(bcvNumRadioButton);
        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(3, 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(3, 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(3, 24, 0, 0);
        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(3, 0, 0, 0);
        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(3, 0, 0, 0);
        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(3, 0, 0, 0);
        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(3, 0, 0, 0);
        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(3, 0, 0, 0);
        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(3, 0, 0, 0);
        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;
        add(jPanel5, gridBagConstraints);
    }// </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.JCheckBox headingsCheckBox;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JCheckBox morphCheckBox;
    private javax.swing.JCheckBox noVNumCheckBox;
    private javax.swing.JCheckBox notesCheckBox;
    private javax.swing.JCheckBox strongsCheckBox;
    private javax.swing.JCheckBox tinyVNumCheckBox;
    private javax.swing.JCheckBox vLineCheckBox;
    private javax.swing.JRadioButton vNumRadioButton;
    private javax.swing.ButtonGroup verseButtonGroup;
    private javax.swing.JPanel verseNumbersPane;
    private javax.swing.JCheckBox xRefCheckBox;
    // End of variables declaration//GEN-END:variables

    
    protected void initCustom() {
        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);
                }
            }
        });
    }
    
    /** Show as Dialog 
     * @param parentComponent {@code Component}
     */
    public int showDialog(Component parentComponent) {
        int choice = JOptionPane.showConfirmDialog(parentComponent,this,bundle.getString("CTL_Title.Text"),JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
        return choice;
    }
    
    public void setTransformerHints(TransformerHints<TransformerHints.Key,Object> transformerHints) {
        this.transformerHints = transformerHints;
        if (transformerHints == null) {
            return;
        }
        
        Object val;
        
        val = transformerHints.get(TransformerHints.NO_VERSE_NUMBERS);
        noVNumCheckBox.setSelected(((Boolean)val).booleanValue());
        val = transformerHints.get(TransformerHints.VERSE_NUMBERS);
        boolean vNum = ((Boolean)val).booleanValue();
        val = transformerHints.get(TransformerHints.CHAPTER_VERSE_NUMBERS);
        boolean cvNum = ((Boolean)val).booleanValue();
        
        if (vNum) {
            vNumRadioButton.setSelected(true);
        } else {
            if (cvNum) {
                cvNumRadioButton.setSelected(true);
            } else {
                bcvNumRadioButton.setSelected(true);
            }
        }
        
        val = transformerHints.get(TransformerHints.TINY_VERSE_NUMBERS);
        tinyVNumCheckBox.setSelected(((Boolean)val).booleanValue());
        val = transformerHints.get(TransformerHints.START_VERSE_ON_NEWLINE);
        vLineCheckBox.setSelected(((Boolean)val).booleanValue());
        val = transformerHints.get(TransformerHints.HEADINGS);
        headingsCheckBox.setSelected(((Boolean)val).booleanValue());
        val = transformerHints.get(TransformerHints.NOTES);
        notesCheckBox.setSelected(((Boolean)val).booleanValue());
        val = transformerHints.get(TransformerHints.STRONGS_NUMBERS);
        strongsCheckBox.setSelected(((Boolean)val).booleanValue());
        val = transformerHints.get(TransformerHints.MORPH);
        morphCheckBox.setSelected(((Boolean)val).booleanValue());
        val = transformerHints.get(TransformerHints.XREF);
        xRefCheckBox.setSelected(((Boolean)val).booleanValue());
    }
    
    public void updateTransformerHintsValue() {
        transformerHints.put(TransformerHints.NO_VERSE_NUMBERS, noVNumCheckBox.isSelected());
        transformerHints.put(TransformerHints.VERSE_NUMBERS, vNumRadioButton.isSelected());
        transformerHints.put(TransformerHints.CHAPTER_VERSE_NUMBERS, cvNumRadioButton.isSelected());
        transformerHints.put(TransformerHints.BOOK_CHAPTER_VERSE_NUMBERS, bcvNumRadioButton.isSelected());
        transformerHints.put(TransformerHints.TINY_VERSE_NUMBERS, tinyVNumCheckBox.isSelected());
        transformerHints.put(TransformerHints.START_VERSE_ON_NEWLINE, vLineCheckBox.isSelected());
        transformerHints.put(TransformerHints.HEADINGS, headingsCheckBox.isSelected());
        transformerHints.put(TransformerHints.NOTES, notesCheckBox.isSelected());
        transformerHints.put(TransformerHints.STRONGS_NUMBERS, strongsCheckBox.isSelected());
        transformerHints.put(TransformerHints.MORPH, morphCheckBox.isSelected());
        transformerHints.put(TransformerHints.XREF, xRefCheckBox.isSelected());
    }
}
