Source Code Cross Referenced for XGraphicButton.java in  » XML-UI » xui32 » com » xoetrope » awt » 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 » XML UI » xui32 » com.xoetrope.awt 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.xoetrope.awt;
002:
003:        import java.awt.Color;
004:        import java.awt.Dimension;
005:        import java.awt.Font;
006:        import java.awt.FontMetrics;
007:        import java.awt.Graphics;
008:        import java.awt.geom.Rectangle2D;
009:
010:        import net.xoetrope.awt.XLabel;
011:        import net.xoetrope.xui.XProject;
012:        import net.xoetrope.xui.XProjectManager;
013:        import net.xoetrope.xui.style.XStyleFactory;
014:
015:        /**
016:         * A graphical button that is drawn with rounded edges.
017:         * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
018:         * the GNU Public License (GPL), please see license.txt for more details. If
019:         * you make commercial use of this software you must purchase a commercial
020:         * license from Xoetrope.</p>
021:         * $Revision: 1.3 $ not attributable
022:         */
023:        public class XGraphicButton extends XLabel {
024:            /**
025:             * Rounded edges, but no fill
026:             */
027:            public static final int LINE_STYLE = 0;
028:
029:            /**
030:             * Rounded edges and filled
031:             */
032:            public static final int SOLID_STYLE = 1;
033:
034:            /**
035:             * Rounded corner on the bottom right corner
036:             */
037:            public static final int BOTTOM_RIGHT_STYLE = 2;
038:
039:            /**
040:             * Rounded corner on the bottom left corner
041:             */
042:            public static final int BOTTOM_LEFT_STYLE = 3;
043:
044:            private int drawStyle;
045:            private boolean drawArrow = true;
046:            private boolean center = false;
047:            private XStyleFactory componentFactory;
048:
049:            public XGraphicButton() {
050:                XProject currentProject = XProjectManager.getCurrentProject();
051:                componentFactory = new XStyleFactory(currentProject,
052:                        "net.xoetrope.awt");
053:                componentFactory.setResourceBundle(currentProject
054:                        .getStartupParam("Language"));
055:            }
056:
057:            public XGraphicButton(String title) {
058:                this (title, LINE_STYLE);
059:            }
060:
061:            public XGraphicButton(String title, int style) {
062:                super ();
063:                drawStyle = style;
064:                setText(title);
065:            }
066:
067:            /**
068:             * Set the button style
069:             * @param style "0"=LINE_STYLE, "1"=SOLID_STYLE, "2"=BOTTOM_RIGHT_STYLE, "3"=BOTTOM_LEFT_STYLE
070:             */
071:            public void setDrawStyle(String style) {
072:                drawStyle = Integer.parseInt(style);
073:            }
074:
075:            /**
076:             * Set the button style
077:             * @param style LINE_STYLE, SOLID_STYLE, BOTTOM_RIGHT_STYLE, BOTTOM_LEFT_STYLE
078:             */
079:            public void setDrawStyle(int style) {
080:                drawStyle = style;
081:            }
082:
083:            /**
084:             * Set the button caption
085:             * @param title the text to display
086:             */
087:            public void setTitle(String title) {
088:                setText(componentFactory.translate(title));
089:            }
090:
091:            /**
092:             * Set the attributes of the button, see setDrawStyle
093:             * @param attribName the attribute name
094:             * @param attribValue the attribute value
095:             */
096:            public void setAttribute(String attribName, String attribValue) {
097:                String attribNameLwr = attribName.toLowerCase();
098:                String attribValueLwr = attribValue.toLowerCase();
099:                if (attribNameLwr.compareTo("drawstyle") == 0)
100:                    setDrawStyle(attribValueLwr);
101:                else
102:                    super .setAttribute(attribName, attribValue);
103:            }
104:
105:            public void paint(Graphics g) {
106:                switch (drawStyle) {
107:                case LINE_STYLE:
108:                    drawLineStyle(g);
109:                    break;
110:                case SOLID_STYLE:
111:                    drawSolidStyle(g);
112:                    drawRightArrow(g);
113:                    break;
114:                case BOTTOM_RIGHT_STYLE:
115:                    drawSolidStyle(g);
116:                    completeBotRightStyle(g);
117:                    drawRightArrow(g);
118:                    break;
119:                case BOTTOM_LEFT_STYLE:
120:                    drawSolidStyle(g);
121:                    completeBotLeftStyle(g);
122:                    drawLeftArrow(g);
123:                    break;
124:                }
125:                drawText(g);
126:            }
127:
128:            private void drawText(Graphics g) {
129:                Font f = new Font("Arial", Font.BOLD, 12);
130:                g.setFont(f);
131:
132:                if (drawStyle == BOTTOM_LEFT_STYLE) {
133:                    FontMetrics fm = g.getFontMetrics(f);
134:                    Rectangle2D rect = fm.getStringBounds(getText(), g);
135:                    g
136:                            .drawString(
137:                                    getText(),
138:                                    34/*getSize().width - rect.getBounds().width - 8*/,
139:                                    14);
140:                } else if (center) {
141:                    FontMetrics fm = g.getFontMetrics(f);
142:                    Rectangle2D rect = fm.getStringBounds(getText(), g);
143:                    int mid = getSize().width / 2;
144:                    mid = mid - (rect.getBounds().width / 2);
145:                    g.drawString(getText(), mid, 14);
146:                } else {
147:                    g.drawString(getText(), 10, 14);
148:                }
149:            }
150:
151:            private void drawLineStyle(Graphics g) {
152:                Dimension size = getSize();
153:                int w = size.width;
154:                g.setColor(Color.red);
155:                g.drawRoundRect(0, 0, w - 1, size.height - 1, 16, 16);
156:                drawRightArrow(g);
157:                g.setColor(Color.red);
158:            }
159:
160:            private void drawSolidStyle(Graphics g) {
161:                Dimension size = getSize();
162:                int w = size.width;
163:                g.setColor(Color.red);
164:                g.fillRoundRect(0, 0, w, size.height - 1, 16, 16);
165:                g.setColor(Color.white);
166:            }
167:
168:            private void completeBotRightStyle(Graphics g) {
169:                g.setColor(Color.red);
170:                int w = getSize().width;
171:                g.fillRect(0, 0, w, 10);
172:                g.setColor(Color.white);
173:                //    drawRightArrow( g );
174:                g.fillRect(w - 27, 0, 3, getSize().height);
175:            }
176:
177:            private void completeBotLeftStyle(Graphics g) {
178:                g.setColor(Color.red);
179:                int w = getSize().width;
180:                g.fillRect(0, 0, w, 10);
181:                g.setColor(Color.white);
182:                //    drawLeftArrow( g );
183:                g.fillRect(27, 0, 3, getSize().height);
184:            }
185:
186:            private void drawRightArrow(Graphics g) {
187:                if (!drawArrow)
188:                    return;
189:
190:                int w = getSize().width;
191:
192:                g.fillOval(w - 8, 9, 2, 2);
193:                g.fillOval(w - 11, 9, 2, 2);
194:                g.fillOval(w - 14, 9, 2, 2);
195:                g.fillOval(w - 17, 9, 2, 2);
196:                g.fillOval(w - 20, 9, 2, 2);
197:
198:                g.fillOval(w - 12, 5, 2, 2);
199:                g.fillOval(w - 10, 7, 2, 2);
200:                g.fillOval(w - 10, 11, 2, 2);
201:                g.fillOval(w - 12, 13, 2, 2);
202:            }
203:
204:            private void drawLeftArrow(Graphics g) {
205:                if (!drawArrow)
206:                    return;
207:
208:                int w = getSize().width;
209:
210:                g.fillOval(8, 9, 2, 2);
211:                g.fillOval(11, 9, 2, 2);
212:                g.fillOval(14, 9, 2, 2);
213:                g.fillOval(17, 9, 2, 2);
214:                g.fillOval(20, 9, 2, 2);
215:
216:                g.fillOval(12, 5, 2, 2);
217:                g.fillOval(10, 7, 2, 2);
218:                g.fillOval(10, 11, 2, 2);
219:                g.fillOval(12, 13, 2, 2);
220:            }
221:
222:            public void update(Graphics g) {
223:                paint(g);
224:            }
225:
226:            public void doLayout() {
227:                super .doLayout();
228:                repaint();
229:            }
230:
231:            /**
232:             * Center the text
233:             * @param c true to center the text
234:             */
235:            public void setCentered(boolean c) {
236:                center = c;
237:            }
238:
239:            /**
240:             * Turn on drawing of the arrow
241:             * @param draw true to draw the arrow
242:             */
243:            public void setDrawArrow(boolean draw) {
244:                drawArrow = draw;
245:            }
246:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.