001: /*
002: * Copyright 2007, Maxim Zakharenkov
003: * All rights reserved.
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
018: *
019: * $Header: /cvs/swingexplorer/src/sample/FRMPerson.java,v 1.4 2008/03/07 11:46:51 maxz1 Exp $
020: */
021: package sample;
022:
023: import javax.swing.JDialog;
024: import javax.swing.JOptionPane;
025:
026: /**
027: *
028: * @author Maxim Zakharenkov
029: */
030: public class FRMPerson extends javax.swing.JFrame {
031:
032: /** Creates new form FRMPerson */
033: public FRMPerson() {
034: initComponents();
035: }
036:
037: /** This method is called from within the constructor to
038: * initialize the form.
039: * WARNING: Do NOT modify this code. The content of this method is
040: * always regenerated by the Form Editor.
041: */
042: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
043: private void initComponents() {
044:
045: grpGender = new javax.swing.ButtonGroup();
046: btnCheckEDT = new javax.swing.JButton();
047: lblName = new javax.swing.JLabel();
048: txtName = new javax.swing.JTextField();
049: lblSurename = new javax.swing.JLabel();
050: txtSurename = new javax.swing.JTextField();
051: pnlGender = new javax.swing.JPanel();
052: rbnMale = new javax.swing.JRadioButton();
053: rbnFemale = new javax.swing.JRadioButton();
054: lblCountry = new javax.swing.JLabel();
055: cmbCountry = new javax.swing.JComboBox();
056: lblDescription = new javax.swing.JLabel();
057: btnModalDialog = new javax.swing.JButton();
058: btnOwnerlessModalDialog = new javax.swing.JButton();
059: btnModelessDialog = new javax.swing.JButton();
060: btnOwnerlessModelessDialog = new javax.swing.JButton();
061: btnThreadViolation = new javax.swing.JButton();
062: btnEdtHang = new javax.swing.JButton();
063:
064: btnCheckEDT.setText("jButton1");
065: btnCheckEDT
066: .addActionListener(new java.awt.event.ActionListener() {
067: public void actionPerformed(
068: java.awt.event.ActionEvent evt) {
069: btnCheckEDTActionPerformed(evt);
070: }
071: });
072:
073: setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
074: setTitle("Personal Data");
075:
076: lblName.setText("Name:");
077:
078: lblSurename.setText("Surename:");
079:
080: pnlGender.setBorder(javax.swing.BorderFactory
081: .createTitledBorder(javax.swing.BorderFactory
082: .createEtchedBorder(), "Gender"));
083: pnlGender.addMouseListener(new java.awt.event.MouseAdapter() {
084: public void mouseClicked(java.awt.event.MouseEvent evt) {
085: pnlGenderMouseClicked(evt);
086: }
087: });
088:
089: grpGender.add(rbnMale);
090: rbnMale.setMnemonic('e');
091: rbnMale.setSelected(true);
092: rbnMale.setText("Male");
093: rbnMale.setBorder(javax.swing.BorderFactory.createEmptyBorder(
094: 0, 0, 0, 0));
095: rbnMale.setMargin(new java.awt.Insets(0, 0, 0, 0));
096:
097: grpGender.add(rbnFemale);
098: rbnFemale.setMnemonic('e');
099: rbnFemale.setText("Female");
100: rbnFemale.setBorder(javax.swing.BorderFactory
101: .createEmptyBorder(0, 0, 0, 0));
102: rbnFemale.setMargin(new java.awt.Insets(0, 0, 0, 0));
103:
104: org.jdesktop.layout.GroupLayout pnlGenderLayout = new org.jdesktop.layout.GroupLayout(
105: pnlGender);
106: pnlGender.setLayout(pnlGenderLayout);
107: pnlGenderLayout
108: .setHorizontalGroup(pnlGenderLayout
109: .createParallelGroup(
110: org.jdesktop.layout.GroupLayout.LEADING)
111: .add(
112: pnlGenderLayout
113: .createSequentialGroup()
114: .addContainerGap()
115: .add(
116: pnlGenderLayout
117: .createParallelGroup(
118: org.jdesktop.layout.GroupLayout.LEADING)
119: .add(rbnMale)
120: .add(rbnFemale))
121: .addContainerGap(363,
122: Short.MAX_VALUE)));
123: pnlGenderLayout
124: .setVerticalGroup(pnlGenderLayout
125: .createParallelGroup(
126: org.jdesktop.layout.GroupLayout.LEADING)
127: .add(
128: pnlGenderLayout
129: .createSequentialGroup()
130: .add(rbnMale)
131: .addPreferredGap(
132: org.jdesktop.layout.LayoutStyle.RELATED)
133: .add(rbnFemale)
134: .addContainerGap(
135: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
136: Short.MAX_VALUE)));
137:
138: lblCountry.setText("Country:");
139:
140: cmbCountry.setModel(new javax.swing.DefaultComboBoxModel(
141: new String[] { "England", "Belgium", "France", "Spain",
142: "Italy", "Germany" }));
143:
144: lblDescription.setFont(new java.awt.Font("Tahoma", 1, 12));
145: lblDescription
146: .setText("This is sample Swing application to demonstrate Swing Explorer");
147:
148: btnModalDialog.setText("Modal Dialog");
149: btnModalDialog
150: .addActionListener(new java.awt.event.ActionListener() {
151: public void actionPerformed(
152: java.awt.event.ActionEvent evt) {
153: btnModalDialogActionPerformed(evt);
154: }
155: });
156:
157: btnOwnerlessModalDialog.setText("Ownerless Modal Dialog");
158: btnOwnerlessModalDialog
159: .addActionListener(new java.awt.event.ActionListener() {
160: public void actionPerformed(
161: java.awt.event.ActionEvent evt) {
162: btnOwnerlessModalDialogActionPerformed(evt);
163: }
164: });
165:
166: btnModelessDialog.setText("Modeless Dialog");
167: btnModelessDialog
168: .addActionListener(new java.awt.event.ActionListener() {
169: public void actionPerformed(
170: java.awt.event.ActionEvent evt) {
171: btnModelessDialogActionPerformed(evt);
172: }
173: });
174:
175: btnOwnerlessModelessDialog.setText("Ownerless Modeless Dialog");
176: btnOwnerlessModelessDialog
177: .addActionListener(new java.awt.event.ActionListener() {
178: public void actionPerformed(
179: java.awt.event.ActionEvent evt) {
180: btnOwnerlessModelessDialogActionPerformed(evt);
181: }
182: });
183:
184: btnThreadViolation.setText("Thread Violation");
185: btnThreadViolation
186: .setToolTipText("<html>\nPress this button to simulate<br>\nthread violation.<br> \nCalls method of swing component<br> \nfrom non AWT Dispatch Thread.\n</html>\n");
187: btnThreadViolation
188: .addActionListener(new java.awt.event.ActionListener() {
189: public void actionPerformed(
190: java.awt.event.ActionEvent evt) {
191: btnThreadViolationActionPerformed(evt);
192: }
193: });
194:
195: btnEdtHang.setText("EDT Hang");
196: btnEdtHang
197: .setToolTipText("<html>\nSimulate long operation in<br>\nAWT dispatch thread causing<br>\nhanging for 2 seconds\n</html>");
198: btnEdtHang
199: .addActionListener(new java.awt.event.ActionListener() {
200: public void actionPerformed(
201: java.awt.event.ActionEvent evt) {
202: btnEdtHangActionPerformed(evt);
203: }
204: });
205:
206: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
207: getContentPane());
208: getContentPane().setLayout(layout);
209: layout
210: .setHorizontalGroup(layout
211: .createParallelGroup(
212: org.jdesktop.layout.GroupLayout.LEADING)
213: .add(
214: layout
215: .createSequentialGroup()
216: .addContainerGap()
217: .add(
218: layout
219: .createParallelGroup(
220: org.jdesktop.layout.GroupLayout.LEADING)
221: .add(
222: pnlGender,
223: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
224: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
225: Short.MAX_VALUE)
226: .add(
227: org.jdesktop.layout.GroupLayout.TRAILING,
228: layout
229: .createSequentialGroup()
230: .add(
231: layout
232: .createParallelGroup(
233: org.jdesktop.layout.GroupLayout.LEADING)
234: .add(
235: lblSurename)
236: .add(
237: lblName))
238: .addPreferredGap(
239: org.jdesktop.layout.LayoutStyle.RELATED)
240: .add(
241: layout
242: .createParallelGroup(
243: org.jdesktop.layout.GroupLayout.LEADING)
244: .add(
245: txtName,
246: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
247: 380,
248: Short.MAX_VALUE)
249: .add(
250: txtSurename,
251: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
252: 380,
253: Short.MAX_VALUE)))
254: .add(
255: layout
256: .createSequentialGroup()
257: .add(
258: lblCountry)
259: .addPreferredGap(
260: org.jdesktop.layout.LayoutStyle.RELATED)
261: .add(
262: cmbCountry,
263: 0,
264: 389,
265: Short.MAX_VALUE))
266: .add(
267: lblDescription)
268: .add(
269: layout
270: .createSequentialGroup()
271: .add(
272: layout
273: .createParallelGroup(
274: org.jdesktop.layout.GroupLayout.LEADING,
275: false)
276: .add(
277: btnModalDialog,
278: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
279: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
280: Short.MAX_VALUE)
281: .add(
282: btnModelessDialog,
283: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
284: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
285: Short.MAX_VALUE))
286: .add(
287: 0,
288: 0,
289: 0)
290: .add(
291: layout
292: .createParallelGroup(
293: org.jdesktop.layout.GroupLayout.LEADING,
294: false)
295: .add(
296: btnOwnerlessModalDialog,
297: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
298: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
299: Short.MAX_VALUE)
300: .add(
301: btnOwnerlessModelessDialog,
302: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
303: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
304: Short.MAX_VALUE))
305: .addPreferredGap(
306: org.jdesktop.layout.LayoutStyle.UNRELATED)
307: .add(
308: layout
309: .createParallelGroup(
310: org.jdesktop.layout.GroupLayout.LEADING,
311: false)
312: .add(
313: btnEdtHang,
314: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
315: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
316: Short.MAX_VALUE)
317: .add(
318: btnThreadViolation,
319: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
320: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
321: Short.MAX_VALUE))))
322: .addContainerGap()));
323: layout
324: .setVerticalGroup(layout
325: .createParallelGroup(
326: org.jdesktop.layout.GroupLayout.LEADING)
327: .add(
328: layout
329: .createSequentialGroup()
330: .add(lblDescription)
331: .addPreferredGap(
332: org.jdesktop.layout.LayoutStyle.RELATED)
333: .add(
334: layout
335: .createParallelGroup(
336: org.jdesktop.layout.GroupLayout.BASELINE)
337: .add(lblName)
338: .add(
339: txtName,
340: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
341: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
342: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
343: .addPreferredGap(
344: org.jdesktop.layout.LayoutStyle.RELATED)
345: .add(
346: layout
347: .createParallelGroup(
348: org.jdesktop.layout.GroupLayout.BASELINE)
349: .add(
350: lblSurename)
351: .add(
352: txtSurename,
353: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
354: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
355: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
356: .addPreferredGap(
357: org.jdesktop.layout.LayoutStyle.RELATED)
358: .add(
359: pnlGender,
360: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
361: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
362: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
363: .addPreferredGap(
364: org.jdesktop.layout.LayoutStyle.RELATED)
365: .add(
366: layout
367: .createParallelGroup(
368: org.jdesktop.layout.GroupLayout.BASELINE)
369: .add(lblCountry)
370: .add(
371: cmbCountry,
372: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
373: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
374: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
375: .addPreferredGap(
376: org.jdesktop.layout.LayoutStyle.UNRELATED)
377: .add(
378: layout
379: .createParallelGroup(
380: org.jdesktop.layout.GroupLayout.BASELINE)
381: .add(
382: btnModalDialog)
383: .add(
384: btnOwnerlessModalDialog)
385: .add(
386: btnThreadViolation))
387: .add(0, 0, 0)
388: .add(
389: layout
390: .createParallelGroup(
391: org.jdesktop.layout.GroupLayout.BASELINE)
392: .add(
393: btnModelessDialog)
394: .add(
395: btnOwnerlessModelessDialog)
396: .add(btnEdtHang))
397: .addContainerGap(71,
398: Short.MAX_VALUE)));
399:
400: pack();
401: }// </editor-fold>//GEN-END:initComponents
402:
403: private void pnlGenderMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pnlGenderMouseClicked
404: System.out.println("Sample: Mouse clicked on pnlGender");
405: }//GEN-LAST:event_pnlGenderMouseClicked
406:
407: private void btnModalDialogActionPerformed(
408: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnModalDialogActionPerformed
409: JOptionPane.showMessageDialog(this , "Just simple modal dialog",
410: "Sample dialog", JOptionPane.INFORMATION_MESSAGE);
411: }//GEN-LAST:event_btnModalDialogActionPerformed
412:
413: private void btnOwnerlessModalDialogActionPerformed(
414: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOwnerlessModalDialogActionPerformed
415: JOptionPane.showMessageDialog(null,
416: "Just simple ownerless modal dialog", "Sample dialog",
417: JOptionPane.INFORMATION_MESSAGE);
418: }//GEN-LAST:event_btnOwnerlessModalDialogActionPerformed
419:
420: private void btnModelessDialogActionPerformed(
421: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnModelessDialogActionPerformed
422: JDialog dlg = new JDialog(this );
423: dlg.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
424: dlg.setTitle("Sample modeless dialog");
425: dlg.setBounds(100, 100, 200, 50);
426: dlg.setVisible(rootPaneCheckingEnabled);
427: }//GEN-LAST:event_btnModelessDialogActionPerformed
428:
429: private void btnOwnerlessModelessDialogActionPerformed(
430: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOwnerlessModelessDialogActionPerformed
431: JDialog dlg = new JDialog();
432: dlg.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
433: dlg.setTitle("Sample ownerless dialog");
434: dlg.setBounds(100, 100, 200, 50);
435: dlg.setVisible(rootPaneCheckingEnabled);
436: }//GEN-LAST:event_btnOwnerlessModelessDialogActionPerformed
437:
438: private void btnCheckEDTActionPerformed(
439: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCheckEDTActionPerformed
440:
441: }//GEN-LAST:event_btnCheckEDTActionPerformed
442:
443: private void btnThreadViolationActionPerformed(
444: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnThreadViolationActionPerformed
445: new Thread() {
446: public void run() {
447: rbnFemale.setToolTipText("Sample");
448: // rbnFemale.scrollRectToVisible(null);
449: }
450: }.start();
451: }//GEN-LAST:event_btnThreadViolationActionPerformed
452:
453: private void btnEdtHangActionPerformed(
454: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEdtHangActionPerformed
455: try {
456: Thread.sleep(2000);//GEN-LAST:event_btnEdtHangActionPerformed
457: } catch (InterruptedException ex) {
458:
459: }
460: }
461:
462: /**
463: * @param args the command line arguments
464: */
465: public static void main(String args[]) {
466: java.awt.EventQueue.invokeLater(new Runnable() {
467: public void run() {
468: FRMPerson frmPerson = new FRMPerson();
469: frmPerson.setVisible(true);
470: }
471: });
472: }
473:
474: // Variables declaration - do not modify//GEN-BEGIN:variables
475: private javax.swing.JButton btnCheckEDT;
476: private javax.swing.JButton btnEdtHang;
477: private javax.swing.JButton btnModalDialog;
478: private javax.swing.JButton btnModelessDialog;
479: private javax.swing.JButton btnOwnerlessModalDialog;
480: private javax.swing.JButton btnOwnerlessModelessDialog;
481: private javax.swing.JButton btnThreadViolation;
482: private javax.swing.JComboBox cmbCountry;
483: private javax.swing.ButtonGroup grpGender;
484: private javax.swing.JLabel lblCountry;
485: private javax.swing.JLabel lblDescription;
486: private javax.swing.JLabel lblName;
487: private javax.swing.JLabel lblSurename;
488: private javax.swing.JPanel pnlGender;
489: private javax.swing.JRadioButton rbnFemale;
490: private javax.swing.JRadioButton rbnMale;
491: private javax.swing.JTextField txtName;
492: private javax.swing.JTextField txtSurename;
493: // End of variables declaration//GEN-END:variables
494:
495: }
496:
497: /*
498: * $Log: FRMPerson.java,v $
499: * Revision 1.4 2008/03/07 11:46:51 maxz1
500: * Added thread violation monitor and EDT hang monitor. Changed L & F.
501: *
502: * Revision 1.3 2008/02/13 21:52:12 maxz1
503: * Added event filtering functionality
504: *
505: * Revision 1.2 2008/02/06 08:36:10 maxz1
506: * Changed license header
507: *
508: * Revision 1.1 2007/06/27 19:41:40 maxz1
509: * new
510: *
511: */
|