/*
 * JLoadPrefs.java
 *
 * Created on 23 Ιούνιος 2005, 2:27 μμ
 *
 * This file is part of Jubler.
 *
 * Jubler is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 2.
 *
 *
 * Jubler is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Jubler; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

package com.panayotis.jubler.options;
import com.panayotis.jubler.options.gui.JRateChooser;
import java.awt.BorderLayout;
import java.util.Properties;

import static com.panayotis.jubler.i18n.I18N._;
import com.panayotis.jubler.media.MediaFile;
import com.panayotis.jubler.subs.Subtitles;
import javax.swing.Icon;
import javax.swing.ImageIcon;

/**
 *
 * @author  teras
 */
public class JLoadOptions extends JFileOptions {
    
    private String enc1_state, enc2_state, enc3_state, fps_state;
    private JRateChooser CFPS;
    
    /** Creates new form JLoadPrefs */
    public JLoadOptions() {
        super();
        initComponents();
        
        /* Fix DialogVisible */
        add(DialogVisible, java.awt.BorderLayout.SOUTH);
        DialogVisible.setText(_(" Show load preferences while loading file"));
        DialogVisible.setToolTipText(_("Show preferences every time the user loads a subtitle file"));
        
        CFPS = new JRateChooser();
        FPSPanel.add(CFPS, BorderLayout.CENTER);
        fillComponents();
    }
    
    
    public void updateVisuals(MediaFile mfile, Subtitles subs) {
        CFPS.setDataFiles(mfile, subs);
    }
    
    private void fillComponents() {
        int i;
        for ( i = 0 ; i < JPreferences.AvailEncodings.length ; i++) {
            CEnc1.addItem(JPreferences.AvailEncodings[i]);
            CEnc2.addItem(JPreferences.AvailEncodings[i]);
            CEnc3.addItem(JPreferences.AvailEncodings[i]);
        }
    }
    
    
    public float getFPS() {
        return CFPS.getFPSValue();
    }
    
    public String[] getEncodings() {
        String [] encs  = new String[3];
        encs[0] = getItemName(CEnc1);
        encs[1] = getItemName(CEnc2);
        encs[2] = getItemName(CEnc3);
        return encs;
    }
    
    public void loadPreferences() {
        String e1, e2, e3;
        String fps;
        
        e1 = Options.getOption("Load.Encoding1", JPreferences.DefaultEncodings[0]);
        e2 = Options.getOption("Load.Encoding2", JPreferences.DefaultEncodings[1]);
        e3 = Options.getOption("Load.Encoding3", JPreferences.DefaultEncodings[2]);
        fps = Options.getOption("Load.FPS", JRateChooser.DefaultFPSEntry);
        setCombo(CEnc1, e1, "US-ASCII");
        setCombo(CEnc2, e2, "US-ASCII");
        setCombo(CEnc3, e3, "US-ASCII");
        CFPS.setFPS(fps);
        
        DialogVisible.setSelected(Options.getOption("System.ShowLoadDialog", "true").equals("true"));
    }
    
    public void savePreferences() {
        Options.setOption("Load.Encoding1", getItemName(CEnc1));
        Options.setOption("Load.Encoding2", getItemName(CEnc2));
        Options.setOption("Load.Encoding3", getItemName(CEnc3));
        Options.setOption("Load.FPS", CFPS.getFPS());
        Options.setOption("System.ShowLoadDialog", DialogVisible.isSelected() ? "true" : "false");
    }
    
    public String getTabName() { return _("Load"); }
    public String getTabTooltip() { return _("Load subtitles options"); }
    public Icon getTabIcon() { return new ImageIcon(getClass().getResource("/icons/load_small.png")); }
    
    /** 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() {
        OptsP = new javax.swing.JPanel();
        CEnc1L = new javax.swing.JLabel();
        CEnc1 = new javax.swing.JComboBox();
        CEnc2L = new javax.swing.JLabel();
        CEnc2 = new javax.swing.JComboBox();
        CEnc3L = new javax.swing.JLabel();
        CEnc3 = new javax.swing.JComboBox();
        FPSL = new javax.swing.JLabel();
        FPSPanel = new javax.swing.JPanel();

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

        OptsP.setLayout(new java.awt.GridLayout(4, 2));

        OptsP.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 4, 0));
        CEnc1L.setText(_("First Encoding"));
        OptsP.add(CEnc1L);

        CEnc1.setToolTipText(_("Select the encoding to be searched first"));
        OptsP.add(CEnc1);

        CEnc2L.setText(_("Second Encoding"));
        OptsP.add(CEnc2L);

        CEnc2.setToolTipText(_("Select the encoding to be searched second"));
        OptsP.add(CEnc2);

        CEnc3L.setText(_("Third Encoding"));
        OptsP.add(CEnc3L);

        CEnc3.setToolTipText(_("Select the encoding to be searched last"));
        OptsP.add(CEnc3);

        FPSL.setText(_("FPS"));
        OptsP.add(FPSL);

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

        OptsP.add(FPSPanel);

        add(OptsP, java.awt.BorderLayout.NORTH);

    }// </editor-fold>//GEN-END:initComponents
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox CEnc1;
    private javax.swing.JLabel CEnc1L;
    private javax.swing.JComboBox CEnc2;
    private javax.swing.JLabel CEnc2L;
    private javax.swing.JComboBox CEnc3;
    private javax.swing.JLabel CEnc3L;
    private javax.swing.JLabel FPSL;
    private javax.swing.JPanel FPSPanel;
    private javax.swing.JPanel OptsP;
    // End of variables declaration//GEN-END:variables
    
}
