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 java.awt.Font;

import org.openide.util.NbBundle;

class DownloadProgressPanel extends javax.swing.JPanel implements ProgressDialog {

    private static final String EMPTY_STRING = ""; // NOI18N

    /** The dialog */
    private Dialog dialog;
    /** Title of the dialog */
    private String title;
    /** Current value of the jProgressBar2 */
    private int overallValue;
    /** Current value of the jProgressBar1 */
    private int partialValue;

    static final long serialVersionUID =1986287669107010921L;
    
    private Wizard.WizardPanel wizardPanel;
    
    /** Creates new form DownloadProgressPanel */
    public DownloadProgressPanel(Wizard.WizardPanel wizardPanel) {        
        this.wizardPanel = wizardPanel;
        putClientProperty("WizardPanel_contentSelectedIndex", new Integer(2)); // NOI18N
        setName(getBundle("LBL_Download"));
        initComponents();
        
        jLabel2.setText( EMPTY_STRING );
        jLabel1.setText( EMPTY_STRING );

        getAccessibleContext().setAccessibleName(getBundle("LBL_Download"));
        getAccessibleContext().setAccessibleDescription(getBundle("LBL_31"));
        jTextArea1.getAccessibleContext().setAccessibleName(getBundle("ACS_31"));
        jTextArea1.getAccessibleContext().setAccessibleDescription(getBundle("ACSD_31"));        
        jProgressBar1.getAccessibleContext().setAccessibleDescription(getBundle("ACSD_ProgressBar1"));
        jProgressBar2.getAccessibleContext().setAccessibleDescription(getBundle("ACSD_ProgressBar2"));
        
    }
    
   
    
    /** Overload getPreffered size to get a bit bigger dialog */
    public java.awt.Dimension getPreferredSize() {
        return new java.awt.Dimension( 350, super.getPreferredSize().height );
    }
    
    /** 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;

        jTextArea1 = new javax.swing.JTextArea();
        jLabel1 = new javax.swing.JLabel();
        jProgressBar1 = new javax.swing.JProgressBar();
        jLabel2 = new javax.swing.JLabel();
        jProgressBar2 = new javax.swing.JProgressBar();
        bottomLabel = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();

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

        jTextArea1.setBackground(jLabel1.getBackground());
        jTextArea1.setEditable(false);
        jTextArea1.setFont(new Font("Dialog", Font.PLAIN, jTextArea1.getFont().getSize()));
        jTextArea1.setLineWrap(true);
        jTextArea1.setText(getBundle("LBL_31"));
        jTextArea1.setWrapStyleWord(true);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 1.0;
        add(jTextArea1, gridBagConstraints);

        jLabel1.setLabelFor(jProgressBar1);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 0);
        add(jLabel1, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.ipady = 10;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        add(jProgressBar1, gridBagConstraints);

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

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.ipady = 10;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        add(jProgressBar2, gridBagConstraints);

        bottomLabel.setLabelFor(this);
        bottomLabel.setText(getBundle("LBL_32"));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 0);
        add(bottomLabel, gridBagConstraints);

        jButton1.setMnemonic(getBundle("BTN_Stop_Mnem").charAt(0));
        jButton1.setText(getBundle("BTN_Stop"));
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

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

    }//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        if (IncompleteDialog.showDialog() == IncompleteDialog.STOP)
            wizardPanel.end(false);
    }//GEN-LAST:event_jButton1ActionPerformed
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel bottomLabel;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JProgressBar jProgressBar1;
    private javax.swing.JProgressBar jProgressBar2;
    private javax.swing.JTextArea jTextArea1;
    // End of variables declaration//GEN-END:variables

    private static final java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/autoupdate/Bundle"); // NOI18N

    void setEnableStop(boolean enable) {
        jButton1.setEnabled(enable);
    }
    
    // IMPLEMENTATION OF ProgressDialog -----------------------------------------

    /** Closes the dialog */
    public void close() {
        dialog.setVisible( false );
        dialog.dispose();
        dialog = null;
    }

    /** Indexed getter for property gaugeValue.
     *@param index Index of the property.
     *@return Value of the property at index.
     */
    public int getGaugeValue(int gauge) {
        if ( gauge == PARTIAL_GAUGE ) {
            return partialValue;
        }
        else if ( gauge == OVERALL_GAUGE ) {
            return overallValue;
        }
        else {
            return -1;
        }
    }

    /** Indexed setter for property gaugeValue.
     *@param index Index of the property.
     *@param gaugeValue New value of the property at index.
     */
    public void setGaugeValue(int gauge, final int gaugeValue) {
        if ( gauge == PARTIAL_GAUGE ) {
            partialValue = gaugeValue;
            javax.swing.SwingUtilities.invokeLater( new Runnable() {
                                                        public void run() {
                                                            jProgressBar1.setValue( gaugeValue );
                                                        }
                                                    } );
        }
        else if ( gauge == OVERALL_GAUGE ) {
            overallValue = gaugeValue;
            javax.swing.SwingUtilities.invokeLater( new Runnable() {
                                                        public void run() {
                                                            jProgressBar2.setValue( gaugeValue );
                                                        }
                                                    } );
        }
    }

    /** Indexed setter for property gaugeBounds.
     *@param index Index of the property.
     *@param gaugeBounds New value of the property at index.
     */
    public void setGaugeBounds(int gauge, final int gaugeMin, final int gaugeMax) {
        if ( gauge == PARTIAL_GAUGE ) {
            javax.swing.SwingUtilities.invokeLater( new Runnable() {
                                                        public void run() {
                                                            jProgressBar1.setMinimum( gaugeMin );
                                                            jProgressBar1.setMaximum( gaugeMax );
                                                        }
                                                    } );
        }
        else if ( gauge == OVERALL_GAUGE ) {
            javax.swing.SwingUtilities.invokeLater( new Runnable() {
                                                        public void run() {
                                                            jProgressBar2.setMinimum( gaugeMin );
                                                            jProgressBar2.setMaximum( gaugeMax );
                                                        }
                                                    } );
        }
    }

    /** Indexed getter for property labelText.
     *@param index Index of the property.
     *@return Value of the property at index.
     */
    public String getLabelText(int label) {
        if ( label == PARTIAL_LABEL ) {
            return jLabel1.getText();
        }
        else if ( label == OVERALL_LABEL ) {
            return jLabel2.getText();
        }
        else if ( label == EXTRA_LABEL ) {
            return bottomLabel.getText();
        }

        else {
            return null;
        }
    }

    /** Indexed setter for property labelText.
     *@param index Index of the property.
     *@param labelText New value of the property at index.
     */
    public void setLabelText(int label, final String labelText) {
        if ( label == PARTIAL_LABEL ) {
            javax.swing.SwingUtilities.invokeLater( new Runnable() {
                                                        public void run() {
                                                            jLabel1.setText( labelText );
                                                        }
                                                    } );
        }
        else if ( label == OVERALL_LABEL ) {
            javax.swing.SwingUtilities.invokeLater( new Runnable() {
                                                        public void run() {
                                                            jLabel2.setText( labelText );
                                                        }
                                                    } );
        }
        else if ( label == EXTRA_LABEL ) {
            javax.swing.SwingUtilities.invokeLater( new Runnable() {
                                                        public void run() {
                                                            bottomLabel.setText( labelText );
                                                        }
                                                    } );
        }
    }

    /** Getter for property title.
     *@return Value of property title.
     */
    public String getTitle() {
        return title;
    }

    /** Setter for property title.
     *@param title New value of property title.
     */
    public void setTitle(String title) {
        this.title = title;
    }
    
    private static String getBundle( String key ) {
        return NbBundle.getMessage( DownloadProgressPanel.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.