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

/*
 * AddServerPanel.java
 *
 * Created on November 6, 2002, 10:49 AM
 */

package org.netbeans.modules.j2ee.deployment.impl.ui;

import java.awt.Dialog;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import org.openide.DialogDescriptor;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.event.DocumentListener;
import javax.swing.event.DocumentEvent;
import org.openide.util.NbBundle;
import org.openide.util.HelpCtx;

/**
 *
 * @author  J Lockhart
 */
public class FindServerPanel extends javax.swing.JPanel {
    
    
    private Dialog		  dialog;
    private DialogDescriptor      dialogDescriptor;
    
    /** Creates new form FindServerPanel */
    public FindServerPanel() {
        initComponents();
        initComponentsMore();
    }
    
    /** 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.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
        java.awt.GridBagConstraints gridBagConstraints;

        introLbl = new javax.swing.JLabel();
        urlLbl = new javax.swing.JLabel();
        urlTxt = new javax.swing.JTextField();
        usernameLbl = new javax.swing.JLabel();
        usernameTxt = new javax.swing.JTextField();
        pwLbl = new javax.swing.JLabel();
        pwTxt = new javax.swing.JPasswordField();

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

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(12, 12, 12, 12);
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        add(introLbl, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 12);
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        add(urlLbl, gridBagConstraints);

        urlTxt.setColumns(33);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 12);
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 0.1;
        gridBagConstraints.weighty = 0.1;
        add(urlTxt, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 12);
        add(usernameLbl, gridBagConstraints);

        usernameTxt.setColumns(20);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 12);
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 0.1;
        gridBagConstraints.weighty = 0.1;
        add(usernameTxt, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.insets = new java.awt.Insets(12, 12, 12, 12);
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        add(pwLbl, gridBagConstraints);

        pwTxt.setColumns(20);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(12, 0, 12, 12);
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 0.1;
        gridBagConstraints.weighty = 0.1;
        add(pwTxt, gridBagConstraints);

    }//GEN-END:initComponents
    
    private void  initComponentsMore() {
        getAccessibleContext().setAccessibleName(NbBundle.getMessage(FindServerPanel.class, "LBL_Add_Server_Panel"));
        getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(FindServerPanel.class, "LBL_Add_Server_Intro"));
        
        // If the intro text is too long, split it into two
        String intro = NbBundle.getMessage(FindServerPanel.class, "LBL_Add_Server_Intro");
        if (intro.length() > 70) {
            int mid = intro.length() / 2;
            String temp =   "" +                                        //NOI18N
                            intro.substring(0, intro.indexOf(" ", mid)) +     //NOI18N
                            "
" + //NOI18N intro.substring(intro.indexOf(" ", mid) + 1) + //NOI18N ""; //NOI18N introLbl.setText(temp); }else { introLbl.setText(intro); } urlLbl.setText(NbBundle.getMessage(FindServerPanel.class, "LBL_Url")); urlLbl.setDisplayedMnemonic(NbBundle.getMessage(FindServerPanel.class, "LBL_Url_Mnemonic").charAt(0)); urlLbl.setLabelFor(urlTxt); usernameLbl.setText(NbBundle.getMessage(FindServerPanel.class, "LBL_Username")); usernameLbl.setDisplayedMnemonic(NbBundle.getMessage(FindServerPanel.class, "LBL_Username_Mnemonic").charAt(0)); usernameLbl.setLabelFor(usernameTxt); pwLbl.setText(NbBundle.getMessage(FindServerPanel.class, "LBL_Pw")); pwLbl.setDisplayedMnemonic(NbBundle.getMessage(FindServerPanel.class, "LBL_Pw_Mnemonic").charAt(0)); pwLbl.setLabelFor(pwTxt); urlTxt.getDocument().addDocumentListener(new DocumentListener() { public void insertUpdate(DocumentEvent e) { enableOK(); } public void removeUpdate(DocumentEvent e) { enableOK(); } public void changedUpdate(DocumentEvent e) { enableOK(); } private void enableOK() { enableOKButton(getUrl().length() > 0); } }); } /** * Embeds this component in a DialogDescriptor and displays * it in a java.awt.Dialog with two buttons, OK and Cancel. * The URL field is required input, user name and password * are optional (but may be required by the server) * * @param title Title to be used on the dialog. * @param helpId A HelpCtx ID, or null if there is no Help * * @return true if the user has made a valid choice and * selected the OK button. * false if the user selected Cancel. */ public boolean showDialog (String title, String helpId) { // ActionListener listener = new ActionListener () { // public void actionPerformed (ActionEvent evt) { // Object o = evt.getSource (); // if (o == NotifyDescriptor.CANCEL_OPTION ) { // closeDialog (); // return; // } // // } // }; if (title == null) { title = NbBundle.getMessage(FindServerPanel.class, "LBL_Add_Server_Instance_From_Url"); } dialogDescriptor = new DialogDescriptor (this, title); if (helpId!=null) dialogDescriptor.setHelpCtx(new HelpCtx(helpId)); // dialogDescriptor.setClosingOptions (new Object [] { NotifyDescriptor.CANCEL_OPTION }); enableOKButton(false); dialog = DialogDisplayer.getDefault ().createDialog (dialogDescriptor); dialog.setVisible (true); if (dialogDescriptor.getValue () == NotifyDescriptor.OK_OPTION ) { // System.out.println("FindServerPanel showDialog returning true"); return true; } dialogDescriptor = null; return false; } private void enableOKButton (boolean b) { if (dialogDescriptor != null) { dialogDescriptor.setValid(b); } } private void closeDialog () { dialog.setVisible (false); dialog.dispose (); dialog = null; } /** * * @return A String containing the URL that the user entered. * Or an empty string if nothing was entered. */ public String getUrl() { String url = urlTxt.getText(); if (url == null) { return ""; } url.trim(); if (url.length() < 1 ) { return ""; } return url.trim(); } /** * * @return A String containing the user name that the user entered. * Or an empty string if nothing was entered. */ public String getUsername() { String username = usernameTxt.getText(); if (username == null || username.length() == 0 ) { return ""; } return username; } /** * * @return A String containing the URL that the user entered. * Or an empty string if nothing was entered. */ public String getPassword() { String pw = pwTxt.getText(); if (pw == null || pw.length() == 0 ) { return ""; } return pw; } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JPasswordField pwTxt; private javax.swing.JLabel pwLbl; private javax.swing.JTextField usernameTxt; private javax.swing.JTextField urlTxt; private javax.swing.JLabel introLbl; private javax.swing.JLabel urlLbl; private javax.swing.JLabel usernameLbl; // End of variables declaration//GEN-END:variables }
... 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.