Source Code Cross Referenced for SmoothGradientToggleButtonUI.java in  » Database-Client » executequery » org » underworldlabs » swing » plaf » smoothgradient » 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 » Database Client » executequery » org.underworldlabs.swing.plaf.smoothgradient 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * SmoothGradientToggleButtonUI.java
003:         *
004:         * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis
005:         *
006:         * This program is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU General Public License
008:         * as published by the Free Software Foundation; either version 2
009:         * of the License, or any later version.
010:         *
011:         * This program is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014:         * GNU General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU General Public License
017:         * along with this program; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
019:         *
020:         */
021:
022:        package org.underworldlabs.swing.plaf.smoothgradient;
023:
024:        import java.awt.Container;
025:        import java.awt.Dimension;
026:        import java.awt.Font;
027:        import java.awt.FontMetrics;
028:        import java.awt.Graphics;
029:        import java.awt.Insets;
030:        import java.awt.Rectangle;
031:
032:        import javax.swing.AbstractButton;
033:        import javax.swing.ButtonModel;
034:        import javax.swing.JComponent;
035:        import javax.swing.JToolBar;
036:        import javax.swing.SwingUtilities;
037:        import javax.swing.UIManager;
038:        import javax.swing.plaf.ComponentUI;
039:        import javax.swing.plaf.basic.BasicHTML;
040:        import javax.swing.plaf.metal.MetalToggleButtonUI;
041:        import javax.swing.text.View;
042:
043:        /* ----------------------------------------------------------
044:         * CVS NOTE: Changes to the CVS repository prior to the 
045:         *           release of version 3.0.0beta1 has meant a 
046:         *           resetting of CVS revision numbers.
047:         * ----------------------------------------------------------
048:         */
049:
050:        /**
051:         *
052:         * @author   Takis Diakoumis
053:         * @version  $Revision: 1.4 $
054:         * @date     $Date: 2006/05/14 06:56:07 $
055:         */
056:        public class SmoothGradientToggleButtonUI extends MetalToggleButtonUI {
057:
058:            private static final SmoothGradientToggleButtonUI INSTANCE = new SmoothGradientToggleButtonUI();
059:
060:            /* 
061:             * Implementation note: The protected visibility prevents
062:             * the String value from being encrypted by the obfuscator.
063:             * An encrypted String key would break the client property lookup
064:             * in the #paint method below.
065:             */
066:            protected static final String HTML_KEY = BasicHTML.propertyKey;
067:
068:            private boolean borderPaintsFocus;
069:
070:            public static ComponentUI createUI(JComponent b) {
071:                return INSTANCE;
072:            }
073:
074:            /**
075:             * Installs defaults and honors the client property <code>isNarrow</code>.
076:             */
077:            public void installDefaults(AbstractButton b) {
078:                super .installDefaults(b);
079:                borderPaintsFocus = Boolean.TRUE.equals(UIManager
080:                        .get("ToggleButton.borderPaintsFocus"));
081:            }
082:
083:            public void update(Graphics g, JComponent c) {
084:                AbstractButton b = (AbstractButton) c;
085:                if (c.isOpaque()) {
086:                    if (isToolBarButton(b)) {
087:                        c.setOpaque(false);
088:                    } else if (b.isContentAreaFilled()) {
089:                        g.setColor(c.getBackground());
090:                        g.fillRect(0, 0, c.getWidth(), c.getHeight());
091:
092:                        Rectangle r = new Rectangle(1, 1, c.getWidth() - 2, c
093:                                .getHeight() - 1);
094:                        SmoothGradientUtils.add3DEffekt(g, r);
095:
096:                    }
097:                }
098:                paint(g, c);
099:            }
100:
101:            /**
102:             * Paints the focus close to the button's border.
103:             */
104:            protected void paintFocus(Graphics g, AbstractButton b,
105:                    Rectangle viewRect, Rectangle textRect, Rectangle iconRect) {
106:
107:                if (borderPaintsFocus)
108:                    return;
109:
110:                boolean isDefault = false;
111:                int topLeftInset = isDefault ? 3 : 2;
112:                int width = b.getWidth() - 1 - topLeftInset * 2;
113:                int height = b.getHeight() - 1 - topLeftInset * 2;
114:
115:                g.setColor(getFocusColor());
116:                g.drawRect(topLeftInset, topLeftInset, width - 1, height - 1);
117:            }
118:
119:            /**
120:             * Unlike the BasicToggleButtonUI.paint, we don't fill the content area;
121:             * this has been done by the update method before.
122:             */
123:            public void paint(Graphics g, JComponent c) {
124:                AbstractButton b = (AbstractButton) c;
125:                ButtonModel model = b.getModel();
126:
127:                Dimension size = b.getSize();
128:                FontMetrics fm = g.getFontMetrics();
129:
130:                Insets i = c.getInsets();
131:
132:                Rectangle viewRect = new Rectangle(size);
133:
134:                viewRect.x += i.left;
135:                viewRect.y += i.top;
136:                viewRect.width -= (i.right + viewRect.x);
137:                viewRect.height -= (i.bottom + viewRect.y);
138:
139:                Rectangle iconRect = new Rectangle();
140:                Rectangle textRect = new Rectangle();
141:
142:                Font f = c.getFont();
143:                g.setFont(f);
144:
145:                // layout the text and icon
146:                String text = SwingUtilities.layoutCompoundLabel(c, fm, b
147:                        .getText(), b.getIcon(), b.getVerticalAlignment(), b
148:                        .getHorizontalAlignment(), b.getVerticalTextPosition(),
149:                        b.getHorizontalTextPosition(), viewRect, iconRect,
150:                        textRect, b.getText() == null ? 0
151:                                : getDefaultTextIconGap(b));
152:                // [Pending 1.4]: b.getIconTextGap());
153:
154:                g.setColor(b.getBackground());
155:
156:                if (model.isArmed() && model.isPressed() || model.isSelected())
157:                    paintButtonPressed(g, b);
158:
159:                // Paint the Icon
160:                if (b.getIcon() != null)
161:                    paintIcon(g, b, iconRect);
162:
163:                // Draw the Text
164:                if (text != null && !text.equals("")) {
165:                    View v = (View) c.getClientProperty(HTML_KEY);
166:                    if (v != null) {
167:                        v.paint(g, textRect);
168:                    } else {
169:                        paintText(g, c, textRect, text);
170:                    }
171:                }
172:
173:                // draw the dashed focus line.
174:                if (b.isFocusPainted() && b.hasFocus()) {
175:                    paintFocus(g, b, viewRect, textRect, iconRect);
176:                }
177:            }
178:
179:            // Private Helper Code **************************************************************
180:
181:            /**
182:             * Checks and answers if this is button is in a tool bar.
183:             * 
184:             * @param b   the button to check
185:             * @return true if in tool bar, false otherwise
186:             */
187:            protected boolean isToolBarButton(AbstractButton b) {
188:                Container parent = b.getParent();
189:                return parent != null
190:                        && (parent instanceof  JToolBar || parent.getParent() instanceof  JToolBar);
191:            }
192:
193:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.