/*
 * NewJPanel.java
 *
 * Created on 2008/03/19, 23:23
 */
package peercast4j;

import java.awt.Color;
import java.net.URL;

/**
 *
 * @author  ab
 */
public class YPSettingPanel extends javax.swing.JPanel {

    public YPSettingPanel(String s) {
        initComponents();
        ypUrlTextField.setText(s);
    }

    /** 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() {

        jLabel1 = new javax.swing.JLabel();
        ypNameTextField = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        ypUrlTextField = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        ypStreamTypeTextField = new javax.swing.JTextField();
        applyButton = new javax.swing.JButton();

        setName("YP"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(peercast4j.Peercast4jApp.class).getContext().getResourceMap(YPSettingPanel.class);
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        ypNameTextField.setText(resourceMap.getString("ypname.text")); // NOI18N
        ypNameTextField.setName("ypname"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        ypUrlTextField.setText(resourceMap.getString("ypUrlTextField.text")); // NOI18N
        ypUrlTextField.setName("ypUrlTextField"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        ypStreamTypeTextField.setText(resourceMap.getString("ypStreamTypeTextField.text")); // NOI18N
        ypStreamTypeTextField.setName("ypStreamTypeTextField"); // NOI18N

        applyButton.setText(resourceMap.getString("applyButton.text")); // NOI18N
        applyButton.setName("applyButton"); // NOI18N
        applyButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                applyButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(applyButton, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 118, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(ypUrlTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 253, Short.MAX_VALUE)
                            .addComponent(ypNameTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 253, Short.MAX_VALUE)
                            .addComponent(ypStreamTypeTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 253, Short.MAX_VALUE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(ypNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(ypUrlTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ypStreamTypeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 173, Short.MAX_VALUE)
                .addComponent(applyButton)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents
    private void applyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_applyButtonActionPerformed
        boolean ok = true;
        if ("".equals(ypNameTextField.getText())) {
            ypNameTextField.setBackground(Color.RED);
            ok = false;
        } else {
            ypNameTextField.setBackground(Color.WHITE);
        }
        if ("".equals(ypUrlTextField.getText())) {
            ypUrlTextField.setBackground(Color.RED);
            ok = false;
        } else {
            ypUrlTextField.setBackground(Color.WHITE);
        }
        if (ok) {
            try {
                URL url = new URL(ypUrlTextField.getText());
                if (!"http".equals(url.getProtocol().toLowerCase())) {
                    ypUrlTextField.setBackground(Color.RED);
                    ok = false;
                }
            } catch (Exception e) {
                ypUrlTextField.setBackground(Color.RED);
                ok = false;
            }
            if (ok) {
                ypUrlTextField.setBackground(Color.WHITE);
            }
        }
    }//GEN-LAST:event_applyButtonActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton applyButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JTextField ypNameTextField;
    private javax.swing.JTextField ypStreamTypeTextField;
    private javax.swing.JTextField ypUrlTextField;
    // End of variables declaration//GEN-END:variables
}
