Source Code Cross Referenced for ProgessCallBackDialog.java in  » Database-Client » squirrel-sql-2.6.5a » net » sourceforge » squirrel_sql » client » gui » 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 » squirrel sql 2.6.5a » net.sourceforge.squirrel_sql.client.gui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sourceforge.squirrel_sql.client.gui;
002:
003:        /*
004:         * Copyright (C) 2007 Rob Manning
005:         * manningr@user.sourceforge.net
006:         *
007:         * This library is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU Lesser General Public
009:         * License as published by the Free Software Foundation; either
010:         * version 2.1 of the License, or (at your option) any later version.
011:         *
012:         * This library is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this library; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
020:         */
021:        import java.awt.Dialog;
022:        import java.awt.Dimension;
023:        import java.awt.Frame;
024:        import java.awt.GridBagConstraints;
025:        import java.awt.GridBagLayout;
026:        import java.awt.Insets;
027:        import java.awt.Window;
028:
029:        import javax.swing.BorderFactory;
030:        import javax.swing.JDialog;
031:        import javax.swing.JFrame;
032:        import javax.swing.JLabel;
033:        import javax.swing.JPanel;
034:        import javax.swing.JProgressBar;
035:
036:        import net.sourceforge.squirrel_sql.client.ApplicationArguments;
037:        import net.sourceforge.squirrel_sql.fw.gui.GUIUtils;
038:        import net.sourceforge.squirrel_sql.fw.sql.ProgressCallBack;
039:        import net.sourceforge.squirrel_sql.fw.util.StringManager;
040:        import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
041:        import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
042:        import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
043:
044:        /**
045:         * A simple class that can be used to show the user a dialog to indicate the 
046:         * progress of some task using the ProgressCallBack interface.  Since certain
047:         * classes in fw module interact with the database and certain operations can 
048:         * take quite a long time, letting the user know how it's going is nice.  
049:         * However, fw module classes don't (and shouldn't) know anything about the UI
050:         * as this is the responsibility of the app module classes.  So, this class 
051:         * can be passed in by app classes to certain fw long-running methods to 
052:         * bridge the gap and provide feedback to the user.
053:         *   
054:         * @author manningr
055:         */
056:        public class ProgessCallBackDialog extends JDialog implements 
057:                ProgressCallBack {
058:
059:            /** Logger for this class. */
060:            private final static ILogger s_log = LoggerController
061:                    .createLogger(ProgessCallBackDialog.class);
062:
063:            /** Internationalized strings for this class */
064:            private static final StringManager s_stringMgr = StringManagerFactory
065:                    .getStringManager(ProgessCallBackDialog.class);
066:
067:            static interface i18n {
068:                //i18n[ProgressCallBackDialog.defaultLoadingPrefix=Loading:]
069:                String DEFAULT_LOADING_PREFIX = s_stringMgr
070:                        .getString("ProgressCallBackDialog.defaultLoadingPrefix");
071:
072:                //i18n[ProgressCallBackDialog.initialLoadingPrefix=Loading...]
073:                String INITIAL_LOADING_PREFIX = s_stringMgr
074:                        .getString("ProgressCallBackDialog.initialLoadingPrefix");
075:            }
076:
077:            private int itemCount = 0;
078:
079:            private JProgressBar progressBar = null;
080:
081:            private JLabel statusLabel = null;
082:
083:            private String _loadingPrefix = i18n.DEFAULT_LOADING_PREFIX;
084:
085:            public ProgessCallBackDialog(Dialog owner, String title,
086:                    int totalItems) {
087:                super (owner, title);
088:                init(totalItems);
089:            }
090:
091:            public ProgessCallBackDialog(Frame owner, String title,
092:                    int totalItems) {
093:                super (owner, title);
094:                setLocationRelativeTo(owner);
095:                init(totalItems);
096:            }
097:
098:            private void init(int totalItems) {
099:                itemCount = totalItems;
100:                final Window owner = super .getOwner();
101:                final ProgessCallBackDialog dialog = this ;
102:
103:                GUIUtils.processOnSwingEventThread(new Runnable() {
104:                    public void run() {
105:                        createGUI();
106:                        setLocationRelativeTo(owner);
107:                        dialog.setVisible(true);
108:                    }
109:                }, true);
110:
111:            }
112:
113:            public void setTotalItems(int totalItems) {
114:                itemCount = totalItems;
115:                progressBar.setMaximum(totalItems);
116:            }
117:
118:            /**
119:             * Sets the text that is displayed before each thing being loaded.  By 
120:             * default this is the string "Loading:".
121:             * @param loadingPrefix
122:             */
123:            public void setLoadingPrefix(String loadingPrefix) {
124:                if (loadingPrefix != null) {
125:                    _loadingPrefix = loadingPrefix;
126:                }
127:            }
128:
129:            /* (non-Javadoc)
130:             * @see net.sourceforge.squirrel_sql.fw.sql.ProgressCallBack#currentlyLoading(java.lang.String)
131:             */
132:            public void currentlyLoading(final String simpleName) {
133:                final StringBuilder statusText = new StringBuilder();
134:                statusText.append(_loadingPrefix);
135:                statusText.append(" ");
136:                statusText.append(simpleName);
137:                try {
138:                    GUIUtils.processOnSwingEventThread(new Runnable() {
139:                        public void run() {
140:                            statusLabel.setText(statusText.toString());
141:                            progressBar.setValue(progressBar.getValue() + 1);
142:                            if (finishedLoading()) {
143:                                ProgessCallBackDialog.this .setVisible(false);
144:                                return;
145:                            }
146:                        }
147:                    });
148:                } catch (Exception e) {
149:                    s_log.error("Unexpected exception: " + e.getMessage(), e);
150:                }
151:            }
152:
153:            public boolean finishedLoading() {
154:                return progressBar.getValue() >= itemCount - 1;
155:            }
156:
157:            private void createGUI() {
158:                JPanel dialogPanel = new JPanel(new GridBagLayout());
159:                dialogPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0,
160:                        10));
161:                GridBagConstraints c;
162:
163:                c = new GridBagConstraints();
164:                c.gridx = 0;
165:                c.gridy = 0;
166:                c.fill = GridBagConstraints.HORIZONTAL;
167:                c.anchor = GridBagConstraints.WEST;
168:
169:                statusLabel = new JLabel(i18n.INITIAL_LOADING_PREFIX);
170:                dialogPanel.add(statusLabel, c);
171:
172:                progressBar = new JProgressBar(0, itemCount);
173:                c = new GridBagConstraints();
174:                c.gridx = 0;
175:                c.gridy = 1;
176:                c.anchor = GridBagConstraints.WEST;
177:                c.fill = GridBagConstraints.HORIZONTAL;
178:                c.insets = new Insets(0, 0, 10, 0);
179:                c.weightx = 1.0;
180:
181:                dialogPanel.add(progressBar, c);
182:                super .getContentPane().add(dialogPanel);
183:                super .pack();
184:                super .setSize(new Dimension(400, 100));
185:            }
186:
187:            /**
188:             * @param args
189:             */
190:            public static void main(String[] args) throws Exception {
191:                ApplicationArguments.initialize(new String[] {});
192:                String[] tables = new String[] { "table_a", "table_b",
193:                        "table_c", "table_d", "table_e", };
194:                JFrame parent = new JFrame();
195:                GUIUtils.centerWithinScreen(parent);
196:                parent.setSize(new Dimension(200, 200));
197:                parent.setVisible(true);
198:                ProgessCallBackDialog dialog = new ProgessCallBackDialog(
199:                        parent, "test", 5);
200:
201:                dialog.setVisible(true);
202:                for (int i = 0; i < 5; i++) {
203:                    dialog.currentlyLoading(tables[i]);
204:                    Thread.sleep(1000);
205:                }
206:                System.exit(0);
207:            }
208:
209:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.