1 19 20 package org.netbeans.modules.project.ui.groups; 21 22 import java.util.Arrays ; 23 import java.util.HashSet ; 24 import javax.swing.event.DocumentEvent ; 25 import javax.swing.event.DocumentListener ; 26 import org.netbeans.api.project.Project; 27 import org.netbeans.api.project.ProjectUtils; 28 import org.netbeans.api.project.ui.OpenProjects; 29 30 35 public class NewGroupPanelBasic extends AbstractNewGroupPanel { 36 37 public NewGroupPanelBasic() { 38 initComponents(); 39 DocumentListener l = new DocumentListener () { 40 public void insertUpdate(DocumentEvent e) { 41 firePropertyChange(PROP_READY, null, null); 42 } 43 public void removeUpdate(DocumentEvent e) { 44 firePropertyChange(PROP_READY, null, null); 45 } 46 public void changedUpdate(DocumentEvent 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 <Project>(Arrays.asList(OpenProjects.getDefault().getOpenProjects()))); 64 g.setMainProject(OpenProjects.getDefault().getMainProject()); 65 } 66 return g; 67 } 68 69 74 private void initComponents() { 76 77 useOpenCheckbox = new javax.swing.JCheckBox (); 78 nameLabel = new javax.swing.JLabel (); 79 nameField = new javax.swing.JTextField (); 80 81 useOpenCheckbox.setSelected(true); 82 org.openide.awt.Mnemonics.setLocalizedText(useOpenCheckbox, org.openide.util.NbBundle.getMessage(NewGroupPanelBasic.class, "NewGroupPanel.useOpenCheckbox.text")); 84 nameLabel.setLabelFor(nameField); 85 org.openide.awt.Mnemonics.setLocalizedText(nameLabel, org.openide.util.NbBundle.getMessage(NewGroupPanelBasic.class, "NewGroupPanel.nameLabel.text")); 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 } 114 115 private javax.swing.JTextField nameField; 117 private javax.swing.JLabel nameLabel; 118 private javax.swing.JCheckBox useOpenCheckbox; 119 121 } 122 | Popular Tags |