/*
 * NeuronPropertiesDialog.java
 *
 * Created on March 30, 2009, 1:20 AM
 */

package org.neuroph.easyneurons.dialog;

import org.jdesktop.application.Action;
import org.neuroph.core.Neuron;
import org.neuroph.core.Weight;
import org.neuroph.nnet.comp.InputOutputNeuron;
import org.neuroph.nnet.comp.ThresholdNeuron;
import org.neuroph.util.plugins.LabelsPlugin;


/**
 *
 * @author  Zoran Sevarac <sevarac@gmail.com>
 */
public class NeuronPropertiesDialog extends javax.swing.JDialog {

    /** Creates new form NeuronPropertiesDialog */
    public NeuronPropertiesDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }
    
    public NeuronPropertiesDialog(java.awt.Frame parent, boolean modal, Neuron neuron) {
        super(parent, modal);
        initComponents();
	
	inputField.setText(Double.toString(neuron.getNetInput()));
	outputField.setText(Double.toString(neuron.getOutput()));
	
	if (neuron instanceof InputOutputNeuron)
		biasField.setText(Double.toString(((InputOutputNeuron)neuron).getBias()));
	else if (neuron instanceof ThresholdNeuron)
		biasField.setText(Double.toString(((ThresholdNeuron)neuron).getThresh()));

	weightFuncField.setText(neuron.getInputFunction().getWeightsFunction().getClass().getName());
	sumFuncField.setText(neuron.getInputFunction().getSummingFunction().getClass().getName());
	transFuncField.setText(neuron.getTransferFunction().getClass().getName());
	
	String weightsText = new String();
	for(Weight weight : neuron.getWeightsVector()) {
		weightsText += Double.toString( weight.getValue() ) + "\n";
	}
	
	weightsField.setText(weightsText);

	String neuronLabel =  ((LabelsPlugin)neuron.getParentLayer().getParentNetwork().getPlugin("LabelsPlugin")).getLabel(neuron);
	labelField.setText(neuronLabel);
			
    }    

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

                jPanel1 = new javax.swing.JPanel();
                jLabel1 = new javax.swing.JLabel();
                jLabel2 = new javax.swing.JLabel();
                jLabel3 = new javax.swing.JLabel();
                jLabel4 = new javax.swing.JLabel();
                jLabel5 = new javax.swing.JLabel();
                inputField = new javax.swing.JTextField();
                outputField = new javax.swing.JTextField();
                biasField = new javax.swing.JTextField();
                weightFuncField = new javax.swing.JTextField();
                sumFuncField = new javax.swing.JTextField();
                jLabel6 = new javax.swing.JLabel();
                transFuncField = new javax.swing.JTextField();
                jScrollPane1 = new javax.swing.JScrollPane();
                weightsField = new javax.swing.JTextArea();
                jLabel7 = new javax.swing.JLabel();
                jLabel8 = new javax.swing.JLabel();
                labelField = new javax.swing.JTextField();
                jPanel2 = new javax.swing.JPanel();
                closeButton = new javax.swing.JButton();

                setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
                org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(org.neuroph.easyneurons.EasyNeuronsApplication.class).getContext().getResourceMap(NeuronPropertiesDialog.class);
                setTitle(resourceMap.getString("Form.title")); // NOI18N
                setName("Form"); // NOI18N
                setResizable(false);
                getContentPane().setLayout(new java.awt.GridBagLayout());

                jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
                jPanel1.setName("jPanel1"); // NOI18N
                jPanel1.setLayout(new java.awt.GridBagLayout());

                jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
                jLabel1.setName("jLabel1"); // NOI18N
                gridBagConstraints = new java.awt.GridBagConstraints();
                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
                gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
                jPanel1.add(jLabel1, gridBagConstraints);

                jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
                jLabel2.setName("jLabel2"); // NOI18N
                gridBagConstraints = new java.awt.GridBagConstraints();
                gridBagConstraints.gridx = 0;
                gridBagConstraints.gridy = 1;
                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
                gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
                jPanel1.add(jLabel2, gridBagConstraints);

                jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
                jLabel3.setName("jLabel3"); // NOI18N
                gridBagConstraints = new java.awt.GridBagConstraints();
                gridBagConstraints.gridx = 0;
                gridBagConstraints.gridy = 6;
                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
                gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
                jPanel1.add(jLabel3, gridBagConstraints);

                jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
                jLabel4.setName("jLabel4"); // NOI18N
                gridBagConstraints = new java.awt.GridBagConstraints();
                gridBagConstraints.gridx = 0;
                gridBagConstraints.gridy = 3;
                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
                gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
                jPanel1.add(jLabel4, gridBagConstraints);

                jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
                jLabel5.setName("jLabel5"); // NOI18N
                gridBagConstraints = new java.awt.GridBagConstraints();
                gridBagConstraints.gridx = 0;
                gridBagConstraints.gridy = 4;
                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
                gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
                jPanel1.add(jLabel5, gridBagConstraints);

                inputField.setBackground(resourceMap.getColor("weightsField.background")); // NOI18N
                inputField.setColumns(25);
                inputField.setEditable(false);
                inputField.setText(resourceMap.getString("inputField.text")); // NOI18N
                inputField.setName("inputField"); // NOI18N
                gridBagConstraints = new java.awt.GridBagConstraints();
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
                gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
                jPanel1.add(inputField, gridBagConstraints);

                outputField.setBackground(resourceMap.getColor("weightsField.background")); // NOI18N
                outputField.setColumns(25);
                outputField.setEditable(false);
                outputField.setText(resourceMap.getString("outputField.text")); // NOI18N
                outputField.setName("outputField"); // NOI18N
                gridBagConstraints = new java.awt.GridBagConstraints();
                gridBagConstraints.gridx = 1;
                gridBagConstraints.gridy = 1;
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
                gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
                jPanel1.add(outputField, gridBagConstraints);

                biasField.setBackground(resourceMap.getColor("weightsField.background")); // NOI18N
                biasField.setColumns(25);
                biasField.setEditable(false);
                biasField.setText(resourceMap.getString("biasField.text")); // NOI18N
                biasField.setName("biasField"); // NOI18N
                gridBagConstraints = new java.awt.GridBagConstraints();
                gridBagConstraints.gridx = 1;
                gridBagConstraints.gridy = 6;
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
                gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
                jPanel1.add(biasField, gridBagConstraints);

                weightFuncField.setBackground(resourceMap.getColor("weightsField.background")); // NOI18N
                weightFuncField.setColumns(25);
                weightFuncField.setEditable(false);
                weightFuncField.setText(resourceMap.getString("weightFuncField.text")); // NOI18N
                weightFuncField.setName("weightFuncField"); // NOI18N
                gridBagConstraints = new java.awt.GridBagConstraints();
                gridBagConstraints.gridx = 1;
                gridBagConstraints.gridy = 3;
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
                gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
                jPanel1.add(weightFuncField, gridBagConstraints);

                sumFuncField.setBackground(resourceMap.getColor("weightsField.background")); // NOI18N
                sumFuncField.setColumns(25);
                sumFuncField.setEditable(false);
                sumFuncField.setText(resourceMap.getString("sumFuncField.text")); // NOI18N
                sumFuncField.setName("sumFuncField"); // NOI18N
                gridBagConstraints = new java.awt.GridBagConstraints();
                gridBagConstraints.gridx = 1;
                gridBagConstraints.gridy = 4;
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
                gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
                jPanel1.add(sumFuncField, gridBagConstraints);

                jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
                jLabel6.setName("jLabel6"); // NOI18N
                gridBagConstraints = new java.awt.GridBagConstraints();
                gridBagConstraints.gridx = 0;
                gridBagConstraints.gridy = 5;
                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
                gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
                jPanel1.add(jLabel6, gridBagConstraints);

                transFuncField.setBackground(resourceMap.getColor("weightsField.background")); // NOI18N
                transFuncField.setColumns(25);
                transFuncField.setEditable(false);
                transFuncField.setText(resourceMap.getString("transFuncField.text")); // NOI18N
                transFuncField.setName("transFuncField"); // NOI18N
                gridBagConstraints = new java.awt.GridBagConstraints();
                gridBagConstraints.gridx = 1;
                gridBagConstraints.gridy = 5;
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
                gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
                jPanel1.add(transFuncField, gridBagConstraints);

                jScrollPane1.setName("jScrollPane1"); // NOI18N

                weightsField.setBackground(resourceMap.getColor("weightsField.background")); // NOI18N
                weightsField.setColumns(25);
                weightsField.setEditable(false);
                weightsField.setRows(7);
                weightsField.setName("weightsField"); // NOI18N
                jScrollPane1.setViewportView(weightsField);

                gridBagConstraints = new java.awt.GridBagConstraints();
                gridBagConstraints.gridx = 1;
                gridBagConstraints.gridy = 7;
                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
                gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
                jPanel1.add(jScrollPane1, gridBagConstraints);

                jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
                jLabel7.setName("jLabel7"); // NOI18N
                gridBagConstraints = new java.awt.GridBagConstraints();
                gridBagConstraints.gridx = 0;
                gridBagConstraints.gridy = 7;
                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
                gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
                jPanel1.add(jLabel7, gridBagConstraints);

                jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
                jLabel8.setName("jLabel8"); // NOI18N
                gridBagConstraints = new java.awt.GridBagConstraints();
                gridBagConstraints.gridx = 0;
                gridBagConstraints.gridy = 2;
                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
                gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
                jPanel1.add(jLabel8, gridBagConstraints);

                labelField.setBackground(resourceMap.getColor("labelField.background")); // NOI18N
                labelField.setColumns(25);
                labelField.setEditable(false);
                labelField.setText(resourceMap.getString("labelField.text")); // NOI18N
                labelField.setName("labelField"); // NOI18N
                gridBagConstraints = new java.awt.GridBagConstraints();
                gridBagConstraints.gridx = 1;
                gridBagConstraints.gridy = 2;
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
                gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
                jPanel1.add(labelField, gridBagConstraints);

                getContentPane().add(jPanel1, new java.awt.GridBagConstraints());

                jPanel2.setName("jPanel2"); // NOI18N

                javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(org.neuroph.easyneurons.EasyNeuronsApplication.class).getContext().getActionMap(NeuronPropertiesDialog.class, this);
                closeButton.setAction(actionMap.get("close")); // NOI18N
                closeButton.setText(resourceMap.getString("closeButton.text")); // NOI18N
                closeButton.setName("closeButton"); // NOI18N
                jPanel2.add(closeButton);

                gridBagConstraints = new java.awt.GridBagConstraints();
                gridBagConstraints.gridx = 0;
                gridBagConstraints.gridy = 1;
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
                gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5);
                getContentPane().add(jPanel2, gridBagConstraints);

                pack();
        }// </editor-fold>//GEN-END:initComponents

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                NeuronPropertiesDialog dialog = new NeuronPropertiesDialog(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

	@Action
	public void close() {
		this.dispose();
	}

        // Variables declaration - do not modify//GEN-BEGIN:variables
        private javax.swing.JTextField biasField;
        private javax.swing.JButton closeButton;
        private javax.swing.JTextField inputField;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JLabel jLabel4;
        private javax.swing.JLabel jLabel5;
        private javax.swing.JLabel jLabel6;
        private javax.swing.JLabel jLabel7;
        private javax.swing.JLabel jLabel8;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JPanel jPanel2;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JTextField labelField;
        private javax.swing.JTextField outputField;
        private javax.swing.JTextField sumFuncField;
        private javax.swing.JTextField transFuncField;
        private javax.swing.JTextField weightFuncField;
        private javax.swing.JTextArea weightsField;
        // End of variables declaration//GEN-END:variables

}
