Source Code Cross Referenced for BasicGraphicsUtils.java in  » Apache-Harmony-Java-SE » javax-package » javax » swing » plaf » basic » 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.basic 
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 Vadim L. Bogdanov
019:         * @version $Revision$
020:         */package javax.swing.plaf.basic;
021:
022:        import java.awt.Color;
023:        import java.awt.Dimension;
024:        import java.awt.FontMetrics;
025:        import java.awt.Graphics;
026:        import java.awt.Insets;
027:        import java.awt.Rectangle;
028:
029:        import javax.swing.AbstractButton;
030:
031:        import org.apache.harmony.x.swing.ButtonCommons;
032:        import org.apache.harmony.x.swing.Utilities;
033:
034:        /*
035:         * Appearence is taken from 1.5 release appearence.
036:         * Needs to be kept the same to 1.5 since client applications may use
037:         * this functionality in their UIs.
038:         */
039:        public class BasicGraphicsUtils {
040:            public static void drawEtchedRect(final Graphics g, final int x,
041:                    final int y, final int w, final int h, final Color shadow,
042:                    final Color darkShadow, final Color highlight,
043:                    final Color lightHighlight) {
044:                Color color = g.getColor();
045:
046:                drawTwoLines(g, shadow, x, y + h - 2, x, y, x + w - 2, y);
047:                drawTwoLines(g, darkShadow, x + 1, y + h - 3, x + 1, y + 1, x
048:                        + w - 3, y + 1);
049:                drawTwoLines(g, lightHighlight, x, y + h - 1, x + w - 1, y + h
050:                        - 1, x + w - 1, y);
051:                drawTwoLines(g, highlight, x + 1, y + h - 2, x + w - 2, y + h
052:                        - 2, x + w - 2, y + 1);
053:
054:                g.setColor(color);
055:            }
056:
057:            public static Insets getEtchedInsets() {
058:                return new Insets(2, 2, 2, 2);
059:            }
060:
061:            public static void drawGroove(final Graphics g, final int x,
062:                    final int y, final int w, final int h, final Color shadow,
063:                    final Color highlight) {
064:                drawLoweredBezel(g, x, y, w, h, highlight, shadow, shadow,
065:                        highlight);
066:            }
067:
068:            public static Insets getGrooveInsets() {
069:                return new Insets(2, 2, 2, 2);
070:            }
071:
072:            public static void drawBezel(final Graphics g, final int x,
073:                    final int y, final int w, final int h,
074:                    final boolean isPressed, final boolean isDefault,
075:                    final Color shadow, final Color darkShadow,
076:                    final Color highlight, final Color lightHighlight) {
077:                if (!isDefault) {
078:                    if (isPressed) {
079:                        drawLoweredBezel(g, x, y, w, h, shadow, darkShadow,
080:                                highlight, lightHighlight);
081:                    } else {
082:                        drawLoweredBezel(g, x, y, w, h, highlight,
083:                                lightHighlight, shadow, darkShadow);
084:                    }
085:                    return;
086:                }
087:
088:                Color color = g.getColor();
089:                if (isPressed) {
090:                    g.setColor(shadow);
091:                    g.drawRect(x + 1, y + 1, w - 3, h - 3);
092:                } else {
093:                    drawLoweredBezel(g, x + 1, y + 1, w - 2, h - 2, highlight,
094:                            lightHighlight, shadow, darkShadow);
095:                }
096:                g.setColor(darkShadow);
097:                g.drawRect(x, y, w - 1, h - 1);
098:                g.setColor(color);
099:            }
100:
101:            public static void drawLoweredBezel(final Graphics g, final int x,
102:                    final int y, final int w, final int h, final Color shadow,
103:                    final Color darkShadow, final Color highlight,
104:                    final Color lightHighlight) {
105:                drawEtchedRect(g, x, y, w, h, darkShadow, shadow, highlight,
106:                        lightHighlight);
107:            }
108:
109:            public static void drawString(final Graphics g, final String text,
110:                    final int underlinedChar, final int x, final int y) {
111:
112:                drawStringUnderlineCharAt(g, text, getDisplayedMnemonicIndex(
113:                        text, underlinedChar), x, y);
114:            }
115:
116:            public static void drawStringUnderlineCharAt(final Graphics g,
117:                    final String text, final int underlinedIndex, final int x,
118:                    final int y) {
119:                g.drawString(text, x, y);
120:                if (Utilities.insideString(text, underlinedIndex)) {
121:                    final Rectangle box = getStringUnderscoreBounds(g
122:                            .getFontMetrics(), text, underlinedIndex);
123:                    g.fillRect(x + box.x, y + box.y, box.width, box.height);
124:                }
125:            }
126:
127:            public static void drawDashedRect(final Graphics g, final int x,
128:                    final int y, final int width, final int height) {
129:                int maxX = x + width - 1;
130:                int maxY = y + height - 1;
131:                int dot;
132:                for (dot = x; dot < x + width; dot += 2) {
133:                    g.drawLine(dot, y, dot, y);
134:                    g.drawLine(dot, maxY, dot, maxY);
135:                }
136:                for (dot = y; dot < y + height; dot += 2) {
137:                    g.drawLine(x, dot, x, dot);
138:                    g.drawLine(maxX, dot, maxX, dot);
139:                }
140:            }
141:
142:            public static Dimension getPreferredButtonSize(
143:                    final AbstractButton b, final int textIconGap) {
144:                return ButtonCommons.getPreferredSize(b, null, textIconGap);
145:            }
146:
147:            private static void drawTwoLines(final Graphics g, final Color c,
148:                    final int x1, final int y1, final int x2, final int y2,
149:                    final int x3, final int y3) {
150:                int xs[] = { x1, x2, x3 };
151:                int ys[] = { y1, y2, y3 };
152:                g.setColor(c);
153:                g.drawPolyline(xs, ys, 3);
154:            }
155:
156:            private static Rectangle getStringUnderscoreBounds(
157:                    final FontMetrics fm, final String str,
158:                    final int underscoreIndex) {
159:                final int width = fm.charWidth(str.charAt(underscoreIndex));
160:                final int height = 1;
161:                final int x = underscoreIndex > 0 ? fm.stringWidth(str
162:                        .substring(0, underscoreIndex)) : 0;
163:                final int y = fm.getDescent() - height;
164:                return new Rectangle(x, y, width, height);
165:            }
166:
167:            private static int getDisplayedMnemonicIndex(final String text,
168:                    final int mnemonicChar) {
169:                if (text == null) {
170:                    return -1;
171:                }
172:
173:                int index = text.toUpperCase().indexOf(mnemonicChar);
174:                return index != -1 ? index : text.toLowerCase().indexOf(
175:                        mnemonicChar);
176:
177:                // TODO: uncomment after moving to 1.5
178:                //        return text != null
179:                //                ? text.toUpperCase().indexOf(Character.toUpperCase(mnemonicChar))
180:                //                : -1;
181:            }
182:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.