/*
 * 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/>.
 *
 *
 *
 * MaianaExportPanel.java
 *
 * Created on 11.10.2010, 15:33:31
 */

package org.wandora.application.tools.maiana;


import java.text.SimpleDateFormat;

import javax.swing.JDialog;

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

/**
 *
 * @author akivela
 */
public class MaianaExportPanel extends javax.swing.JPanel {

	private static final long serialVersionUID = 1L;
	
	private boolean wasAccepted = false;
	private JDialog window = null;





    /** Creates new form MaianaExportPanel */
    public MaianaExportPanel() {
        initComponents();
    }




    public void open(Wandora wandora) {
        window = new JDialog(wandora, true);
        window.setSize(800, 280);
        window.add(this);
        window.setTitle("Export to Waiana");
        wandora.centerWindow(window);
        window.setVisible(true);
    }

    


    public void setApiKey(String key) {
        apiKeyTextField.setText(key);
    }

    public String getApiKey() {
        return apiKeyTextField.getText();
    }

    public void setTopicMapName(String n) {
        nameTextField.setText(n);
    }

    public String getTopicMapName() {
        return nameTextField.getText();
    }

    public void setShortName(String sn) {
        shortNameTextField.setText(sn);
    }

    public String getShortName() {
        return shortNameTextField.getText();
    }

    public void setPublic(boolean isPublic) {
        isPublicCheckBox.setSelected(isPublic);
    }

    public boolean isPublic() {
        return isPublicCheckBox.isSelected();
    }

    public void setDownloadable(boolean isDownloadable) {
        isDownloadableCheckBox.setSelected(isDownloadable);
    }

    public boolean isDownloable() {
        return isDownloadableCheckBox.isSelected();
    }

    public void setEditable(boolean isEditable) {
        isEditableCheckBox.setSelected(isEditable);
    }
    
    public boolean isEditable() {
        return isEditableCheckBox.isSelected();
    }
    
    public void setSchema(boolean isSchema) {
        isSchemaCheckBox.setSelected(isSchema);
    }

    public boolean isSchema() {
        return isSchemaCheckBox.isSelected();
    }
    
    public String getApiEndPoint() {
        return apiEndPointField.getSelectedItem().toString();
    }

    public void setApiEndPoint(String endpoint) {
        apiEndPointField.setSelectedItem(endpoint);
    }

    

    public boolean wasAccepted() {
        return wasAccepted;
    }




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

        contentPanel = new javax.swing.JPanel();
        infoLabel = new SimpleLabel();
        apiEndPointLabel = new javax.swing.JLabel();
        apiEndPointField = new javax.swing.JComboBox();
        apiKeyLabel = new SimpleLabel();
        apiKeyTextField = new SimpleField();
        nameLabel = new SimpleLabel();
        nameTextField = new SimpleField();
        shortNameLabel = new SimpleLabel();
        shortNamePanel = new javax.swing.JPanel();
        shortNameTextField = new SimpleField();
        addDateStampButton = new SimpleButton();
        flagsLabel = new SimpleLabel();
        flagsPanel = new javax.swing.JPanel();
        isPublicCheckBox = new SimpleCheckBox();
        isDownloadableCheckBox = new SimpleCheckBox();
        isEditableCheckBox = new SimpleCheckBox();
        isSchemaCheckBox = new SimpleCheckBox();
        flagsFillerPanel = new javax.swing.JPanel();
        buttonPanel = new javax.swing.JPanel();
        buttonFillerPanel = new javax.swing.JPanel();
        uploadButton = new SimpleButton();
        cancelButton = new SimpleButton();

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

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

        infoLabel.setText("<html>Export selected topic map or selected topics to Waiana or Maiana. Check the API endpoint, your personal API key, topic map names and publishing settings. Topic map's short name is unique and can contain only alphanum characters.</html>");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 15, 0);
        contentPanel.add(infoLabel, gridBagConstraints);

        apiEndPointLabel.setText("API endpoint");
        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);
        contentPanel.add(apiEndPointLabel, gridBagConstraints);

        apiEndPointField.setEditable(true);
        apiEndPointField.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "http://127.0.0.1:8898/waiana/", "http://maiana.topicmapslab.de/api" }));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 2, 0);
        contentPanel.add(apiEndPointField, gridBagConstraints);

        apiKeyLabel.setText("API key");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 2, 4);
        contentPanel.add(apiKeyLabel, 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);
        contentPanel.add(apiKeyTextField, gridBagConstraints);

        nameLabel.setText("Topic map name");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 2, 4);
        contentPanel.add(nameLabel, 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);
        contentPanel.add(nameTextField, gridBagConstraints);

        shortNameLabel.setText("Short name");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 2, 4);
        contentPanel.add(shortNameLabel, gridBagConstraints);

        shortNamePanel.setLayout(new java.awt.GridBagLayout());
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 2, 0);
        shortNamePanel.add(shortNameTextField, gridBagConstraints);

        addDateStampButton.setText("add date stamp");
        addDateStampButton.setMargin(new java.awt.Insets(0, 2, 0, 2));
        addDateStampButton.setPreferredSize(new java.awt.Dimension(87, 25));
        addDateStampButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addDateStampButtonActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 2, 0);
        shortNamePanel.add(addDateStampButton, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        contentPanel.add(shortNamePanel, gridBagConstraints);

        flagsLabel.setText("Exported topic map is");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 2, 4);
        contentPanel.add(flagsLabel, gridBagConstraints);

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

        isPublicCheckBox.setFont(org.wandora.application.gui.UIConstants.labelFont);
        isPublicCheckBox.setSelected(true);
        isPublicCheckBox.setText("public");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 5);
        flagsPanel.add(isPublicCheckBox, gridBagConstraints);

        isDownloadableCheckBox.setFont(org.wandora.application.gui.UIConstants.labelFont);
        isDownloadableCheckBox.setSelected(true);
        isDownloadableCheckBox.setText("downloadable");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 5);
        flagsPanel.add(isDownloadableCheckBox, gridBagConstraints);

        isEditableCheckBox.setFont(org.wandora.application.gui.UIConstants.labelFont);
        isEditableCheckBox.setSelected(true);
        isEditableCheckBox.setText("editable");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 5);
        flagsPanel.add(isEditableCheckBox, gridBagConstraints);

        isSchemaCheckBox.setFont(org.wandora.application.gui.UIConstants.labelFont);
        isSchemaCheckBox.setText("schema");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 5);
        flagsPanel.add(isSchemaCheckBox, gridBagConstraints);

        flagsFillerPanel.setPreferredSize(new java.awt.Dimension(101, 15));

        javax.swing.GroupLayout flagsFillerPanelLayout = new javax.swing.GroupLayout(flagsFillerPanel);
        flagsFillerPanel.setLayout(flagsFillerPanelLayout);
        flagsFillerPanelLayout.setHorizontalGroup(
            flagsFillerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        flagsFillerPanelLayout.setVerticalGroup(
            flagsFillerPanelLayout.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;
        flagsPanel.add(flagsFillerPanel, 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);
        contentPanel.add(flagsPanel, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(8, 8, 8, 8);
        add(contentPanel, 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);

        uploadButton.setText("Export");
        uploadButton.setPreferredSize(new java.awt.Dimension(75, 23));
        uploadButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                uploadButtonActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 4);
        buttonPanel.add(uploadButton, gridBagConstraints);

        cancelButton.setText("Cancel");
        cancelButton.setPreferredSize(new java.awt.Dimension(75, 23));
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(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(0, 8, 8, 8);
        add(buttonPanel, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents

    private void uploadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_uploadButtonActionPerformed
        wasAccepted = true;
        if(window != null) window.setVisible(false);
    }//GEN-LAST:event_uploadButtonActionPerformed

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        wasAccepted = false;
        if(window != null) window.setVisible(false);
    }//GEN-LAST:event_cancelButtonActionPerformed

    private void addDateStampButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addDateStampButtonActionPerformed
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
        String stamp = sdf.format(System.currentTimeMillis());
        shortNameTextField.setText(shortNameTextField.getText()+"_"+stamp);
    }//GEN-LAST:event_addDateStampButtonActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addDateStampButton;
    private javax.swing.JComboBox apiEndPointField;
    private javax.swing.JLabel apiEndPointLabel;
    private javax.swing.JLabel apiKeyLabel;
    private javax.swing.JTextField apiKeyTextField;
    private javax.swing.JPanel buttonFillerPanel;
    private javax.swing.JPanel buttonPanel;
    private javax.swing.JButton cancelButton;
    private javax.swing.JPanel contentPanel;
    private javax.swing.JPanel flagsFillerPanel;
    private javax.swing.JLabel flagsLabel;
    private javax.swing.JPanel flagsPanel;
    private javax.swing.JLabel infoLabel;
    private javax.swing.JCheckBox isDownloadableCheckBox;
    private javax.swing.JCheckBox isEditableCheckBox;
    private javax.swing.JCheckBox isPublicCheckBox;
    private javax.swing.JCheckBox isSchemaCheckBox;
    private javax.swing.JLabel nameLabel;
    private javax.swing.JTextField nameTextField;
    private javax.swing.JLabel shortNameLabel;
    private javax.swing.JPanel shortNamePanel;
    private javax.swing.JTextField shortNameTextField;
    private javax.swing.JButton uploadButton;
    // End of variables declaration//GEN-END:variables

}
