// GraphTea Project: http://github.com/graphtheorysoftware/GraphTea
// Copyright (C) 2012 Graph Theory Software Foundation: http://GraphTheorySoftware.com
// Copyright (C) 2008 Mathematical Science Department of Sharif University of Technology
// Distributed under the terms of the GNU General Public License (GPL): http://www.gnu.org/licenses/
package graphtea.ui.components;

import graphtea.platform.extension.Extension;
import graphtea.platform.extension.ExtensionExternalData;

import javax.swing.*;

/**
 * this is a frame fo showing the configurations before running an Extension
 *
 * @author azin azadi
 * @see graphtea.ui.extension.AbstractExtensionAction
 * @see Extension
 */
public class ExtensionConfigFrame extends javax.swing.JFrame {

    Extension e;

    /**
     * Creates new form ExtensionConfigFrame
     */
    public ExtensionConfigFrame(Extension e, final ExtensionExternalData data) {
        this.e = e;
        initComponents();
        this.setDefaultCloseOperation(HIDE_ON_CLOSE);
        if (data == null) {
            sourceCodeBtn.setEnabled(false);
            helpBtn.setEnabled(false);
        } else {
            if (data.helpURL() != null) {
                helpBtn.addActionListener(e1 -> {
//                        try {
//                            Browser.browse(new URL(data.helpURL()));
//                        } catch (MalformedURLException e1) {
//                            e1.printStackTrace();
//                        }

                });
            }
            if (data.sourceCodeURL() != null) {
                helpBtn.addActionListener(e12 -> {
//                        try {
//                            Browser.browse(new URL(data.sourceCodeURL()));
//                        } catch (MalformedURLException e1) {
//                            e1.printStackTrace();
//                        }

                });
            }

        }
        extensionParametersPanel.add(new JButton("Aaa"));
        validate();
    }

    /**
     * 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 ">
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        extensionParametersPanel = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        helpBtn = new javax.swing.JButton();
        sourceCodeBtn = new javax.swing.JButton();
        descriptionLabel = new javax.swing.JLabel();

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

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle(e.getName());
        jPanel1.setLayout(new java.awt.GridBagLayout());

        jLabel1.setText("Extension Parameters:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanel1.add(jLabel1, gridBagConstraints);

//        extensionParametersPanel.setLayout();

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        jPanel1.add(extensionParametersPanel, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weighty = 1.0;
        getContentPane().add(jPanel1, gridBagConstraints);

        jPanel2.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        helpBtn.setText("Help");
        jPanel2.add(helpBtn);

        sourceCodeBtn.setText("Source Code");
        jPanel2.add(sourceCodeBtn);

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

        descriptionLabel.setText(e.getDescription());
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        getContentPane().add(descriptionLabel, gridBagConstraints);

        pack();
    }// </editor-fold>


    // Variables declaration - do not modify
    private javax.swing.JLabel descriptionLabel;
    private javax.swing.JPanel extensionParametersPanel;
    private javax.swing.JButton helpBtn;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JButton sourceCodeBtn;
    // End of variables declaration

}
