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


001:        package net.sourceforge.squirrel_sql.plugins.dataimport.gui;
002:
003:        /*
004:         * Copyright (C) 2007 Thorsten Mürell
005:         *
006:         * This program is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU General Public License
008:         * as published by the Free Software Foundation; either version 2
009:         * of the License, or any later version.
010:         *
011:         * This program is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014:         * GNU General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU General Public License
017:         * along with this program; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
019:         */
020:
021:        import java.awt.BorderLayout;
022:        import java.awt.FlowLayout;
023:        import java.awt.Frame;
024:        import java.awt.GridBagConstraints;
025:        import java.awt.GridBagLayout;
026:        import java.awt.Insets;
027:        import java.awt.event.ActionListener;
028:
029:        import javax.swing.BorderFactory;
030:        import javax.swing.JButton;
031:        import javax.swing.JDialog;
032:        import javax.swing.JLabel;
033:        import javax.swing.JPanel;
034:        import javax.swing.JProgressBar;
035:        import javax.swing.SwingUtilities;
036:
037:        import net.sourceforge.squirrel_sql.fw.util.StringManager;
038:        import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
039:        import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
040:        import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
041:
042:        /**
043:         * This class shows a progress dialog while the file is imported.
044:         * 
045:         * @author Thorsten Mürell
046:         */
047:        public class ProgressBarDialog {
048:
049:            private static JProgressBar progressBar = null;
050:            private static JLabel message = null;
051:            private static JButton cancelButton = null;
052:
053:            private static JDialog dialog = null;
054:
055:            /** Internationalized strings for this class */
056:            private static final StringManager stringMgr = StringManagerFactory
057:                    .getStringManager(ProgressBarDialog.class);
058:
059:            /** Logger for this class. */
060:            private final static ILogger log = LoggerController
061:                    .createLogger(ProgressBarDialog.class);
062:
063:            /**
064:             * Returns the dialog
065:             * 
066:             * @param owner The owner
067:             * @param title The title for the dialog
068:             * @param modal If this should be a modal dialog
069:             * @param listener The listener for actions
070:             * @return The dialog to show
071:             */
072:            public static JDialog getDialog(final Frame owner,
073:                    final String title, final boolean modal,
074:                    final ActionListener listener) {
075:                if (SwingUtilities.isEventDispatchThread()) {
076:                    _getDialog(owner, title, modal, listener);
077:                } else {
078:                    try {
079:                        SwingUtilities.invokeAndWait(new Runnable() {
080:                            public void run() {
081:                                _getDialog(owner, title, modal, listener);
082:                            }
083:                        });
084:                    } catch (Exception e) {
085:                        //i18n[ProgressBarDialog.error.getdialog=getDialog: unable to invokeAndWait for dialog]
086:                        log
087:                                .error(
088:                                        stringMgr
089:                                                .getString("ProgressBarDialog.error.getdialog"),
090:                                        e);
091:                    }
092:                }
093:
094:                return dialog;
095:            }
096:
097:            private static void _getDialog(Frame owner, String title,
098:                    boolean modal, ActionListener listener) {
099:                dialog = new JDialog(owner, title, modal);
100:                dialog.getContentPane().setLayout(new BorderLayout());
101:                dialog.getContentPane().add(buildPanel(), BorderLayout.CENTER);
102:                dialog.getContentPane().add(buildButtonPanel(),
103:                        BorderLayout.SOUTH);
104:                dialog.setSize(250, 135);
105:                dialog.setLocationRelativeTo(owner);
106:                cancelButton.addActionListener(listener);
107:                dialog.setVisible(true);
108:            }
109:
110:            private static JPanel buildPanel() {
111:                JPanel dataPanel = new JPanel();
112:                dataPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0,
113:                        10));
114:                GridBagLayout gl = new GridBagLayout();
115:                dataPanel.setLayout(gl);
116:                GridBagConstraints c;
117:
118:                c = new GridBagConstraints();
119:                c.gridx = 0;
120:                c.gridy = 0;
121:                c.fill = GridBagConstraints.HORIZONTAL;
122:                c.anchor = GridBagConstraints.WEST;
123:                // i18n[ProgressBarDialog.insertingRecordsLabel=Copying records]
124:                String topLabelText = stringMgr
125:                        .getString("ProgressBarDialog.insertingRecordsLabel");
126:                message = new JLabel(topLabelText);
127:                dataPanel.add(message, c);
128:
129:                c = new GridBagConstraints();
130:                c.gridx = 0;
131:                c.gridy = 1;
132:                c.anchor = GridBagConstraints.WEST;
133:                c.fill = GridBagConstraints.HORIZONTAL;
134:                c.insets = new Insets(0, 0, 10, 0);
135:                c.weightx = 1.0;
136:                progressBar = new JProgressBar(0, 10);
137:                dataPanel.add(progressBar, c);
138:
139:                return dataPanel;
140:            }
141:
142:            private static JPanel buildButtonPanel() {
143:                JPanel buttonPanel = new JPanel(new FlowLayout());
144:                // i18n[ProgressBarDialog.cancelButtonLabel=Cancel]
145:                String buttonText = stringMgr
146:                        .getString("ProgressBarDialog.cancelButtonLabel");
147:                cancelButton = new JButton(buttonText);
148:                buttonPanel.add(cancelButton);
149:                return buttonPanel;
150:            }
151:
152:            /**
153:             * Sets the message for the progress bar dialog
154:             * 
155:             * @param msg The message to show
156:             */
157:            public static void setMessage(final String msg) {
158:                if (SwingUtilities.isEventDispatchThread()) {
159:                    message.setText(msg);
160:                } else {
161:                    SwingUtilities.invokeLater(new Runnable() {
162:                        public void run() {
163:                            message.setText(msg);
164:                        }
165:                    });
166:                }
167:            }
168:
169:            /**
170:             * Sets the Dialog to indeterminate.
171:             * 
172:             * Use this, when you do not know the number
173:             * of items to process.
174:             */
175:            public static void setIndeterminate() {
176:                if (SwingUtilities.isEventDispatchThread()) {
177:                    progressBar.setIndeterminate(true);
178:                } else {
179:                    SwingUtilities.invokeLater(new Runnable() {
180:                        public void run() {
181:                            progressBar.setIndeterminate(true);
182:                        }
183:                    });
184:                }
185:            }
186:
187:            /**
188:             * Sets the minimum and maximum values for the dialog.
189:             * 
190:             * @param min The minimum value
191:             * @param max The maximum value
192:             */
193:            public static void setBarMinMax(final int min, final int max) {
194:                if (progressBar.getMinimum() == min
195:                        && progressBar.getMaximum() == max) {
196:                    return;
197:                }
198:                if (SwingUtilities.isEventDispatchThread()) {
199:                    progressBar.setMinimum(min);
200:                    progressBar.setMaximum(max);
201:                } else {
202:                    SwingUtilities.invokeLater(new Runnable() {
203:                        public void run() {
204:                            progressBar.setMinimum(min);
205:                            progressBar.setMaximum(max);
206:                        }
207:                    });
208:                }
209:            }
210:
211:            /**
212:             * Sets the value for the progress bar
213:             * 
214:             * @param value The current value
215:             */
216:            public static void setBarValue(final int value) {
217:                if (SwingUtilities.isEventDispatchThread()) {
218:                    progressBar.setValue(value);
219:                } else {
220:                    SwingUtilities.invokeLater(new Runnable() {
221:                        public void run() {
222:                            progressBar.setValue(value);
223:                        }
224:                    });
225:                }
226:            }
227:
228:            /**
229:             * Increments the progress bar by the given value
230:             * 
231:             * @param value The value to increment the bar
232:             */
233:            public static void incrementBar(final int value) {
234:                final int newValue = progressBar.getValue() + value;
235:                if (SwingUtilities.isEventDispatchThread()) {
236:                    progressBar.setValue(newValue);
237:                } else {
238:                    SwingUtilities.invokeLater(new Runnable() {
239:                        public void run() {
240:                            progressBar.setValue(newValue);
241:                        }
242:                    });
243:                }
244:            }
245:
246:            /**
247:             * Sets the visibiility of the progress dialog
248:             * 
249:             * @param visible a boolean value indicating whether or not to make the 
250:             *                dialog visible.
251:             */
252:            public static void setVisible(final boolean visible) {
253:                if (dialog == null) {
254:                    return;
255:                }
256:                if (dialog.isVisible() != visible) {
257:                    if (SwingUtilities.isEventDispatchThread()) {
258:                        dialog.setVisible(visible);
259:                    } else {
260:                        SwingUtilities.invokeLater(new Runnable() {
261:                            public void run() {
262:                                dialog.setVisible(visible);
263:                            }
264:                        });
265:                    }
266:                }
267:            }
268:
269:            /**
270:             * Closes the progress dialog.
271:             */
272:            public static void dispose() {
273:                if (dialog == null) {
274:                    return;
275:                }
276:                if (SwingUtilities.isEventDispatchThread()) {
277:                    dialog.dispose();
278:                } else {
279:                    SwingUtilities.invokeLater(new Runnable() {
280:                        public void run() {
281:                            dialog.dispose();
282:                        }
283:                    });
284:                }
285:            }
286:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.