Source Code Cross Referenced for EventCustomEditor.java in  » IDE-Netbeans » form » org » netbeans » modules » form » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » form » org.netbeans.modules.form 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package org.netbeans.modules.form;
043:
044:        import java.util.*;
045:        import javax.swing.DefaultListModel;
046:
047:        import org.openide.DialogDisplayer;
048:        import org.openide.NotifyDescriptor;
049:        import org.openide.awt.Mnemonics;
050:
051:        /**
052:         *
053:         * @author  Pavel Buzek
054:         */
055:        public class EventCustomEditor extends javax.swing.JPanel {
056:
057:            static final long serialVersionUID = -4825059521634962952L;
058:
059:            /** Creates new form EventCustomEditor */
060:            EventCustomEditor(EventProperty eventProperty) {
061:                this .eventProperty = eventProperty;
062:
063:                initComponents();
064:                enableButtons();
065:
066:                Mnemonics.setLocalizedText(addButton, FormUtils
067:                        .getBundleString("CTL_EE_ADD")); // NOI18N
068:                Mnemonics.setLocalizedText(removeButton, FormUtils
069:                        .getBundleString("CTL_EE_REMOVE")); // NOI18N
070:                Mnemonics.setLocalizedText(editButton, FormUtils
071:                        .getBundleString("CTL_EE_RENAME")); // NOI18N
072:                Mnemonics.setLocalizedText(handlersListLabel, FormUtils
073:                        .getBundleString("CTL_EE_Handlers")); // NOI18N
074:
075:                handlersList.getAccessibleContext().setAccessibleDescription(
076:                        FormUtils.getBundleString("ACSD_CTL_EE_Handlers")); // NOI18N
077:                addButton.getAccessibleContext().setAccessibleDescription(
078:                        FormUtils.getBundleString("ACSD_CTL_EE_ADD")); // NOI18N
079:                removeButton.getAccessibleContext().setAccessibleDescription(
080:                        FormUtils.getBundleString("ACSD_CTL_EE_REMOVE")); // NOI18N
081:                editButton.getAccessibleContext().setAccessibleDescription(
082:                        FormUtils.getBundleString("ACSD_CTL_EE_RENAME")); // NOI18N
083:                getAccessibleContext().setAccessibleDescription(
084:                        FormUtils.getBundleString("ACSD_EventCustomEditor")); // NOI18N
085:            }
086:
087:            /** This method is called from within the constructor to
088:             * initialize the form.
089:             * WARNING: Do NOT modify this code. The content of this method is
090:             * always regenerated by the FormEditor.
091:             */
092:            // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
093:            private void initComponents() {
094:                java.awt.GridBagConstraints gridBagConstraints;
095:
096:                handlersListLabel = new javax.swing.JLabel();
097:                jScrollPane1 = new javax.swing.JScrollPane();
098:                String[] handlers = eventProperty.getEventHandlers();
099:                for (int i = 0; i < handlers.length; i++) {
100:                    handlersModel.addElement(handlers[i]);
101:                }
102:                handlersList = new javax.swing.JList();
103:                handlersList.setModel(handlersModel);
104:                if (handlers.length > 0) {
105:                    handlersList.setSelectedIndex(0);
106:                }
107:                addButton = new javax.swing.JButton();
108:                removeButton = new javax.swing.JButton();
109:                editButton = new javax.swing.JButton();
110:
111:                setLayout(new java.awt.GridBagLayout());
112:
113:                setPreferredSize(new java.awt.Dimension(300, 300));
114:                handlersListLabel.setLabelFor(handlersList);
115:                handlersListLabel.setText("Handlers");
116:                gridBagConstraints = new java.awt.GridBagConstraints();
117:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
118:                gridBagConstraints.insets = new java.awt.Insets(12, 12, 2, 0);
119:                add(handlersListLabel, gridBagConstraints);
120:
121:                handlersList
122:                        .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
123:                            public void valueChanged(
124:                                    javax.swing.event.ListSelectionEvent evt) {
125:                                handlersListValueChanged(evt);
126:                            }
127:                        });
128:
129:                jScrollPane1.setViewportView(handlersList);
130:
131:                gridBagConstraints = new java.awt.GridBagConstraints();
132:                gridBagConstraints.gridx = 0;
133:                gridBagConstraints.gridy = 1;
134:                gridBagConstraints.gridheight = 4;
135:                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
136:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
137:                gridBagConstraints.weightx = 0.9;
138:                gridBagConstraints.weighty = 1.0;
139:                gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 11);
140:                add(jScrollPane1, gridBagConstraints);
141:
142:                addButton.setText("Add...");
143:                addButton
144:                        .addActionListener(new java.awt.event.ActionListener() {
145:                            public void actionPerformed(
146:                                    java.awt.event.ActionEvent evt) {
147:                                addButtonActionPerformed(evt);
148:                            }
149:                        });
150:
151:                gridBagConstraints = new java.awt.GridBagConstraints();
152:                gridBagConstraints.gridx = 1;
153:                gridBagConstraints.gridy = 1;
154:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
155:                gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
156:                gridBagConstraints.weightx = 0.1;
157:                gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 11);
158:                add(addButton, gridBagConstraints);
159:
160:                removeButton.setText("Remove");
161:                removeButton
162:                        .addActionListener(new java.awt.event.ActionListener() {
163:                            public void actionPerformed(
164:                                    java.awt.event.ActionEvent evt) {
165:                                removeButtonActionPerformed(evt);
166:                            }
167:                        });
168:
169:                gridBagConstraints = new java.awt.GridBagConstraints();
170:                gridBagConstraints.gridx = 1;
171:                gridBagConstraints.gridy = 2;
172:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
173:                gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
174:                gridBagConstraints.weightx = 0.1;
175:                gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 11);
176:                add(removeButton, gridBagConstraints);
177:
178:                editButton.setText("Rename...");
179:                editButton
180:                        .addActionListener(new java.awt.event.ActionListener() {
181:                            public void actionPerformed(
182:                                    java.awt.event.ActionEvent evt) {
183:                                editButtonActionPerformed(evt);
184:                            }
185:                        });
186:
187:                gridBagConstraints = new java.awt.GridBagConstraints();
188:                gridBagConstraints.gridx = 1;
189:                gridBagConstraints.gridy = 3;
190:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
191:                gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
192:                gridBagConstraints.weightx = 0.1;
193:                gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 11);
194:                add(editButton, gridBagConstraints);
195:
196:            }// </editor-fold>//GEN-END:initComponents
197:
198:            private void handlersListValueChanged(
199:                    javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_handlersListValueChanged
200:                enableButtons();
201:            }//GEN-LAST:event_handlersListValueChanged
202:
203:            private void enableButtons() {
204:                if (handlersList.isSelectionEmpty()) {
205:                    removeButton.setEnabled(false);
206:                } else {
207:                    removeButton.setEnabled(true);
208:                }
209:                editButton
210:                        .setEnabled(handlersList.getSelectedIndices().length == 1);
211:            }
212:
213:            private void editButtonActionPerformed(
214:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editButtonActionPerformed
215:                // Add your handling code here:
216:                int i = handlersList.getSelectedIndex();
217:                if (i >= 0) {
218:                    String oldName = (String) handlersModel.get(i);
219:                    NotifyDescriptor.InputLine nd = new NotifyDescriptor.InputLine(
220:                            FormUtils.getBundleString("CTL_EE_RENAME_LABEL"), // NOI18N
221:                            FormUtils.getBundleString("CTL_EE_RENAME_CAPTION")); // NOI18N
222:                    nd.setInputText(oldName);
223:
224:                    if (DialogDisplayer.getDefault().notify(nd).equals(
225:                            NotifyDescriptor.OK_OPTION)) {
226:                        String newName = nd.getInputText();
227:                        if (newName.equals(oldName))
228:                            return; // no change
229:
230:                        if (!org.openide.util.Utilities
231:                                .isJavaIdentifier(newName)) { // invalid name
232:                            NotifyDescriptor.Message msg = new NotifyDescriptor.Message(
233:                                    FormUtils
234:                                            .getBundleString("CTL_EE_NOT_IDENTIFIER"), // NOI18N
235:                                    NotifyDescriptor.ERROR_MESSAGE);
236:                            DialogDisplayer.getDefault().notify(msg);
237:                            return;
238:                        }
239:
240:                        if (handlersModel.indexOf(newName) >= 0) { // already exists
241:                            NotifyDescriptor.Message msg = new NotifyDescriptor.Message(
242:                                    FormUtils
243:                                            .getBundleString("CTL_EE_ALREADY_EXIST"), // NOI18N
244:                                    NotifyDescriptor.INFORMATION_MESSAGE);
245:                            DialogDisplayer.getDefault().notify(msg);
246:                            return;
247:                        }
248:
249:                        int ii = changes.getAdded().indexOf(oldName);
250:                        if (ii >= 0) { // a newly added handler was renamed
251:                            changes.getAdded().set(ii, newName);
252:                        } else {
253:                            ii = changes.getRenamedNewNames().indexOf(oldName);
254:                            if (ii >= 0) // this handler has been already renamed
255:                                changes.getRenamedNewNames().set(ii, newName);
256:                            else {
257:                                changes.getRenamedOldNames().add(oldName);
258:                                changes.getRenamedNewNames().add(newName);
259:                            }
260:                        }
261:
262:                        handlersModel.set(i, newName);
263:                        handlersList.setSelectedIndex(i);
264:                        enableButtons();
265:                    }
266:                }
267:            }//GEN-LAST:event_editButtonActionPerformed
268:
269:            private void removeButtonActionPerformed(
270:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed
271:                Object[] handlers = handlersList.getSelectedValues();
272:                for (int i = 0; i < handlers.length; i++) {
273:                    int ii = changes.getAdded().indexOf(handlers[i]);
274:                    if (ii >= 0) { // the handler was previously added - cancel it
275:                        changes.getAdded().remove(ii);
276:                    } else {
277:                        ii = changes.getRenamedNewNames().indexOf(handlers[i]);
278:                        String toRemove;
279:                        if (ii >= 0) { // the handler was previously renamed - cancel it
280:                            changes.getRenamedNewNames().remove(ii);
281:                            toRemove = changes.getRenamedOldNames().get(ii);
282:                            changes.getRenamedOldNames().remove(ii);
283:                        } else
284:                            toRemove = (String) handlers[i];
285:
286:                        changes.getRemoved().add(toRemove);
287:                    }
288:                    handlersModel.removeElement(handlers[i]);
289:                    enableButtons();
290:                }
291:            }//GEN-LAST:event_removeButtonActionPerformed
292:
293:            private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed
294:                NotifyDescriptor.InputLine nd = new NotifyDescriptor.InputLine(
295:                        FormUtils.getBundleString("CTL_EE_ADD_LABEL"), // NOI18N
296:                        FormUtils.getBundleString("CTL_EE_ADD_CAPTION")); // NOI18N
297:                if (DialogDisplayer.getDefault().notify(nd).equals(
298:                        NotifyDescriptor.OK_OPTION)) {
299:                    String newHandler = nd.getInputText();
300:                    if (!org.openide.util.Utilities
301:                            .isJavaIdentifier(newHandler)) {
302:                        NotifyDescriptor.Message msg = new NotifyDescriptor.Message(
303:                                FormUtils
304:                                        .getBundleString("CTL_EE_NOT_IDENTIFIER"), // NOI18N
305:                                NotifyDescriptor.ERROR_MESSAGE);
306:                        DialogDisplayer.getDefault().notify(msg);
307:                        return;
308:                    }
309:
310:                    if (handlersModel.indexOf(newHandler) >= 0) {
311:                        NotifyDescriptor.Message msg = new NotifyDescriptor.Message(
312:                                FormUtils
313:                                        .getBundleString("CTL_EE_ALREADY_EXIST"), // NOI18N
314:                                NotifyDescriptor.INFORMATION_MESSAGE);
315:                        DialogDisplayer.getDefault().notify(msg);
316:                        return;
317:                    }
318:
319:                    int ir = changes.getRemoved().indexOf(newHandler);
320:                    if (ir >= 0) {
321:                        changes.getRemoved().remove(ir);
322:                    } else {
323:                        changes.getAdded().add(newHandler);
324:                    }
325:                    handlersModel.addElement(newHandler);
326:                    handlersList.setSelectedIndex(handlersModel.size() - 1);
327:                    enableButtons();
328:                }
329:            }//GEN-LAST:event_addButtonActionPerformed
330:
331:            public void doChanges() {
332:                try {
333:                    eventProperty.setValue(changes);
334:                } catch (Exception e) { // should not happen
335:                    e.printStackTrace();
336:                }
337:            }
338:
339:            // Variables declaration - do not modify//GEN-BEGIN:variables
340:            private javax.swing.JButton addButton;
341:            private javax.swing.JButton editButton;
342:            private javax.swing.JList handlersList;
343:            private javax.swing.JLabel handlersListLabel;
344:            private javax.swing.JScrollPane jScrollPane1;
345:            private javax.swing.JButton removeButton;
346:            // End of variables declaration//GEN-END:variables
347:
348:            EventProperty eventProperty;
349:            DefaultListModel handlersModel = new DefaultListModel();
350:            EventProperty.Change changes = new EventProperty.Change();
351:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.