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-2003 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.modules.autoupdate;

import java.awt.Font;
import java.awt.KeyboardFocusManager;
import java.awt.Window;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
import java.util.Iterator;

import javax.swing.JFileChooser;
import javax.swing.DefaultListModel;
import javax.swing.DefaultListSelectionModel;

import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import org.openide.util.NbBundle;
import org.openide.util.Utilities;
import org.openide.windows.WindowManager;

class SelectModulesPanel extends javax.swing.JPanel {
    
    private static final String EMPTY_STRING = ""; // NOI18N

    private static final javax.swing.filechooser.FileFilter NBM_FILE_FILTER = new NbmFileFilter();

    /** The list model */
    private DefaultListModel modulesModel;

    /** Stores the last selected directory */
    static File defaultDir = null;

    private Wizard.Validator validator;

    static final long serialVersionUID =8279789280479374665L;
    
    /** Creates new form SelectModulesPanel */
    public SelectModulesPanel(Wizard.Validator validator) {
        putClientProperty("WizardPanel_contentSelectedIndex", new Integer(1)); // NOI18N
        setName(getBundle("LAB_Select"));
        initComponents();
        
        this.validator = validator;

        getAccessibleContext().setAccessibleName(getBundle("LAB_Select"));
        getAccessibleContext().setAccessibleDescription(getBundle("LAB_21") + getBundle("LAB_22"));
        jTextArea.getAccessibleContext().setAccessibleDescription(getBundle("ACS_21"));
        addButton.getAccessibleContext().setAccessibleDescription(getBundle("ACS_Add"));
        removeButton.getAccessibleContext().setAccessibleDescription(getBundle("ACS_Remove"));
        jList.getAccessibleContext().setAccessibleDescription(getBundle("ACS_InstallList"));
        
        listLabel.setDisplayedMnemonic(getBundle("LAB_ModulesList_Mnemonic").charAt(0));

        reset();
    }

    /** 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;

        jTextArea = new javax.swing.JTextArea();
        jScrollPane1 = new javax.swing.JScrollPane();
        jList = new javax.swing.JList();
        addButton = new javax.swing.JButton();
        removeButton = new javax.swing.JButton();
        nextLabel = new javax.swing.JLabel();
        listLabel = new javax.swing.JLabel();

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

        jTextArea.setBackground(nextLabel.getBackground());
        jTextArea.setFont(new Font("Dialog", Font.PLAIN, jTextArea.getFont().getSize()));
        jTextArea.setLineWrap(true);
        jTextArea.setText(getBundle("LAB_21"));
        jTextArea.setWrapStyleWord(true);
        jTextArea.setDisabledTextColor(java.awt.Color.black);
        jTextArea.setEnabled(false);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0);
        add(jTextArea, gridBagConstraints);

        jList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                jListValueChanged(evt);
            }
        });

        jScrollPane1.setViewportView(jList);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        add(jScrollPane1, gridBagConstraints);

        addButton.setMnemonic(getBundle("BTN_Add_Mnemonic").charAt(0));
        addButton.setText(getBundle("BTN_Add"));
        addButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addButtonActionPerformed(evt);
            }
        });

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

        removeButton.setMnemonic(getBundle("BTN_Remove_Mnemonic").charAt(0));
        removeButton.setText(getBundle("BTN_Remove"));
        removeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeButtonActionPerformed(evt);
            }
        });

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

        nextLabel.setLabelFor(this);
        nextLabel.setText(getBundle("LAB_22"));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 0);
        add(nextLabel, gridBagConstraints);

        listLabel.setLabelFor(jList);
        listLabel.setText(getBundle("LAB_ModulesList"));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 2, 0);
        add(listLabel, gridBagConstraints);

    }//GEN-END:initComponents

    private void jListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jListValueChanged
        buttonsCheck();
    }//GEN-LAST:event_jListValueChanged

    private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed
        Object[] sel = jList.getSelectedValues();
        for (int i=0;i 0 && jList.getSelectedIndex() != -1 )
            removeButton.setEnabled(true);
        else
            removeButton.setEnabled(false);
    }

    private static class NbmFileFilter extends javax.swing.filechooser.FileFilter {
        public boolean accept( File f ) {
            return f.isDirectory () || f.getName().toLowerCase().endsWith( ".nbm" ); // NOI18N
        }

        public String getDescription() {
            return getBundle( "CTL_FileFilterDescription" );
        }
    }
    
    static File getDefaultDir() {
        File defDir = new File( System.getProperty("user.home") );  // NOI18N
        try {
            if ( Utilities.isUnix() )
                return defDir;
            else if ( Utilities.isWindows() ) {
                do {
                    defDir = defDir.getParentFile();
                } while ( defDir != null && defDir.getParentFile() != null );
            }
        }
        catch (Exception ex) {
            defDir = null;
        }
        return defDir;
    }

    static List selectNbmFiles() {
        JFileChooser chooser = new JFileChooser();
        chooser.setFileSelectionMode( JFileChooser.FILES_AND_DIRECTORIES );
        chooser.addChoosableFileFilter( NBM_FILE_FILTER );
        chooser.setFileFilter(NBM_FILE_FILTER);
        chooser.setMultiSelectionEnabled( true );
        chooser.setFileHidingEnabled( false );
        chooser.setDialogTitle(getBundle("CTL_FileChooser_Title"));
        
        if (defaultDir == null)
            defaultDir = getDefaultDir();

        if ( defaultDir != null) {
            chooser.setCurrentDirectory( defaultDir );
        }

        List files = null;
        
        Window focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager ().getActiveWindow ();

        if (chooser.showDialog (KeyboardFocusManager.getCurrentKeyboardFocusManager ().getActiveWindow (), 
                               getBundle("CTL_FileChooser_Approve_Button"))
                == JFileChooser.APPROVE_OPTION) {

            File[] selected = chooser.getSelectedFiles();

            File dir = null;
            files = new ArrayList();

            for (int i=0; i
... 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.