/*
 * 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/>.
 *
 * 
 * ImportConfiguration.java
 *
 * Created on 10.7.2006, 12:39
 */

package org.wandora.application.tools.importers;


import org.wandora.application.gui.simple.SimpleButton;
import org.wandora.application.gui.simple.SimpleCheckBox;
import org.wandora.utils.swing.GuiTools;



/**
 *
 * @author  olli
 */
public class ImportConfiguration extends javax.swing.JDialog {


	private static final long serialVersionUID = 1L;

	private boolean cancelled=true;
    
    /** Creates new form ImportConfiguration */
    public ImportConfiguration(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        this.setTitle("OBO configuration");
        GuiTools.centerWindow(this,parent);
    }
    
    /** 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;

        resetFirstCheckBox = new SimpleCheckBox();
        directMergeCheckBox = new SimpleCheckBox();
        newLayerCheckBox = new SimpleCheckBox();
        webImportCheckBox = new SimpleCheckBox();
        askSourceCheckBox = new SimpleCheckBox();
        jPanel1 = new javax.swing.JPanel();
        okButton = new SimpleButton();
        cancelButton = new SimpleButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(new java.awt.GridBagLayout());

        resetFirstCheckBox.setText("Reset topic map before import");
        resetFirstCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        resetFirstCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 5, 10);
        getContentPane().add(resetFirstCheckBox, gridBagConstraints);

        directMergeCheckBox.setText("Merge directly to topic map");
        directMergeCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        directMergeCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(5, 10, 5, 10);
        getContentPane().add(directMergeCheckBox, gridBagConstraints);

        newLayerCheckBox.setText("Make new layer for imported topic map");
        newLayerCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        newLayerCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(5, 10, 5, 10);
        getContentPane().add(newLayerCheckBox, gridBagConstraints);

        webImportCheckBox.setText("Import from web");
        webImportCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        webImportCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(5, 10, 5, 10);
        getContentPane().add(webImportCheckBox, gridBagConstraints);

        askSourceCheckBox.setText("Ask import source");
        askSourceCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        askSourceCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(5, 10, 5, 10);
        getContentPane().add(askSourceCheckBox, gridBagConstraints);

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

        okButton.setText("OK");
        okButton.setMargin(new java.awt.Insets(2, 5, 2, 5));
        okButton.setPreferredSize(new java.awt.Dimension(70, 23));
        okButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okButtonActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 5);
        jPanel1.add(okButton, gridBagConstraints);

        cancelButton.setText("Cancel");
        cancelButton.setMargin(new java.awt.Insets(2, 5, 2, 5));
        cancelButton.setPreferredSize(new java.awt.Dimension(70, 23));
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 5);
        jPanel1.add(cancelButton, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(5, 10, 10, 10);
        getContentPane().add(jPanel1, gridBagConstraints);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-311)/2, (screenSize.height-210)/2, 311, 210);
    }// </editor-fold>//GEN-END:initComponents

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        cancelled=true;
        this.setVisible(false);
    }//GEN-LAST:event_cancelButtonActionPerformed

    private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
        cancelled=false;
        this.setVisible(false);
    }//GEN-LAST:event_okButtonActionPerformed
    
    public boolean wasCancelled(){return cancelled;}
    
    public int getOptions(){
        int options=0;
        if(resetFirstCheckBox.isSelected()) options|=AbstractImportTool.TOPICMAP_RESET_FIRST;
        if(directMergeCheckBox.isSelected()) options|=AbstractImportTool.TOPICMAP_DIRECT_MERGE;
        if(newLayerCheckBox.isSelected()) options|=AbstractImportTool.TOPICMAP_MAKE_NEW_LAYER;
        if(webImportCheckBox.isSelected()) options|=AbstractImportTool.WEB_IMPORT;
        if(askSourceCheckBox.isSelected()) options|=AbstractImportTool.ASK_SOURCE;
        return options;
    }
    
    public void setOptions(int options){
        resetFirstCheckBox.setSelected((options&AbstractImportTool.TOPICMAP_RESET_FIRST)!=0);
        directMergeCheckBox.setSelected((options&AbstractImportTool.TOPICMAP_DIRECT_MERGE)!=0);
        newLayerCheckBox.setSelected((options&AbstractImportTool.TOPICMAP_MAKE_NEW_LAYER)!=0);
        webImportCheckBox.setSelected((options&AbstractImportTool.WEB_IMPORT)!=0);
        askSourceCheckBox.setSelected((options&AbstractImportTool.ASK_SOURCE)!=0);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox askSourceCheckBox;
    private javax.swing.JButton cancelButton;
    private javax.swing.JCheckBox directMergeCheckBox;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JCheckBox newLayerCheckBox;
    private javax.swing.JButton okButton;
    private javax.swing.JCheckBox resetFirstCheckBox;
    private javax.swing.JCheckBox webImportCheckBox;
    // End of variables declaration//GEN-END:variables
    
}
