KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > scripting > php > dbginterface > ui > VariablesFilter


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

19
20 package org.netbeans.modules.scripting.php.dbginterface.ui;
21
22 import java.awt.event.ItemEvent JavaDoc;
23 import javax.swing.JPanel JavaDoc;
24 import org.netbeans.modules.scripting.php.dbginterface.api.VariableNode;
25 import org.netbeans.modules.scripting.php.dbginterface.VariablesModelFilter;
26 import org.openide.DialogDescriptor;
27 import org.openide.DialogDisplayer;
28
29 /**
30  *
31  * @author Peter Williams
32  */

33 public class VariablesFilter extends JPanel JavaDoc {
34     
35     // Temporary to default functions to off and test filtering code.
36
private boolean [] filters;
37     private boolean initializing;
38     
39     /** Creates new form VariablesFilter */
40     public VariablesFilter(boolean [] currentFilters) {
41         filters = currentFilters;
42         initializing = false;
43         
44         initComponents();
45         initUserComponents();
46         initState();
47     }
48     
49     public boolean [] getFilters() {
50         return filters;
51     }
52     
53     /** This method is called from within the constructor to
54      * initialize the form.
55      * WARNING: Do NOT modify this code. The content of this method is
56      * always regenerated by the Form Editor.
57      */

58     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
59
private void initComponents() {
60         labelFieldsToDisplay = new javax.swing.JLabel JavaDoc();
61         checkScriptField = new javax.swing.JCheckBox JavaDoc();
62         checkJavaField = new javax.swing.JCheckBox JavaDoc();
63         checkUndefinedField = new javax.swing.JCheckBox JavaDoc();
64         checkScriptAdapter = new javax.swing.JCheckBox JavaDoc();
65         checkFunctions = new javax.swing.JCheckBox JavaDoc();
66
67         labelFieldsToDisplay.setText("Select the fields to show:");
68
69         checkScriptField.setText("Script Field");
70         checkScriptField.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
71         checkScriptField.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
72         checkScriptField.addItemListener(new java.awt.event.ItemListener JavaDoc() {
73             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
74                 checkScriptFieldItemStateChanged(evt);
75             }
76         });
77
78         checkJavaField.setText("Java Field");
79         checkJavaField.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
80         checkJavaField.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
81         checkJavaField.addItemListener(new java.awt.event.ItemListener JavaDoc() {
82             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
83                 checkJavaFieldItemStateChanged(evt);
84             }
85         });
86
87         checkUndefinedField.setText("Undefined Field");
88         checkUndefinedField.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
89         checkUndefinedField.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
90         checkUndefinedField.addItemListener(new java.awt.event.ItemListener JavaDoc() {
91             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
92                 checkUndefinedFieldItemStateChanged(evt);
93             }
94         });
95
96         checkScriptAdapter.setText("Script Adapter");
97         checkScriptAdapter.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
98         checkScriptAdapter.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
99         checkScriptAdapter.addItemListener(new java.awt.event.ItemListener JavaDoc() {
100             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
101                 checkScriptAdapterItemStateChanged(evt);
102             }
103         });
104
105         checkFunctions.setText("Functions");
106         checkFunctions.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
107         checkFunctions.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
108         checkFunctions.addItemListener(new java.awt.event.ItemListener JavaDoc() {
109             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
110                 checkFunctionsItemStateChanged(evt);
111             }
112         });
113
114         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
115         this.setLayout(layout);
116         layout.setHorizontalGroup(
117             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
118             .add(layout.createSequentialGroup()
119                 .addContainerGap()
120                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
121                     .add(layout.createSequentialGroup()
122                         .add(12, 12, 12)
123                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
124                             .add(checkJavaField)
125                             .add(checkScriptField)
126                             .add(checkUndefinedField)
127                             .add(checkScriptAdapter)
128                             .add(checkFunctions)))
129                     .add(labelFieldsToDisplay))
130                 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
131         );
132         layout.setVerticalGroup(
133             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
134             .add(layout.createSequentialGroup()
135                 .addContainerGap()
136                 .add(labelFieldsToDisplay)
137                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
138                 .add(checkScriptField)
139                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
140                 .add(checkJavaField)
141                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
142                 .add(checkUndefinedField)
143                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
144                 .add(checkScriptAdapter)
145                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
146                 .add(checkFunctions)
147                 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
148         );
149     }// </editor-fold>//GEN-END:initComponents
150

151     private void checkFunctionsItemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {//GEN-FIRST:event_checkFunctionsItemStateChanged
152
setFilter(evt, VariableNode.TYPE_FUNCTION);
153     }//GEN-LAST:event_checkFunctionsItemStateChanged
154

155     private void checkScriptAdapterItemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {//GEN-FIRST:event_checkScriptAdapterItemStateChanged
156
setFilter(evt, VariableNode.TYPE_SCRIPT_ADAPTER);
157     }//GEN-LAST:event_checkScriptAdapterItemStateChanged
158

159     private void checkUndefinedFieldItemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {//GEN-FIRST:event_checkUndefinedFieldItemStateChanged
160
setFilter(evt, VariableNode.TYPE_UNDEFINED_FIELD);
161     }//GEN-LAST:event_checkUndefinedFieldItemStateChanged
162

163     private void checkJavaFieldItemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {//GEN-FIRST:event_checkJavaFieldItemStateChanged
164
setFilter(evt, VariableNode.TYPE_JAVA_FIELD);
165     }//GEN-LAST:event_checkJavaFieldItemStateChanged
166

167     private void checkScriptFieldItemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {//GEN-FIRST:event_checkScriptFieldItemStateChanged
168
setFilter(evt, VariableNode.TYPE_SCRIPT_FIELD);
169     }//GEN-LAST:event_checkScriptFieldItemStateChanged
170

171     
172     // Variables declaration - do not modify//GEN-BEGIN:variables
173
private javax.swing.JCheckBox JavaDoc checkFunctions;
174     private javax.swing.JCheckBox JavaDoc checkJavaField;
175     private javax.swing.JCheckBox JavaDoc checkScriptAdapter;
176     private javax.swing.JCheckBox JavaDoc checkScriptField;
177     private javax.swing.JCheckBox JavaDoc checkUndefinedField;
178     private javax.swing.JLabel JavaDoc labelFieldsToDisplay;
179     // End of variables declaration//GEN-END:variables
180

181     private void initUserComponents() {
182         // set icons to checkboxes -- !PW FIXME need a way to get icons from debugger/core
183
// checkFunctions.setIcon(new ImageIcon(Utilities.loadImage("/" + VariableNode.FUNCTION_ICON)));
184
// checkJavaField.setIcon(new ImageIcon(Utilities.loadImage("/" + VariableNode.JAVA_FIELD_ICON)));
185
// checkScriptAdapter.setIcon(new ImageIcon(Utilities.loadImage("/" + VariableNode.SCRIPT_ADAPTER_ICON)));
186
// checkScriptField.setIcon(new ImageIcon(Utilities.loadImage("/" + VariableNode.SCRIPT_FIELD_ICON)));
187
// checkUndefinedField.setIcon(new ImageIcon(Utilities.loadImage("/" + VariableNode.UNDEFINED_FIELD_ICON)));
188
}
189     
190     private void initState() {
191         try {
192             initializing = true;
193             checkFunctions.setSelected(filters[VariableNode.TYPE_FUNCTION]);
194             checkJavaField.setSelected(filters[VariableNode.TYPE_JAVA_FIELD]);
195             checkScriptAdapter.setSelected(filters[VariableNode.TYPE_SCRIPT_ADAPTER]);
196             checkScriptField.setSelected(filters[VariableNode.TYPE_SCRIPT_FIELD]);
197             checkUndefinedField.setSelected(filters[VariableNode.TYPE_UNDEFINED_FIELD]);
198         } finally {
199             initializing = false;
200         }
201     }
202     
203     private void setFilter(ItemEvent JavaDoc e, int type) {
204         if(!initializing) {
205             filters[type] = interpretCheckboxState(e);
206         }
207     }
208     
209     private boolean interpretCheckboxState(ItemEvent JavaDoc e) {
210         boolean state = false;
211
212         if(e.getStateChange() == ItemEvent.SELECTED) {
213             state = true;
214         } else if(e.getStateChange() == ItemEvent.DESELECTED) {
215             state = false;
216         }
217
218         return state;
219     }
220     
221     public static void showDialog() {
222         VariablesFilter filterPanel = new VariablesFilter(VariablesModelFilter.getFilterSettings());
223         DialogDescriptor desc = new DialogDescriptor(filterPanel, "Local Variable Filters");
224         DialogDisplayer.getDefault().createDialog(desc).setVisible(true);
225         if (desc.getValue().equals(DialogDescriptor.OK_OPTION)) {
226             VariablesModelFilter.setFilters(filterPanel.getFilters());
227         }
228     }
229
230 }
231
Popular Tags