Source Code Cross Referenced for XColorPicker.java in  » Swing-Library » wings3 » org » wingx » 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 » Swing Library » wings3 » org.wingx 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2000,2006 wingS development team.
003:         *
004:         * This file is part of wingS (http://wingsframework.org).
005:         *
006:         * wingS is free software; you can redistribute it and/or modify
007:         * it under the terms of the GNU Lesser General Public License
008:         * as published by the Free Software Foundation; either version 2.1
009:         * of the License, or (at your option) any later version.
010:         *
011:         * Please see COPYING for the complete licence.
012:         */
013:
014:        package org.wingx;
015:
016:        import java.awt.Color;
017:        import javax.swing.event.ChangeEvent;
018:        import org.wings.LowLevelEventListener;
019:        import org.wings.SComponent;
020:        import org.wings.ReloadManager;
021:        import org.wings.SForm;
022:        import org.wings.event.SAjaxChangeListener;
023:        import org.wings.session.Session;
024:        import org.wings.session.SessionManager;
025:        import org.wingx.plaf.css.ColorPickerCG;
026:
027:        /**
028:         * A component to choose a color. Adopted and enhanced from the YUI library examples
029:         * (see http://developer.yahoo.com/yui/slider/).
030:         */
031:        public class XColorPicker extends SComponent implements 
032:                LowLevelEventListener, XColorPickerInterface {
033:
034:            /**
035:             * red RGB part
036:             */
037:            private int red = 255;
038:
039:            /**
040:             * green RGB part
041:             */
042:            private int green = 255;
043:
044:            /**
045:             * blue RGB part
046:             */
047:            private int blue = 255;
048:
049:            /**
050:             * @see #setImmediateUpdate(boolean b)
051:             */
052:            private boolean immediateUpdate = true;
053:
054:            /**
055:             * Ajax request timeout in ms
056:             */
057:            private int timeout = 5000;
058:
059:            private ReloadManager reloadManager = SessionManager.getSession()
060:                    .getReloadManager();
061:
062:            /**
063:             * Creates a color picker with the default color (white) and immediate
064:             * updates.
065:             * @see #setImmediateUpdate(boolean b)
066:             */
067:            public XColorPicker() {
068:                ((ColorPickerCG) getCG()).prepareIds(this );
069:            }
070:
071:            /**
072:             * Creates a color picker with the given color set as default and
073:             * immediate updates.
074:             * @param red
075:             * @param green
076:             * @param blue
077:             * @see #setImmediateUpdate(boolean b)
078:             */
079:            public XColorPicker(int red, int green, int blue) {
080:                this ();
081:                this .red = red;
082:                this .green = green;
083:                this .blue = blue;
084:            }
085:
086:            /**
087:             * Creates a color picker with the given color and immediate update
088:             * option set.
089:             * @param red
090:             * @param green
091:             * @param blue
092:             * @param immediateUpdate see setImmediateUpdate(boolean b)
093:             */
094:            public XColorPicker(int red, int green, int blue,
095:                    boolean immediateUpdate) {
096:                this (red, green, blue);
097:                this .immediateUpdate = immediateUpdate;
098:            }
099:
100:            /**
101:             * @return color selected by user
102:             */
103:            public Color getSelectedColor() {
104:                return new Color(red, green, blue);
105:            }
106:
107:            public boolean setSelectedColor(int red, int green, int blue) {
108:                Color oldColor = this .getSelectedColor();
109:
110:                this .red = red;
111:                this .green = green;
112:                this .blue = blue;
113:
114:                Color newColor = this .getSelectedColor();
115:
116:                if (newColor != oldColor) {
117:                    fireStateChanged();
118:                    if (this .immediateUpdate
119:                            && reloadManager.getDirtyFrames().contains(
120:                                    this .getParentFrame()))
121:                        return true;
122:                }
123:
124:                return false;
125:            }
126:
127:            /**
128:             * If true (which is the default) all dirty components will be requested to
129:             * refresh after a change of this component.
130:             * @see #setSelectedColor(int red, int green, int blue)
131:             */
132:            public void setImmediateUpdate(boolean b) {
133:                this .immediateUpdate = b;
134:            }
135:
136:            /**
137:             * @see #setImmediateUpdate(boolean b)
138:             */
139:            public boolean isImmediateUpdate() {
140:                return this .immediateUpdate;
141:            }
142:
143:            /**
144:             * Adds the specified <code>SAjaxChangeListener</code> to the color picker.
145:             * @param l the <code>SAjaxChangeListener</code> to add
146:             */
147:            public void addAjaxChangeListener(SAjaxChangeListener l) {
148:                addEventListener(SAjaxChangeListener.class, l);
149:            }
150:
151:            /**
152:             * Removes a <code>SAjaxChangeListener</code> from the color picker.
153:             *
154:             * @param l the <code>SAjaxChangeListener</code> to remove
155:             */
156:            public void removeAjaxChangeListener(SAjaxChangeListener l) {
157:                removeEventListener(SAjaxChangeListener.class, l);
158:            }
159:
160:            /**
161:             * Returns an array of all the <code>SAjaxChangeListener</code>s added
162:             * to this color picker with <code>addAjaxChangeListener</code>.
163:             *
164:             * @return all of the <code>SAjaxChangeListener</code>s added or an empty
165:             *         array if no listeners have been added
166:             */
167:            public SAjaxChangeListener[] getAjaxChangeListeners() {
168:                return (SAjaxChangeListener[]) getListeners(SAjaxChangeListener.class);
169:            }
170:
171:            public boolean hasAjaxChangeListener() {
172:                return (getListenerCount(SAjaxChangeListener.class) > 0) ? true
173:                        : false;
174:            }
175:
176:            /**
177:             * Notifies all listeners that have registered interest in
178:             * <code>ChangeEvent</code>s.
179:             */
180:            protected void fireStateChanged() {
181:                SAjaxChangeListener[] listeners = (SAjaxChangeListener[]) getListeners(SAjaxChangeListener.class);
182:                for (int i = 0; i < listeners.length; i++) {
183:                    SAjaxChangeListener listener = listeners[i];
184:                    listener.stateChanged(new ChangeEvent(this ));
185:                }
186:            }
187:
188:            public void fireFinalEvents() {
189:                fireStateChanged();
190:            }
191:
192:            public void fireIntermediateEvents() {
193:                // nothing to do
194:            }
195:
196:            public boolean isEpochCheckEnabled() {
197:                return true;
198:            }
199:
200:            public void processLowLevelEvent(String action, String[] values) {
201:                processKeyEvents(values);
202:                if (action.endsWith("_keystroke"))
203:                    return;
204:
205:                Color oldColor = this .getSelectedColor();
206:
207:                String rAction = (String) this 
208:                        .getClientProperty("pickerRvalId");
209:                String gAction = (String) this 
210:                        .getClientProperty("pickerGvalId");
211:                String bAction = (String) this 
212:                        .getClientProperty("pickerBvalId");
213:
214:                int newRed = this .red;
215:                int newGreen = this .green;
216:                int newBlue = this .blue;
217:
218:                if (action.compareTo(rAction) == 0) {
219:                    newRed = Integer.parseInt(values[0]);
220:                } else if (action.compareTo(gAction) == 0) {
221:                    newGreen = Integer.parseInt(values[0]);
222:                } else if (action.compareTo(bAction) == 0) {
223:                    newBlue = Integer.parseInt(values[0]);
224:                }
225:
226:                Color newColor = new Color(newRed, newGreen, newBlue);
227:
228:                if (oldColor != newColor) {
229:                    this .red = newRed;
230:                    this .green = newGreen;
231:                    this .blue = newBlue;
232:                    SForm.addArmedComponent(this );
233:                }
234:
235:            }
236:
237:            /**
238:             * Set Ajax request timeout.
239:             * @param timeout in ms
240:             */
241:            public void setTimeout(int timeout) {
242:                int oldTimeout = this .timeout;
243:                this .timeout = timeout;
244:                reloadIfChange(oldTimeout, timeout);
245:            }
246:
247:            /**
248:             * @see org.wingx.XSuggest#setTimeout(int timeout)
249:             */
250:            public int getTimeout() {
251:                return timeout;
252:            }
253:
254:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.