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


001:        /*
002:         * RolloverButton.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;
023:
024:        import java.awt.Color;
025:        import java.awt.Dimension;
026:        import java.awt.event.MouseListener;
027:        import java.awt.event.MouseEvent;
028:        import java.awt.Insets;
029:
030:        import javax.swing.JButton;
031:        import javax.swing.ImageIcon;
032:        import javax.swing.Action;
033:        import javax.swing.BorderFactory;
034:        import javax.swing.JToolTip;
035:        import javax.swing.UIManager;
036:        import javax.swing.border.Border;
037:        import org.underworldlabs.swing.plaf.UIUtils;
038:        import org.underworldlabs.swing.plaf.base.AcceleratorToolTipUI;
039:
040:        /* ----------------------------------------------------------
041:         * CVS NOTE: Changes to the CVS repository prior to the 
042:         *           release of version 3.0.0beta1 has meant a 
043:         *           resetting of CVS revision numbers.
044:         * ----------------------------------------------------------
045:         */
046:
047:        /**
048:         * This class creates a JButton where the borders are painted only
049:         * when the mouse is positioned over it. <br>
050:         *
051:         * When the mouse pointer is moved away from the button, the borders are removed.
052:         *
053:         * @author   Takis Diakoumis
054:         * @version  $Revision: 1.8 $
055:         * @date     $Date: 2006/07/15 12:52:21 $
056:         */
057:        public class RolloverButton extends JButton implements  MouseListener {
058:
059:            private String toolTip;
060:            private String imagePath;
061:            private String selectImagePath;
062:            private ImageIcon image;
063:            private ImageIcon selectImage;
064:            private boolean selectionEnabled;
065:
066:            private static Insets buttonInsets;
067:
068:            /**
069:             * Creates a new RolloverButton with an associated image
070:             * and tool tip.
071:             * 
072:             * @param img the ImageIcon to be displayed on the button
073:             * @param tip the button's tool tip
074:             */
075:            public RolloverButton(ImageIcon img, String tip) {
076:                super (img);
077:                toolTip = tip;
078:                init();
079:            }
080:
081:            /**
082:             * Creates a new RolloverButton with an associated image
083:             * and tool tip.
084:             * 
085:             * @param a the Action to be associated with this button
086:             * @param tip the button's tool tip
087:             */
088:            public RolloverButton(Action a, String tip) {
089:                super (a);
090:                toolTip = tip;
091:                init();
092:            }
093:
094:            /**
095:             * Creates a new RolloverButton with an associated image
096:             * and tool tip.
097:             * 
098:             * @param label the button's label
099:             * @param tip the button's tool tip
100:             */
101:            public RolloverButton(String label, String tip, int h, int w) {
102:                super (label);
103:                toolTip = tip;
104:                init();
105:                setButtonSize(h, w);
106:            }
107:
108:            /**
109:             * Creates a new RolloverButton with an associated image
110:             * and tool tip.
111:             * 
112:             * @param label the button's label
113:             * @param tip the button's tool tip
114:             */
115:            public RolloverButton(ImageIcon img, String tip, int h, int w) {
116:                super (img);
117:                toolTip = tip;
118:                init();
119:                setButtonSize(h, w);
120:            }
121:
122:            /**
123:             * Creates a new RolloverButton with an associated image
124:             * and tool tip.
125:             * 
126:             * @param imgPath the path relative to this class of
127:             *                  the button icon image
128:             * @param tip the button's tool tip
129:             */
130:            public RolloverButton(String imgPath, String tip) {
131:                this (imgPath, tip, -1);
132:            }
133:
134:            /**
135:             * Creates a new RolloverButton with an associated image
136:             * and tool tip.
137:             * 
138:             * @param imgPath the path relative to this class of
139:             *                  the button icon image
140:             * @param tip the button's tool tip
141:             */
142:            public RolloverButton(String imgPath, String tip, int size) {
143:                super ();
144:                setButtonIcon(imgPath);
145:                selectImagePath = null;
146:                toolTip = tip;
147:                init();
148:            }
149:
150:            public RolloverButton() {
151:                init();
152:            }
153:
154:            static {
155:                buttonInsets = new Insets(1, 1, 1, 1);
156:            }
157:
158:            /** 
159:             * Initialises the state of the button. 
160:             */
161:            private void init() {
162:                selectionEnabled = true;
163:                setMargin(buttonInsets);
164:                setToolTipText(toolTip);
165:                setBorderPainted(false);
166:                setContentAreaFilled(false);
167:                addMouseListener(this );
168:            }
169:
170:            /**
171:             * Resets the buttons rollover state.
172:             */
173:            public void reset() {
174:                mouseOver = false;
175:                setBorderPainted(false);
176:                setContentAreaFilled(false);
177:            }
178:
179:            private void setButtonSize(int height, int width) {
180:                setPreferredSize(new Dimension(width, height));
181:                setMaximumSize(new Dimension(width, height));
182:            }
183:
184:            /**
185:             * Sets the image associated with the button.
186:             *
187:             * @param path the path relative to this class of
188:             *               the button icon image
189:             */
190:            public void setButtonIcon(String path) {
191:                image = new ImageIcon(RolloverButton.class.getResource(path));
192:                setIcon(image);
193:            }
194:
195:            public void enableSelectionRollover(boolean enable) {
196:                selectionEnabled = enable;
197:            }
198:
199:            public boolean isSelectionRolloverEnabled() {
200:                return selectionEnabled;
201:            }
202:
203:            /** indicates a current rollover */
204:            private boolean mouseOver;
205:
206:            /**
207:             * Paints the button's borders as the mouse pointer enters.
208:             *
209:             * @param e the MouseEvent that created this event
210:             */
211:            public void mouseEntered(MouseEvent e) {
212:                if (isEnabled() && isSelectionRolloverEnabled()) {
213:                    mouseOver = true;
214:                    setBorderPainted(true);
215:                    setContentAreaFilled(true);
216:                }
217:            }
218:
219:            /** Override the <code>isFocusable()</code>
220:             *  method of <code>Component</code> (JDK1.4) to
221:             *  return false so the button never maintains
222:             *  the focus.
223:             *
224:             *  @return false
225:             */
226:            public boolean isFocusable() {
227:                return false;
228:            }
229:
230:            /**
231:             * Sets the button's borders unpainted as the mouse
232:             * pointer exits.
233:             *
234:             * @param e the MouseEvent that created this event
235:             */
236:            public void mouseExited(MouseEvent e) {
237:                mouseOver = false;
238:                setBorderPainted(false);
239:                setContentAreaFilled(false);
240:            }
241:
242:            public void mouseReleased(MouseEvent e) {
243:            }
244:
245:            public void mousePressed(MouseEvent e) {
246:            }
247:
248:            public void mouseClicked(MouseEvent e) {
249:            }
250:
251:            public JToolTip createToolTip() {
252:                JToolTip tip = new PaintedButtonToolTip();
253:                tip.setComponent(this );
254:                return tip;
255:            }
256:
257:            class PaintedButtonToolTip extends JToolTip {
258:                public void updateUI() {
259:                    setUI(new AcceleratorToolTipUI());
260:                }
261:            } // class PaintedButtonToolTip
262:
263:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.