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.vcscore.ui;

/**
 *
 * @author  Milos Kleint
 */

import org.netbeans.modules.vcscore.util.table.*;
import org.openide.filesystems.*;
import java.util.*;
import javax.swing.table.*;
import javax.swing.*;
import java.lang.reflect.*;
import org.openide.util.*;


public class ToAddFilesPanel extends javax.swing.JPanel {

    private TableInfoModel model;

    /** 
     * Creates new panel with files that should be added (verify group action)
     */
    public ToAddFilesPanel(List fileObjectList) {
        initComponents();

        cbPerform.setMnemonic (org.openide.util.NbBundle.getBundle (ToAddFilesPanel.class).getString ("ToAddFilesPanel.cbPerform.mnemonic").charAt (0));
        rbAll.setMnemonic (org.openide.util.NbBundle.getBundle (ToAddFilesPanel.class).getString ("ToAddFilesPanel.rbAll.mnemonic").charAt (0));
        rbSelectedOnly.setMnemonic (org.openide.util.NbBundle.getBundle (ToAddFilesPanel.class).getString ("ToAddFilesPanel.rbSelectedOnly.mnemonic").charAt (0));
        jTextArea1.setFont (javax.swing.UIManager.getFont ("Label.font"));
        jTextArea1.setForeground (javax.swing.UIManager.getColor ("Label.foreground"));

        rbAll.setSelected(true);
        rbSelectedOnly.setSelected(false);
        rbAll.setEnabled(false);
        rbSelectedOnly.setEnabled(false);
        buttonGroup1.add(rbAll);
        buttonGroup1.add(rbSelectedOnly);
        // setting the model....
        model = new TableInfoModel();
        Class classa = FileObject.class;
        String  column1 = NbBundle.getBundle(ToAddFilesPanel.class).getString("ToAddFilesPanel.fileColumn"); // NOI18N
        String  column2 = NbBundle.getBundle(ToAddFilesPanel.class).getString("ToAddFilesPanel.pathColumn"); // NOI18N
        try {
            Method method1 = classa.getMethod("getNameExt", null);     // NOI18N
            Method method2 = classa.getMethod("getParent", null);     // NOI18N
            model.setColumnDefinition(0, column1, method1, true, null);
            model.setColumnDefinition(1, column2, method2, true, new PackageComparator());
        } catch (NoSuchMethodException exc) {
            Thread.dumpStack();
        } catch (SecurityException exc2) {
            Thread.dumpStack();
        }
        Iterator it = fileObjectList.iterator();
        while (it.hasNext()) {
            model.addElement(it.next());
        }
        tblToBeAddedFiles.setModel(model);
        JTableHeader head = tblToBeAddedFiles.getTableHeader();
        head.setUpdateTableInRealTime(true);
        ColumnSortListener listen = new ColumnSortListener(tblToBeAddedFiles);
        head.addMouseListener(listen);        
        initAccessibility();
    }

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

        buttonGroup1 = new javax.swing.ButtonGroup();
        jTextArea1 = new javax.swing.JTextArea();
        cbPerform = new javax.swing.JCheckBox();
        rbAll = new javax.swing.JRadioButton();
        rbSelectedOnly = new javax.swing.JRadioButton();
        spToBeAddedFiles = new javax.swing.JScrollPane();
        tblToBeAddedFiles = new javax.swing.JTable();

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

        setPreferredSize(new java.awt.Dimension(250, 250));
        jTextArea1.setEditable(false);
        jTextArea1.setLineWrap(true);
        jTextArea1.setText(org.openide.util.NbBundle.getBundle(ToAddFilesPanel.class).getString("ToAddFilesPanel.lblDescription.text"));
        jTextArea1.setWrapStyleWord(true);
        jTextArea1.setOpaque(false);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(12, 12, 12, 11);
        add(jTextArea1, gridBagConstraints);
        jTextArea1.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ToAddFilesPanel.class, "ACS_ToAddFilesPanel.jTextArea"));
        jTextArea1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ToAddFilesPanel.class, "ACSD_ToAddFilesPanel.jTextArea"));

        cbPerform.setText(org.openide.util.NbBundle.getBundle(ToAddFilesPanel.class).getString("ToAddFilesPanel.cbPerform.text"));
        cbPerform.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbPerformActionPerformed(evt);
            }
        });

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

        rbAll.setText(org.openide.util.NbBundle.getBundle(ToAddFilesPanel.class).getString("ToAddFilesPanel.rbAll.text"));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 11);
        add(rbAll, gridBagConstraints);

        rbSelectedOnly.setText(org.openide.util.NbBundle.getBundle(ToAddFilesPanel.class).getString("ToAddFilesPanel.rbSelectedOnly.text"));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 11);
        add(rbSelectedOnly, gridBagConstraints);

        spToBeAddedFiles.setMinimumSize(new java.awt.Dimension(150, 120));
        spToBeAddedFiles.setViewportView(tblToBeAddedFiles);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(5, 30, 11, 11);
        add(spToBeAddedFiles, gridBagConstraints);

    }//GEN-END:initComponents

    private void cbPerformActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbPerformActionPerformed
        // Add your handling code here:
        rbAll.setEnabled(cbPerform.isSelected());
        rbSelectedOnly.setEnabled(cbPerform.isSelected());
    }//GEN-LAST:event_cbPerformActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JCheckBox cbPerform;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JRadioButton rbAll;
    private javax.swing.JRadioButton rbSelectedOnly;
    private javax.swing.JScrollPane spToBeAddedFiles;
    private javax.swing.JTable tblToBeAddedFiles;
    // End of variables declaration//GEN-END:variables

    private static final long serialVersionUID = -6548817009138402660L;    

    private void initAccessibility() {
        cbPerform.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ToAddFilesPanel.class, "ACSD.ToAddFilesPanel.cbPerform"));
        jTextArea1.getAccessibleContext().setAccessibleName(NbBundle.getMessage(ToAddFilesPanel.class, "ACSN.ToAddFilesPanel.jTextArea1"));
        jTextArea1.getAccessibleContext().setAccessibleName(NbBundle.getMessage(ToAddFilesPanel.class, "ACSD.ToAddFilesPanel.jTextArea1"));
        spToBeAddedFiles.getAccessibleContext().setAccessibleName(cbPerform.getText());
        spToBeAddedFiles.getAccessibleContext().setAccessibleDescription(jTextArea1.getText());
        rbAll.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ToAddFilesPanel.class, "ACSD.ToAddFilesPanel.rbAll"));
        rbSelectedOnly.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ToAddFilesPanel.class, "ACSD.ToAddFilesPanel.rbSelectedOnly"));
        tblToBeAddedFiles.getAccessibleContext().setAccessibleName(NbBundle.getMessage(ToAddFilesPanel.class, "ACSN.ToAddFilesPanel.tblToBeAddedFiles"));
        tblToBeAddedFiles.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ToAddFilesPanel.class, "ACSD.ToAddFilesPanel.tblToBeAddedFiles"));
    }
    
    /** 
     * returns the selected fileobjects. if the action should not be performed, returns null
     */
    
    public java.util.List getFileObjects() {
        if (cbPerform.isSelected()) {
            if (rbAll.isSelected()) {
               return model.getList();
            } else {
                java.util.List list = new LinkedList();
                int[] rows = tblToBeAddedFiles.getSelectedRows();
                for (int i = 0; i< rows.length; i++) {
                    list.add(model.getElementAt(rows[i]));
                }
                return list;
            }
        }
        return null;
    }
    
}
... 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.