Source Code Cross Referenced for DefaultCheckbox.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » awt » theme » 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 » org package » org.apache.harmony.awt.theme 
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 Dmitry A. Durnev, Pavel Dolgov
019:         * @version $Revision$
020:         */package org.apache.harmony.awt.theme;
021:
022:        import java.awt.BasicStroke;
023:        import java.awt.Color;
024:        import java.awt.Dimension;
025:        import java.awt.Graphics;
026:        import java.awt.Graphics2D;
027:        import java.awt.Point;
028:        import java.awt.Rectangle;
029:        import java.awt.Stroke;
030:        import java.awt.SystemColor;
031:
032:        import org.apache.harmony.awt.state.CheckboxState;
033:        import org.apache.harmony.awt.state.TextState;
034:
035:        /**
036:         * Implementation of Checkbox' default visual style
037:         */
038:        public class DefaultCheckbox extends DefaultStyle {
039:            static Color pressedColor = new Color(236, 233, 216);
040:
041:            public static void drawBackground(Graphics g, CheckboxState s,
042:                    Rectangle r) {
043:
044:                Dimension size = s.getSize();
045:                boolean group = s.isInGroup();
046:
047:                g.setColor(s.getBackground());
048:                g.fillRect(0, 0, size.width, size.height);
049:                Rectangle checkRect = drawCheckBox(g, s);
050:                g.setColor(s.getTextColor());
051:                if (s.isChecked()) {
052:                    if (group) {
053:                        drawRoundCheckMark(g, checkRect);
054:                    } else {
055:                        drawCheckMark(g, checkRect);
056:                    }
057:                }
058:
059:                if (s.isFocused()) {
060:                    r.grow(1, 1);
061:                    drawFocusRect(g, r.x, r.y, r.width, r.height);
062:                }
063:            }
064:
065:            public static Rectangle getTextRect(CheckboxState s) {
066:
067:                if (s.getText() == null) {
068:                    return s.getBounds();
069:                }
070:
071:                Dimension size = s.getSize();
072:                Dimension textSize = getTextSize(s);
073:
074:                int centerY = size.height / 2;
075:                int textCenterY = textSize.height / 2;
076:
077:                int margin = ABS_MARGIN + CB_SIZE
078:                        + (int) (REL_MARGIN * textSize.height / 2);
079:                int baseX = margin; // + textSize.width;
080:
081:                int baseY = centerY + textCenterY;
082:
083:                return new Rectangle(baseX, baseY - textSize.height,
084:                        textSize.width, textSize.height);
085:
086:            }
087:
088:            public static void drawText(Graphics g, TextState s, Rectangle r) {
089:                String text = s.getText();
090:                if (text == null) {
091:                    return;
092:                }
093:                int baseX = r.x;
094:                int h = getTextSize(s).height;
095:                int baseY = r.y + r.height - h / 5;
096:                g.setFont(s.getFont());
097:                g.setColor(s.getTextColor());
098:                if (s.isEnabled()) {
099:                    g.drawString(text, baseX, baseY);
100:                } else {
101:                    drawDisabledString(g, text, baseX, baseY);
102:                }
103:            }
104:
105:            public static void calculate(CheckboxState s) {
106:                Dimension textSize = getTextSize(s);
107:
108:                Dimension cbSize = new Dimension();
109:                cbSize.width = textSize.width
110:                        + (int) (2 * REL_MARGIN * textSize.height) + 2
111:                        * ABS_MARGIN;
112:                cbSize.width += CB_SIZE;
113:                cbSize.height = (int) ((2 * REL_MARGIN + 1) * textSize.height)
114:                        + 2 * ABS_MARGIN;
115:                s.setDefaultMinimumSize(cbSize);
116:                s.setTextSize(textSize);
117:            }
118:
119:            private static void drawRoundCheckMark(Graphics g, Rectangle rect) {
120:                int dx = rect.width / 3;
121:                int dy = rect.height / 3;
122:                g.fillOval(rect.x + dx, rect.y + dy, dx + 1, dy + 1);
123:            }
124:
125:            private static void drawCheckMark(Graphics g, Rectangle rect) {
126:
127:                Graphics2D g2d = (Graphics2D) g;
128:                Stroke stroke = g2d.getStroke();
129:                g2d.setStroke(new BasicStroke(3));
130:                int w = rect.width;
131:                int h = rect.height;
132:                Point p2 = new Point(rect.x + w / 2 - 1, rect.y + h - 3);
133:                int x0 = p2.x;
134:                int y0 = p2.y;
135:                Point p1 = new Point(x0 - w / 4 + 1, y0 - h / 4 + 1);
136:                Point p3 = new Point(x0 + w / 3, y0 - h / 3);
137:                g.drawLine(p1.x, p1.y, x0, y0);
138:                g.drawLine(x0, y0, p3.x, p3.y);
139:
140:                g2d.setStroke(stroke);
141:            }
142:
143:            private static Rectangle drawCheckBox(Graphics g, CheckboxState s) {
144:                Dimension size = s.getSize();
145:                boolean group = s.isInGroup();
146:                boolean pressed = s.isPressed();
147:                int x = ABS_MARGIN;
148:                int y = size.height / 2 - CB_SIZE / 2;
149:                Rectangle r = new Rectangle(x, y, CB_SIZE, CB_SIZE);
150:                if (!group) {
151:                    drawPressedRect(g, r, pressed);
152:                } else {
153:                    drawPressedCircle(g, r, pressed);
154:                }
155:
156:                return r;
157:            }
158:
159:            private static void drawPressedRect(Graphics g, Rectangle rect,
160:                    boolean pressed) {
161:                int w = rect.width;
162:                int h = rect.height;
163:                int x = rect.x;
164:                int y = rect.y;
165:                g.setColor(SystemColor.controlHighlight);
166:
167:                g.drawLine(x + w - 1, y, x + w - 1, y + h - 1);
168:                g.drawLine(x, y + h - 1, x + w - 1, y + h - 1);
169:                g.setColor(SystemColor.controlShadow);
170:                g.drawLine(x + 1, y + 1, x + w - 3, y + 1);
171:                g.drawLine(x + 1, y + 1, x + 1, y + h - 3);
172:                g.setColor(SystemColor.controlDkShadow);
173:                g.drawLine(x, y, x + w - 2, y);
174:                g.drawLine(x, y, x, y + h - 2);
175:                g.setColor(pressed ? pressedColor : SystemColor.window);
176:                g.fillRect(x + 2, y + 2, CB_SIZE - 2, CB_SIZE - 2);
177:            }
178:
179:            private static void drawPressedCircle(Graphics g, Rectangle rect,
180:                    boolean pressed) {
181:                int w = rect.width;
182:                int h = rect.height;
183:                int x = rect.x;
184:                int y = rect.y;
185:
186:                g.setColor(SystemColor.controlShadow);
187:                int startAngle = 45;
188:                int angle = 180;
189:                int endAngle = startAngle + angle;
190:                g.drawArc(x, y, w, h, startAngle, angle);
191:                g.setColor(SystemColor.controlDkShadow);
192:                g.drawArc(x + 1, y + 1, w - 1, h - 1, startAngle, angle);
193:
194:                g.setColor(SystemColor.controlHighlight);
195:                g.drawArc(x, y, w, h, endAngle, angle);
196:                g.setColor(SystemColor.controlLtHighlight);
197:                g.drawArc(x + 1, y + 1, w - 1, h - 1, endAngle, angle);
198:                g.setColor(pressed ? pressedColor : SystemColor.window);
199:                g.fillOval(x + 2, y + 2, CB_SIZE - 2, CB_SIZE - 2);
200:
201:            }
202:
203:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.