Source Code Cross Referenced for WizardSheet.java in  » IDE-Netbeans » uml » org » netbeans » modules » uml » ui » support » wizard » 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 » uml » org.netbeans.modules.uml.ui.support.wizard 
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-2007 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.uml.ui.support.wizard;
043:
044:        import java.awt.BorderLayout;
045:        import java.awt.Component;
046:        import java.awt.Cursor;
047:        import java.awt.Dimension;
048:        import java.awt.Frame;
049:        import java.awt.GraphicsConfiguration;
050:        import java.awt.GridBagConstraints;
051:        import java.awt.GridBagLayout;
052:        import java.awt.Insets;
053:        import java.awt.event.ActionEvent;
054:        import java.awt.event.KeyEvent;
055:
056:        import javax.swing.BorderFactory;
057:        import javax.swing.Icon;
058:        import javax.swing.JButton;
059:        import javax.swing.JLabel;
060:        import javax.swing.JPanel;
061:
062:        import org.netbeans.modules.uml.ui.swing.commondialogs.JCenterDialog;
063:
064:        public abstract class WizardSheet extends JCenterDialog implements 
065:                IWizardSheet {
066:
067:            private JLabel spacer1 = new JLabel();
068:            private JButton jbNext = new JButton();
069:            private JPanel pnlButtonBar = new JPanel();
070:            private JButton jbFinish = new JButton();
071:            private JButton jbCancel = new JButton();
072:            private JLabel spacer2 = new JLabel();
073:            private JLabel spacer3 = new JLabel();
074:            private JButton jbBack = new JButton();
075:            private JLabel spacer4 = new JLabel();
076:            private JLabel spacer5 = new JLabel();
077:            private JLabel spacer6 = new JLabel();
078:
079:            private CardPanel wizardPages = null;
080:            private int lastButtonPressed;
081:
082:            /// watermark image to use on EndPages (pages at beginning or end of the wizard)
083:            private Icon bmpWatermark = null;
084:
085:            /// header image used on all InteriorPages
086:            private Icon bmpHeader = null;
087:
088:            private String m_Title = null;
089:
090:            /// name of this Wizard's help file, get it from Kathy
091:            /// do not include the extension, always assumed to be ".hlp"
092:            protected String m_sHelpFilePath;
093:
094:            public WizardSheet(int nIDCaption, Frame pParentWnd,
095:                    int iSelectPage, Icon hbmWatermark,
096:                    GraphicsConfiguration hpalWatermark, Icon hbmHeader) {
097:                this (
098:                        "", pParentWnd, iSelectPage, hbmWatermark, hpalWatermark, hbmHeader); //$NON-NLS-1$
099:            }
100:
101:            public WizardSheet(String pszCaption, Frame pParentWnd,
102:                    int iSelectPage, Icon hbmWatermark,
103:                    GraphicsConfiguration hpalWatermark, Icon hbmHeader) {
104:                this (pParentWnd, pszCaption, true);
105:                this .bmpWatermark = hbmWatermark;
106:                this .bmpHeader = hbmHeader;
107:            }
108:
109:            public WizardSheet(Frame frame, String title, boolean modal) {
110:                super (frame, title, modal);
111:                m_Title = title;
112:
113:                try {
114:                    createUI();
115:                    pack();
116:
117:                    this .setResizable(false);
118:
119:                    // center on screen
120:                    Dimension SS = this .getToolkit().getScreenSize();
121:                    Dimension CS = this .getSize();
122:                    this .setLocation((SS.width - CS.width) / 2,
123:                            (SS.height - CS.height) / 2);
124:
125:                } catch (Exception ex) {
126:                    ex.printStackTrace();
127:                }
128:            }
129:
130:            public WizardSheet() {
131:                this (null, "", true); //$NON-NLS-1$
132:            }
133:
134:            public boolean is256ColorsSupported() {
135:                return true;
136:            }
137:
138:            /**
139:             * Enables us to adjust the panel size to handle larger fonts
140:             * CBeckham
141:             */
142:            private Dimension setPanelSize() {
143:
144:                int fontsize;
145:                java.awt.Font f = javax.swing.UIManager.getFont("controlFont"); //NOI18N
146:                if (f != null) {
147:                    fontsize = f.getSize();
148:                } else {
149:                    fontsize = 12;
150:                }
151:                int width = 500;
152:                int height = 350;
153:                int multiplyer = 2;
154:
155:                if (fontsize > 17)
156:                    multiplyer = 3;
157:                width = width
158:                        + Math.round(width * (multiplyer * fontsize / 100f));
159:                height = height
160:                        + Math.round(height * (multiplyer * fontsize / 100f));
161:
162:                return new java.awt.Dimension(width, height);
163:            }
164:
165:            private void createUI() {
166:                wizardPages = new CardPanel(this );
167:
168:                wizardPages.setPreferredSize(setPanelSize());
169:                this .getContentPane().setLayout(new BorderLayout());
170:
171:                pnlButtonBar.setBorder(BorderFactory.createRaisedBevelBorder());
172:                pnlButtonBar.setLayout(new GridBagLayout());
173:
174:                this .jbBack.setMnemonic(KeyEvent.VK_B);
175:                this .jbNext.setMnemonic(KeyEvent.VK_N);
176:                this .jbFinish.setMnemonic(KeyEvent.VK_F);
177:
178:                Insets insets = new java.awt.Insets(10, 5, 10, 5);
179:                if (canAddNavigationButtons() == true) {
180:                    jbBack.setText(getBackButtonCaption());
181:                    jbNext.setText(getNextButtonCaption());
182:                    pnlButtonBar.add(spacer1, new GridBagConstraints(1, 0, // gridx, gridy
183:                            1, 1, // gridwidth, gridheight
184:                            1.0, 0.0, // weightx, weighty
185:                            GridBagConstraints.CENTER, // anchor
186:                            GridBagConstraints.BOTH, // fill
187:                            insets, // insets
188:                            0, // ipadx
189:                            0));
190:                    pnlButtonBar.add(jbBack, new GridBagConstraints(2, 0, // gridx, gridy
191:                            1, 1, // gridwidth, gridheight
192:                            0.0, 0.0, // weightx, weighty
193:                            GridBagConstraints.CENTER, // anchor
194:                            GridBagConstraints.BOTH, // fill
195:                            insets, // insets
196:                            0, // ipadx
197:                            0));
198:                    pnlButtonBar.add(jbNext, new GridBagConstraints(3, 0, // gridx, gridy
199:                            1, 1, // gridwidth, gridheight
200:                            0.0, 0.0, // weightx, weighty
201:                            GridBagConstraints.CENTER, // anchor
202:                            GridBagConstraints.BOTH, // fill
203:                            insets, // insets
204:                            0, // ipadx
205:                            0));
206:                } else {
207:                    pnlButtonBar.add(spacer4, new GridBagConstraints(1, 0, // gridx, gridy
208:                            1, 1, // gridwidth, gridheight
209:                            1.0, 0.0, // weightx, weighty
210:                            GridBagConstraints.CENTER, // anchor
211:                            GridBagConstraints.BOTH, // fill
212:                            insets, // insets
213:                            0, // ipadx
214:                            0));
215:                    pnlButtonBar.add(spacer5, new GridBagConstraints(2, 0, // gridx, gridy
216:                            1, 1, // gridwidth, gridheight
217:                            0.0, 0.0, // weightx, weighty
218:                            GridBagConstraints.CENTER, // anchor
219:                            GridBagConstraints.BOTH, // fill
220:                            insets, // insets
221:                            0, // ipadx
222:                            0));
223:                    pnlButtonBar.add(spacer6, new GridBagConstraints(3, 0, // gridx, gridy
224:                            1, 1, // gridwidth, gridheight
225:                            0.0, 0.0, // weightx, weighty
226:                            GridBagConstraints.CENTER, // anchor
227:                            GridBagConstraints.BOTH, // fill
228:                            insets, // insets
229:                            0, // ipadx
230:                            0));
231:                }
232:
233:                jbFinish.setText(getCommitButtonCaption());
234:                getRootPane().setDefaultButton(jbFinish);
235:
236:                jbCancel.setText(getCancelButtonCaption());
237:                Dimension buttonSize = getMaxButtonWidth();
238:                jbBack.setMaximumSize(buttonSize);
239:                jbBack.setPreferredSize(buttonSize);
240:                jbBack.getAccessibleContext().setAccessibleDescription(
241:                        WizardResouces
242:                                .getString("WizardSheet.BACK_BTN_Description"));
243:                jbCancel.setMaximumSize(buttonSize);
244:                jbCancel.setPreferredSize(buttonSize);
245:                jbCancel
246:                        .getAccessibleContext()
247:                        .setAccessibleDescription(
248:                                WizardResouces
249:                                        .getString("WizardSheet.CANCEL_BTN_Description"));
250:                jbFinish.setMaximumSize(buttonSize);
251:                jbFinish.setPreferredSize(buttonSize);
252:                jbNext.setMaximumSize(buttonSize);
253:                jbNext.setPreferredSize(buttonSize);
254:                jbNext.getAccessibleContext().setAccessibleDescription(
255:                        WizardResouces
256:                                .getString("WizardSheet.NEXT_BTN_Description"));
257:
258:                pnlButtonBar.add(jbFinish, new GridBagConstraints(4, 0, // gridx, gridy
259:                        1, 1, // gridwidth, gridheight
260:                        0.0, 0.0, // weightx, weighty
261:                        GridBagConstraints.CENTER, // anchor
262:                        GridBagConstraints.BOTH, // fill
263:                        insets, // insets
264:                        0, // ipadx
265:                        0));
266:
267:                /*pnlButtonBar.add(spacer2, new GridBagConstraints(
268:                5, 0, // gridx, gridy
269:                1, 1, // gridwidth, gridheight
270:                0.0, 0.0, // weightx, weighty
271:                GridBagConstraints.CENTER, // anchor
272:                GridBagConstraints.BOTH, // fill
273:                insets, // insets
274:                0, // ipadx
275:                0));
276:                 */
277:                pnlButtonBar.add(jbCancel, new GridBagConstraints(6, 0, // gridx, gridy
278:                        1, 1, // gridwidth, gridheight
279:                        0.0, 0.0, // weightx, weighty
280:                        GridBagConstraints.CENTER, // anchor
281:                        GridBagConstraints.BOTH, // fill
282:                        insets, // insets
283:                        0, // ipadx
284:                        0));
285:                pnlButtonBar.add(spacer3, new GridBagConstraints(7, 0, // gridx, gridy
286:                        1, 1, // gridwidth, gridheight
287:                        0.0, 0.0, // weightx, weighty
288:                        GridBagConstraints.CENTER, // anchor
289:                        GridBagConstraints.BOTH, // fill
290:                        insets, // insets
291:                        0, // ipadx
292:                        0));
293:
294:                this .getContentPane().add(wizardPages, BorderLayout.CENTER);
295:                this .getContentPane().add(pnlButtonBar, BorderLayout.SOUTH);
296:                this .addActionListeners();
297:            }
298:
299:            /**
300:             * @return
301:             */
302:            protected String getCancelButtonCaption() {
303:                return WizardResouces.getString("WizardSheet.CANCEL_BTN"); //$NON-NLS-1$
304:            }
305:
306:            /**
307:             * @return
308:             */
309:            protected String getCommitButtonCaption() {
310:                return WizardResouces.getString("WizardSheet.COMMIT_BTN"); //$NON-NLS-1$
311:            }
312:
313:            /**
314:             * @return
315:             */
316:            protected String getNextButtonCaption() {
317:                return WizardResouces.getString("WizardSheet.NEXT_BTN"); //$NON-NLS-1$
318:            }
319:
320:            /**
321:             * @return
322:             */
323:            protected String getBackButtonCaption() {
324:                return WizardResouces.getString("WizardSheet.BACK_BTN"); //$NON-NLS-1$
325:            }
326:
327:            /**
328:             * @return
329:             */
330:            protected boolean canAddNavigationButtons() {
331:                return true;
332:            }
333:
334:            private void addActionListeners() {
335:                jbBack.addActionListener(new java.awt.event.ActionListener() {
336:                    public void actionPerformed(ActionEvent e) {
337:                        jbBack_actionPerformed(e);
338:                    }
339:                });
340:
341:                jbNext.addActionListener(new java.awt.event.ActionListener() {
342:                    public void actionPerformed(ActionEvent e) {
343:                        jbNext_actionPerformed(e);
344:                    }
345:                });
346:
347:                jbFinish.addActionListener(new java.awt.event.ActionListener() {
348:                    public void actionPerformed(ActionEvent e) {
349:                        jbFinish_actionPerformed(e);
350:                    }
351:                });
352:
353:                jbCancel.addActionListener(new java.awt.event.ActionListener() {
354:                    public void actionPerformed(ActionEvent e) {
355:                        jbCancel_actionPerformed(e);
356:                    }
357:                });
358:
359:            }
360:
361:            // override this method to add your pages plus any other setup
362:            // @warning be sure to call Init() from your derived class!
363:            public void init(Icon hbmWatermark,
364:                    GraphicsConfiguration hpalWatermark, Icon hbmHeader) {
365:
366:                this .bmpWatermark = hbmWatermark;
367:                this .bmpHeader = hbmHeader;
368:
369:            }
370:
371:            protected void showPage(String pageName) {
372:                wizardPages.showCard(pageName);
373:            }
374:
375:            protected void addPage(IWizardPage page, String pageName) {
376:                if (page instanceof  JPanel) {
377:                    page.setParentSheet(this );
378:                    wizardPages.add((JPanel) page, pageName);
379:                }
380:            }
381:
382:            void jbBack_actionPerformed(ActionEvent e) {
383:                onWizardBack();
384:            }
385:
386:            void jbNext_actionPerformed(ActionEvent e) {
387:                onWizardNext();
388:            }
389:
390:            void jbFinish_actionPerformed(ActionEvent e) {
391:                onWizardFinish();
392:            }
393:
394:            void jbCancel_actionPerformed(ActionEvent e) {
395:                onWizardCancel();
396:            }
397:
398:            public Icon getBmpHeader() {
399:                return bmpHeader;
400:            }
401:
402:            public Icon getBmpWatermark() {
403:                return bmpWatermark;
404:            }
405:
406:            public void setTitle(String title) {
407:                this .m_Title = title;
408:                if (title != null) {
409:                    super .setTitle(title);
410:                }
411:            }
412:
413:            public int getActiveIndex() {
414:                return wizardPages.getCurrentCardIndex();
415:            }
416:
417:            public void setActivePage(int pIndex) {
418:                wizardPages.showCard(pIndex);
419:            }
420:
421:            public int getPageCount() {
422:                return wizardPages.getCardCount();
423:            }
424:
425:            // notification from cardPanel that a page event has occured
426:            public void onPageChange() {
427:
428:                updateButtons();
429:
430:                Component currCard = wizardPages.getCurrentCard();
431:
432:                if (currCard instanceof  IWizardPage) {
433:
434:                    IWizardPage currPage = ((IWizardPage) currCard);
435:                    String pageCaption = currPage.getCaption();
436:
437:                    if (pageCaption != null && pageCaption.length() > 0) {
438:                        super .setTitle(pageCaption);
439:                    } else {
440:                        super .setTitle(m_Title);
441:                    }
442:                    currPage.onSetActive();
443:                }
444:
445:            }
446:
447:            private void updateButtons() {
448:                int nIndex = getActiveIndex();
449:                if (nIndex == 0) {
450:                    jbBack.setEnabled(false);
451:                    jbNext.setEnabled(true);
452:                    jbFinish.setEnabled(false);
453:
454:                } else if (nIndex > 0 && nIndex < getPageCount() - 1) {
455:                    jbBack.setEnabled(true);
456:                    jbNext.setEnabled(true);
457:                    jbFinish.setEnabled(false);
458:
459:                } else if (nIndex == getPageCount() - 1) {
460:                    jbBack.setEnabled(true);
461:                    jbNext.setEnabled(false);
462:                    jbFinish.setEnabled(true);
463:                }
464:            }
465:
466:            public void onWizardBack() {
467:
468:                lastButtonPressed = IWizardSheet.PSWIZB_BACK;
469:                Component currCard = wizardPages.getCurrentCard();
470:
471:                if (currCard instanceof  IWizardPage) {
472:                    IWizardPage currPage = ((IWizardPage) currCard);
473:                    currPage.onWizardBack();
474:                }
475:            }
476:
477:            public void onWizardNext() {
478:
479:                lastButtonPressed = IWizardSheet.PSWIZB_NEXT;
480:                Component currCard = wizardPages.getCurrentCard();
481:                if (currCard instanceof  IWizardPage) {
482:                    IWizardPage currPage = ((IWizardPage) currCard);
483:                    currPage.onWizardNext();
484:                }
485:            }
486:
487:            public void onWizardCancel() {
488:                lastButtonPressed = IWizardSheet.PSWIZB_CANCEL;
489:                this .dispose();
490:            }
491:
492:            public void onWizardFinish() {
493:                lastButtonPressed = IWizardSheet.PSWIZB_FINISH;
494:                Component currCard = wizardPages.getCurrentCard();
495:
496:                boolean bDispose = true;
497:
498:                if (currCard instanceof  IWizardPage) {
499:                    IWizardPage currPage = ((IWizardPage) currCard);
500:                    bDispose = currPage.onDismiss();
501:                }
502:
503:                if (bDispose) {
504:                    dispose();
505:                }
506:            }
507:
508:            public int doModal() {
509:
510:                super .setVisible(true);
511:                return this .lastButtonPressed;
512:            }
513:
514:            public void setCursor(int newValue) {
515:                switch (newValue) {
516:                case Cursor.DEFAULT_CURSOR:
517:                    this .setCursor(Cursor
518:                            .getPredefinedCursor(Cursor.DEFAULT_CURSOR));
519:                    break;
520:
521:                case Cursor.WAIT_CURSOR:
522:                    this .setCursor(Cursor
523:                            .getPredefinedCursor(Cursor.WAIT_CURSOR));
524:                    break;
525:
526:                }
527:            }
528:
529:            public void setButtonEnabled(int button, boolean enabled) {
530:                switch (button) {
531:                case IWizardSheet.PSWIZB_BACK:
532:                    this .jbBack.setEnabled(enabled);
533:                    break;
534:                case IWizardSheet.PSWIZB_NEXT:
535:                    this .jbNext.setEnabled(enabled);
536:                    break;
537:                case IWizardSheet.PSWIZB_CANCEL:
538:                    this .jbCancel.setEnabled(enabled);
539:                    break;
540:                case IWizardSheet.PSWIZB_FINISH:
541:                    this .jbFinish.setEnabled(enabled);
542:                    break;
543:                }
544:
545:            }
546:
547:            private Dimension getMaxButtonWidth() {
548:                Dimension ret = null;
549:                Dimension d = jbBack.getPreferredSize();
550:                double max = d.width;
551:
552:                d = jbCancel.getPreferredSize();
553:                if (d.width > max) {
554:                    max = d.width;
555:                    ret = d;
556:                }
557:                d = jbFinish.getPreferredSize();
558:                if (d.width > max) {
559:                    max = d.width;
560:                    ret = d;
561:                }
562:                d = jbNext.getPreferredSize();
563:                if (d.width > max) {
564:                    max = d.width;
565:                    ret = d;
566:                }
567:
568:                return ret;
569:
570:            }
571:        }
w__w___w___.__jav___a__2_s_._co__m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.