Source Code Cross Referenced for GUIUtilities.java in  » Database-Client » executequery » org » executequery » 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 » Database Client » executequery » org.executequery 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * GUIUtilities.java
0003:         *
0004:         * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis
0005:         *
0006:         * This program is free software; you can redistribute it and/or
0007:         * modify it under the terms of the GNU General Public License
0008:         * as published by the Free Software Foundation; either version 2
0009:         * of the License, or any later version.
0010:         *
0011:         * This program is distributed in the hope that it will be useful,
0012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014:         * GNU General Public License for more details.
0015:         *
0016:         * You should have received a copy of the GNU General Public License
0017:         * along with this program; if not, write to the Free Software
0018:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
0019:         *
0020:         */
0021:
0022:        package org.executequery;
0023:
0024:        import java.awt.BorderLayout;
0025:        import java.awt.Color;
0026:        import java.awt.Component;
0027:        import java.awt.Dimension;
0028:        import java.awt.Frame;
0029:        import java.awt.Point;
0030:        import java.io.File;
0031:
0032:        import java.io.PrintStream;
0033:        import java.util.ArrayList;
0034:        import java.util.HashMap;
0035:        import java.util.List;
0036:        import java.util.Map;
0037:        import javax.swing.ActionMap;
0038:        import javax.swing.Icon;
0039:        import javax.swing.ImageIcon;
0040:        import javax.swing.InputMap;
0041:        import javax.swing.JComponent;
0042:        import javax.swing.JDialog;
0043:        import javax.swing.JFrame;
0044:        import javax.swing.JLayeredPane;
0045:        import javax.swing.JMenuBar;
0046:        import javax.swing.JOptionPane;
0047:        import javax.swing.JPanel;
0048:        import javax.swing.SwingConstants;
0049:        import javax.swing.SwingUtilities;
0050:        import javax.swing.UIManager;
0051:        import org.executequery.components.StatusBarPanel;
0052:        import org.executequery.gui.MainMenu;
0053:        import org.executequery.gui.editor.QueryEditor;
0054:        import org.executequery.gui.text.TextEditorContainer;
0055:        import org.underworldlabs.swing.toolbar.ToolBarProperties;
0056:        import org.executequery.toolbars.ToolBarManager;
0057:        import org.underworldlabs.swing.actions.BaseActionCommand;
0058:        import org.executequery.actions.editcommands.*;
0059:        import org.underworldlabs.swing.actions.ActionBuilder;
0060:        import org.executequery.base.DesktopMediator;
0061:        import org.executequery.base.DockedTabListener;
0062:        import org.executequery.base.DockedTabView;
0063:        import org.executequery.base.TabComponent;
0064:        import org.underworldlabs.swing.ExceptionErrorDialog;
0065:        import org.underworldlabs.swing.util.IconUtilities;
0066:        import org.executequery.util.SystemResources;
0067:        import org.executequery.gui.SaveFunction;
0068:        import org.executequery.print.PrintFunction;
0069:        import org.executequery.gui.text.TextEditor;
0070:        import org.executequery.databasemediators.DatabaseConnection;
0071:        import org.executequery.gui.BaseDialog;
0072:        import org.executequery.gui.MultiplePanelInstance;
0073:        import org.executequery.gui.OpenComponentRegister;
0074:        import org.executequery.gui.PanelCacheObject;
0075:        import org.executequery.gui.SystemOutputPanel;
0076:        import org.executequery.gui.SystemPropertiesDockedTab;
0077:        import org.executequery.gui.UndoableComponent;
0078:        import org.underworldlabs.jdbc.DataSourceException;
0079:        import org.executequery.gui.browser.ConnectionsTreePanel;
0080:        import org.executequery.gui.drivers.DriversTreePanel;
0081:        import org.executequery.gui.editor.QueryEditorSettings;
0082:        import org.executequery.gui.keywords.KeywordsDockedPanel;
0083:        import org.executequery.gui.sqlstates.SQLStateCodesDockedPanel;
0084:        import org.executequery.util.Log;
0085:        import org.executequery.util.SystemErrLogger;
0086:        import org.underworldlabs.swing.GUIUtils;
0087:        import org.underworldlabs.util.SystemProperties;
0088:
0089:        /* ----------------------------------------------------------
0090:         * CVS NOTE: Changes to the CVS repository prior to the 
0091:         *           release of version 3.0.0beta1 has meant a 
0092:         *           resetting of CVS revision numbers.
0093:         * ----------------------------------------------------------
0094:         */
0095:
0096:        /** 
0097:         * <p>The GUIUtilities is the primary 'controller' class for all
0098:         * Execute Query GUI components. It provides access to resources
0099:         * in addition to many utility helper methods such as displaying
0100:         * simple dialogs and updating menus.
0101:         *
0102:         * <p>This class will hold a reference to all primary components
0103:         * for access by other classes. This includes those currently in-focus
0104:         * components such as the Query Editor or other text components.
0105:         *
0106:         * <p>All internal frames are added (and closed via relevant 'Close'
0107:         * buttons as may apply) from here.
0108:         *
0109:         * @author   Takis Diakoumis
0110:         * @version  $Revision: 1.17 $
0111:         * @date     $Date: 2006/09/26 13:15:31 $
0112:         */
0113:        public class GUIUtilities {
0114:
0115:            /** The tool bar manager instance */
0116:            private static ToolBarManager toolBar;
0117:
0118:            /** The window status bar */
0119:            private static StatusBarPanel statusBar;
0120:
0121:            /** The window menu bar */
0122:            private static MainMenu menuBar;
0123:
0124:            /** The currently installed look and feel */
0125:            private static int lookAndFeel;
0126:
0127:            /** The maximum allowable open query editors */
0128:            private static int maxOpenEditors;
0129:
0130:            /** The open dialog in focus */
0131:            private static JDialog focusedDialog;
0132:
0133:            /** register for all open components - dialogs, tabs etc. */
0134:            private static OpenComponentRegister register;
0135:
0136:            /** the application frame */
0137:            private static JFrame frame;
0138:
0139:            /** panel and desktop mediator object */
0140:            private static DesktopMediator desktopMediator;
0141:
0142:            /** default icon for open tabs - when none is provided */
0143:            private static Icon defaultIcon;
0144:
0145:            /** the layout properties controller */
0146:            private static UserLayoutProperties layoutProperties;
0147:
0148:            /** docked panel cache of non-central pane tabs */
0149:            private static Map<String, JPanel> dockedTabComponents;
0150:
0151:            /** the resource path to the image directory */
0152:            public static final String IMAGE_PATH = "/org/executequery/images/";
0153:
0154:            /** the resource path to the icon directory */
0155:            public static final String ICON_PATH = "/org/executequery/icons/";
0156:
0157:            /** System.err logger */
0158:            private static SystemErrLogger errLogger;
0159:
0160:            /** System.out logger */
0161:            private static SystemErrLogger outLogger;
0162:
0163:            /** private constructor */
0164:            private GUIUtilities() {
0165:            }
0166:
0167:            public static void initDesktop(JFrame aFrame) {
0168:                frame = aFrame;
0169:                // create the mediator object
0170:                desktopMediator = new DesktopMediator(frame);
0171:
0172:                // initialise and add the status bar
0173:                statusBar = new StatusBarPanel(" Not Connected",
0174:                        Constants.EMPTY);
0175:                statusBar.setFourthLabelText("JDK"
0176:                        + System.getProperty("java.version").substring(0, 5),
0177:                        SwingConstants.CENTER);
0178:
0179:                frame.add(statusBar, BorderLayout.SOUTH);
0180:
0181:                // init the layout properties
0182:                layoutProperties = new UserLayoutProperties();
0183:            }
0184:
0185:            public static void initPanels() {
0186:                // init the open component register and set as a listener
0187:                register = new OpenComponentRegister();
0188:                desktopMediator.addDockedTabListener(register);
0189:
0190:                // setup the default docked tabs and their positions        
0191:                setDockedTabViews(false);
0192:
0193:                // add a query editor
0194:                addCentralPane(QueryEditor.TITLE, QueryEditor.FRAME_ICON,
0195:                        new QueryEditor(), null, false);
0196:
0197:                // divider locations
0198:                setDividerLocations();
0199:
0200:                // add the split pane divider listener
0201:                desktopMediator.addPropertyChangeListener(layoutProperties);
0202:                desktopMediator.addDockedTabDragListener(layoutProperties);
0203:                desktopMediator.addDockedTabListener(layoutProperties);
0204:
0205:                // select the first main panel
0206:                desktopMediator.setSelectedPane(SwingConstants.CENTER, 0);
0207:
0208:                //desktopMediator.resetPaneToPreferredSizes(SwingConstants.WEST, false);
0209:            }
0210:
0211:            /**
0212:             * Sets the divider locations to previously saved (or default) values.
0213:             */
0214:            protected static void setDividerLocations() {
0215:                String[] keys = DesktopMediator.DIVIDER_LOCATION_KEYS;
0216:                for (int i = 0; i < keys.length; i++) {
0217:                    String key = keys[i];
0218:                    int location = SystemProperties.getIntProperty("user", key);
0219:                    //Log.debug("key: "+key+" loc: "+location);
0220:                    if (location > 0) {
0221:                        desktopMediator.setSplitPaneDividerLocation(key,
0222:                                location);
0223:                    }
0224:                }
0225:            }
0226:
0227:            /**
0228:             * Removes the specified docked tab listener.
0229:             *
0230:             * @param the listener
0231:             */
0232:            public void removeDockedTabListener(DockedTabListener listener) {
0233:                desktopMediator.removeDockedTabListener(listener);
0234:            }
0235:
0236:            /**
0237:             * Adds the specified docked tab listener.
0238:             *
0239:             * @param the listener
0240:             */
0241:            public void addDockedTabListener(DockedTabListener listener) {
0242:                desktopMediator.addDockedTabListener(listener);
0243:            }
0244:
0245:            /**
0246:             * Sets the default icon to that specified.
0247:             *
0248:             * @param the icon to be set as the default
0249:             */
0250:            public static void setDefaultIcon(Icon icon) {
0251:                defaultIcon = icon;
0252:            }
0253:
0254:            /**
0255:             * Adds the specified component as a docked tab component
0256:             * in the specified position.
0257:             *
0258:             * @param the tab title
0259:             * @param the tab icon
0260:             * @param the component
0261:             * @param the tab's tool tip
0262:             */
0263:            public static void addCentralPane(String title, Icon icon,
0264:                    Component component, String tip, boolean selected) {
0265:                addDockedTab(title, icon, component, tip,
0266:                        SwingConstants.CENTER, selected);
0267:            }
0268:
0269:            /**
0270:             * Adds the specified component as a docked tab component
0271:             * in the specified position.
0272:             *
0273:             * @param the tab title
0274:             * @param the tab icon
0275:             * @param the component
0276:             * @param the tab's tool tip
0277:             */
0278:            public static void addCentralPane(String title, String icon,
0279:                    Component component, String tip, boolean selected) {
0280:                addDockedTab(title, loadIcon(icon, true), component, tip,
0281:                        SwingConstants.CENTER, selected);
0282:            }
0283:
0284:            /**
0285:             * Adds the specified component as a docked tab component
0286:             * in the specified position.
0287:             *
0288:             * @param the tab title
0289:             * @param the component
0290:             * @param the position
0291:             */
0292:            public static void addDockedTab(String title, Component component,
0293:                    int position, boolean selected) {
0294:                addDockedTab(title, null, component, null, position, selected);
0295:            }
0296:
0297:            /**
0298:             * Adds the specified component as a docked tab component
0299:             * in the specified position.
0300:             *
0301:             * @param the tab title
0302:             * @param the tab icon
0303:             * @param the component
0304:             * @param the position
0305:             */
0306:            public static void addDockedTab(String title, Icon icon,
0307:                    Component component, int position, boolean selected) {
0308:                addDockedTab(title, icon, component, null, position, selected);
0309:            }
0310:
0311:            /**
0312:             * Adds the specified component as a docked tab component
0313:             * in the specified position.
0314:             *
0315:             * @param the tab title
0316:             * @param the tab icon
0317:             * @param the component
0318:             * @param the tab's tool tip
0319:             * @param the position
0320:             */
0321:            public static void addDockedTab(String title, Icon icon,
0322:                    Component component, String tip, int position,
0323:                    boolean selected) {
0324:
0325:                // change the title if a save function
0326:                if (component instanceof  MultiplePanelInstance) {
0327:                    MultiplePanelInstance mpi = (MultiplePanelInstance) component;
0328:                    String _title = mpi.getDisplayName();
0329:                    if (_title.length() > 0) {
0330:                        title = _title;
0331:                        tip = _title;
0332:                    }
0333:                }
0334:
0335:                // if this is a main window component, add to cache
0336:                if (position == SwingConstants.CENTER) {
0337:                    register.addOpenPanel(title, component);
0338:                }
0339:
0340:                desktopMediator.addDockedTab(title, icon, component, tip,
0341:                        position, selected);
0342:                GUIUtils.scheduleGC();
0343:            }
0344:
0345:            /**
0346:             * Closed the specfied docked component with name at the specified position.
0347:             * 
0348:             * @param the name of the tab component
0349:             * @param the position
0350:             */
0351:            public static void closeDockedComponent(String name, int position) {
0352:                desktopMediator.closeTabComponent(name, position);
0353:            }
0354:
0355:            // -------------------------------------------------------
0356:
0357:            /** <p>Retrieves the parent frame of the application.
0358:             *
0359:             *  @return the parent frame
0360:             */
0361:            public static Frame getParentFrame() {
0362:                return frame;
0363:            }
0364:
0365:            /**
0366:             * Selects the next tab from the current selection.
0367:             */
0368:            public static void selectNextTab() {
0369:                desktopMediator.selectNextTab();
0370:            }
0371:
0372:            /**
0373:             * Selects the previous tab from the current selection.
0374:             */
0375:            public static void selectPreviousTab() {
0376:                desktopMediator.selectPreviousTab();
0377:            }
0378:
0379:            public static void setMaximumOpenEditors(int _maxOpenEditors) {
0380:                maxOpenEditors = _maxOpenEditors;
0381:            }
0382:
0383:            /** <p>Builds and sets the main tool bar. */
0384:            public static void createToolBar() {
0385:                toolBar = new ToolBarManager();
0386:                frame.add(toolBar.getToolBarBasePanel(), BorderLayout.NORTH);
0387:            }
0388:
0389:            /**
0390:             * <p>Determines whether upon selection of the print
0391:             *  action, the currently open and in focus frame does
0392:             *  have a printable area - is an instance of a <code>
0393:             *  BrowserPanel</code> or <code>TextEditor</code>.
0394:             * 
0395:             * @return whether printing may be performed from the
0396:             *          open frame
0397:             */
0398:            public static boolean canPrint() {
0399:
0400:                // check the dialog in focus first
0401:                if (focusedDialog != null) {
0402:
0403:                    if (focusedDialog instanceof  PrintFunction) {
0404:                        return ((PrintFunction) focusedDialog).canPrint();
0405:                    }
0406:
0407:                }
0408:
0409:                Object object = getSelectedCentralPane();
0410:                if (!(object instanceof  PrintFunction)) {
0411:                    return false;
0412:                }
0413:
0414:                PrintFunction printFunction = (PrintFunction) object;
0415:                return printFunction.canPrint();
0416:
0417:            }
0418:
0419:            /** <p>Returns the <code>PrintFunction</code> object
0420:             *  from the currently in-focus frame. If the in-focus
0421:             *  frame is not an instance of <code>PrintFunction</code>,
0422:             *  <code>null</code> is returned.
0423:             *
0424:             *  @return the in-focus <code>PrintFunction</code> object
0425:             */
0426:            public static PrintFunction getPrintableInFocus() {
0427:                // check the open dialogs first
0428:                if (register.getOpenDialogCount() > 0) {
0429:                    List<JDialog> list = register.getOpenDialogs();
0430:                    for (int i = 0, k = list.size(); i < k; i++) {
0431:                        JDialog dialog = list.get(i);
0432:                        if (!dialog.isModal() || dialog.isFocused()) {
0433:                            if (dialog instanceof  BaseDialog) {
0434:                                // check the content panel
0435:                                JPanel panel = ((BaseDialog) dialog)
0436:                                        .getConentPanel();
0437:                                if (panel instanceof  PrintFunction) {
0438:                                    return (PrintFunction) panel;
0439:                                }
0440:                            } else if (dialog instanceof  PrintFunction) {
0441:                                return (PrintFunction) dialog;
0442:                            }
0443:                        }
0444:                    }
0445:                }
0446:
0447:                // check the open panels register
0448:                if (register.getOpenPanelCount() > 0) {
0449:                    Component component = register.getSelectedComponent();
0450:                    //Log.debug("test print component: "+ component.getClass().getName());
0451:                    if (component instanceof  PrintFunction) {
0452:                        return (PrintFunction) component;
0453:                    }
0454:                }
0455:
0456:                return null;
0457:                /*
0458:                
0459:                 // check the dialog in focus first
0460:                 if (focusedDialog != null) {
0461:                
0462:                 if (focusedDialog instanceof PrintFunction) {
0463:                 return (PrintFunction)focusedDialog;
0464:                 }
0465:                
0466:                 } 
0467:                
0468:                 Object object = getSelectedCentralPane();
0469:                 if (object instanceof PrintFunction) {
0470:                 return (PrintFunction)object;
0471:                 }
0472:                 else {
0473:                 return null;
0474:                 }
0475:                 */
0476:            }
0477:
0478:            /**
0479:             * Sets the selected tab in the central pane as the tab
0480:             * component with the specified name.
0481:             *
0482:             * @param the name of the tab to be selected in the central pane
0483:             */
0484:            public static void setSelectedCentralPane(String name) {
0485:                desktopMediator.setSelectedPane(SwingConstants.CENTER, name);
0486:            }
0487:
0488:            public static JPanel getCentralPane(String name) {
0489:                return (JPanel) register.getOpenPanel(name);
0490:                /*
0491:                TabComponent tabComponent = 
0492:                        desktopMediator.getTabComponent(SwingConstants.CENTER, name);
0493:                if (tabComponent != null) {
0494:                    return ((JPanel)tabComponent.getComponent());
0495:                }
0496:                 */
0497:            }
0498:
0499:            /**
0500:             * Returns the tab component with the specified name at
0501:             * the specified position within the tab structure.
0502:             *
0503:             * @param the position (SwingContants)
0504:             * @name the panel name/title
0505:             */
0506:            public static TabComponent getTabComponent(int position, String name) {
0507:                return desktopMediator.getTabComponent(position, name);
0508:            }
0509:
0510:            public static JPanel getSelectedCentralPane(String name) {
0511:                return (JPanel) register.getSelectedComponent();
0512:                /*
0513:                TabComponent tabComponent = 
0514:                        desktopMediator.getSelectedComponent(SwingConstants.CENTER);
0515:                //JInternalFrame frame = desktop.getSelectedFrame();
0516:                if (tabComponent != null) {
0517:                    // if its a name check
0518:                    if (name != null) {
0519:                        if (tabComponent.getTitle().startsWith(name)) {
0520:                            return (JPanel)tabComponent.getComponent();
0521:                            //return ((BaseInternalFrame)frame).getFrameContents();
0522:                        }
0523:                    }
0524:                    return (JPanel)tabComponent.getComponent();            
0525:                }
0526:                return null;
0527:                 */
0528:            }
0529:
0530:            /**
0531:             * Registers the specified dialog with the cache.
0532:             *
0533:             * @param the dialog to be registered
0534:             */
0535:            public static void registerDialog(JDialog dialog) {
0536:                register.addDialog(dialog);
0537:            }
0538:
0539:            /**
0540:             * Registers the specified dialog with the cache.
0541:             *
0542:             * @param the dialog to be registered
0543:             */
0544:            public static void deregisterDialog(JDialog dialog) {
0545:                register.removeDialog(dialog);
0546:            }
0547:
0548:            public static void setFocusedDialog(JDialog _focusedDialog) {
0549:                focusedDialog = _focusedDialog;
0550:            }
0551:
0552:            public static void removeFocusedDialog(JDialog _focusedDialog) {
0553:                if (focusedDialog == _focusedDialog) {
0554:                    focusedDialog = null;
0555:                }
0556:            }
0557:
0558:            /**
0559:             * Retrieves the <code>TextEditor</code> instance
0560:             * that currently has focus or NULL if none exists.
0561:             * 
0562:             * @return that instance of <code>TeTextEditorcode>
0563:             */
0564:            public static TextEditor getTextEditorInFocus() {
0565:                // check the open dialogs first
0566:                if (register.getOpenDialogCount() > 0) {
0567:                    List<JDialog> list = register.getOpenDialogs();
0568:                    for (int i = 0, k = list.size(); i < k; i++) {
0569:                        JDialog dialog = list.get(i);
0570:                        // check if its focused or not modal
0571:                        if (!dialog.isModal() || dialog.isFocused()) {
0572:                            // check if its a base dialog
0573:                            if (dialog instanceof  BaseDialog) {
0574:                                // check the content panel
0575:                                JPanel panel = ((BaseDialog) dialog)
0576:                                        .getConentPanel();
0577:                                if (panel instanceof  TextEditor) {
0578:                                    return (TextEditor) panel;
0579:                                } else if (panel instanceof  TextEditorContainer) {
0580:                                    return ((TextEditorContainer) panel)
0581:                                            .getTextEditor();
0582:                                }
0583:                            } else if (dialog instanceof  TextEditor) {
0584:                                return (TextEditor) dialog;
0585:                            } else if (dialog instanceof  TextEditorContainer) {
0586:                                return ((TextEditorContainer) dialog)
0587:                                        .getTextEditor();
0588:                            }
0589:                        }
0590:                    }
0591:                }
0592:
0593:                // check the open panels register
0594:                if (register.getOpenPanelCount() > 0) {
0595:                    Component component = register.getSelectedComponent();
0596:                    if (component instanceof  TextEditor) {
0597:                        return (TextEditor) component;
0598:                    } else if (component instanceof  TextEditorContainer) {
0599:                        return ((TextEditorContainer) component)
0600:                                .getTextEditor();
0601:                    }
0602:
0603:                }
0604:                return null;
0605:            }
0606:
0607:            /** <p>Retrieves the contents of the in-focus
0608:             *  internal frame as a <code>JPanel</code>.
0609:             *
0610:             *  @return the panel in focus
0611:             */
0612:            public static JPanel getSelectedCentralPane() {
0613:                return getSelectedCentralPane(null);
0614:            }
0615:
0616:            /** <p>Retrieves the <code>SaveFunction</code> in focus.
0617:             *
0618:             *  @return the <code>SaveFunction</code> in focus
0619:             */
0620:            public static SaveFunction getSaveFunctionInFocus() {
0621:                // check the open dialogs first
0622:                if (register.getOpenDialogCount() > 0) {
0623:                    List<JDialog> list = register.getOpenDialogs();
0624:                    for (int i = 0, k = list.size(); i < k; i++) {
0625:                        JDialog dialog = list.get(i);
0626:                        // check if its focused
0627:                        // TODO: try a focus lost on the dialog ?????????????????
0628:                        if (!dialog.isModal() || dialog.isFocused()) {
0629:                            // check if its a base dialog
0630:                            if (dialog instanceof  BaseDialog) {
0631:                                // check the content panel
0632:                                JPanel panel = ((BaseDialog) dialog)
0633:                                        .getConentPanel();
0634:                                if (panel instanceof  SaveFunction) {
0635:                                    return (SaveFunction) panel;
0636:                                }
0637:                            } else if (dialog instanceof  SaveFunction) {
0638:                                return (SaveFunction) dialog;
0639:                            }
0640:                        }
0641:                    }
0642:                }
0643:
0644:                // check the open panels register
0645:                if (register.getOpenPanelCount() > 0) {
0646:                    Component component = register.getSelectedComponent();
0647:                    if (component instanceof  SaveFunction) {
0648:                        return (SaveFunction) component;
0649:                    }
0650:                }
0651:                return null;
0652:            }
0653:
0654:            public static UndoableComponent getUndoableInFocus() {
0655:                // check the open dialogs first
0656:                if (register.getOpenDialogCount() > 0) {
0657:                    List<JDialog> list = register.getOpenDialogs();
0658:                    for (int i = 0, k = list.size(); i < k; i++) {
0659:                        JDialog dialog = list.get(i);
0660:                        // check if its focused
0661:                        if (dialog.isFocused()) {
0662:                            if (dialog instanceof  UndoableComponent) {
0663:                                return (UndoableComponent) dialog;
0664:                            }
0665:                        }
0666:                    }
0667:                }
0668:
0669:                // check the open panels register
0670:                if (register.getOpenPanelCount() > 0) {
0671:                    Component component = register.getSelectedComponent();
0672:                    if (component instanceof  UndoableComponent) {
0673:                        return (UndoableComponent) component;
0674:                    }
0675:                }
0676:                return null;
0677:                /*
0678:                // check the dialog in focus first
0679:                if (focusedDialog != null) {
0680:
0681:                    if (focusedDialog instanceof UndoableComponent) {
0682:                        return (UndoableComponent)focusedDialog;
0683:                    }
0684:
0685:                } 
0686:                else {
0687:                    JPanel panel = getSelectedCentralPane();
0688:
0689:                    if (panel instanceof UndoableComponent) {
0690:                        return (UndoableComponent)panel;
0691:                    } else {
0692:                        return null;
0693:                    }
0694:
0695:                } 
0696:                return null;
0697:                 */
0698:            }
0699:
0700:            public static void registerUndoRedoComponent(
0701:                    UndoableComponent undoable) {
0702:                BaseActionCommand undo = (BaseActionCommand) ActionBuilder
0703:                        .get("undo-command");
0704:                BaseActionCommand redo = (BaseActionCommand) ActionBuilder
0705:                        .get("redo-command");
0706:
0707:                if (undoable == null) {
0708:                    undo.setEnabled(false);
0709:                    redo.setEnabled(false);
0710:                }
0711:
0712:                UndoCommand _undo = (UndoCommand) undo.getCommand();
0713:                RedoCommand _redo = (RedoCommand) redo.getCommand();
0714:
0715:                _undo.setUndoableComponent(undoable);
0716:                _redo.setUndoableComponent(undoable);
0717:            }
0718:
0719:            /** <p>Retrieves the applications <code>InputMap</code>.
0720:             *
0721:             *  @return the <code>InputMap</code>
0722:             */
0723:            public static InputMap getInputMap(int condition) {
0724:                //        return desktop.getDesktopInputMap(condition);
0725:
0726:                // TODO: INPUT MAP
0727:                return desktopMediator.getInputMap(condition);
0728:                //return desktop.getInputMap(condition);
0729:            }
0730:
0731:            /** <p>Retrieves the applications <code>ActionMap</code>.
0732:             *
0733:             *  @return the <code>ActionMap</code>
0734:             */
0735:            public static ActionMap getActionMap() {
0736:                // TODO: ACTION MAP
0737:                return desktopMediator.getActionMap();
0738:            }
0739:
0740:            /** <p>Registers the main menu bar with this class.
0741:             *
0742:             *  @param the menu bar
0743:             */
0744:            public static void registerMenuBar(JMenuBar menu) {
0745:                menuBar = (MainMenu) menu;
0746:            }
0747:
0748:            /** 
0749:             * Initialises and starts the system logger.
0750:             * The logger's stream is also registered for
0751:             * <code>System.err</code> and <code>System.out</code>.
0752:             */
0753:            public static void startLogger() {
0754:                // init the cache
0755:                if (dockedTabComponents == null) {
0756:                    dockedTabComponents = new HashMap<String, JPanel>();
0757:                }
0758:                // add the output panel to the cache
0759:                SystemOutputPanel panel = new SystemOutputPanel();
0760:                dockedTabComponents.put(SystemOutputPanel.PROPERTY_KEY, panel);
0761:
0762:                // set system error stream to the output panel
0763:                boolean logToConsole = SystemProperties.getBooleanProperty(
0764:                        "user", "system.log.err");
0765:                errLogger = new SystemErrLogger(logToConsole,
0766:                        SystemErrLogger.SYSTEM_ERR);
0767:                PrintStream errStream = new PrintStream(errLogger, true);
0768:                System.setErr(errStream);
0769:
0770:                // set system error stream to the output panel
0771:                logToConsole = SystemProperties.getBooleanProperty("user",
0772:                        "system.log.out");
0773:                outLogger = new SystemErrLogger(logToConsole,
0774:                        SystemErrLogger.SYSTEM_OUT);
0775:                PrintStream outStream = new PrintStream(outLogger, true);
0776:                System.setOut(outStream);
0777:            }
0778:
0779:            /** <p>Calculates and returns the centered position
0780:             *  of a dialog with the specified size to be added
0781:             *  to the desktop area - ie. taking into account the
0782:             *  size and location of all docked panels.
0783:             *
0784:             *  @param the size of the dialog to be added as a
0785:             *         <code>Dimension</code> object
0786:             *  @return the <code>Point</code> at which to add the dialog
0787:             */
0788:            public static Point getLocationForDialog(Dimension dialogDim) {
0789:                return GUIUtils.getLocationForDialog(frame, dialogDim);
0790:            }
0791:
0792:            /** 
0793:             * Propagates the call to GUIUtils and schedules 
0794:             * the garbage collector to run.
0795:             */
0796:            public static void scheduleGC() {
0797:                GUIUtils.scheduleGC();
0798:            }
0799:
0800:            /**
0801:             * Returns whether the frame's glass pane is visible or not.
0802:             *
0803:             * @return true | false
0804:             */
0805:            public static boolean isGlassPaneVisible() {
0806:                return frame.getRootPane().getGlassPane().isVisible();
0807:            }
0808:
0809:            /**
0810:             * Shows/hides the frame's glass pane as specified.
0811:             *
0812:             * @param visible - true | false
0813:             */
0814:            public static void setGlassPaneVisible(final boolean visible) {
0815:                GUIUtils.invokeLater(new Runnable() {
0816:                    public void run() {
0817:                        if (isGlassPaneVisible() == visible) {
0818:                            return;
0819:                        }
0820:                        frame.getRootPane().getGlassPane().setVisible(visible);
0821:                    }
0822:                });
0823:            }
0824:
0825:            /** 
0826:             * Sets the application cursor to the system normal cursor 
0827:             */
0828:            public static void showNormalCursor() {
0829:                GUIUtils.invokeAndWait(new Runnable() {
0830:                    public void run() {
0831:                        GUIUtils.showNormalCursor(frame);
0832:                    }
0833:                });
0834:                //GUIUtils.showNormalCursor(frame);
0835:            }
0836:
0837:            /** 
0838:             * Sets the application cursor to the system wait cursor 
0839:             */
0840:            public static void showWaitCursor() {
0841:                GUIUtils.invokeAndWait(new Runnable() {
0842:                    public void run() {
0843:                        GUIUtils.showWaitCursor(frame);
0844:                    }
0845:                });
0846:                //GUIUtils.showWaitCursor(frame);
0847:            }
0848:
0849:            /** 
0850:             * Sets the application cursor to the system wait cursor 
0851:             * on the specified component.
0852:             */
0853:            public static void showWaitCursor(final Component component) {
0854:                GUIUtils.invokeAndWait(new Runnable() {
0855:                    public void run() {
0856:                        GUIUtils.showWaitCursor(component);
0857:                    }
0858:                });
0859:            }
0860:
0861:            /** 
0862:             * Sets the application cursor to the system normal cursor 
0863:             * on the specified component.
0864:             */
0865:            public static void showNormalCursor(final Component component) {
0866:                GUIUtils.invokeAndWait(new Runnable() {
0867:                    public void run() {
0868:                        GUIUtils.showNormalCursor(component);
0869:                    }
0870:                });
0871:            }
0872:
0873:            /** <p>Resets the tool bars. */
0874:            public static void resetToolBar(final boolean resetMenu) {
0875:                SwingUtilities.invokeLater(new Runnable() {
0876:                    public void run() {
0877:                        toolBar.buildToolbars(true);
0878:                        ToolBarProperties.saveTools();
0879:                        if (resetMenu) {
0880:                            initialiseViewToolsMenuItems();
0881:                        }
0882:                    }
0883:                });
0884:            }
0885:
0886:            /**
0887:             * Loads and returns the specified image with the specified name.
0888:             * The default path to the image dir appended to the start of
0889:             * the name is /org/executequery/images.
0890:             *
0891:             * @param name - the image file name to load
0892:             * @return the loaded image
0893:             */
0894:            public static ImageIcon loadImage(String name) {
0895:                return IconUtilities.loadImage(IMAGE_PATH + name);
0896:            }
0897:
0898:            /**
0899:             * Loads and returns the specified icon with the specified name.
0900:             * The default path to the icon dir appended to the start of
0901:             * the name is /org/executequery/icons.
0902:             *
0903:             * @param name - the icon file name to load
0904:             * @return the loaded icon image
0905:             */
0906:            public static ImageIcon loadIcon(String name) {
0907:                return loadIcon(name, false);
0908:            }
0909:
0910:            /**
0911:             * Loads and returns the specified icon with the specified name.
0912:             * The default path to the icon dir appended to the start of
0913:             * the name is /org/executequery/icons.
0914:             *
0915:             * @param name - the icon file name to load
0916:             * @param store - whether to store the icon in the icon cache 
0917:             *                for future use after loading
0918:             * @return the loaded icon image
0919:             */
0920:            public static ImageIcon loadIcon(String name, boolean store) {
0921:                return IconUtilities.loadIcon(ICON_PATH + name, store);
0922:            }
0923:
0924:            /**
0925:             * Returns the absolute icon resource path by appending
0926:             * the package icon path to the specified icon file name.
0927:             *
0928:             * @param name - the icon file name
0929:             * @return the absolute package path of the icon
0930:             */
0931:            public static String getAbsoluteIconPath(String name) {
0932:                return ICON_PATH + name;
0933:            }
0934:
0935:            /** 
0936:             * Sets the system display options and writes the
0937:             * preferences to file if specified.
0938:             *
0939:             * @param whether to save the preferences to file
0940:             */
0941:            public static void setDisplayOptions(boolean writeFile) {
0942:                // apply these properties to relevant objects
0943:                displayStatusBar(SystemProperties.getBooleanProperty("user",
0944:                        "system.display.statusbar"));
0945:
0946:                // set the menu's display options as retrieved above
0947:                menuBar.setViewOptions();
0948:
0949:                // update the action shortcuts
0950:                ActionBuilder.updateUserDefinedShortcuts(
0951:                        getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW),
0952:                        SystemResources.getUserActionShortcuts());
0953:            }
0954:
0955:            /**
0956:             * Convenience method for consistent border colour.
0957:             *
0958:             * @return the system default border colour
0959:             */
0960:            public static Color getDefaultBorderColour() {
0961:                return UIManager.getColor("controlShadow");
0962:            }
0963:
0964:            /**
0965:             * Returns the docked component (non-central pane) with
0966:             * the specified name.
0967:             *
0968:             * @param the name of the component
0969:             * @return the panel component
0970:             */
0971:            public static JPanel getDockedTabComponent(String key) {
0972:                if (dockedTabComponents == null
0973:                        || dockedTabComponents.isEmpty()
0974:                        || !dockedTabComponents.containsKey(key)) {
0975:                    return null;
0976:                }
0977:                return dockedTabComponents.get(key);
0978:            }
0979:
0980:            /**
0981:             * Initialises the docked tab view with the specified
0982:             * property key.
0983:             *
0984:             * @param the property key of the panel to be initialised
0985:             */
0986:            private static void initDockedTabView(String key) {
0987:                if (dockedTabComponents.containsKey(key)) {
0988:                    return;
0989:                }
0990:
0991:                JPanel panel = null;
0992:                // determine which panel to initialise
0993:                if (key.equals(ConnectionsTreePanel.PROPERTY_KEY)) {
0994:                    panel = new ConnectionsTreePanel();
0995:                } else if (key.equals(DriversTreePanel.PROPERTY_KEY)) {
0996:                    panel = new DriversTreePanel();
0997:                } else if (key.equals(SystemPropertiesDockedTab.PROPERTY_KEY)) {
0998:                    panel = new SystemPropertiesDockedTab();
0999:                } else if (key.equals(SystemOutputPanel.PROPERTY_KEY)) {
1000:                    // init the logger 
1001:                    // this method will add the output panel
1002:                    startLogger();
1003:                } else if (key.equals(KeywordsDockedPanel.PROPERTY_KEY)) {
1004:                    panel = new KeywordsDockedPanel();
1005:                } else if (key.equals(SQLStateCodesDockedPanel.PROPERTY_KEY)) {
1006:                    panel = new SQLStateCodesDockedPanel();
1007:                }
1008:
1009:                if (panel != null) {
1010:                    dockedTabComponents.put(key, panel);
1011:                }
1012:
1013:            }
1014:
1015:            /**
1016:             * Returns the docked component (non-central pane) with
1017:             * the specified name. If the option to display is set to
1018:             * true, the component will be displayed in the default or
1019:             * user preferred position.
1020:             *
1021:             * @param key - the property key of the component
1022:             */
1023:            public static void ensureDockedTabVisible(String key) {
1024:
1025:                JPanel panel = getDockedTabComponent(key);
1026:                if (panel != null && panel instanceof  DockedTabView) {
1027:                    DockedTabView _panel = (DockedTabView) panel;
1028:                    String title = _panel.getTitle();
1029:
1030:                    // check if its visible already
1031:                    int position = getDockedComponentPosition(key);
1032:                    TabComponent tab = getTabComponent(position, title);
1033:                    if (tab == null) {
1034:
1035:                        // check if its minimised
1036:                        if (desktopMediator.isMinimised(position, title)) {
1037:                            desktopMediator.restore(position, title);
1038:                        }
1039:                        // otherwise add the component to the view
1040:                        else {
1041:                            addDockedTab(title, panel, position, true);
1042:                            layoutProperties.setDockedPaneVisible(key, true);
1043:                            SystemProperties.setBooleanProperty("user", key,
1044:                                    true);
1045:                        }
1046:
1047:                    } else { // otherwise make sure its selected
1048:                        desktopMediator.setSelectedPane(position, title);
1049:                    }
1050:
1051:                } else { // otherwise, initialise the tab
1052:                    initDockedTabView(key);
1053:                    ensureDockedTabVisible(key); // replay
1054:                }
1055:
1056:            }
1057:
1058:            /**
1059:             * Returns the user specified (or default) position for the
1060:             * non-central pane docked component with the specified name.
1061:             *
1062:             * @param the key
1063:             * @return the position (SwingConstants)
1064:             */
1065:            public static int getDockedComponentPosition(String key) {
1066:                int position = layoutProperties.getPosition(key);
1067:                if (position == -1) {
1068:                    // default NORTH_WEST position
1069:                    position = SwingConstants.NORTH_WEST;
1070:                }
1071:                return position;
1072:            }
1073:
1074:            /**
1075:             * Called to indicate that a docked tab view was selected.
1076:             *
1077:             * @param the property key
1078:             */
1079:            public static void dockedTabComponentSelected(String key) {
1080:                // update the system properties visible key
1081:                SystemProperties.setBooleanProperty("user", key, true);
1082:
1083:                // update the view menu item
1084:                JPanel panel = getDockedTabComponent(key);
1085:                if (panel != null && panel instanceof  DockedTabView) {
1086:                    DockedTabView tab = (DockedTabView) panel;
1087:                    menuBar.setViewOption(tab.getMenuItemKey(), true);
1088:                }
1089:
1090:                // update properties to file
1091:                updatePreferencesToFile();
1092:            }
1093:
1094:            /**
1095:             * Called to indicate that a docked tab view has closed.
1096:             *
1097:             * @param the property key
1098:             */
1099:            public static void dockedTabComponentClosed(String key) {
1100:                // save the change
1101:                //layoutProperties.setDockedPaneVisible(key, false);
1102:
1103:                // update the system properties visible key
1104:                SystemProperties.setBooleanProperty("user", key, false);
1105:
1106:                // update the view menu item
1107:                JPanel panel = getDockedTabComponent(key);
1108:                if (panel != null && panel instanceof  DockedTabView) {
1109:                    DockedTabView tab = (DockedTabView) panel;
1110:                    menuBar.setViewOption(tab.getMenuItemKey(), false);
1111:                }
1112:
1113:                // update properties to file
1114:                updatePreferencesToFile();
1115:            }
1116:
1117:            /**
1118:             * Displays or hides the docked tab component of the specified type.
1119:             *
1120:             * @param the property key of the component
1121:             * @param show/hide the view
1122:             */
1123:            public static void displayDockedComponent(String key,
1124:                    boolean display) {
1125:
1126:                if (display) {
1127:                    ensureDockedTabVisible(key);
1128:                } else {
1129:                    // retrieve the panel from the cache
1130:                    JPanel panel = getDockedTabComponent(key);
1131:                    if (panel != null && panel instanceof  DockedTabView) {
1132:                        DockedTabView _panel = (DockedTabView) panel;
1133:                        String title = _panel.getTitle();
1134:                        int position = getDockedComponentPosition(key);
1135:
1136:                        // remove it from the pane
1137:                        closeDockedComponent(title, position);
1138:
1139:                        // save the change
1140:                        layoutProperties.setDockedPaneVisible(key, false);
1141:                    }
1142:                }
1143:
1144:            }
1145:
1146:            /** 
1147:             * Closes the dialog with the specified title.
1148:             */
1149:            public static void closeDialog(String title) {
1150:                if (register.getOpenDialogCount() > 0) {
1151:                    List<JDialog> list = register.getOpenDialogs();
1152:                    for (int i = 0, k = list.size(); i < k; i++) {
1153:                        JDialog dialog = list.get(i);
1154:                        if (dialog.getTitle().startsWith(title)) {
1155:                            dialog.dispose();
1156:                            return;
1157:                        }
1158:                    }
1159:                }
1160:            }
1161:
1162:            /** 
1163:             * Closes the currently in-focus dialog. 
1164:             */
1165:            public static void closeSelectedDialog() {
1166:                if (register.getOpenDialogCount() > 0) {
1167:                    List<JDialog> list = register.getOpenDialogs();
1168:                    for (int i = 0, k = list.size(); i < k; i++) {
1169:                        JDialog dialog = list.get(i);
1170:                        // check if this is focused
1171:                        if (dialog.isFocused()) {
1172:                            // dialog dispose
1173:                            dialog.dispose();
1174:                            return;
1175:                        }
1176:                    }
1177:                }
1178:            }
1179:
1180:            /** <p>Displays or hides the specified tool bar.
1181:             *
1182:             *  @param the tool bar
1183:             *  @param <code>true</code> to display | <code>false</code> to hide
1184:             */
1185:            public static void displayToolBar(String name, boolean display) {
1186:                ToolBarProperties.setToolBarVisible(name, display);
1187:                resetToolBar(false);
1188:            }
1189:
1190:            public static void initialiseViewToolsMenuItems() {
1191:                menuBar
1192:                        .initialiseViewToolsMenuItems(
1193:                                ToolBarProperties
1194:                                        .isToolBarVisible(ToolBarManager.FILE_TOOLS),
1195:                                ToolBarProperties
1196:                                        .isToolBarVisible(ToolBarManager.EDIT_TOOLS),
1197:                                ToolBarProperties
1198:                                        .isToolBarVisible(ToolBarManager.SEARCH_TOOLS),
1199:                                ToolBarProperties
1200:                                        .isToolBarVisible(ToolBarManager.DATABASE_TOOLS),
1201:                                ToolBarProperties
1202:                                        .isToolBarVisible(ToolBarManager.BROWSER_TOOLS),
1203:                                ToolBarProperties
1204:                                        .isToolBarVisible(ToolBarManager.IMPORT_EXPORT_TOOLS),
1205:                                ToolBarProperties
1206:                                        .isToolBarVisible(ToolBarManager.SYSTEM_TOOLS));
1207:            }
1208:
1209:            /** 
1210:             * Displays or hides the main application status bar.
1211:             *
1212:             * @param <code>true</code> to display | <code>false</code> to hide
1213:             */
1214:            public static void displayStatusBar(boolean display) {
1215:                statusBar.setVisible(display);
1216:                SystemProperties.setBooleanProperty("user",
1217:                        "system.display.statusbar", display);
1218:            }
1219:
1220:            /** <p>Registers the application status bar with this class.
1221:             *
1222:             *  @param the status bar
1223:             */
1224:            public static void registerStatusBar(StatusBarPanel status) {
1225:                statusBar = status;
1226:            }
1227:
1228:            /** <p>Retrieves the main frame's layered pane object.
1229:             *
1230:             *  @return the frame's <code>JLayeredPane</code>
1231:             */
1232:            public static JLayeredPane getFrameLayeredPane() {
1233:                return ((JFrame) getParentFrame()).getLayeredPane();
1234:            }
1235:
1236:            /** <p>Retrieves the application's status bar as
1237:             *  registered with this class.
1238:             *
1239:             *  @return the application status bar
1240:             */
1241:            public static final StatusBarPanel getStatusBar() {
1242:                return statusBar;
1243:            }
1244:
1245:            public static void refreshConnectionMenu(
1246:                    DatabaseConnection[] savedConns) {
1247:                if (menuBar != null) {
1248:                    menuBar.setConnectionsMenu(savedConns);
1249:                }
1250:            }
1251:
1252:            public static void addNewConnToMenu(DatabaseConnection c) {
1253:                menuBar.addNewConnectionMenu(c);
1254:            }
1255:
1256:            public static void addNewRecentFileToMenu(File file) {
1257:                String path = file.getAbsolutePath();
1258:                SystemUtilities.addRecentOpenFile(path);
1259:                menuBar.reloadRecentFileMenu();
1260:                /*
1261:                if (SystemUtilities.addRecentOpenFile(path)) {
1262:                    menuBar.addNewRecentFileMenu(file.getName(), path);
1263:                }*/
1264:            }
1265:
1266:            public static void setLookAndFeel(int _lookAndFeel) {
1267:                lookAndFeel = _lookAndFeel;
1268:            }
1269:
1270:            /**
1271:             * Returns the current look and feel value.
1272:             */
1273:            public static final int getLookAndFeel() {
1274:                return lookAndFeel;
1275:            }
1276:
1277:            /**
1278:             * Saves the user preferences to file.
1279:             */
1280:            protected static void updatePreferencesToFile() {
1281:                GUIUtils.startWorker(new Runnable() {
1282:                    public void run() {
1283:                        SystemResources.setUserPreferences(SystemProperties
1284:                                .getProperties("user"));
1285:                    }
1286:                });
1287:            }
1288:
1289:            /**
1290:             * Sets the docked tab views according to user preference.
1291:             */
1292:            private static void setDockedTabViews(boolean reload) {
1293:                List<UserLayoutObject> list = layoutProperties
1294:                        .getLayoutObjectsSorted();
1295:                for (int i = 0, n = list.size(); i < n; i++) {
1296:                    UserLayoutObject object = list.get(i);
1297:                    String key = object.getKey();
1298:                    if (object.isVisible()) {
1299:                        initDockedTabView(key);
1300:                        JPanel panel = getDockedTabComponent(key);
1301:                        DockedTabView tab = (DockedTabView) panel;
1302:
1303:                        String title = tab.getTitle();
1304:                        int position = object.getPosition();
1305:                        // first check if its already displayed
1306:                        if (desktopMediator.getTabComponent(position, title) == null) {
1307:                            // add the component to the view
1308:                            addDockedTab(title, panel, position, false);
1309:
1310:                            //Log.debug("Adding docked tab: " + title);
1311:
1312:                            // check if its minimised
1313:                            if (object.isMinimised()) {
1314:                                desktopMediator.minimiseDockedTab(position,
1315:                                        title);
1316:                            }
1317:
1318:                        }
1319:
1320:                    } else {
1321:                        if (reload) {
1322:                            displayDockedComponent(key, false);
1323:                        }
1324:                    }
1325:                }
1326:            }
1327:
1328:            /**
1329:             * Notifies that user preferences have changed.<br>
1330:             * This will update relevant components and settings
1331:             * and save the new preferences to file.
1332:             */
1333:            public static void preferencesChanged() {
1334:                SwingUtilities.invokeLater(new Runnable() {
1335:                    public void run() {
1336:                        try {
1337:                            // save to file
1338:                            updatePreferencesToFile();
1339:
1340:                            // update the logger level
1341:                            Log.setLevel(SystemProperties.getProperty("user",
1342:                                    "system.log.level"));
1343:
1344:                            // update the System.out/err output options
1345:                            if (errLogger != null) {
1346:                                errLogger.setUseConsole(SystemProperties
1347:                                        .getBooleanProperty("user",
1348:                                                "system.log.err"));
1349:                            }
1350:
1351:                            if (outLogger != null) {
1352:                                outLogger.setUseConsole(SystemProperties
1353:                                        .getBooleanProperty("user",
1354:                                                "system.log.out"));
1355:                            }
1356:
1357:                            // update the proxy info
1358:                            SystemUtilities.initProxySettings();
1359:
1360:                            // set misc display options
1361:                            setDisplayOptions(false);
1362:
1363:                            // update any open editors
1364:                            updateOpenEditors(false);
1365:
1366:                            // update the docked tab view options
1367:                            String[] keys = {
1368:                                    ConnectionsTreePanel.PROPERTY_KEY,
1369:                                    DriversTreePanel.PROPERTY_KEY,
1370:                                    KeywordsDockedPanel.PROPERTY_KEY,
1371:                                    SQLStateCodesDockedPanel.PROPERTY_KEY,
1372:                                    SystemPropertiesDockedTab.PROPERTY_KEY,
1373:                                    SystemOutputPanel.PROPERTY_KEY };
1374:
1375:                            for (int i = 0; i < keys.length; i++) {
1376:                                layoutProperties.setDockedPaneVisible(keys[i],
1377:                                        SystemProperties.getBooleanProperty(
1378:                                                "user", keys[i]), false);
1379:                            }
1380:                            layoutProperties.persist(); // save after looping all
1381:
1382:                            // update the docked tab view display
1383:                            setDockedTabViews(true);
1384:
1385:                            //setBrowserDisplayOptions(false);
1386:
1387:                            JDialog
1388:                                    .setDefaultLookAndFeelDecorated(SystemProperties
1389:                                            .getBooleanProperty("user",
1390:                                                    "decorate.dialog.look"));
1391:
1392:                            JFrame
1393:                                    .setDefaultLookAndFeelDecorated(SystemProperties
1394:                                            .getBooleanProperty("user",
1395:                                                    "decorate.frame.look"));
1396:
1397:                            // todo: conn options
1398:
1399:                            /*
1400:                            if (SystemUtilities.isConnected()) {
1401:                                DBConnection dbConn = new DBConnection();
1402:                                dbConn.updateConnectionProperties();
1403:                            }                
1404:                             */
1405:
1406:                            Log.info("System properties modified.");
1407:                        } finally {
1408:                            showNormalCursor();
1409:                        }
1410:                    }
1411:                });
1412:            }
1413:
1414:            /**
1415:             * Updates open editors with the user preferences.
1416:             * This will usually only be called following a user 
1417:             * preference change.
1418:             */
1419:            public static void updateOpenEditors(boolean writeFile) {
1420:                QueryEditorSettings.initialise();
1421:
1422:                if (register.getOpenPanelCount() > 0) {
1423:                    List<PanelCacheObject> list = register.getOpenPanels();
1424:                    for (int i = 0, k = list.size(); i < k; i++) {
1425:                        Component component = list.get(i).getComponent();
1426:                        if (component instanceof  QueryEditor) {
1427:                            QueryEditor editor = (QueryEditor) component;
1428:                            editor.setEditorPreferences();
1429:                        }
1430:                    }
1431:                }
1432:                menuBar.setEditorViewOptions();
1433:
1434:                if (writeFile) {
1435:                    updatePreferencesToFile();
1436:                }
1437:
1438:            }
1439:
1440:            /**
1441:             * Retrieves a list of the open central panels that implement
1442:             * SaveFunction.
1443:             *
1444:             * @return the open SaveFunction panels
1445:             */
1446:            public static List<SaveFunction> getOpenSaveFunctionPanels() {
1447:                List<SaveFunction> saveFunctions = new ArrayList<SaveFunction>();
1448:                List<PanelCacheObject> panels = register.getOpenPanels();
1449:                for (int i = 0, k = panels.size(); i < k; i++) {
1450:                    Component c = panels.get(i).getComponent();
1451:                    if (c instanceof  SaveFunction) {
1452:                        SaveFunction saveFunction = (SaveFunction) c;
1453:                        if (saveFunction.promptToSave()) {
1454:                            saveFunctions.add(saveFunction);
1455:                        }
1456:                    }
1457:                }
1458:                return saveFunctions;
1459:            }
1460:
1461:            /**
1462:             * Retrieves the number of open central panels that implement
1463:             * SaveFunction.
1464:             *
1465:             * @return the open SaveFunction panels count
1466:             */
1467:            public static int getOpenSaveFunctionCount() {
1468:                int count = 0;
1469:                List<PanelCacheObject> panels = register.getOpenPanels();
1470:                for (int i = 0, k = panels.size(); i < k; i++) {
1471:                    if (panels.get(i).getComponent() instanceof  SaveFunction) {
1472:                        count++;
1473:                    }
1474:                }
1475:                return count;
1476:            }
1477:
1478:            public static void closeConnection() {
1479:                // grab the selected connection from the 
1480:                // connections tree docked panel and close it
1481:                JPanel panel = getDockedTabComponent(ConnectionsTreePanel.PROPERTY_KEY);
1482:                if (panel != null) {
1483:                    DatabaseConnection dc = ((ConnectionsTreePanel) panel)
1484:                            .getSelectedDatabaseConnection();
1485:                    if (dc != null && dc.isConnected()) {
1486:                        try {
1487:                            SystemUtilities.disconnect(dc);
1488:                        } catch (DataSourceException e) {
1489:                            displayErrorMessage("Error disconnecting selected data source:\n"
1490:                                    + e.getMessage());
1491:                        }
1492:                    }
1493:                }
1494:            }
1495:
1496:            public static final void shuttingDown() {
1497:                Log.info("System exiting...");
1498:                /*
1499:                JPanel panel = getDockedTabComponent(SystemOutputPanel.PROPERTY_KEY);
1500:                if (panel != null) {
1501:                    ((SystemOutputPanel)panel).shuttingDown();
1502:                }*/
1503:            }
1504:
1505:            /**
1506:             * Sets the title for the specified component to the newTitle
1507:             * within central tab pane.
1508:             *
1509:             * @param the component to be renamed
1510:             * @the new title to set
1511:             */
1512:            public static void setTabTitleForComponent(JPanel contents,
1513:                    String newTitle) {
1514:                setTabTitleForComponent(SwingUtilities.CENTER, contents,
1515:                        newTitle);
1516:            }
1517:
1518:            /**
1519:             * Sets the tool tip for the specified component to toolTipText.
1520:             *
1521:             * @param the tab pane position
1522:             * @param the component where the tool tip should be set
1523:             * @param the tool tip text to be displayed in the tab
1524:             */
1525:            public static void setToolTipTextForComponent(int position,
1526:                    Component component, String toolTipText) {
1527:                desktopMediator.setToolTipTextForComponent(position, component,
1528:                        toolTipText);
1529:            }
1530:
1531:            /**
1532:             * Sets the title for the specified component to toolTipText.
1533:             *
1534:             * @param the tab pane position
1535:             * @param the component where the tool tip should be set
1536:             * @param the title to be displayed in the tab
1537:             */
1538:            public static void setTabTitleForComponent(int position,
1539:                    Component component, String title) {
1540:                desktopMediator.setTabTitleForComponent(position, component,
1541:                        title);
1542:            }
1543:
1544:            /**
1545:             * Sets the tool tip for the specified component within the 
1546:             * central main pane to title.
1547:             *
1548:             * @param the component where the tool tip should be set
1549:             * @param the tool tip text to be displayed in the tab
1550:             */
1551:            public static void setToolTipTextForComponent(Component component,
1552:                    String toolTipText) {
1553:                setToolTipTextForComponent(SwingConstants.CENTER, component,
1554:                        toolTipText);
1555:            }
1556:
1557:            /**
1558:             * Sets the title for the specified component within the 
1559:             * central main pane to toolTipText.
1560:             *
1561:             * @param the component where the tool tip should be set
1562:             * @param the title text to be displayed in the tab
1563:             */
1564:            public static void setTabTitleForComponent(Component component,
1565:                    String title) {
1566:                setTabTitleForComponent(SwingConstants.CENTER, component, title);
1567:            }
1568:
1569:            /**
1570:             * Attempts to locate the actionable dialog that is
1571:             * currently open and brings it to the front.
1572:             */
1573:            public static void acionableDialogToFront() {
1574:                if (register.getOpenDialogCount() > 0) {
1575:                    List<JDialog> list = register.getOpenDialogs();
1576:                    for (int i = 0, k = list.size(); i < k; i++) {
1577:                        JDialog dialog = list.get(i);
1578:
1579:                        // check if its a BaseDialog
1580:                        if (dialog instanceof  BaseDialog) {
1581:                            // check the content panel
1582:                            JPanel panel = ((BaseDialog) dialog)
1583:                                    .getConentPanel();
1584:                            if (panel instanceof  ActiveComponent) {
1585:                                dialog.toFront();
1586:                            }
1587:                        } else if (dialog instanceof  ActiveComponent) {
1588:                            dialog.toFront();
1589:                        }
1590:                    }
1591:                }
1592:            }
1593:
1594:            /**
1595:             * Checks if an actionable dialog is currently open.
1596:             *
1597:             * @return true | false
1598:             */
1599:            public static boolean isActionableDialogOpen() {
1600:                if (register.getOpenDialogCount() > 0) {
1601:                    List<JDialog> list = register.getOpenDialogs();
1602:                    for (int i = 0, k = list.size(); i < k; i++) {
1603:                        JDialog dialog = list.get(i);
1604:                        // check if its a BaseDialog
1605:                        if (dialog instanceof  BaseDialog) {
1606:                            // check the content panel
1607:                            JPanel panel = ((BaseDialog) dialog)
1608:                                    .getConentPanel();
1609:                            if (panel instanceof  ActiveComponent) {
1610:                                return true;
1611:                            }
1612:                        } else if (dialog instanceof  ActiveComponent) {
1613:                            return true;
1614:                        }
1615:                    }
1616:                }
1617:                return false;
1618:            }
1619:
1620:            public static boolean hasValidSaveFunction() {
1621:                // check the open panels register first
1622:                if (register.getOpenPanelCount() > 0) {
1623:                    List<PanelCacheObject> list = register.getOpenPanels();
1624:                    for (int i = 0, k = list.size(); i < k; i++) {
1625:                        Component component = list.get(i).getComponent();
1626:                        if (component instanceof  SaveFunction) {
1627:                            SaveFunction saveFunction = (SaveFunction) component;
1628:                            if (saveFunction.promptToSave()) {
1629:                                return true;
1630:                            }
1631:                        }
1632:                    }
1633:                }
1634:
1635:                // check the open dialogs
1636:                if (register.getOpenDialogCount() > 0) {
1637:                    List<JDialog> list = register.getOpenDialogs();
1638:                    for (int i = 0, k = list.size(); i < k; i++) {
1639:                        JDialog dialog = list.get(i);
1640:                        if (dialog instanceof  SaveFunction) {
1641:                            SaveFunction saveFunction = (SaveFunction) dialog;
1642:                            if (saveFunction.promptToSave()) {
1643:                                return true;
1644:                            }
1645:                        }
1646:                    }
1647:                }
1648:
1649:                return false;
1650:
1651:                /*
1652:                
1653:                // if we have none return false
1654:                if (desktopMediator.getTabCount(SwingConstants.CENTER) == 0) {
1655:                    return false;
1656:                }        
1657:
1658:                List<TabComponent> tabs = desktopMediator.getOpenTabs(SwingConstants.CENTER);
1659:                for (int i = 0, k = tabs.size(); i < k; i++) {
1660:                    TabComponent tab = tabs.get(i);
1661:                    Component component = tab.getComponent();
1662:
1663:                    if (component instanceof SaveFunction) {
1664:                        SaveFunction saveFunction = (SaveFunction)component;
1665:                        if (saveFunction.promptToSave()) {
1666:                            return true;
1667:                        } 
1668:                    }
1669:
1670:                }
1671:                return false;
1672:
1673:                /*
1674:                JInternalFrame[] _frames = getAllOpenFrames();
1675:                
1676:                for (int i = 0; i < _frames.length; i++) {
1677:                    
1678:                    if (_frames[i] instanceof BaseInternalFrame) {
1679:                        BaseInternalFrame frame = (BaseInternalFrame)_frames[i];
1680:                        JPanel contents = frame.getFrameContents();
1681:                        
1682:                        if (contents instanceof SaveFunction) {
1683:                            SaveFunction saveFunction = (SaveFunction)contents;
1684:                            
1685:                            if (saveFunction.promptToSave()) {
1686:                                validSaves = true;
1687:                                break;
1688:                            } 
1689:                            
1690:                        } 
1691:                        
1692:                    } 
1693:                    
1694:                } 
1695:
1696:                return validSaves; */
1697:            }
1698:
1699:            /**
1700:             * Checks if the panel with the specified title is open.
1701:             * 
1702:             * @return true | false
1703:             */
1704:            public static boolean isPanelOpen(String title) {
1705:                return register.isPanelOpen(title);
1706:                //return getCentralPane(title) != null;
1707:                //return getOpenFrame(title) != null;
1708:            }
1709:
1710:            /**
1711:             * Checks if the dialog with the specified title is open.
1712:             * 
1713:             * @return true | false
1714:             */
1715:            public static boolean isDialogOpen(String title) {
1716:                return register.isDialogOpen(title);
1717:            }
1718:
1719:            /**
1720:             * Checks if the dialog with the specified title is open.
1721:             * 
1722:             * @return true | false
1723:             */
1724:            public static void setSelectedDialog(String title) {
1725:                JDialog dialog = register.getOpenDialog(title);
1726:                if (dialog != null) {
1727:                    dialog.toFront();
1728:                }
1729:            }
1730:
1731:            public static JPanel getOpenFrame(String title) {
1732:                return (JPanel) register.getOpenPanel(title);
1733:            }
1734:
1735:            /**
1736:             * Resets (clears) the system output log.
1737:             */
1738:            private static void resetSystemOutputLog() {
1739:                JPanel panel = getDockedTabComponent(SystemOutputPanel.PROPERTY_KEY);
1740:                if (panel != null) {
1741:                    ((SystemOutputPanel) panel).resetSystemLog();
1742:                }
1743:            }
1744:
1745:            public static void resetSystemLog() {
1746:                int yesno = displayConfirmDialog("Are you sure you want to reset the system activity log?");
1747:
1748:                if (yesno == JOptionPane.YES_OPTION) {
1749:                    resetSystemOutputLog();
1750:                }
1751:            }
1752:
1753:            public static void resetImportLog() {
1754:                int yesno = displayConfirmDialog("Are you sure you want to reset the data import log?");
1755:
1756:                if (yesno == JOptionPane.YES_OPTION) {
1757:                    SystemResources.resetLog("import.log");
1758:                }
1759:            }
1760:
1761:            public static void resetExportLog() {
1762:                int yesno = displayConfirmDialog("Are you sure you want to reset the data export log?");
1763:
1764:                if (yesno == JOptionPane.YES_OPTION) {
1765:                    SystemResources.resetLog("export.log");
1766:                }
1767:            }
1768:
1769:            public static void resetAllLogs() {
1770:                int yesno = displayConfirmDialog("Are you sure you want to reset ALL system logs?");
1771:
1772:                if (yesno == JOptionPane.YES_OPTION) {
1773:                    resetSystemOutputLog();
1774:                    SystemResources.resetLog("export.log");
1775:                    SystemResources.resetLog("import.log");
1776:                }
1777:
1778:            }
1779:
1780:            public static boolean saveOpenChanges(SaveFunction saveFunction) {
1781:                int result = displayConfirmCancelDialog("Do you wish to save changes to "
1782:                        + saveFunction.getDisplayName() + "?");
1783:
1784:                if (result == JOptionPane.YES_OPTION) {
1785:                    int saved = saveFunction.save(false);
1786:                    if (saved != SaveFunction.SAVE_COMPLETE) {
1787:                        return false;
1788:                    }
1789:                } else if (result == JOptionPane.CANCEL_OPTION) {
1790:                    return false;
1791:                }
1792:                return true;
1793:            }
1794:
1795:            /**
1796:             * Displays the error dialog displaying the stack trace from a
1797:             * throws/caught exception.
1798:             *
1799:             * @param message - the error message to display
1800:             * @param e - the throwable
1801:             */
1802:            public static void displayExceptionErrorDialog(
1803:                    final String message, final Throwable e) {
1804:                GUIUtils.invokeAndWait(new Runnable() {
1805:                    public void run() {
1806:                        new ExceptionErrorDialog(frame, message, e);
1807:                    }
1808:                });
1809:            }
1810:
1811:            // -------------------------------------------------------
1812:            // ------ Helper methods for various option dialogs ------
1813:            // -------------------------------------------------------
1814:
1815:            // These have been revised to use JDialog as the wrapper to
1816:            // ensure the dialog is centered within the dektop pane and not
1817:            // within the entire screen as you get with JOptionPane.showXXX()
1818:
1819:            public static final void displayInformationMessage(String message) {
1820:                GUIUtils.displayInformationMessage(frame, message);
1821:            }
1822:
1823:            public static final void displayWarningMessage(String message) {
1824:                GUIUtils.displayWarningMessage(frame, message);
1825:            }
1826:
1827:            public static final void displayErrorMessage(String message) {
1828:                GUIUtils.displayErrorMessage(frame, message);
1829:            }
1830:
1831:            public static final String displayInputMessage(String title,
1832:                    String message) {
1833:                return GUIUtils.displayInputMessage(frame, title, message);
1834:            }
1835:
1836:            public static final int displayConfirmCancelErrorMessage(
1837:                    String message) {
1838:                return GUIUtils
1839:                        .displayConfirmCancelErrorMessage(frame, message);
1840:            }
1841:
1842:            public static final int displayYesNoDialog(String message,
1843:                    String title) {
1844:                return GUIUtils.displayYesNoDialog(frame, message, title);
1845:            }
1846:
1847:            public static final int displayConfirmCancelDialog(String message) {
1848:                return GUIUtils.displayConfirmCancelDialog(frame, message);
1849:            }
1850:
1851:            public static final int displayConfirmDialog(String message) {
1852:                return GUIUtils.displayConfirmDialog(frame, message);
1853:            }
1854:
1855:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.