Source Code Cross Referenced for ProgressMonitor.java in  » Apache-Harmony-Java-SE » javax-package » javax » swing » 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 » Apache Harmony Java SE » javax package » javax.swing 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:
018:        package javax.swing;
019:
020:        import java.awt.Component;
021:        import java.awt.IllegalComponentStateException;
022:        import java.awt.Point;
023:        import java.awt.Rectangle;
024:        import java.awt.event.ActionEvent;
025:        import java.awt.event.WindowAdapter;
026:        import java.awt.event.WindowEvent;
027:        import java.beans.PropertyChangeEvent;
028:        import java.beans.PropertyChangeListener;
029:        import java.util.Locale;
030:        import javax.accessibility.Accessible;
031:        import javax.accessibility.AccessibleComponent;
032:        import javax.accessibility.AccessibleContext;
033:        import javax.accessibility.AccessibleRole;
034:        import javax.accessibility.AccessibleStateSet;
035:        import javax.accessibility.AccessibleText;
036:        import javax.accessibility.AccessibleValue;
037:        import javax.swing.event.ChangeEvent;
038:        import javax.swing.event.ChangeListener;
039:        import javax.swing.text.AttributeSet;
040:        import org.apache.harmony.luni.util.NotImplementedException;
041:
042:        /**
043:         * <p>
044:         * <i>ProgressMonitor</i>
045:         * </p>
046:         * <h3>Implementation Notes:</h3>
047:         * <ul>
048:         * <li>The <code>serialVersionUID</code> fields are explicitly declared as a performance
049:         * optimization, not as a guarantee of serialization compatibility.</li>
050:         * </ul>
051:         */
052:        public class ProgressMonitor implements  Accessible {
053:            protected class AccessibleProgressMonitor extends AccessibleContext
054:                    implements  AccessibleText, ChangeListener,
055:                    PropertyChangeListener {
056:                protected AccessibleProgressMonitor() {
057:                }
058:
059:                public void stateChanged(ChangeEvent e)
060:                        throws NotImplementedException {
061:                    throw new NotImplementedException();
062:                }
063:
064:                public void propertyChange(PropertyChangeEvent e)
065:                        throws NotImplementedException {
066:                    throw new NotImplementedException();
067:                }
068:
069:                @Override
070:                public String getAccessibleName()
071:                        throws NotImplementedException {
072:                    throw new NotImplementedException();
073:                }
074:
075:                @Override
076:                public String getAccessibleDescription()
077:                        throws NotImplementedException {
078:                    throw new NotImplementedException();
079:                }
080:
081:                @Override
082:                public AccessibleRole getAccessibleRole()
083:                        throws NotImplementedException {
084:                    throw new NotImplementedException();
085:                }
086:
087:                @Override
088:                public AccessibleStateSet getAccessibleStateSet()
089:                        throws NotImplementedException {
090:                    throw new NotImplementedException();
091:                }
092:
093:                @Override
094:                public Accessible getAccessibleParent()
095:                        throws NotImplementedException {
096:                    throw new NotImplementedException();
097:                }
098:
099:                @Override
100:                public int getAccessibleIndexInParent()
101:                        throws NotImplementedException {
102:                    throw new NotImplementedException();
103:                }
104:
105:                @Override
106:                public int getAccessibleChildrenCount()
107:                        throws NotImplementedException {
108:                    throw new NotImplementedException();
109:                }
110:
111:                @Override
112:                public Accessible getAccessibleChild(int i)
113:                        throws NotImplementedException {
114:                    throw new NotImplementedException();
115:                }
116:
117:                @Override
118:                public Locale getLocale()
119:                        throws IllegalComponentStateException,
120:                        NotImplementedException {
121:                    throw new NotImplementedException();
122:                }
123:
124:                @Override
125:                public AccessibleComponent getAccessibleComponent()
126:                        throws NotImplementedException {
127:                    throw new NotImplementedException();
128:                }
129:
130:                @Override
131:                public AccessibleValue getAccessibleValue()
132:                        throws NotImplementedException {
133:                    throw new NotImplementedException();
134:                }
135:
136:                @Override
137:                public AccessibleText getAccessibleText()
138:                        throws NotImplementedException {
139:                    throw new NotImplementedException();
140:                }
141:
142:                public int getIndexAtPoint(Point p)
143:                        throws NotImplementedException {
144:                    throw new NotImplementedException();
145:                }
146:
147:                public Rectangle getCharacterBounds(int i)
148:                        throws NotImplementedException {
149:                    throw new NotImplementedException();
150:                }
151:
152:                public int getCharCount() throws NotImplementedException {
153:                    throw new NotImplementedException();
154:                }
155:
156:                public int getCaretPosition() throws NotImplementedException {
157:                    throw new NotImplementedException();
158:                }
159:
160:                public String getAtIndex(int part, int index)
161:                        throws NotImplementedException {
162:                    throw new NotImplementedException();
163:                }
164:
165:                public String getAfterIndex(int part, int index)
166:                        throws NotImplementedException {
167:                    throw new NotImplementedException();
168:                }
169:
170:                public String getBeforeIndex(int part, int index)
171:                        throws NotImplementedException {
172:                    throw new NotImplementedException();
173:                }
174:
175:                public AttributeSet getCharacterAttribute(int i)
176:                        throws NotImplementedException {
177:                    throw new NotImplementedException();
178:                }
179:
180:                public int getSelectionStart() throws NotImplementedException {
181:                    throw new NotImplementedException();
182:                }
183:
184:                public int getSelectionEnd() throws NotImplementedException {
185:                    throw new NotImplementedException();
186:                }
187:
188:                public String getSelectedText() throws NotImplementedException {
189:                    throw new NotImplementedException();
190:                }
191:            }
192:
193:            private Action cancelAction = new AbstractAction() {
194:                private static final long serialVersionUID = 1L;
195:
196:                public void actionPerformed(ActionEvent e) {
197:                    close();
198:                    isCancelled = true;
199:                }
200:            };
201:
202:            protected AccessibleContext accessibleContext;
203:
204:            private static final int DEFAULT_MILLIS_TO_DECIDE = 500;
205:
206:            private static final int DEFAULT_MILLIS_TO_POPUP = 2000;
207:
208:            private int millisToDecideToPopup = DEFAULT_MILLIS_TO_DECIDE;
209:
210:            private int millisToPopup = DEFAULT_MILLIS_TO_POPUP;
211:
212:            private Timer shouldShowTimer;
213:
214:            private int max;
215:
216:            private int min;
217:
218:            private int progress;
219:
220:            private JProgressBar progressBar;
221:
222:            private JDialog progressDialog;
223:
224:            private Component parentComponent;
225:
226:            private JLabel noteLabel;
227:
228:            private Object message;
229:
230:            private boolean shouldShow;
231:
232:            private boolean isCancelled;
233:
234:            public ProgressMonitor(Component parentComponent, Object message,
235:                    String note, int min, int max) {
236:                this .parentComponent = parentComponent;
237:                this .message = message;
238:                noteLabel = new JLabel(note);
239:                this .min = min;
240:                progress = min;
241:                this .max = max;
242:                startShouldShowTimer();
243:            }
244:
245:            public void setProgress(int progress) {
246:                int oldProgress = this .progress;
247:                if (progress >= max) {
248:                    close();
249:                } else if (progress > this .progress) {
250:                    this .progress = progress;
251:                    if (shouldShow && !isCancelled
252:                            && progressVisible(oldProgress, progress)) {
253:                        if (progressDialog == null) {
254:                            showDialog();
255:                        }
256:                        progressBar.setValue(progress);
257:                    }
258:                }
259:            }
260:
261:            public void close() {
262:                if (progressDialog != null) {
263:                    progressDialog.dispose();
264:                    progressDialog = null;
265:                }
266:            }
267:
268:            public int getMinimum() {
269:                return min;
270:            }
271:
272:            public void setMinimum(int min) {
273:                this .min = min;
274:                if (progressBar != null) {
275:                    progressBar.setMinimum(min);
276:                }
277:            }
278:
279:            public int getMaximum() {
280:                return max;
281:            }
282:
283:            public void setMaximum(int max) {
284:                this .max = max;
285:                if (progressBar != null) {
286:                    progressBar.setMaximum(max);
287:                }
288:            }
289:
290:            public boolean isCanceled() {
291:                return isCancelled;
292:            }
293:
294:            public void setMillisToDecideToPopup(int millisToDecideToPopup) {
295:                this .millisToDecideToPopup = millisToDecideToPopup;
296:                if (shouldShowTimer != null) {
297:                    shouldShowTimer.setDelay(millisToDecideToPopup);
298:                }
299:            }
300:
301:            public int getMillisToDecideToPopup() {
302:                return millisToDecideToPopup;
303:            }
304:
305:            public void setMillisToPopup(int millisToPopup) {
306:                this .millisToPopup = millisToPopup;
307:            }
308:
309:            public int getMillisToPopup() {
310:                return millisToPopup;
311:            }
312:
313:            public void setNote(String note) {
314:                noteLabel.setText(note);
315:            }
316:
317:            public String getNote() {
318:                return noteLabel.getText();
319:            }
320:
321:            public AccessibleContext getAccessibleContext() {
322:                if (accessibleContext == null) {
323:                    accessibleContext = new AccessibleProgressMonitor();
324:                }
325:                return accessibleContext;
326:            }
327:
328:            private void startShouldShowTimer() {
329:                shouldShow = false;
330:                if (shouldShowTimer == null) {
331:                    shouldShowTimer = new Timer(millisToDecideToPopup,
332:                            new AbstractAction() {
333:                                private static final long serialVersionUID = 1L;
334:
335:                                public void actionPerformed(ActionEvent e) {
336:                                    shouldShow = (max - min)
337:                                            * millisToDecideToPopup > millisToPopup
338:                                            * (progress - min);
339:                                }
340:                            });
341:                }
342:                shouldShowTimer.setRepeats(false);
343:                shouldShowTimer.restart();
344:            }
345:
346:            private void showDialog() {
347:                progressBar = new JProgressBar(min, max);
348:                JButton cancelButton = new JButton();
349:                cancelButton.setAction(cancelAction);
350:                cancelButton.setText(UIManager
351:                        .getString("OptionPane.cancelButtonText"));
352:                cancelButton.setMnemonic(UIManager
353:                        .getInt("OptionPane.cancelButtonMnemonic"));
354:                Object[] topPanel = { message, noteLabel, progressBar };
355:                Object[] bottomPanel = { cancelButton };
356:                JOptionPane dialogCreator = new JOptionPane(topPanel,
357:                        JOptionPane.INFORMATION_MESSAGE,
358:                        JOptionPane.DEFAULT_OPTION, null, bottomPanel);
359:                progressDialog = dialogCreator.createDialog(parentComponent,
360:                        UIManager.getString("ProgressMonitor.progressText"));
361:                progressDialog.setModal(false);
362:                progressDialog.addWindowListener(new WindowAdapter() {
363:                    @Override
364:                    public void windowClosing(WindowEvent e) {
365:                        cancelAction.actionPerformed(null);
366:                    }
367:                });
368:                progressDialog.setVisible(true);
369:            }
370:
371:            private boolean progressVisible(int oldProgress, int newProgress) {
372:                return (newProgress - oldProgress) * 100 >= (max - min);
373:            }
374:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.