Source Code Cross Referenced for MultiplePageDialog.java in  » Swing-Library » jide-common » com » jidesoft » dialog » 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 » Swing Library » jide common » com.jidesoft.dialog 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * @(#)MultiplePageDialog.java
0003:         *
0004:         * Copyright 2002 - 2003 JIDE Software. All rights reserved.
0005:         */
0006:        package com.jidesoft.dialog;
0007:
0008:        import com.jidesoft.plaf.UIDefaultsLookup;
0009:        import com.jidesoft.swing.JideButton;
0010:        import com.jidesoft.swing.JideScrollPane;
0011:
0012:        import javax.swing.*;
0013:        import javax.swing.event.*;
0014:        import javax.swing.tree.*;
0015:        import java.awt.*;
0016:        import java.awt.event.ActionEvent;
0017:        import java.beans.PropertyChangeEvent;
0018:        import java.beans.PropertyChangeListener;
0019:        import java.util.*;
0020:
0021:        /**
0022:         * MultiplePageDialog is a StandardDialog which can have multiple AbstractDialogPages.
0023:         * You can choose one from four predefined styles of how to change the page visibility.
0024:         * Those four styles are TAB_STYLE, ICON_STYLE, LIST_STYLE and TREE_STYLE.
0025:         * <p/>
0026:         * To use this class, just create a PageList of AbstractDialogPage and call setPageList() to
0027:         * set to this dialog. Based on the style, the class will automatically layout those pages
0028:         * correctly and hook up actions to switch based on user selection.
0029:         * <p/>
0030:         * As AbstractDialogPage extends AbstractPage, so you can always use PageListener to decide what to
0031:         * do when page is opened, closing, closed, activated or deactivated.
0032:         * <p/>
0033:         * We automatically create a button panel which have three button - OK, Cancel and Apply. The
0034:         * ButtonPanel listens to ButtonEvent from all the pages. You can simply fireButtonEvent in the
0035:         * page to change the state of those buttons. Or if you want to create your own button panel, just
0036:         * override createButtonPanel() method.
0037:         * <p/>
0038:         * If you choose LIST_STYLE and TREE_STYLE, you can set your own ListCellRenderer and
0039:         * TreeCellRenderer. Just call setListCellRenderer() and setTreeCellRenderer(). The value passed in
0040:         * the renderer is an instance of AbstractDialogPage associated with that list row or tree node.
0041:         */
0042:        public class MultiplePageDialog extends StandardDialog {
0043:            /**
0044:             * Predefined style of multiple page dialog.
0045:             */
0046:            public static final int TAB_STYLE = 0;
0047:
0048:            /**
0049:             * Predefined style of multiple page dialog.
0050:             */
0051:            public static final int TREE_STYLE = 1;
0052:
0053:            /**
0054:             * Predefined style of multiple page dialog.
0055:             */
0056:            public static final int LIST_STYLE = 2;
0057:
0058:            /**
0059:             * Predefined style of multiple page dialog.
0060:             */
0061:            public static final int ICON_STYLE = 3;
0062:
0063:            private int _style;
0064:
0065:            private PageList _pageList;
0066:
0067:            /**
0068:             * The left pane to show the icon, list etc.
0069:             * It's an index area to choose which page.
0070:             */
0071:            private JComponent _indexPanel;
0072:
0073:            /**
0074:             * The panel contains all the pages. In TAB_STYLE, it
0075:             * is a tabbed pane and in other styles, it's a panel with CardLayout.
0076:             */
0077:            private JComponent _pagesPanel;
0078:            private CardLayout _cardLayout;
0079:
0080:            /**
0081:             * Map that maps from page full title to tree node.
0082:             * It provides a fast access from page full title to the tree node in TREE_STYLE.
0083:             */
0084:            private Map _titleNodeMap;
0085:
0086:            private JButton _okButton;
0087:            private JButton _cancelButton;
0088:            private JButton _applyButton;
0089:
0090:            private TreeCellRenderer _treeCellRenderer;
0091:
0092:            private ListCellRenderer _listCellRenderer;
0093:            private JTabbedPane _tabbedPane;
0094:
0095:            private String _initialPageTitle;
0096:            public JTree _tree;
0097:
0098:            /**
0099:             * Creates a non-modal MultiplePageDialog without a title and without a specified
0100:             * <code>Frame</code> owner.  A shared, hidden frame will be
0101:             * set as the owner of the dialog.
0102:             * By default TAB_STYLE is used.
0103:             *
0104:             * @throws HeadlessException
0105:             */
0106:            public MultiplePageDialog() throws HeadlessException {
0107:                this ((Frame) null);
0108:            }
0109:
0110:            /**
0111:             * Creates a non-modal MultiplePageDialog without a title with the
0112:             * specified <code>Frame</code> as its owner.  If <code>owner</code>
0113:             * is <code>null</code>, a shared, hidden frame will be set as the
0114:             * owner of the dialog.
0115:             * By default TAB_STYLE is used.
0116:             *
0117:             * @param owner
0118:             * @throws HeadlessException
0119:             */
0120:            public MultiplePageDialog(Frame owner) throws HeadlessException {
0121:                this (owner, false);
0122:            }
0123:
0124:            /**
0125:             * Creates a modal or non-modal MultiplePageDialog without a title and
0126:             * with the specified owner <code>Frame</code>.  If <code>owner</code>
0127:             * is <code>null</code>, a shared, hidden frame will be set as the
0128:             * owner of the dialog.
0129:             * By default TAB_STYLE is used.
0130:             *
0131:             * @param owner the <code>Frame</code> from which the dialog is displayed
0132:             * @param modal true for a modal dialog, false for one that allows
0133:             *              others windows to be active at the same time
0134:             * @throws HeadlessException
0135:             */
0136:            public MultiplePageDialog(Frame owner, boolean modal)
0137:                    throws HeadlessException {
0138:                this (owner, "", modal);
0139:            }
0140:
0141:            /**
0142:             * Creates a non-modal MultiplePageDialog with the specified title and
0143:             * with the specified owner frame.  If <code>owner</code>
0144:             * is <code>null</code>, a shared, hidden frame will be set as the
0145:             * owner of the dialog.
0146:             *
0147:             * @param owner the <code>Frame</code> from which the dialog is displayed
0148:             * @param title the <code>String</code> to display in the dialog's
0149:             *              title bar
0150:             * @throws HeadlessException if GraphicsEnvironment.isHeadless()
0151:             *                           returns true.
0152:             * @see java.awt.GraphicsEnvironment#isHeadless
0153:             * @see JComponent#getDefaultLocale
0154:             */
0155:            public MultiplePageDialog(Frame owner, String title)
0156:                    throws HeadlessException {
0157:                this (owner, title, true);
0158:            }
0159:
0160:            /**
0161:             * Creates a modal or non-modal dialog with the specified title
0162:             * and the specified owner <code>Frame</code>.  If <code>owner</code>
0163:             * is <code>null</code>, a shared, hidden frame will be set as the
0164:             * owner of this dialog.
0165:             *
0166:             * @param owner the <code>Frame</code> from which the dialog is displayed
0167:             * @param title the <code>String</code> to display in the dialog's
0168:             *              title bar
0169:             * @param modal true for a modal dialog, false for one that allows
0170:             *              other windows to be active at the same time
0171:             * @throws HeadlessException if GraphicsEnvironment.isHeadless()
0172:             *                           returns true.
0173:             * @see java.awt.GraphicsEnvironment#isHeadless
0174:             * @see JComponent#getDefaultLocale
0175:             */
0176:            public MultiplePageDialog(Frame owner, String title, boolean modal)
0177:                    throws HeadlessException {
0178:                this (owner, title, modal, TAB_STYLE);
0179:            }
0180:
0181:            /**
0182:             * Creates a modal or non-modal MultiplePageDialog with the specified style, the specified title
0183:             * and the specified owner <code>Frame</code>.  If <code>owner</code>
0184:             * is <code>null</code>, a shared, hidden frame will be set as the
0185:             * owner of this dialog.  All constructors defer to this one.
0186:             *
0187:             * @param owner the <code>Frame</code> from which the dialog is displayed
0188:             * @param title the <code>String</code> to display in the dialog's
0189:             *              title bar
0190:             * @param modal true for a modal dialog, false for one that allows
0191:             *              other windows to be active at the same time
0192:             * @param style the style. It must be one of the following: TAB_STYLE, ICON_STYLE, LIST_STYLE or TREE_STYLE.
0193:             * @throws HeadlessException if GraphicsEnvironment.isHeadless()
0194:             *                           returns true.
0195:             * @see java.awt.GraphicsEnvironment#isHeadless
0196:             * @see JComponent#getDefaultLocale
0197:             */
0198:            public MultiplePageDialog(Frame owner, String title, boolean modal,
0199:                    int style) throws HeadlessException {
0200:                super (owner, title, modal);
0201:                setStyle(style);
0202:            }
0203:
0204:            /**
0205:             * Creates a non-modal MultiplePageDialog without a title with the
0206:             * specified <code>Dialog</code> as its owner.  If <code>owner</code>
0207:             * is <code>null</code>, a shared, hidden frame will be set as the
0208:             * owner of the dialog.
0209:             * By default TAB_STYLE is used.
0210:             *
0211:             * @param owner
0212:             * @throws HeadlessException
0213:             */
0214:            public MultiplePageDialog(Dialog owner) throws HeadlessException {
0215:                this (owner, false);
0216:            }
0217:
0218:            /**
0219:             * Creates a modal or non-modal MultiplePageDialog without a title and
0220:             * with the specified owner <code>Dialog</code>.  If <code>owner</code>
0221:             * is <code>null</code>, a shared, hidden frame will be set as the
0222:             * owner of the dialog.
0223:             * By default TAB_STYLE is used.
0224:             *
0225:             * @param owner the <code>Frame</code> from which the dialog is displayed
0226:             * @param modal true for a modal dialog, false for one that allows
0227:             *              others windows to be active at the same time
0228:             * @throws HeadlessException
0229:             */
0230:            public MultiplePageDialog(Dialog owner, boolean modal)
0231:                    throws HeadlessException {
0232:                this (owner, "", modal);
0233:            }
0234:
0235:            /**
0236:             * Creates a non-modal MultiplePageDialog with the specified title and
0237:             * with the specified owner frame.  If <code>owner</code>
0238:             * is <code>null</code>, a shared, hidden frame will be set as the
0239:             * owner of the dialog.
0240:             *
0241:             * @param owner the <code>Frame</code> from which the dialog is displayed
0242:             * @param title the <code>String</code> to display in the dialog's
0243:             *              title bar
0244:             * @throws HeadlessException if GraphicsEnvironment.isHeadless()
0245:             *                           returns true.
0246:             * @see java.awt.GraphicsEnvironment#isHeadless
0247:             * @see JComponent#getDefaultLocale
0248:             */
0249:            public MultiplePageDialog(Dialog owner, String title)
0250:                    throws HeadlessException {
0251:                this (owner, title, true);
0252:            }
0253:
0254:            /**
0255:             * Creates a modal or non-modal dialog with the specified title
0256:             * and the specified owner <code>Dialog</code>.  If <code>owner</code>
0257:             * is <code>null</code>, a shared, hidden frame will be set as the
0258:             * owner of this dialog.
0259:             *
0260:             * @param owner the <code>Dialog</code> from which the dialog is displayed
0261:             * @param title the <code>String</code> to display in the dialog's
0262:             *              title bar
0263:             * @param modal true for a modal dialog, false for one that allows
0264:             *              other windows to be active at the same time
0265:             * @throws HeadlessException if GraphicsEnvironment.isHeadless()
0266:             *                           returns true.
0267:             * @see java.awt.GraphicsEnvironment#isHeadless
0268:             * @see JComponent#getDefaultLocale
0269:             */
0270:            public MultiplePageDialog(Dialog owner, String title, boolean modal)
0271:                    throws HeadlessException {
0272:                this (owner, title, modal, TAB_STYLE);
0273:            }
0274:
0275:            /**
0276:             * Creates a modal or non-modal MultiplePageDialog with the specified style, the specified title
0277:             * and the specified owner <code>Dialog</code>.  If <code>owner</code>
0278:             * is <code>null</code>, a shared, hidden frame will be set as the
0279:             * owner of this dialog.  All constructors defer to this one.
0280:             *
0281:             * @param owner the <code>Dialog</code> from which the dialog is displayed
0282:             * @param title the <code>String</code> to display in the dialog's
0283:             *              title bar
0284:             * @param modal true for a modal dialog, false for one that allows
0285:             *              other windows to be active at the same time
0286:             * @param style the style. It must be one of the following: TAB_STYLE, ICON_STYLE, LIST_STYLE or TREE_STYLE.
0287:             * @throws HeadlessException if GraphicsEnvironment.isHeadless()
0288:             *                           returns true.
0289:             * @see java.awt.GraphicsEnvironment#isHeadless
0290:             * @see JComponent#getDefaultLocale
0291:             */
0292:            public MultiplePageDialog(Dialog owner, String title,
0293:                    boolean modal, int style) throws HeadlessException {
0294:                super (owner, title, modal);
0295:                setStyle(style);
0296:            }
0297:
0298:            /**
0299:             * Implements the method in StandardDialog.
0300:             * You can override this method to create a BannerPanel.
0301:             *
0302:             * @return the BannerPanel
0303:             */
0304:            @Override
0305:            public JComponent createBannerPanel() {
0306:                return null;
0307:            }
0308:
0309:            /**
0310:             * Implements the method in StandardDialog.
0311:             * You can override this method to create a ContentPanel.
0312:             * By default, a JPanel with BorderLayout is created.
0313:             * IndexPanel is added to WEST and PagesPanel is added to CENTER.
0314:             *
0315:             * @return the ContentPanel
0316:             */
0317:            @Override
0318:            public JComponent createContentPanel() {
0319:                _indexPanel = createIndexPanel();
0320:                _pagesPanel = createPagesPanel();
0321:                if (_pageList.getPageCount() > 0) {
0322:                    if (getInitialPageTitle() != null) {
0323:                        setCurrentPage(getInitialPageTitle());
0324:                    } else {
0325:                        setCurrentPage(_pageList.getPage(0));
0326:                    }
0327:                }
0328:                return setupContentPanel(_indexPanel, _pagesPanel);
0329:            }
0330:
0331:            /**
0332:             * Setups the content panel. It will use the index panel and the pages panel created earlier and put it into another panel.
0333:             *
0334:             * @param indexPanel the index panel. It has the nagivation control to control which page to show.
0335:             * @param pagesPanel the pages panel. It contains all the pages of this dialog.
0336:             * @return the panel that contains both index panel and pages panel.
0337:             */
0338:            protected JComponent setupContentPanel(JComponent indexPanel,
0339:                    JComponent pagesPanel) {
0340:                JPanel middlePanel = new JPanel(new BorderLayout(10, 10));
0341:                if (indexPanel != null) {
0342:                    middlePanel
0343:                            .add(indexPanel, BorderLayout.BEFORE_LINE_BEGINS);
0344:                }
0345:                if (pagesPanel != null) {
0346:                    middlePanel.add(pagesPanel, BorderLayout.CENTER);
0347:                }
0348:                return middlePanel;
0349:            }
0350:
0351:            /**
0352:             * Creates the button panel. It has three buttons - OK, Cancel and Apply.
0353:             * If you want to create your own button panel, just override this method.
0354:             *
0355:             * @return button panel
0356:             */
0357:            @Override
0358:            public ButtonPanel createButtonPanel() {
0359:                ButtonPanel buttonPanel = new ButtonPanel();
0360:                _okButton = new JButton();
0361:                _cancelButton = new JButton();
0362:                _applyButton = new JButton();
0363:                _okButton.setName(OK);
0364:                _cancelButton.setName(CANCEL);
0365:                _applyButton.setName(APPLY);
0366:                buttonPanel
0367:                        .addButton(_okButton, ButtonPanel.AFFIRMATIVE_BUTTON);
0368:                buttonPanel.addButton(_cancelButton, ButtonPanel.CANCEL_BUTTON);
0369:                buttonPanel.addButton(_applyButton, ButtonPanel.OTHER_BUTTON);
0370:
0371:                Locale l = getLocale();
0372:                _okButton.setAction(new AbstractAction(UIDefaultsLookup
0373:                        .getString("OptionPane.okButtonText", l)) {
0374:                    public void actionPerformed(ActionEvent e) {
0375:                        setDialogResult(RESULT_AFFIRMED);
0376:                        setVisible(false);
0377:                        dispose();
0378:                    }
0379:                });
0380:                _cancelButton.setAction(new AbstractAction(UIDefaultsLookup
0381:                        .getString("OptionPane.cancelButtonText", l)) {
0382:                    public void actionPerformed(ActionEvent e) {
0383:                        setDialogResult(RESULT_CANCELLED);
0384:                        setVisible(false);
0385:                        dispose();
0386:                    }
0387:                });
0388:                _applyButton.setAction(new AbstractAction(ButtonResources
0389:                        .getResourceBundle(Locale.getDefault()).getString(
0390:                                "Button.apply")) {
0391:                    public void actionPerformed(ActionEvent e) {
0392:                        if (getCurrentPage() != null) {
0393:                            getCurrentPage().fireButtonEvent(
0394:                                    ButtonEvent.DISABLE_BUTTON, APPLY);
0395:                        }
0396:                    }
0397:                });
0398:                _applyButton.setMnemonic(ButtonResources.getResourceBundle(
0399:                        Locale.getDefault()).getString("Button.apply.mnemonic")
0400:                        .charAt(0));
0401:                _applyButton.setEnabled(false);
0402:
0403:                setDefaultCancelAction(_cancelButton.getAction());
0404:                setDefaultAction(_okButton.getAction());
0405:                getRootPane().setDefaultButton(_okButton);
0406:                return buttonPanel;
0407:            }
0408:
0409:            /**
0410:             * Gets the OK Button
0411:             * only if you didn't override
0412:             * the createButtonPanel() and remove the OK button.
0413:             *
0414:             * @return the OK Button
0415:             */
0416:            public JButton getOkButton() {
0417:                return _okButton;
0418:            }
0419:
0420:            /**
0421:             * Gets the cancel button.
0422:             * only if you didn't override
0423:             * the createButtonPanel() and remove the cancel button.
0424:             *
0425:             * @return the cancel button.
0426:             */
0427:            public JButton getCancelButton() {
0428:                return _cancelButton;
0429:            }
0430:
0431:            /**
0432:             * Gets the apply button.
0433:             * only if you didn't override
0434:             * the createButtonPanel() and remove the apply button.
0435:             *
0436:             * @return the apply button.
0437:             */
0438:            public JButton getApplyButton() {
0439:                return _applyButton;
0440:            }
0441:
0442:            /**
0443:             * Creates the pages panel. If it's TAB_STYLE, a tabbed pane will be created.
0444:             * If it's any other styles, a JPanel with CardLayout will be created.
0445:             *
0446:             * @return a panel containing all the pages.
0447:             */
0448:            protected JComponent createPagesPanel() {
0449:                if (_style == TAB_STYLE) {
0450:                    _tabbedPane = new JTabbedPane(JTabbedPane.TOP);
0451:                    for (int i = 0; i < _pageList.getPageCount(); i++) {
0452:                        AbstractDialogPage page = _pageList.getPage(i);
0453:                        page.addButtonListener(getButtonPanel());
0454:                        _tabbedPane.addTab(page.getTitle(), page.getIcon(),
0455:                                page, page.getDescription());
0456:                        _tabbedPane.setEnabledAt(i, page.isPageEnabled());
0457:                        final int index = i;
0458:                        page
0459:                                .addPropertyChangeListener(new PropertyChangeListener() {
0460:                                    public void propertyChange(
0461:                                            PropertyChangeEvent evt) {
0462:                                        if (AbstractDialogPage.PROPERTY_PAGE_ENABLED
0463:                                                .equals(evt.getPropertyName())) {
0464:                                            _tabbedPane.setEnabledAt(index,
0465:                                                    Boolean.TRUE.equals(evt
0466:                                                            .getNewValue()));
0467:                                        } else if (AbstractDialogPage.ICON_PROPERTY
0468:                                                .equals(evt.getPropertyName())) {
0469:                                            _tabbedPane.setIconAt(index,
0470:                                                    (Icon) evt.getNewValue());
0471:                                        } else if (AbstractDialogPage.TITLE_PROPERTY
0472:                                                .equals(evt.getPropertyName())) {
0473:                                            _tabbedPane.setTitleAt(index,
0474:                                                    (String) evt.getNewValue());
0475:                                        } else if (AbstractDialogPage.DESCRIPTION_PROPERTY
0476:                                                .equals(evt.getPropertyName())) {
0477:                                            _tabbedPane.setToolTipTextAt(index,
0478:                                                    (String) evt.getNewValue());
0479:                                        }
0480:                                    }
0481:                                });
0482:                    }
0483:                    _pageList.addListDataListener(new ListDataListener() {
0484:                        public void intervalAdded(ListDataEvent e) {
0485:                            for (int i = e.getIndex0(); i <= e.getIndex1(); i++) {
0486:                                AbstractDialogPage page = _pageList.getPage(i);
0487:                                _tabbedPane.insertTab(page.getTitle(), page
0488:                                        .getIcon(), page,
0489:                                        page.getDescription(), i);
0490:                            }
0491:                        }
0492:
0493:                        public void intervalRemoved(ListDataEvent e) {
0494:                            for (int i = e.getIndex1(); i >= e.getIndex0(); i--) {
0495:                                _tabbedPane.removeTabAt(i);
0496:                            }
0497:                        }
0498:
0499:                        public void contentsChanged(ListDataEvent e) {
0500:                        }
0501:                    });
0502:                    return _tabbedPane;
0503:                } else {
0504:                    final JPanel pagesPanel = new JPanel();
0505:                    _cardLayout = new CardLayout();
0506:                    pagesPanel.setLayout(_cardLayout);
0507:
0508:                    for (int i = 0; i < _pageList.getPageCount(); i++) {
0509:                        AbstractDialogPage page = _pageList.getPage(i);
0510:                        page.addButtonListener(getButtonPanel());
0511:                        page.setName(page.getFullTitle());
0512:                        page
0513:                                .addPropertyChangeListener(new PropertyChangeListener() {
0514:                                    public void propertyChange(
0515:                                            PropertyChangeEvent evt) {
0516:                                        if (AbstractDialogPage.TITLE_PROPERTY
0517:                                                .equals(evt.getPropertyName())) {
0518:                                            for (int j = 0; j < pagesPanel
0519:                                                    .getComponentCount(); j++) {
0520:                                                Component c = pagesPanel
0521:                                                        .getComponent(j);
0522:                                                boolean wasVisible = c
0523:                                                        .isVisible();
0524:                                                Object source = evt.getSource();
0525:                                                if (source instanceof  AbstractDialogPage
0526:                                                        && c == source) {
0527:                                                    pagesPanel.remove(j);
0528:                                                    String fullTitle = ((AbstractDialogPage) source)
0529:                                                            .getFullTitle();
0530:                                                    pagesPanel
0531:                                                            .add(
0532:                                                                    (AbstractDialogPage) source,
0533:                                                                    fullTitle,
0534:                                                                    j);
0535:                                                    ((AbstractDialogPage) source)
0536:                                                            .setName(fullTitle);
0537:                                                    getIndexPanel().repaint();
0538:                                                    if (wasVisible) {
0539:                                                        _cardLayout.show(
0540:                                                                pagesPanel,
0541:                                                                fullTitle);
0542:                                                    }
0543:                                                    break;
0544:                                                }
0545:                                            }
0546:                                        }
0547:                                    }
0548:                                });
0549:
0550:                        pagesPanel.add(page, page.getFullTitle());
0551:                    }
0552:
0553:                    _pageList.addListDataListener(new ListDataListener() {
0554:                        public void intervalAdded(ListDataEvent e) {
0555:                            for (int i = e.getIndex0(); i <= e.getIndex1(); i++) {
0556:                                AbstractDialogPage page = _pageList.getPage(i);
0557:                                page.setName(page.getFullTitle());
0558:                                pagesPanel.add(page, page.getFullTitle(), i);
0559:                            }
0560:                        }
0561:
0562:                        public void intervalRemoved(ListDataEvent e) {
0563:                            for (int i = e.getIndex1(); i >= e.getIndex0(); i--) {
0564:                                pagesPanel.remove(i);
0565:                            }
0566:                        }
0567:
0568:                        private void dumpPagesPanel() {
0569:                            for (int i = 0; i < pagesPanel.getComponentCount(); i++) {
0570:                                System.out.println("" + i + ": "
0571:                                        + pagesPanel.getComponent(i).getName());
0572:                            }
0573:                        }
0574:
0575:                        public void contentsChanged(ListDataEvent e) {
0576:                        }
0577:                    });
0578:                    return pagesPanel;
0579:                }
0580:            }
0581:
0582:            /**
0583:             * Creates the index panel based on the style.
0584:             *
0585:             * @return the index panel.
0586:             */
0587:            public JComponent createIndexPanel() {
0588:                switch (_style) {
0589:                case ICON_STYLE:
0590:                    return createIconPanel();
0591:                case LIST_STYLE:
0592:                    return createListPanel();
0593:                case TREE_STYLE:
0594:                    return createTreePanel();
0595:                case TAB_STYLE:
0596:                default:
0597:                    return null;
0598:                }
0599:            }
0600:
0601:            /**
0602:             * Sets the page list of this dialog. User must call this method before the
0603:             * dialog is set visible.
0604:             *
0605:             * @param pageList
0606:             */
0607:            public void setPageList(PageList pageList) {
0608:                _pageList = pageList;
0609:            }
0610:
0611:            /**
0612:             * Gets the page list of this dialog.
0613:             */
0614:            public PageList getPageList() {
0615:                return _pageList;
0616:            }
0617:
0618:            /**
0619:             * Gets the current selected page.
0620:             *
0621:             * @return the current selected page.
0622:             */
0623:            public AbstractDialogPage getCurrentPage() {
0624:                return _pageList.getCurrentPage();
0625:            }
0626:
0627:            protected void setCurrentPage(String pageTitle) {
0628:                if (_pageList != null) {
0629:                    setCurrentPage(_pageList.getPageByFullTitle(pageTitle));
0630:                }
0631:            }
0632:
0633:            protected void setCurrentPage(AbstractDialogPage currentPage) {
0634:                setCurrentPage(currentPage, null);
0635:            }
0636:
0637:            protected void setCurrentPage(AbstractDialogPage currentPage,
0638:                    Object source) {
0639:                if (_pageList.getCurrentPage() != null
0640:                        && !_pageList.getCurrentPage().equals(currentPage)) {
0641:                    _pageList.getCurrentPage().setAllowClosing(true);
0642:                    _pageList.getCurrentPage().firePageEvent(source,
0643:                            PageEvent.PAGE_CLOSING);
0644:                    if (!_pageList.getCurrentPage().allowClosing()) {
0645:                        return;
0646:                    }
0647:                    _pageList.getCurrentPage().firePageEvent(source,
0648:                            PageEvent.PAGE_CLOSED);
0649:                }
0650:
0651:                _pageList.setCurrentPage(currentPage);
0652:
0653:                if (_pageList.getCurrentPage() != null) {
0654:                    if (getStyle() == TAB_STYLE) {
0655:                        _tabbedPane.setSelectedComponent(_pageList
0656:                                .getCurrentPage());
0657:                    } else {
0658:                        _cardLayout.show(_pagesPanel, currentPage
0659:                                .getFullTitle());
0660:                    }
0661:                    if (_pageList.getCurrentPage() != null) {
0662:                        _pageList.getCurrentPage().firePageEvent(source,
0663:                                PageEvent.PAGE_OPENED);
0664:                    }
0665:                }
0666:            }
0667:
0668:            private JComponent createTreePanel() {
0669:                final DefaultMutableTreeNode root = new DefaultMutableTreeNode(
0670:                        "", true);
0671:
0672:                _titleNodeMap = new HashMap(
0673:                        (int) (_pageList.getPageCount() * 0.75));
0674:                for (int i = 0; i < _pageList.getPageCount(); i++) {
0675:                    AbstractDialogPage dialogPage = _pageList.getPage(i);
0676:                    addPage(dialogPage, root, false);
0677:                }
0678:
0679:                _tree = createTree(root);
0680:                configureTree(_tree);
0681:                _pageList.addListDataListener(new ListDataListener() {
0682:                    public void intervalAdded(ListDataEvent e) {
0683:                        for (int i = e.getIndex0(); i <= e.getIndex1(); i++) {
0684:                            AbstractDialogPage dialogPage = _pageList
0685:                                    .getPage(i);
0686:                            addPage(dialogPage, (DefaultMutableTreeNode) _tree
0687:                                    .getModel().getRoot(), true);
0688:                        }
0689:                    }
0690:
0691:                    public void intervalRemoved(ListDataEvent e) {
0692:                        // compare PageList with TitleNodeMap to find out what is missing
0693:                        Set set = _titleNodeMap.keySet();
0694:                        Vector toBeRemoved = new Vector();
0695:                        for (Iterator iterator = set.iterator(); iterator
0696:                                .hasNext();) {
0697:                            String title = (String) iterator.next();
0698:                            if (_pageList.getPageByFullTitle(title) == null) {
0699:                                DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) _titleNodeMap
0700:                                        .get(title);
0701:                                if (treeNode != null) {
0702:                                    toBeRemoved.add(title);
0703:                                    DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) treeNode
0704:                                            .getParent();
0705:                                    if (parentNode != null) {
0706:                                        int index = parentNode
0707:                                                .getIndex(treeNode);
0708:                                        parentNode.remove(treeNode);
0709:                                        ((DefaultTreeModel) _tree.getModel())
0710:                                                .nodesWereRemoved(
0711:                                                        parentNode,
0712:                                                        new int[] { index },
0713:                                                        new Object[] { treeNode });
0714:                                    }
0715:                                }
0716:                            }
0717:                        }
0718:                        for (int i = 0; i < toBeRemoved.size(); i++) {
0719:                            _titleNodeMap.remove(toBeRemoved.get(i));
0720:                        }
0721:                    }
0722:
0723:                    public void contentsChanged(ListDataEvent e) {
0724:                        if (e.getIndex0() == -1
0725:                                && e.getIndex1() == -1
0726:                                && e.getType() == ListDataEvent.CONTENTS_CHANGED) {
0727:                            if (_titleNodeMap != null
0728:                                    && _pageList.getCurrentPage() != null) {
0729:                                TreeNode node = (TreeNode) _titleNodeMap
0730:                                        .get(_pageList.getCurrentPage()
0731:                                                .getFullTitle());
0732:                                if (node != null) {
0733:                                    ArrayList list = new ArrayList();
0734:                                    while (node != null) {
0735:                                        list.add(0, node);
0736:                                        node = node.getParent();
0737:                                    }
0738:                                    TreePath treePath = new TreePath(list
0739:                                            .toArray(new TreeNode[list.size()]));
0740:                                    _tree.getSelectionModel().setSelectionPath(
0741:                                            treePath);
0742:                                }
0743:                            }
0744:                        }
0745:                    }
0746:                });
0747:
0748:                JComponent indexPanel = new JPanel(new BorderLayout());
0749:                indexPanel.add(new JScrollPane(_tree), BorderLayout.CENTER);
0750:                return indexPanel;
0751:            }
0752:
0753:            /**
0754:             * Creates tree that is used in TREE_STYLE dialog's index panel. Below is the code we used.
0755:             * If you just want to have a different cell renderer, you can just call
0756:             * {@link #setTreeCellRenderer(javax.swing.tree.TreeCellRenderer)} to set a new one.
0757:             * <pre><code>
0758:             * UIManager.put("Tree.hash", Color.white);
0759:             * return new JTree(root);
0760:             * </code></pre>
0761:             *
0762:             * @param root
0763:             * @return tree
0764:             */
0765:            protected JTree createTree(DefaultMutableTreeNode root) {
0766:                UIManager.put("Tree.hash", Color.white);
0767:                return new JTree(root);
0768:            }
0769:
0770:            /**
0771:             * Configure the JTree used in TREE_STYLE dialog. Subclass can override this method to configure the JTree
0772:             * to the way you want. Below is the default implementation of this method.
0773:             * <code><pre>
0774:             * tree.setToggleClickCount(1);
0775:             * tree.setCellRenderer(createTreeCellRenderer());
0776:             * tree.setRootVisible(false);
0777:             * tree.setShowsRootHandles(false);
0778:             * tree.addTreeSelectionListener(new TreeSelectionListener() {
0779:             *     public void valueChanged(TreeSelectionEvent e) {
0780:             *         if (tree.getSelectionPath() == null) {
0781:             *             return;
0782:             *         }
0783:             * <p/>
0784:             *         DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) tree.getSelectionPath().getLastPathComponent();
0785:             *         // comment this while block if you want the parent page shows its own page instead of showing its first child page.
0786:             *         while (!treeNode.isLeaf()) {
0787:             *             final DefaultMutableTreeNode tn = treeNode;
0788:             *             Runnable runnable = new Runnable() {
0789:             *                 public void run() {
0790:             *                     tree.expandPath(new TreePath(tn.getPath()));
0791:             *                 }
0792:             *             };
0793:             *             SwingUtilities.invokeLater(runnable);
0794:             *             treeNode = (DefaultMutableTreeNode) treeNode.getChildAt(0);
0795:             *         }
0796:             * <p/>
0797:             *         if (treeNode != null) {
0798:             *             Object userObject = treeNode.getUserObject();
0799:             *             if (userObject instanceof AbstractDialogPage) {
0800:             *                 setCurrentPage((AbstractDialogPage) userObject, tree);
0801:             *             }
0802:             *         }
0803:             *     }
0804:             * });
0805:             * </pre></code>
0806:             *
0807:             * @param tree
0808:             */
0809:            protected void configureTree(final JTree tree) {
0810:                tree.setToggleClickCount(1);
0811:                tree.setCellRenderer(createTreeCellRenderer());
0812:                tree.setRootVisible(false);
0813:                tree.setShowsRootHandles(false);
0814:                tree.addTreeSelectionListener(new TreeSelectionListener() {
0815:                    public void valueChanged(TreeSelectionEvent e) {
0816:                        if (tree.getSelectionPath() == null) {
0817:                            return;
0818:                        }
0819:
0820:                        DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) tree
0821:                                .getSelectionPath().getLastPathComponent();
0822:
0823:                        // comment this while block if you want the parent page shows its own page instead of showing its first child page.
0824:                        while (!treeNode.isLeaf()) {
0825:                            final DefaultMutableTreeNode tn = treeNode;
0826:                            Runnable runnable = new Runnable() {
0827:                                public void run() {
0828:                                    tree.expandPath(new TreePath(tn.getPath()));
0829:                                }
0830:                            };
0831:                            SwingUtilities.invokeLater(runnable);
0832:                            treeNode = (DefaultMutableTreeNode) treeNode
0833:                                    .getChildAt(0);
0834:                        }
0835:
0836:                        if (treeNode != null) {
0837:                            Object userObject = treeNode.getUserObject();
0838:                            if (userObject instanceof  AbstractDialogPage) {
0839:                                setCurrentPage((AbstractDialogPage) userObject,
0840:                                        tree);
0841:                                if (getCurrentPage() != userObject) {
0842:                                    // TODO select the old path.
0843:                                }
0844:                            }
0845:                        }
0846:                    }
0847:                });
0848:            }
0849:
0850:            private void addPage(AbstractDialogPage dialogPage,
0851:                    final DefaultMutableTreeNode root, boolean fireEvent) {
0852:                if (dialogPage == null) {
0853:                    return;
0854:                }
0855:
0856:                if (dialogPage.getParentPage() == null) {
0857:                    DefaultMutableTreeNode treeNode = new DefaultMutableTreeNode(
0858:                            dialogPage);
0859:                    _titleNodeMap.put(dialogPage.getFullTitle(), treeNode);
0860:                    root.add(treeNode);
0861:                    if (fireEvent) {
0862:                        ((DefaultTreeModel) _tree.getModel())
0863:                                .nodesWereInserted(root, new int[] { root
0864:                                        .getIndex(treeNode) });
0865:                    }
0866:                } else {
0867:                    DefaultMutableTreeNode treeNode = new DefaultMutableTreeNode(
0868:                            dialogPage);
0869:                    _titleNodeMap.put(dialogPage.getFullTitle(), treeNode);
0870:                    DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) _titleNodeMap
0871:                            .get(dialogPage.getParentPage().getFullTitle());
0872:                    if (parentNode != null) {
0873:                        parentNode.add(treeNode);
0874:                        if (fireEvent) {
0875:                            ((DefaultTreeModel) _tree.getModel())
0876:                                    .nodesWereInserted(parentNode,
0877:                                            new int[] { parentNode
0878:                                                    .getIndex(treeNode) });
0879:                        }
0880:                    }
0881:                }
0882:            }
0883:
0884:            private void removePage(AbstractDialogPage dialogPage,
0885:                    final DefaultMutableTreeNode root, boolean fireEvent) {
0886:                if (dialogPage == null) {
0887:                    return;
0888:                }
0889:
0890:                DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) _titleNodeMap
0891:                        .get(dialogPage.getFullTitle());
0892:
0893:                if (treeNode == null) {
0894:                    return;
0895:                }
0896:
0897:                if (treeNode.getChildCount() > 0) {
0898:                    throw new IllegalArgumentException(
0899:                            "Please remove all children pages before removing parent page \""
0900:                                    + dialogPage.getFullTitle() + "\"");
0901:                }
0902:                _titleNodeMap.remove(dialogPage.getFullTitle());
0903:                if (dialogPage.getParentPage() == null) {
0904:                    int index = root.getIndex(treeNode);
0905:                    root.remove(treeNode);
0906:                    if (fireEvent) {
0907:                        ((DefaultTreeModel) _tree.getModel()).nodesWereRemoved(
0908:                                root, new int[] { index },
0909:                                new Object[] { treeNode });
0910:                    }
0911:                } else {
0912:                    DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) _titleNodeMap
0913:                            .get(dialogPage.getParentPage().getFullTitle());
0914:                    if (parentNode != null) {
0915:                        int index = parentNode.getIndex(treeNode);
0916:                        parentNode.remove(treeNode);
0917:                        if (fireEvent) {
0918:                            ((DefaultTreeModel) _tree.getModel())
0919:                                    .nodesWereRemoved(parentNode,
0920:                                            new int[] { index },
0921:                                            new Object[] { treeNode });
0922:                        }
0923:                    }
0924:                }
0925:            }
0926:
0927:            private JComponent createListPanel() {
0928:                final DefaultListModel listModel = new DefaultListModel();
0929:                for (int i = 0; i < _pageList.getPageCount(); i++) {
0930:                    AbstractDialogPage optionsPanel = _pageList.getPage(i);
0931:                    listModel.addElement(optionsPanel);
0932:                }
0933:
0934:                final JList list = createList(listModel);
0935:                if (list.getModel().getSize() > 0) {
0936:                    list.setSelectedIndex(0);
0937:                }
0938:                list.addListSelectionListener(new ListSelectionListener() {
0939:                    public void valueChanged(ListSelectionEvent e) {
0940:                        if (list.getSelectedValue() == getCurrentPage()) {
0941:                            return;
0942:                        }
0943:                        if (e.getValueIsAdjusting()) {
0944:                            AbstractDialogPage page = (AbstractDialogPage) list
0945:                                    .getSelectedValue();
0946:                            if (page != null) {
0947:                                setCurrentPage(page, list);
0948:                                if (getCurrentPage() != page) {
0949:                                    list.setSelectedValue(getCurrentPage(),
0950:                                            true);
0951:                                }
0952:                            } else {
0953:                                list.setSelectedIndex(e.getLastIndex());
0954:                            }
0955:                        }
0956:                    }
0957:                });
0958:                list.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 10));
0959:
0960:                _pageList.addListDataListener(new ListDataListener() {
0961:                    public void intervalAdded(ListDataEvent e) {
0962:                        for (int i = e.getIndex0(); i <= e.getIndex1(); i++) {
0963:                            AbstractDialogPage optionsPanel = _pageList
0964:                                    .getPage(i);
0965:                            listModel.add(i, optionsPanel);
0966:                        }
0967:                    }
0968:
0969:                    public void intervalRemoved(ListDataEvent e) {
0970:                        for (int i = e.getIndex1(); i >= e.getIndex0(); i--) {
0971:                            listModel.remove(i);
0972:                        }
0973:                    }
0974:
0975:                    public void contentsChanged(ListDataEvent e) {
0976:                        if (e.getIndex0() == -1
0977:                                && e.getIndex1() == -1
0978:                                && e.getType() == ListDataEvent.CONTENTS_CHANGED) {
0979:                            if (_pageList.getCurrentPage() != null) {
0980:                                int index = _pageList
0981:                                        .getPageIndexByFullTitle(_pageList
0982:                                                .getCurrentPage().getTitle());
0983:                                list.setSelectedIndex(index);
0984:                            }
0985:                        }
0986:                    }
0987:                });
0988:
0989:                JComponent indexPanel = new JPanel(new BorderLayout(4, 4));
0990:                indexPanel.add(new JideScrollPane(list), BorderLayout.CENTER);
0991:                indexPanel.setOpaque(false);
0992:                return indexPanel;
0993:            }
0994:
0995:            /**
0996:             * Creates list that is used in LIST_STYLE dialog's index panel. Below is the code we used.
0997:             * If you just want to have a different cell renderer, you can just call
0998:             * {@link #setListCellRenderer(javax.swing.ListCellRenderer)} to set a new one.
0999:             * <pre><code>
1000:             * JList list = new JList(listModel);
1001:             * list.setCellRenderer(createListCellRenderer());
1002:             * return list;
1003:             * </code></pre>
1004:             *
1005:             * @param listModel
1006:             * @return list.
1007:             */
1008:            protected JList createList(DefaultListModel listModel) {
1009:                JList list = new JList(listModel);
1010:                list.setCellRenderer(createListCellRenderer());
1011:                list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
1012:                return list;
1013:            }
1014:
1015:            /**
1016:             * Creates the panel that contains several icons. Each icon represents for a page. This is only used for ICON_STYLE.
1017:             *
1018:             * @return a panel that contains several icons.
1019:             */
1020:            protected JComponent createIconPanel() {
1021:                final ButtonPanel buttonsPanel = createIconButtonPanel();
1022:                buttonsPanel.setGroupGap(0);
1023:                buttonsPanel.setButtonGap(0);
1024:
1025:                final ButtonGroup group = new ButtonGroup();
1026:                for (int i = 0; i < _pageList.getPageCount(); i++) {
1027:                    AbstractDialogPage optionsPanel = _pageList.getPage(i);
1028:                    final JideButton button = createIconButton(optionsPanel
1029:                            .getTitle(), optionsPanel.getIcon());
1030:                    button.setToolTipText(optionsPanel.getDescription());
1031:                    button.setEnabled(optionsPanel.isPageEnabled());
1032:                    button.addActionListener(new AbstractAction() {
1033:                        public void actionPerformed(ActionEvent e) {
1034:                            AbstractDialogPage currentPage = _pageList
1035:                                    .getPageByFullTitle(e.getActionCommand());
1036:                            setCurrentPage(currentPage, buttonsPanel);
1037:                            if (getCurrentPage() == currentPage) {
1038:                                group.setSelected(button.getModel(), true);
1039:                            }
1040:                        }
1041:                    });
1042:                    optionsPanel
1043:                            .addPropertyChangeListener(new PropertyChangeListener() {
1044:                                public void propertyChange(
1045:                                        PropertyChangeEvent evt) {
1046:                                    if (AbstractDialogPage.PROPERTY_PAGE_ENABLED
1047:                                            .equals(evt.getPropertyName())) {
1048:                                        button.setEnabled(Boolean.TRUE
1049:                                                .equals(evt.getNewValue()));
1050:                                    } else if (AbstractDialogPage.ICON_PROPERTY
1051:                                            .equals(evt.getPropertyName())) {
1052:                                        button
1053:                                                .setIcon((Icon) evt
1054:                                                        .getNewValue());
1055:                                    } else if (AbstractDialogPage.TITLE_PROPERTY
1056:                                            .equals(evt.getPropertyName())) {
1057:                                        button.setText((String) evt
1058:                                                .getNewValue());
1059:                                    } else if (AbstractDialogPage.DESCRIPTION_PROPERTY
1060:                                            .equals(evt.getPropertyName())) {
1061:                                        button.setToolTipText((String) evt
1062:                                                .getNewValue());
1063:                                    }
1064:                                }
1065:                            });
1066:                    buttonsPanel.addButton(button);
1067:                    group.add(button);
1068:                    if (_pageList.getPageCount() > 0) {
1069:                        if (getInitialPageTitle() != null
1070:                                && getInitialPageTitle().equals(
1071:                                        optionsPanel.getTitle())) {
1072:                            group.setSelected(button.getModel(), true);
1073:                        } else if (getInitialPageTitle() == null && i == 0) {
1074:                            group.setSelected(button.getModel(), true);
1075:                        }
1076:                    }
1077:                }
1078:
1079:                buttonsPanel.setOpaque(false);
1080:                buttonsPanel.setBorder(BorderFactory.createEmptyBorder(10, 10,
1081:                        10, 10));
1082:
1083:                final JScrollPane pane = new JScrollPane(buttonsPanel) {
1084:                    @Override
1085:                    public Dimension getPreferredSize() {
1086:                        if (buttonsPanel.getAlignment() == SwingConstants.TOP
1087:                                || buttonsPanel.getAlignment() == SwingConstants.BOTTOM)
1088:                            return new Dimension(
1089:                                    buttonsPanel.getPreferredSize().width
1090:                                            + getVerticalScrollBar()
1091:                                                    .getPreferredSize().width,
1092:                                    5);
1093:                        else
1094:                            return new Dimension(5, buttonsPanel
1095:                                    .getPreferredSize().height
1096:                                    + getHorizontalScrollBar()
1097:                                            .getPreferredSize().height);
1098:                    }
1099:
1100:                    @Override
1101:                    public Dimension getMinimumSize() {
1102:                        return getPreferredSize();
1103:                    }
1104:                };
1105:
1106:                if (buttonsPanel.getAlignment() == SwingConstants.TOP
1107:                        || buttonsPanel.getAlignment() == SwingConstants.BOTTOM)
1108:                    pane
1109:                            .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
1110:                else
1111:                    pane
1112:                            .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
1113:
1114:                buttonsPanel.setOpaque(false);
1115:
1116:                _pageList.addListDataListener(new ListDataListener() {
1117:                    public void intervalAdded(ListDataEvent e) {
1118:                        for (int i = e.getIndex0(); i <= e.getIndex1(); i++) {
1119:                            addPage(i, group, buttonsPanel);
1120:                        }
1121:                        buttonsPanel.invalidate();
1122:                        buttonsPanel.doLayout();
1123:                    }
1124:
1125:                    public void intervalRemoved(ListDataEvent e) {
1126:                        for (int i = e.getIndex1(); i >= e.getIndex0(); i--) {
1127:                            AbstractButton button = (AbstractButton) buttonsPanel
1128:                                    .getComponent(i);
1129:                            buttonsPanel.remove(button);
1130:                            group.remove(button);
1131:                        }
1132:                        buttonsPanel.invalidate();
1133:                        buttonsPanel.doLayout();
1134:                    }
1135:
1136:                    public void contentsChanged(ListDataEvent e) {
1137:                        if (e.getIndex0() == -1
1138:                                && e.getIndex1() == -1
1139:                                && e.getType() == ListDataEvent.CONTENTS_CHANGED) {
1140:                            AbstractButton button = (AbstractButton) buttonsPanel
1141:                                    .getButtonByName(_pageList.getCurrentPage()
1142:                                            .getTitle());
1143:                            if (button != null) {
1144:                                group.setSelected(button.getModel(), true);
1145:                            }
1146:                        }
1147:                    }
1148:                });
1149:
1150:                pane.getViewport().setOpaque(false);
1151:                return pane;
1152:            }
1153:
1154:            /**
1155:             * Creates the ButtonPanel used by IconPanel. By default, we create it using <code>new ButtonPanel(SwingConstants.TOP, ButtonPanel.SAME_SIZE)</code>.
1156:             *
1157:             * @return the ButtonPanel.
1158:             */
1159:            protected ButtonPanel createIconButtonPanel() {
1160:                return new ScrollableButtonPanel(SwingConstants.TOP,
1161:                        ButtonPanel.SAME_SIZE);
1162:            }
1163:
1164:            private static class ScrollableButtonPanel extends ButtonPanel
1165:                    implements  Scrollable {
1166:
1167:                public ScrollableButtonPanel() {
1168:                }
1169:
1170:                public ScrollableButtonPanel(int alignment) {
1171:                    super (alignment);
1172:                }
1173:
1174:                public ScrollableButtonPanel(int alignment, int sizeContraint) {
1175:                    super (alignment, sizeContraint);
1176:                }
1177:
1178:                public Dimension getPreferredScrollableViewportSize() {
1179:                    return getPreferredSize();
1180:                }
1181:
1182:                public int getScrollableUnitIncrement(Rectangle visibleRect,
1183:                        int orientation, int direction) {
1184:                    if (getComponentCount() > 0) {
1185:                        Component c = getComponent(0);
1186:                        if (orientation == SwingConstants.HORIZONTAL)
1187:                            return c.getWidth();
1188:                        else
1189:                            return c.getHeight();
1190:                    }
1191:                    return 50;
1192:                }
1193:
1194:                public int getScrollableBlockIncrement(Rectangle visibleRect,
1195:                        int orientation, int direction) {
1196:                    if (orientation == SwingConstants.HORIZONTAL)
1197:                        return visibleRect.width;
1198:                    else
1199:                        return visibleRect.width;
1200:                }
1201:
1202:                public boolean getScrollableTracksViewportWidth() {
1203:                    return false;
1204:                }
1205:
1206:                public boolean getScrollableTracksViewportHeight() {
1207:                    return false;
1208:                }
1209:            }
1210:
1211:            private JideButton addPage(int i, final ButtonGroup group,
1212:                    final ButtonPanel buttonsPanel) {
1213:                AbstractDialogPage optionsPanel = _pageList.getPage(i);
1214:                final JideButton button = createIconButton(optionsPanel
1215:                        .getTitle(), optionsPanel.getIcon());
1216:                button.addActionListener(new AbstractAction(optionsPanel
1217:                        .getTitle(), optionsPanel.getIcon()) {
1218:                    public void actionPerformed(ActionEvent e) {
1219:                        group.setSelected(button.getModel(), true);
1220:                        setCurrentPage(_pageList.getPageByFullTitle(e
1221:                                .getActionCommand()), buttonsPanel);
1222:                    }
1223:                });
1224:                buttonsPanel.addButton(button, i);
1225:                group.add(button);
1226:                return button;
1227:            }
1228:
1229:            /**
1230:             * Creates the button for each icon.
1231:             *
1232:             * @param title
1233:             * @param icon
1234:             * @return the button
1235:             */
1236:            protected JideButton createIconButton(String title, Icon icon) {
1237:                final JideButton button = new JideButton(title, icon);
1238:                button.setName(title);
1239:                button.setHorizontalAlignment(SwingConstants.CENTER);
1240:                button.setVerticalTextPosition(SwingConstants.BOTTOM);
1241:                button.setHorizontalTextPosition(SwingConstants.CENTER);
1242:                button.setRequestFocusEnabled(false);
1243:                button.setFocusable(false);
1244:                return button;
1245:            }
1246:
1247:            /**
1248:             * Gets the style of this dialog.
1249:             *
1250:             * @return the style. It can be TAB_STYLE, ICON_STYLE, LIST_STYLE or TREE_STYLE.
1251:             */
1252:            public int getStyle() {
1253:                return _style;
1254:            }
1255:
1256:            /**
1257:             * Sets the style of this dialog. This class doesn't support change style on fly.
1258:             * You can only change style before the dialog is set to visible.
1259:             *
1260:             * @param style It must be one of the following: TAB_STYLE, ICON_STYLE, LIST_STYLE or TREE_STYLE.
1261:             */
1262:            public void setStyle(int style) {
1263:                if (style == TAB_STYLE || style == LIST_STYLE
1264:                        || style == ICON_STYLE || style == TREE_STYLE) {
1265:                    _style = style;
1266:                } else {
1267:                    throw new IllegalArgumentException(
1268:                            "The value of style must be one of the following - TAB_STYLE, ICON_STYLE, LIST_STYLE or TREE_STYLE");
1269:                }
1270:            }
1271:
1272:            /**
1273:             * Gets the index panel.
1274:             *
1275:             * @return the index panel.
1276:             */
1277:            public JComponent getIndexPanel() {
1278:                return _indexPanel;
1279:            }
1280:
1281:            /**
1282:             * Gets the pages panel.
1283:             *
1284:             * @return the pages panel.
1285:             */
1286:            public JComponent getPagesPanel() {
1287:                return _pagesPanel;
1288:            }
1289:
1290:            /**
1291:             * Gets the cell renderer used by the tree. It's used only
1292:             * when the style is TREE_STYLE.
1293:             *
1294:             * @return the tree cell renderer.
1295:             */
1296:            protected TreeCellRenderer getTreeCellRenderer() {
1297:                return _treeCellRenderer;
1298:            }
1299:
1300:            /**
1301:             * Sets the tree cell renderer that will be used by JTree when the style is TREE_STYLE.
1302:             *
1303:             * @param treeCellRenderer
1304:             */
1305:            public void setTreeCellRenderer(TreeCellRenderer treeCellRenderer) {
1306:                _treeCellRenderer = treeCellRenderer;
1307:            }
1308:
1309:            /**
1310:             * Gets the cell renderer used by the list. It's used only
1311:             * when the style is LIST_STYLE.
1312:             *
1313:             * @return the list cell renderer.
1314:             */
1315:            protected ListCellRenderer getListCellRenderer() {
1316:                return _listCellRenderer;
1317:            }
1318:
1319:            /**
1320:             * Sets the list cell renderer that will be used by JList when the style is LIST_STYLE.
1321:             *
1322:             * @param listCellRenderer
1323:             */
1324:            public void setListCellRenderer(ListCellRenderer listCellRenderer) {
1325:                _listCellRenderer = listCellRenderer;
1326:            }
1327:
1328:            /**
1329:             * Creates a list cell renderer used by list in LIST_STYLE dialog's index panel.
1330:             *
1331:             * @return the list cell renderer.
1332:             */
1333:            protected ListCellRenderer createListCellRenderer() {
1334:                if (getListCellRenderer() == null) {
1335:                    setListCellRenderer(new DialogPageListCellRenderer());
1336:                }
1337:                return getListCellRenderer();
1338:            }
1339:
1340:            /**
1341:             * Creates the tree cell renderer used by tree in TREE_STYLE dialog's index panel.
1342:             *
1343:             * @return the tree cell renderer.
1344:             */
1345:            protected TreeCellRenderer createTreeCellRenderer() {
1346:                if (getTreeCellRenderer() == null) {
1347:                    setTreeCellRenderer(new DialogPageTreeCellRenderer());
1348:                }
1349:                return getTreeCellRenderer();
1350:            }
1351:
1352:            /**
1353:             * Gets the initial page title. Initial page is the page that will be selected when the dialog
1354:             * is just opened. Please note the title is the full title. In most case it's just the title of the page.
1355:             * Only in TREE_STYLE, it should be a list of titles that concats with '.'.
1356:             *
1357:             * @return the initial page title.
1358:             */
1359:            public String getInitialPageTitle() {
1360:                return _initialPageTitle;
1361:            }
1362:
1363:            /**
1364:             * Sets the initial page title. Initial page is the page that will be selected when the dialog.
1365:             *
1366:             * @param initialPageTitle
1367:             */
1368:            public void setInitialPageTitle(String initialPageTitle) {
1369:                _initialPageTitle = initialPageTitle;
1370:            }
1371:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.