/*
 * 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/>.
 *
 * 
 * NewTopicPanel.java
 *
 * Created on 29. joulukuuta 2005, 22:04
 */

package org.wandora.application.gui;


import java.awt.event.KeyEvent;

import javax.swing.JDialog;

import org.wandora.application.gui.simple.SimpleButton;
import org.wandora.utils.Textbox;


/**
 * @author  akivela
 */
public class NewTopicPanel extends javax.swing.JPanel {
	
	private static final long serialVersionUID = 1L;
	
    
    private boolean accepted = false;
    private JDialog parent = null;
    
    
    /** Creates new form NewTopicPanel */
    public NewTopicPanel(JDialog parent) {
        this.parent = parent;
        initComponents();
        if(parent != null) {
            parent.add(this);
            parent.setVisible(true);
        }
        
    }
    
    
    public boolean getAccepted() {
        return accepted;
    }
    
    
    public String getBasename() {
        return Textbox.trimExtraSpaces(basenameTextField.getText());
    }
    
    
    public String getSI() {
        return Textbox.trimExtraSpaces(SITextField.getText());
    }
    
    /** 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;

        fieldPanel = new javax.swing.JPanel();
        basenameLabel = new org.wandora.application.gui.simple.SimpleLabel();
        basenameTextField = new org.wandora.application.gui.simple.SimpleField();
        SILabel = new org.wandora.application.gui.simple.SimpleLabel();
        SITextField = new org.wandora.application.gui.simple.SimpleField();
        buttonPanel = new javax.swing.JPanel();
        dummyPanel = new javax.swing.JPanel();
        okButton = new SimpleButton();
        cancelButton = new SimpleButton();

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

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

        basenameLabel.setText("Base name");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 2, 5);
        fieldPanel.add(basenameLabel, gridBagConstraints);

        basenameTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                basenameTextFieldKeyReleased(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 2, 5);
        fieldPanel.add(basenameTextField, gridBagConstraints);

        SILabel.setText("Subject identifier");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
        fieldPanel.add(SILabel, gridBagConstraints);

        SITextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                SITextFieldKeyReleased(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 5);
        fieldPanel.add(SITextField, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        add(fieldPanel, gridBagConstraints);

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

        okButton.setText("Create");
        okButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
        okButton.setMaximumSize(new java.awt.Dimension(70, 23));
        okButton.setMinimumSize(new java.awt.Dimension(70, 23));
        okButton.setPreferredSize(new java.awt.Dimension(70, 23));
        okButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                accepted(evt);
            }
        });
        okButton.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                okButtonKeyReleased(evt);
            }
        });
        buttonPanel.add(okButton, new java.awt.GridBagConstraints());

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

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        add(buttonPanel, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents

    
    private void accepted(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_accepted
        accepted = true;
        if(parent != null) parent.setVisible(false);
    }//GEN-LAST:event_accepted

    private void cancelled(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelled
        accepted = false;
        if(parent != null) parent.setVisible(false);
    }//GEN-LAST:event_cancelled

    private void basenameTextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_basenameTextFieldKeyReleased
        if(evt.getKeyCode() == KeyEvent.VK_ENTER) {
            accepted(null);
        }
    }//GEN-LAST:event_basenameTextFieldKeyReleased

    private void SITextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_SITextFieldKeyReleased
        if(evt.getKeyCode() == KeyEvent.VK_ENTER) {
            accepted(null);
        }
    }//GEN-LAST:event_SITextFieldKeyReleased

    private void okButtonKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_okButtonKeyReleased
        if(evt.getKeyCode() == KeyEvent.VK_ENTER) {
            accepted(null);
        }
    }//GEN-LAST:event_okButtonKeyReleased
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel SILabel;
    private javax.swing.JTextField SITextField;
    private javax.swing.JLabel basenameLabel;
    private javax.swing.JTextField basenameTextField;
    private javax.swing.JPanel buttonPanel;
    private javax.swing.JButton cancelButton;
    private javax.swing.JPanel dummyPanel;
    private javax.swing.JPanel fieldPanel;
    private javax.swing.JButton okButton;
    // End of variables declaration//GEN-END:variables
    
}
