KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > project > ui > groups > NewGroupPanelBasic


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.project.ui.groups;
21
22 import java.util.Arrays JavaDoc;
23 import java.util.HashSet JavaDoc;
24 import javax.swing.event.DocumentEvent JavaDoc;
25 import javax.swing.event.DocumentListener JavaDoc;
26 import org.netbeans.api.project.Project;
27 import org.netbeans.api.project.ProjectUtils;
28 import org.netbeans.api.project.ui.OpenProjects;
29
30 /**
31  * Panel permitting user to create a new project group.
32  * Applicable in basic mode.
33  * @author Jesse Glick
34  */

35 public class NewGroupPanelBasic extends AbstractNewGroupPanel {
36
37     public NewGroupPanelBasic() {
38         initComponents();
39         DocumentListener JavaDoc l = new DocumentListener JavaDoc() {
40             public void insertUpdate(DocumentEvent JavaDoc e) {
41                 firePropertyChange(PROP_READY, null, null);
42             }
43             public void removeUpdate(DocumentEvent JavaDoc e) {
44                 firePropertyChange(PROP_READY, null, null);
45             }
46             public void changedUpdate(DocumentEvent JavaDoc e) {}
47         };
48         nameField.getDocument().addDocumentListener(l);
49         Project p = OpenProjects.getDefault().getMainProject();
50         if (p != null) {
51             nameField.setText(ProjectUtils.getInformation(p).getDisplayName());
52         }
53     }
54
55     public boolean isReady() {
56         return nameField.getText() != null && nameField.getText().trim().length() > 0;
57     }
58
59     public Group create() {
60         assert isReady();
61         AdHocGroup g = AdHocGroup.create(nameField.getText().trim(), true);
62         if (useOpenCheckbox.isSelected()) {
63             g.setProjects(new HashSet JavaDoc<Project>(Arrays.asList(OpenProjects.getDefault().getOpenProjects())));
64             g.setMainProject(OpenProjects.getDefault().getMainProject());
65         }
66         return g;
67     }
68
69     /** This method is called from within the constructor to
70      * initialize the form.
71      * WARNING: Do NOT modify this code. The content of this method is
72      * always regenerated by the Form Editor.
73      */

74     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
75
private void initComponents() {
76
77         useOpenCheckbox = new javax.swing.JCheckBox JavaDoc();
78         nameLabel = new javax.swing.JLabel JavaDoc();
79         nameField = new javax.swing.JTextField JavaDoc();
80
81         useOpenCheckbox.setSelected(true);
82         org.openide.awt.Mnemonics.setLocalizedText(useOpenCheckbox, org.openide.util.NbBundle.getMessage(NewGroupPanelBasic.class, "NewGroupPanel.useOpenCheckbox.text")); // NOI18N
83

84         nameLabel.setLabelFor(nameField);
85         org.openide.awt.Mnemonics.setLocalizedText(nameLabel, org.openide.util.NbBundle.getMessage(NewGroupPanelBasic.class, "NewGroupPanel.nameLabel.text")); // NOI18N
86

87         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
88         this.setLayout(layout);
89         layout.setHorizontalGroup(
90             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
91             .add(layout.createSequentialGroup()
92                 .addContainerGap()
93                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
94                     .add(layout.createSequentialGroup()
95                         .add(nameLabel)
96                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
97                         .add(nameField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 417, Short.MAX_VALUE))
98                     .add(useOpenCheckbox))
99                 .addContainerGap())
100         );
101         layout.setVerticalGroup(
102             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
103             .add(layout.createSequentialGroup()
104                 .addContainerGap()
105                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
106                     .add(nameField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
107                     .add(nameLabel))
108                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
109                 .add(useOpenCheckbox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 23, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
110                 .addContainerGap())
111         );
112     }// </editor-fold>//GEN-END:initComponents
113

114     
115     // Variables declaration - do not modify//GEN-BEGIN:variables
116
private javax.swing.JTextField JavaDoc nameField;
117     private javax.swing.JLabel JavaDoc nameLabel;
118     private javax.swing.JCheckBox JavaDoc useOpenCheckbox;
119     // End of variables declaration//GEN-END:variables
120

121 }
122
Popular Tags