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

/*
 * InputLines.java
 *
 * Created on May 16, 2003, 1:59 PM
 */

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

import org.openide.NotifyDescriptor;
import java.awt.BorderLayout;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.border.*;
import javax.swing.JPanel;
import java.awt.Component;

/**
 * Enhancement from NotifyDescriptor.InputLine (maybe need to move this a general place?)
 * @author  nn136682
 */

public class InputLines extends NotifyDescriptor {
    /**
     * The texts field used to enter the input.
     */
    protected JTextField[] textFields;
    
    /** Construct dialog with the specified title and label text.
     * @param texts label texts
     * @param accessibleTexts accessible texts
     * @param title title of the dialog
     */
    public InputLines(
    final String[] texts, 
    final String[] accessibleTexts,
    final String[] toolTips, 
    final String title) {
        this(texts, accessibleTexts, toolTips, title, OK_CANCEL_OPTION, PLAIN_MESSAGE);
    }
    
    /** Construct dialog with the specified title, label text, option and
     * message types.
     * @param texts label texts
     * @param accessibleTexts accessible texts
     * @param title title of the dialog
     * @param optionType option type (ok, cancel, ...)
     * @param messageType message type (question, ...)
     */
    public InputLines(
    final String[] texts,
    final String[] accessibleTexts,
    final String[] toolTips,
    final String title,
    final int optionType,
    final int messageType) {
        
        super(null, title, optionType, messageType, null, null);
        super.setMessage(createDesign(texts, accessibleTexts, toolTips));
    }
    
    /**
     * Get the text which the user typed into the input line.
     * @return the text entered by the user
     */
    public String getInputText(int i) {
        return textFields[i].getText();
    }
    
    /**
     * Set the text on the input line.
     * @param i index of the input text to set
     * @param text the new text
     */
    public void setInputText(int i , final String text) {
        textFields[i].setText(text);
        textFields[i].selectAll();
    }
    
    /** Make a component representing the input line.
     * @param text a label for the input line
     * @return the component
     */
    protected Component createDesign(
    final String[] texts, 
    final String[] accessibleTexts,
    final String[] toolTips) {
        textFields = new JTextField[texts.length];
        JPanel panel = new JPanel();
        //panel.setLayout(new BorderLayout());
        //panel.setBorder(new EmptyBorder(11, 12, 1, 11));
        panel.setLayout(new java.awt.GridBagLayout());
        panel.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(102, 102, 153)));
        
        panel.getAccessibleContext().setAccessibleDescription(accessibleTexts[0]);
        for (int i=0; i= 0 && index + 1 < text.length()) {
            mnemonic = text.charAt(index + 1);
            txt = text.substring(0, index) + text.substring(index + 1);
        } else {
            txt = text;
        }
        JLabel textLabel = new JLabel(txt);
        if(txt != null && txt.length() > 0) {
            textLabel.setDisplayedMnemonic(mnemonic == 0 ? text.charAt(0) : mnemonic);
        }
        
        textLabel.setLabelFor(textField);
        textLabel.setToolTipText(toolTip);
        
        java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = i;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(12, 12, 12, 12);
        panel.add(textLabel, gridBagConstraints);
        
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = i;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(12, 0, 12, 12);
        panel.add(textField, gridBagConstraints);
        
            /*textLabel.setBorder(new EmptyBorder(0, 0, 0, 10));
            panel.add("West", textLabel); // NOI18N
            panel.add("Center", textField); // NOI18N
            textLabel.setLabelFor(textField);
            textField.setBorder(new CompoundBorder(textField.getBorder(), new EmptyBorder(2, 0, 2, 0)));
             */
        javax.swing.KeyStroke enter = javax.swing.KeyStroke.getKeyStroke(
        java.awt.event.KeyEvent.VK_ENTER, 0
        );
        javax.swing.text.Keymap map = textField.getKeymap();
        
        map.removeKeyStrokeBinding(enter);
        
        return textField;
    }
}
... 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.