/*
 * WANDORA
 * Knowledge Extraction, Management, and Publishing Application
 * http://wandora.org
 * 
 * Copyright (C) 2004-2023 Wandora Team
 * 
 * This program 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, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * 
 * PasteBinConfiguration.java
 *
 * Created on Dec 6, 2011, 5:45:46 PM
 */

package org.wandora.application.tools.occurrences.clipboards;

import java.awt.event.KeyEvent;

import javax.swing.JDialog;

import org.wandora.application.Wandora;
import org.wandora.application.WandoraTool;
import org.wandora.application.gui.simple.SimpleButton;
import org.wandora.application.gui.simple.SimpleCheckBox;
import org.wandora.application.gui.simple.SimpleComboBox;
import org.wandora.application.gui.simple.SimpleField;
import org.wandora.application.gui.simple.SimpleLabel;

/**
 *
 * @author akivela
 */


public class PasteBinConfiguration extends javax.swing.JPanel {

	private static final long serialVersionUID = 1L;

	private JDialog myDialog = null;
    private boolean accepted = false;
    
    
    /** Creates new form PasteBinConfiguration */
    public PasteBinConfiguration() {
        initComponents();
        expireComboBox.setEditable(false);
    }
    
    
    
    public void open(Wandora wandora, WandoraTool t) {
        myDialog = new JDialog(wandora, true);
        myDialog.add(this);
        myDialog.setTitle("Pastebin uploader options");
        myDialog.setSize(500, 220);
        accepted = false;
        if(wandora != null) wandora.centerWindow(myDialog);
        myDialog.setVisible(true);
    }
    
    
    // -------------------------------------------------------------------------
    
    public boolean wasAccepted() {
        return accepted;
    }
    
    
    public String getUserId() {
        return uidTextField.getText();
    }
    
    public void setUserId(String uid) {
        uidTextField.setText(uid);
    }
    
    public boolean getReplaceOccurrence() {
        return replaceOccurrenceCheckBox.isSelected();
    }
    public void setReplaceOccurrence(boolean ro) {
        replaceOccurrenceCheckBox.setSelected(ro);
    }
    
    public boolean getPrivatePaste() {
        return pastePrivateCheckBox.isSelected();
    }
    public void setPrivatePaste(boolean pp) {
        pastePrivateCheckBox.setSelected(pp);
    }
    
    public String getExpiration() {
        String e = expireComboBox.getSelectedItem().toString();
        if("10 minutes".equalsIgnoreCase(e)) return "10M";
        if("1 hour".equalsIgnoreCase(e)) return "1H";
        if("1 day".equalsIgnoreCase(e)) return "1D";
        if("1 month".equalsIgnoreCase(e)) return "1M";
        return "N"; // Never
    }
    
    public void setExpiration(String e) {
        String s = "N";
        if("10 minutes".equalsIgnoreCase(e) || "10M".equalsIgnoreCase(e)) s = "10 minutes";
        if("1 hour".equalsIgnoreCase(e) || "1H".equalsIgnoreCase(e)) s = "1 hour";
        if("1 day".equalsIgnoreCase(e) || "1D".equalsIgnoreCase(e)) s = "1 day";
        if("1 month".equalsIgnoreCase(e) || "1M".equalsIgnoreCase(e)) s = "1 month";
        expireComboBox.setSelectedItem(s);
    }

    
    
    
    // -------------------------------------------------------------------------
    
    
    
    /** 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;

        infoLabel = new SimpleLabel();
        optionsPanel = new javax.swing.JPanel();
        replaceOccurrenceLabel = new SimpleLabel();
        replaceOccurrenceCheckBox = new SimpleCheckBox();
        pastePrivateLabel = new SimpleLabel();
        pastePrivateCheckBox = new SimpleCheckBox();
        uidLabel = new SimpleLabel();
        uidTextField = new SimpleField();
        expireLabel = new SimpleLabel();
        expireComboBox = new SimpleComboBox();
        buttonPanel = new javax.swing.JPanel();
        buttonFillerPanel = new javax.swing.JPanel();
        okButton = new SimpleButton();
        cancelButton = new SimpleButton();

        infoLabel.setText("PasteBin occurrence upload options");

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

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

        replaceOccurrenceLabel.setText("Replace occurrence with Pastebin URL");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 2, 4);
        optionsPanel.add(replaceOccurrenceLabel, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 2, 0);
        optionsPanel.add(replaceOccurrenceCheckBox, gridBagConstraints);

        pastePrivateLabel.setText("Private paste");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 2, 4);
        optionsPanel.add(pastePrivateLabel, gridBagConstraints);

        pastePrivateCheckBox.setSelected(true);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 2, 0);
        optionsPanel.add(pastePrivateCheckBox, gridBagConstraints);

        uidLabel.setText("API user key");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 2, 4);
        optionsPanel.add(uidLabel, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 2, 0);
        optionsPanel.add(uidTextField, gridBagConstraints);

        expireLabel.setText("Expire paste in");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 2, 4);
        optionsPanel.add(expireLabel, gridBagConstraints);

        expireComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "10 Minutes", "1 Hour", "1 Day", "1 Month", "Never" }));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 2, 0);
        optionsPanel.add(expireComboBox, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(10, 20, 10, 10);
        add(optionsPanel, gridBagConstraints);

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

        javax.swing.GroupLayout buttonFillerPanelLayout = new javax.swing.GroupLayout(buttonFillerPanel);
        buttonFillerPanel.setLayout(buttonFillerPanelLayout);
        buttonFillerPanelLayout.setHorizontalGroup(
            buttonFillerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        buttonFillerPanelLayout.setVerticalGroup(
            buttonFillerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        buttonPanel.add(buttonFillerPanel, gridBagConstraints);

        okButton.setText("OK");
        okButton.setMargin(new java.awt.Insets(0, 2, 0, 2));
        okButton.setMinimumSize(new java.awt.Dimension(70, 23));
        okButton.setPreferredSize(new java.awt.Dimension(70, 23));
        okButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                okButtonMouseReleased(evt);
            }
        });
        okButton.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                okButtonKeyReleased(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2);
        buttonPanel.add(okButton, gridBagConstraints);

        cancelButton.setText("Cancel");
        cancelButton.setMargin(new java.awt.Insets(0, 2, 0, 2));
        cancelButton.setMinimumSize(new java.awt.Dimension(70, 23));
        cancelButton.setPreferredSize(new java.awt.Dimension(70, 23));
        cancelButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                cancelButtonMouseReleased(evt);
            }
        });
        buttonPanel.add(cancelButton, new java.awt.GridBagConstraints());

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        add(buttonPanel, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents

    private void okButtonMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_okButtonMouseReleased
        accepted = true;
        if(myDialog != null) myDialog.setVisible(false);
    }//GEN-LAST:event_okButtonMouseReleased

    private void okButtonKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_okButtonKeyReleased
        accepted = true;
        if(evt.getKeyCode() == KeyEvent.VK_ENTER) {
            if(myDialog != null) {
                myDialog.setVisible(false);
            }
        }
    }//GEN-LAST:event_okButtonKeyReleased

    private void cancelButtonMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cancelButtonMouseReleased
        accepted = false;
        if(myDialog != null) myDialog.setVisible(false);
    }//GEN-LAST:event_cancelButtonMouseReleased

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel buttonFillerPanel;
    private javax.swing.JPanel buttonPanel;
    private javax.swing.JButton cancelButton;
    private javax.swing.JComboBox expireComboBox;
    private javax.swing.JLabel expireLabel;
    private javax.swing.JLabel infoLabel;
    private javax.swing.JButton okButton;
    private javax.swing.JPanel optionsPanel;
    private javax.swing.JCheckBox pastePrivateCheckBox;
    private javax.swing.JLabel pastePrivateLabel;
    private javax.swing.JCheckBox replaceOccurrenceCheckBox;
    private javax.swing.JLabel replaceOccurrenceLabel;
    private javax.swing.JLabel uidLabel;
    private javax.swing.JTextField uidTextField;
    // End of variables declaration//GEN-END:variables
}
