Source Code Cross Referenced for VsnetWindowsProgressBarUI.java in  » Swing-Library » jide-common » com » jidesoft » plaf » vsnet » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Swing Library » jide common » com.jidesoft.plaf.vsnet 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * @(#)VsnetWindowsProgressBarUI.java 6/21/2005
003:         *
004:         * Copyright 2002 - 2005 JIDE Software Inc. All rights reserved.
005:         */
006:        package com.jidesoft.plaf.vsnet;
007:
008:        import com.jidesoft.plaf.UIDefaultsLookup;
009:        import com.jidesoft.swing.JideSwingUtilities;
010:        import com.sun.java.swing.plaf.windows.WindowsProgressBarUI;
011:
012:        import javax.swing.*;
013:        import javax.swing.plaf.ComponentUI;
014:        import java.awt.*;
015:        import java.awt.event.ActionEvent;
016:        import java.awt.event.ActionListener;
017:        import java.awt.geom.AffineTransform;
018:
019:        /**
020:         * A better ProgressBarUI for indeterminate progress bar.
021:         * <p/>
022:         * <b>Credit:</b> This implementation is based on work from Santhosh Kumar - santhosh@in.fiorano.com.
023:         */
024:
025:        public class VsnetWindowsProgressBarUI extends WindowsProgressBarUI
026:                implements  ActionListener {
027:            /**
028:             * Interval (in ms) between repaints of the indeterminate progress bar.
029:             * The value of this method is set
030:             * (every time the progress bar changes to indeterminate mode)
031:             * using the
032:             * "ProgressBar.repaintInterval" key in the defaults table.
033:             */
034:            private int repaintInterval;
035:
036:            private int x = 0, y = 0, delta = +1;
037:            private Timer timer = null;
038:
039:            public static ComponentUI createUI(JComponent x) {
040:                return new VsnetWindowsProgressBarUI();
041:            }
042:
043:            @Override
044:            protected void installDefaults() {
045:                super .installDefaults();
046:                initRepaintInterval(); //initialize repaint interval
047:            }
048:
049:            @Override
050:            protected void startAnimationTimer() {
051:                if (timer == null) {
052:                    timer = new Timer(getRepaintInterval() / 20, this );
053:                }
054:                x = y = 0;
055:                delta = 1;
056:                timer.start();
057:            }
058:
059:            @Override
060:            protected void stopAnimationTimer() {
061:                if (timer != null) {
062:                    timer.stop();
063:                }
064:            }
065:
066:            public void actionPerformed(ActionEvent ae) {
067:                // style1
068:                if (x == 0)
069:                    delta = +1;
070:                else if (x == progressBar.getWidth())
071:                    delta = -1;
072:                x += delta;
073:
074:                progressBar.repaint();
075:            }
076:
077:            /**
078:             * Returns the desired number of milliseconds between repaints.
079:             * This value is meaningful
080:             * only if the progress bar is in indeterminate mode.
081:             * The repaint interval determines how often the
082:             * default animation thread's timer is fired.
083:             * It's also used by the default indeterminate progress bar
084:             * painting code when determining
085:             * how far to move the bouncing box per frame.
086:             * The repaint interval is specified by
087:             * the "ProgressBar.repaintInterval" UI default.
088:             *
089:             * @return the repaint interval, in milliseconds
090:             */
091:            protected int getRepaintInterval() {
092:                return repaintInterval;
093:            }
094:
095:            private int initRepaintInterval() {
096:                repaintInterval = UIDefaultsLookup
097:                        .getInt("ProgressBar.repaintInterval");
098:                return repaintInterval;
099:            }
100:
101:            private Rectangle boxRect;
102:
103:            @Override
104:            public void paintIndeterminate(Graphics g, JComponent c) {
105:                super .paintIndeterminate(g, c);
106:                Color startColor = progressBar.getForeground();
107:                Color endColor = VsnetUtils.getLighterColor(startColor, 0.9f);
108:
109:                if (!(g instanceof  Graphics2D)) {
110:                    return;
111:                }
112:
113:                boolean vertical = (progressBar.getOrientation() == JProgressBar.VERTICAL);
114:
115:                Insets b = progressBar.getInsets(); // area for border
116:                b.top = 2;
117:                b.left = 2;
118:                b.right = 2;
119:                b.bottom = 2;
120:                int barRectWidth = progressBar.getWidth() - (b.right + b.left);
121:                int barRectHeight = progressBar.getHeight()
122:                        - (b.top + b.bottom);
123:                g.setColor(progressBar.getBackground());
124:                g.fillRect(b.left, b.top, barRectWidth, barRectHeight);
125:
126:                Graphics2D g2d = (Graphics2D) g;
127:
128:                // Paint the bouncing box.
129:                if (delta > 0) {
130:                    boxRect = new Rectangle(b.left, b.top, x, barRectHeight);
131:                    JideSwingUtilities.fillNormalGradient(g2d, boxRect,
132:                            endColor, startColor, vertical);
133:                } else {
134:                    boxRect = new Rectangle(x, b.top, barRectWidth - x,
135:                            barRectHeight);
136:                    JideSwingUtilities.fillNormalGradient(g2d, boxRect,
137:                            startColor, endColor, vertical);
138:                }
139:
140:                // Deal with possible text painting
141:                if (progressBar.isStringPainted()) {
142:                    if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
143:                        paintString(g2d, b.left, b.top, barRectWidth,
144:                                barRectHeight, boxRect.x, boxRect.width, b);
145:                    } else {
146:                        paintString(g2d, b.left, b.top, barRectWidth,
147:                                barRectHeight, boxRect.y, boxRect.height, b);
148:                    }
149:                }
150:            }
151:
152:            /**
153:             * Paints the progress string.
154:             *
155:             * @param g          Graphics used for drawing.
156:             * @param x          x location of bounding box
157:             * @param y          y location of bounding box
158:             * @param width      width of bounding box
159:             * @param height     height of bounding box
160:             * @param fillStart  start location, in x or y depending on orientation,
161:             *                   of the filled portion of the progress bar.
162:             * @param amountFull size of the fill region, either width or height
163:             *                   depending upon orientation.
164:             * @param b          Insets of the progress bar.
165:             */
166:            private void paintString(Graphics g, int x, int y, int width,
167:                    int height, int fillStart, int amountFull, Insets b) {
168:                if (!(g instanceof  Graphics2D)) {
169:                    return;
170:                }
171:
172:                Graphics2D g2 = (Graphics2D) g;
173:                String progressString = progressBar.getString();
174:                g2.setFont(progressBar.getFont());
175:                Point renderLocation = getStringPlacement(g2, progressString,
176:                        x, y, width, height);
177:                Rectangle oldClip = g2.getClipBounds();
178:
179:                if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
180:                    g2.setColor(getSelectionBackground());
181:                    JideSwingUtilities.drawString(progressBar, g2,
182:                            progressString, renderLocation.x, renderLocation.y);
183:                    g2.setColor(getSelectionForeground());
184:                    g2.clipRect(fillStart, y, amountFull, height);
185:                    JideSwingUtilities.drawString(progressBar, g2,
186:                            progressString, renderLocation.x, renderLocation.y);
187:                } else { // VERTICAL
188:                    g2.setColor(getSelectionBackground());
189:                    AffineTransform rotate = AffineTransform
190:                            .getRotateInstance(Math.PI / 2);
191:                    g2.setFont(progressBar.getFont().deriveFont(rotate));
192:                    renderLocation = getStringPlacement(g2, progressString, x,
193:                            y, width, height);
194:                    JideSwingUtilities.drawString(progressBar, g2,
195:                            progressString, renderLocation.x, renderLocation.y);
196:                    g2.setColor(getSelectionForeground());
197:                    g2.clipRect(x, fillStart, width, amountFull);
198:                    JideSwingUtilities.drawString(progressBar, g2,
199:                            progressString, renderLocation.x, renderLocation.y);
200:                }
201:                g2.setClip(oldClip);
202:            }
203:
204:            public static void main(String[] args) {
205:                try {
206:                    UIManager.setLookAndFeel(UIManager
207:                            .getSystemLookAndFeelClassName());
208:                } catch (Exception e) {
209:                    e.printStackTrace();
210:                }
211:                JProgressBar progressBar = new JProgressBar();
212:                JProgressBar myProgressBar = new JProgressBar();
213:                myProgressBar.setUI(new VsnetWindowsProgressBarUI());
214:                progressBar.setIndeterminate(true);
215:                progressBar.setString("Percent");
216:                progressBar.setStringPainted(true);
217:                myProgressBar.setIndeterminate(true);
218:                myProgressBar.setString("Percent");
219:                myProgressBar.setStringPainted(true);
220:                JPanel panel = new JPanel(new BorderLayout(5, 5));
221:                panel.add(progressBar, BorderLayout.NORTH);
222:                panel.add(myProgressBar, BorderLayout.SOUTH);
223:                JOptionPane.showMessageDialog(null, panel,
224:                        "ProgressBars made intutive - santhosh@in.fiorano.com",
225:                        JOptionPane.INFORMATION_MESSAGE);
226:                System.exit(0);
227:            }
228:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.