Source Code Cross Referenced for MetalSliderUI.java in  » Apache-Harmony-Java-SE » javax-package » javax » swing » plaf » metal » 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.plaf.metal 
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:         * @author Sergey Burlak
019:         * @version $Revision$
020:         */package javax.swing.plaf.metal;
021:
022:        import java.awt.Color;
023:        import java.awt.Dimension;
024:        import java.awt.Graphics;
025:        import java.awt.Rectangle;
026:        import java.beans.PropertyChangeEvent;
027:        import java.beans.PropertyChangeListener;
028:
029:        import javax.swing.Icon;
030:        import javax.swing.JComponent;
031:        import javax.swing.JSlider;
032:        import javax.swing.UIManager;
033:        import javax.swing.plaf.ComponentUI;
034:        import javax.swing.plaf.basic.BasicSliderUI;
035:
036:        import org.apache.harmony.x.swing.StringConstants;
037:
038:        public class MetalSliderUI extends BasicSliderUI {
039:            protected class MetalPropertyListener extends PropertyChangeHandler {
040:                public void propertyChange(final PropertyChangeEvent e) {
041:                    String changedProperty = e.getPropertyName();
042:                    if (StringConstants.COMPONENT_ORIENTATION
043:                            .equals(changedProperty)) {
044:                        recalculateIfOrientationChanged();
045:                    } else if (StringConstants.BORDER_PROPERTY_CHANGED
046:                            .equals(changedProperty)) {
047:                        recalculateIfInsetsChanged();
048:                    }
049:                    calculateGeometry();
050:                    slider.revalidate();
051:                    slider.repaint();
052:                }
053:            }
054:
055:            protected final int TICK_BUFFER = 4;
056:            protected final String SLIDER_FILL = "JSlider.isFilled";
057:            protected boolean filledSlider;
058:            protected static Color thumbColor;
059:            protected static Color highlightColor;
060:            protected static Color darkShadowColor;
061:            protected static int trackWidth;
062:            protected static int tickLength;
063:            protected static Icon horizThumbIcon;
064:            protected static Icon vertThumbIcon;
065:
066:            public MetalSliderUI() {
067:                super (null);
068:            }
069:
070:            public static ComponentUI createUI(final JComponent c) {
071:                return new MetalSliderUI();
072:            }
073:
074:            public void installUI(final JComponent c) {
075:                slider = (JSlider) c;
076:                horizThumbIcon = UIManager
077:                        .getIcon("Slider.horizontalThumbIcon");
078:                vertThumbIcon = UIManager.getIcon("Slider.verticalThumbIcon");
079:                thumbRect.setSize(getThumbSize());
080:
081:                super .installUI(c);
082:
083:                trackWidth = UIManager.getInt("Slider.trackWidth");
084:                tickLength = UIManager.getInt("Slider.majorTickLength");
085:
086:                thumbColor = UIManager.getColor("Slider.foreground");
087:                highlightColor = UIManager.getColor("Slider.highlight");
088:                darkShadowColor = UIManager.getColor("Slider.shadow");
089:            }
090:
091:            protected PropertyChangeListener createPropertyChangeListener(
092:                    final JSlider slider) {
093:                return new MetalPropertyListener();
094:            }
095:
096:            public void paintThumb(final Graphics g) {
097:                Color oldColor = g.getColor();
098:                if (slider.isFocusOwner()) {
099:                    g.setColor(thumbColor);
100:                } else {
101:                    g.setColor(Color.LIGHT_GRAY);
102:                }
103:                if (slider.getOrientation() == JSlider.HORIZONTAL) {
104:                    horizThumbIcon.paintIcon(slider, g, thumbRect.x,
105:                            thumbRect.y);
106:                } else {
107:                    vertThumbIcon
108:                            .paintIcon(slider, g, thumbRect.x, thumbRect.y);
109:                }
110:                Color shadow = Color.GRAY;
111:                Color highlight = Color.WHITE;
112:                Rectangle thumbBounds;
113:                if (slider.getOrientation() == JSlider.HORIZONTAL) {
114:                    thumbBounds = new Rectangle(thumbRect.x + 1, thumbRect.y,
115:                            thumbRect.width, thumbRect.height / 2);
116:                } else {
117:                    thumbBounds = new Rectangle(thumbRect.x, thumbRect.y + 1,
118:                            thumbRect.width / 2, thumbRect.height);
119:                }
120:                MetalBumps.paintBumps(g, thumbBounds, shadow, highlight);
121:                g.setColor(oldColor);
122:            }
123:
124:            public void paintTrack(final Graphics g) {
125:                Color oldColor = g.getColor();
126:                if (slider.getOrientation() == JSlider.HORIZONTAL) {
127:                    int x = trackRect.x;
128:                    int y = thumbRect.y + getThumbSize().height
129:                            - getThumbOverhang() - trackWidth;
130:                    int width = getTrackLength();
131:                    int height = trackWidth;
132:                    paintTrack(g, x, y, width, height);
133:                } else {
134:                    int x = thumbRect.x + getThumbSize().width
135:                            - getThumbOverhang() - trackWidth;
136:                    int y = trackRect.y;
137:                    int width = trackWidth;
138:                    int height = getTrackLength();
139:                    paintTrack(g, x, y, width, height);
140:                }
141:                g.setColor(oldColor);
142:            }
143:
144:            public void paintFocus(final Graphics g) {
145:            }
146:
147:            protected Dimension getThumbSize() {
148:                if (slider.getOrientation() == JSlider.HORIZONTAL) {
149:                    return new Dimension(horizThumbIcon.getIconWidth(),
150:                            horizThumbIcon.getIconHeight());
151:                } else {
152:                    return new Dimension(vertThumbIcon.getIconWidth(),
153:                            vertThumbIcon.getIconHeight());
154:                }
155:            }
156:
157:            public int getTickLength() {
158:                return slider.getPaintTicks() ? tickLength : 0;
159:            }
160:
161:            protected int getTrackWidth() {
162:                if (slider.getOrientation() == JSlider.HORIZONTAL) {
163:                    return trackRect.height;
164:                } else {
165:                    return trackRect.width;
166:                }
167:            }
168:
169:            protected int getTrackLength() {
170:                if (slider.getOrientation() == JSlider.HORIZONTAL) {
171:                    return trackRect.width;
172:                } else {
173:                    return trackRect.height;
174:                }
175:            }
176:
177:            protected int getThumbOverhang() {
178:                return 4;
179:            }
180:
181:            protected void scrollDueToClickInTrack(final int dir) {
182:                scrollByUnit(dir);
183:            }
184:
185:            protected void paintMinorTickForHorizSlider(final Graphics g,
186:                    final Rectangle tickBounds, final int x) {
187:                g.setColor(slider.getForeground());
188:                super .paintMinorTickForHorizSlider(g, tickBounds, x);
189:            }
190:
191:            protected void paintMajorTickForHorizSlider(final Graphics g,
192:                    final Rectangle tickBounds, final int x) {
193:                g.setColor(slider.getForeground());
194:                super .paintMajorTickForHorizSlider(g, tickBounds, x);
195:            }
196:
197:            protected void paintMinorTickForVertSlider(final Graphics g,
198:                    final Rectangle tickBounds, final int y) {
199:                g.setColor(slider.getForeground());
200:                super .paintMinorTickForVertSlider(g, tickBounds, y);
201:            }
202:
203:            protected void paintMajorTickForVertSlider(final Graphics g,
204:                    final Rectangle tickBounds, final int y) {
205:                g.setColor(slider.getForeground());
206:                super .paintMajorTickForVertSlider(g, tickBounds, y);
207:            }
208:
209:            private void paintTrack(final Graphics g, final int x, final int y,
210:                    final int width, final int height) {
211:                g.setColor(getShadowColor().brighter());
212:                g.drawRect(x + 1, y + 1, width, height);
213:                g.setColor(darkShadowColor);
214:                g.drawRect(x, y, width, height);
215:                g.setColor(highlightColor);
216:                g
217:                        .drawLine(x + 1, y + 1 + height, x + 1 + width, y + 1
218:                                + height);
219:                g.drawLine(x + 1 + width, y + 1, x + 1 + width, y + 1 + height);
220:            }
221:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.