KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > execution > beaninfo > editors > NbProcessDescriptorCustomEditor


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.core.execution.beaninfo.editors;
21
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import java.io.File JavaDoc;
25
26 import javax.swing.JFileChooser JavaDoc;
27
28 import org.openide.execution.NbProcessDescriptor;
29 import org.openide.explorer.propertysheet.PropertyEnv;
30 import org.openide.util.HelpCtx;
31 import org.openide.util.NbBundle;
32
33 /** Custom property editor for NbProcessDescriptor class.
34 *
35 * @author Ian Formanek
36 */

37 public class NbProcessDescriptorCustomEditor extends javax.swing.JPanel JavaDoc
38 implements PropertyChangeListener JavaDoc {
39     private NbProcessDescriptorEditor editor;
40
41     private static int DEFAULT_WIDTH = 530;
42     private static int DEFAULT_HEIGHT = 400;
43
44     static final long serialVersionUID =-2766277953540349247L;
45     /** Creates new NbProcessDescriptorCustomEditor
46      * @param editor the NbProcessDescriptorEditor
47      */

48     public NbProcessDescriptorCustomEditor (NbProcessDescriptorEditor editor, PropertyEnv env) {
49         this.editor = editor;
50         initComponents ();
51         
52         if ( editor.pd != null ) {
53             processField.setText (editor.pd.getProcessName ());
54             argumentsArea.setText (editor.pd.getArguments ());
55             hintArea.setText (editor.pd.getInfo ());
56         }
57         
58
59         processField.getAccessibleContext().setAccessibleDescription(getString("ACSD_NbProcessDescriptorCustomEditor.processLabel"));
60         argumentsArea.getAccessibleContext().setAccessibleDescription(getString("ACSD_NbProcessDescriptorCustomEditor.argumentsLabel"));
61         hintArea.getAccessibleContext().setAccessibleDescription(getString("ACSD_NbProcessDescriptorCustomEditor.argumentKeyLabel"));
62         jButton1.getAccessibleContext().setAccessibleDescription(getString("ACSD_NbProcessDescriptorCustomEditor.jButton1"));
63         
64         getAccessibleContext().setAccessibleDescription(getString("ACSD_CustomNbProcessDescriptorEditor"));
65
66         HelpCtx.setHelpIDString (this, NbProcessDescriptorCustomEditor.class.getName ());
67
68         env.setState(PropertyEnv.STATE_NEEDS_VALIDATION);
69         env.addPropertyChangeListener(this);
70     }
71
72     public java.awt.Dimension JavaDoc getPreferredSize() {
73         java.awt.Dimension JavaDoc inh = super.getPreferredSize ();
74         return new java.awt.Dimension JavaDoc (DEFAULT_WIDTH, Math.max (inh.height, DEFAULT_HEIGHT));
75     }
76
77     /** Get the customized property value.
78     * @return the property value
79     * @exception InvalidStateException when the custom property editor does not contain a valid property value
80     * (and thus it should not be set)
81     */

82     private Object JavaDoc getPropertyValue () throws IllegalStateException JavaDoc {
83         if ( editor.pd == null )
84             return new NbProcessDescriptor (processField.getText (), argumentsArea.getText () );
85         return new NbProcessDescriptor (processField.getText (), argumentsArea.getText (), editor.pd.getInfo ());
86     }
87
88     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
89         if (PropertyEnv.PROP_STATE.equals(evt.getPropertyName()) && evt.getNewValue() == PropertyEnv.STATE_VALID) {
90             editor.setValue(getPropertyValue());
91         }
92     }
93     
94     /** This method is called from within the constructor to
95      * initialize the form.
96      * WARNING: Do NOT modify this code. The content of this method is
97      * always regenerated by the FormEditor.
98      */

99     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
100
private void initComponents() {
101         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
102
103         processLabel = new javax.swing.JLabel JavaDoc();
104         processField = new javax.swing.JTextField JavaDoc();
105         jButton1 = new javax.swing.JButton JavaDoc();
106         argumentsLabel = new javax.swing.JLabel JavaDoc();
107         argumentsScrollPane = new javax.swing.JScrollPane JavaDoc();
108         argumentsArea = new javax.swing.JTextArea JavaDoc();
109         jPanel1 = new javax.swing.JPanel JavaDoc();
110         argumentKeyLabel = new javax.swing.JLabel JavaDoc();
111         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
112         hintArea = new javax.swing.JTextArea JavaDoc();
113
114         setBorder(javax.swing.BorderFactory.createEmptyBorder(12, 12, 0, 11));
115         setLayout(new java.awt.GridBagLayout JavaDoc());
116
117         processLabel.setLabelFor(processField);
118         org.openide.awt.Mnemonics.setLocalizedText(processLabel, getString("CTL_NbProcessDescriptorCustomEditor.processLabel.text")); // NOI18N
119
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
120         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
121         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 12);
122         add(processLabel, gridBagConstraints);
123         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
124         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.RELATIVE;
125         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
126         gridBagConstraints.weightx = 3.0;
127         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 5);
128         add(processField, gridBagConstraints);
129
130         org.openide.awt.Mnemonics.setLocalizedText(jButton1, getString("CTL_NbProcessDescriptorCustomEditor.jButton1.text")); // NOI18N
131
jButton1.addActionListener(new java.awt.event.ActionListener JavaDoc() {
132             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
133                 jButton1ActionPerformed(evt);
134             }
135         });
136         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
137         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
138         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
139         add(jButton1, gridBagConstraints);
140
141         argumentsLabel.setLabelFor(argumentsArea);
142         org.openide.awt.Mnemonics.setLocalizedText(argumentsLabel, org.openide.util.NbBundle.getMessage(NbProcessDescriptorCustomEditor.class, "CTL_NbProcessDescriptorCustomEditor.argumentsLabel.text")); // NOI18N
143
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
144         gridBagConstraints.gridx = 0;
145         gridBagConstraints.gridy = 1;
146         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
147         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 12);
148         add(argumentsLabel, gridBagConstraints);
149
150         argumentsScrollPane.setMinimumSize(new java.awt.Dimension JavaDoc(22, 35));
151         argumentsScrollPane.setViewportView(argumentsArea);
152
153         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
154         gridBagConstraints.gridx = 1;
155         gridBagConstraints.gridy = 1;
156         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
157         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
158         gridBagConstraints.weightx = 1.0;
159         gridBagConstraints.weighty = 1.0;
160         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
161         add(argumentsScrollPane, gridBagConstraints);
162
163         jPanel1.setLayout(new java.awt.BorderLayout JavaDoc(0, 2));
164
165         argumentKeyLabel.setLabelFor(hintArea);
166         org.openide.awt.Mnemonics.setLocalizedText(argumentKeyLabel, getString("CTL_NbProcessDescriptorCustomEditor.argumentKeyLabel.text")); // NOI18N
167
jPanel1.add(argumentKeyLabel, java.awt.BorderLayout.NORTH);
168
169         hintArea.setLineWrap(true);
170         hintArea.setEditable(false);
171         hintArea.setBackground((java.awt.Color JavaDoc) javax.swing.UIManager.getDefaults ().get ("Label.background"));
172         jScrollPane1.setViewportView(hintArea);
173
174         jPanel1.add(jScrollPane1, java.awt.BorderLayout.CENTER);
175
176         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
177         gridBagConstraints.gridwidth = 3;
178         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
179         gridBagConstraints.weightx = 7.0;
180         gridBagConstraints.weighty = 7.0;
181         add(jPanel1, gridBagConstraints);
182     }// </editor-fold>//GEN-END:initComponents
183

184     private void jButton1ActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButton1ActionPerformed
185
// Add your handling code here:
186
JFileChooser JavaDoc chooser = org.netbeans.beaninfo.editors.FileEditor.createHackedFileChooser();
187         chooser.setMultiSelectionEnabled (false);
188         File JavaDoc init = new File JavaDoc(processField.getText()); // #13372
189
if (init.isFile()) {
190             chooser.setCurrentDirectory(init.getParentFile());
191             chooser.setSelectedFile(init);
192         }
193         int retVal = chooser.showOpenDialog (this);
194         if (retVal == JFileChooser.APPROVE_OPTION) {
195             String JavaDoc absolute_name = chooser.getSelectedFile ().getAbsolutePath ();
196             //System.out.println("file:" + absolute_name); // NOI18N
197
processField.setText (absolute_name);
198         }
199     }//GEN-LAST:event_jButton1ActionPerformed
200

201
202
203
204     // Variables declaration - do not modify//GEN-BEGIN:variables
205
private javax.swing.JLabel JavaDoc argumentKeyLabel;
206     private javax.swing.JTextArea JavaDoc argumentsArea;
207     private javax.swing.JLabel JavaDoc argumentsLabel;
208     private javax.swing.JScrollPane JavaDoc argumentsScrollPane;
209     private javax.swing.JTextArea JavaDoc hintArea;
210     private javax.swing.JButton JavaDoc jButton1;
211     private javax.swing.JPanel JavaDoc jPanel1;
212     private javax.swing.JScrollPane JavaDoc jScrollPane1;
213     private javax.swing.JTextField JavaDoc processField;
214     private javax.swing.JLabel JavaDoc processLabel;
215     // End of variables declaration//GEN-END:variables
216

217     private static final String JavaDoc getString(String JavaDoc s) {
218         return NbBundle.getMessage(NbProcessDescriptorCustomEditor.class, s);
219     }
220
221 }
222
Popular Tags