alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 * 
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 * 
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.modules.autoupdate;

import java.awt.Dialog;

import org.openide.DialogDescriptor;
import org.openide.DialogDisplayer;
import org.openide.util.NbBundle;

/**
 *
 * @author  Administrator
 * @version 
 */
class ProxyDialog extends javax.swing.JPanel {

    /** Creates new form ProxyDialog */
    public ProxyDialog() {
        initComponents ();

        useCheckBox.setSelected( Autoupdater.isUseProxy() );
        hostTextField.setText( Autoupdater.getProxyHost() );
        portTextField.setText( Autoupdater.getProxyPort() );

        jLabel1.setDisplayedMnemonic(getBundle("ProxyDialog.jLabel1.text_Mnemonic").charAt(0));
        jLabel2.setDisplayedMnemonic(getBundle("ProxyDialog.jLabel2.text_Mnemonic").charAt(0));

        getAccessibleContext().setAccessibleDescription(getBundle("CTL_ProxyDialog_Title"));
        getAccessibleContext().setAccessibleDescription(getBundle("ACS_ProxyDialog"));
        useCheckBox.getAccessibleContext().setAccessibleDescription(getBundle("ACS_ProxyDialog.useCheckBox.text"));
        hostTextField.getAccessibleContext().setAccessibleDescription(getBundle("ACS_ProxyDialog.hostTextField"));
        portTextField.getAccessibleContext().setAccessibleDescription(getBundle("ACS_ProxyDialog.portTextField"));
    }

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

        useCheckBox = new javax.swing.JCheckBox();
        jLabel1 = new javax.swing.JLabel();
        hostTextField = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        portTextField = new javax.swing.JTextField();

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

        setBorder(new javax.swing.border.EmptyBorder(new java.awt.Insets(8, 8, 8, 8)));
        useCheckBox.setMnemonic(getBundle("ProxyDialog.useCheckBox.text_Mnemonic").charAt(0));
        useCheckBox.setText(getBundle("ProxyDialog.useCheckBox.text"));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 8, 0);
        add(useCheckBox, gridBagConstraints);

        jLabel1.setLabelFor(hostTextField);
        jLabel1.setText(getBundle("ProxyDialog.jLabel1.text"));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 8, 0);
        add(jLabel1, gridBagConstraints);

        hostTextField.setColumns(30);
        hostTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                hostTextFieldKeyReleased(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 8, 8, 0);
        add(hostTextField, gridBagConstraints);

        jLabel2.setLabelFor(portTextField);
        jLabel2.setText(getBundle("ProxyDialog.jLabel2.text"));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        add(jLabel2, gridBagConstraints);

        portTextField.setColumns(6);
        portTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                hostTextFieldKeyReleased(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 8, 0, 0);
        add(portTextField, gridBagConstraints);

    }//GEN-END:initComponents

    private void hostTextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_hostTextFieldKeyReleased
        useCheckBox.setSelected(!isEmpty(hostTextField.getText()) || !isEmpty(portTextField.getText()));
    }//GEN-LAST:event_hostTextFieldKeyReleased


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox useCheckBox;
    private javax.swing.JTextField portTextField;
    private javax.swing.JTextField hostTextField;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel1;
    // End of variables declaration//GEN-END:variables


    static void showDialog() {

        ProxyDialog proxyPanel;

        DialogDescriptor dd = new DialogDescriptor(
                                  proxyPanel = new ProxyDialog(),
                                  getBundle( "CTL_ProxyDialog_Title" ),
                                  true,                                                 // Modal
                                  DialogDescriptor.OK_CANCEL_OPTION,                     // Option list
                                  DialogDescriptor.OK_OPTION,                          // Default
                                  DialogDescriptor.BOTTOM_ALIGN,                        // Align
                                  null, //new HelpCtx ( ProxyDialog.class ),                  // Help
                                  null );


        Dialog dialog = DialogDisplayer.getDefault().createDialog( dd );
        dialog.show();

        if ( dd.getValue() == DialogDescriptor.OK_OPTION ) {
            Autoupdater.setProxyConfiguration(
                proxyPanel.useCheckBox.isSelected(),
                proxyPanel.hostTextField.getText(),
                proxyPanel.portTextField.getText() );
        }
    }

    private boolean isEmpty (String text) {
        return text == null || text.length() == 0;
    }
    
    private static String getBundle( String key ) {
        return NbBundle.getMessage( ProxyDialog.class, key );
    }
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.