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


001:        package org.wingx.plaf.css;
002:
003:        import java.text.DateFormat;
004:        import java.text.Format;
005:        import java.text.SimpleDateFormat;
006:        import java.util.ArrayList;
007:        import java.util.Calendar;
008:        import java.util.Collections;
009:        import java.util.Date;
010:        import java.util.GregorianCalendar;
011:        import java.util.List;
012:
013:        import org.wings.SDimension;
014:        import org.wings.SFormattedTextField;
015:        import org.wings.SResourceIcon;
016:        import org.wings.header.Header;
017:        import org.wings.header.SessionHeaders;
018:        import org.wings.io.Device;
019:        import org.wings.plaf.Update;
020:        import org.wings.plaf.css.AbstractComponentCG;
021:        import org.wings.plaf.css.AbstractUpdate;
022:        import org.wings.plaf.css.UpdateHandler;
023:        import org.wings.plaf.css.Utils;
024:        import org.wings.plaf.css.script.OnHeadersLoadedScript;
025:        import org.wings.session.ScriptManager;
026:        import org.wings.util.SStringBuilder;
027:        import org.wingx.XCalendar;
028:
029:        /**
030:         * @author <a href="mailto:e.habicht@thiesen.com">Erik Habicht</a>
031:         * @author Stephan Schuster
032:         */
033:        public class CalendarCG extends AbstractComponentCG<XCalendar>
034:                implements  org.wingx.plaf.CalendarCG<XCalendar> {
035:
036:            private static final long serialVersionUID = 1L;
037:
038:            protected final static List<Header> headers;
039:
040:            static {
041:                String[] images = new String[] {
042:                        "org/wingx/calendar/calcd.gif",
043:                        "org/wingx/calendar/cally.gif",
044:                        "org/wingx/calendar/calry.gif" };
045:
046:                for (int x = 0, y = images.length; x < y; x++) {
047:                    new SResourceIcon(images[x]).getId();
048:                }
049:
050:                List<Header> headerList = new ArrayList<Header>();
051:                headerList
052:                        .add(Utils
053:                                .createExternalizedCSSHeaderFromProperty(Utils.CSS_YUI_ASSETS_CALENDAR));
054:                headerList
055:                        .add(Utils
056:                                .createExternalizedJSHeaderFromProperty(Utils.JS_YUI_CALENDAR));
057:                headerList
058:                        .add(Utils
059:                                .createExternalizedJSHeader("org/wingx/calendar/calendar.js"));
060:                headers = Collections.unmodifiableList(headerList);
061:            }
062:
063:            public CalendarCG() {
064:            }
065:
066:            public void installCG(XCalendar component) {
067:                super .installCG(component);
068:                SessionHeaders.getInstance().registerHeaders(headers);
069:            }
070:
071:            public void uninstallCG(XCalendar component) {
072:                super .uninstallCG(component);
073:                SessionHeaders.getInstance().deregisterHeaders(headers);
074:            }
075:
076:            public void writeInternal(Device device, XCalendar component)
077:                    throws java.io.IOException {
078:                final String idPrefix = "_cal_";
079:                final String idComponent = component.getName();
080:                final String idValue = idPrefix + idComponent + "_val";
081:                final String idButton = idPrefix + idComponent + "_btn";
082:                final String idContainer = idPrefix + idComponent + "_con";
083:                final String idCalendar = idPrefix + idComponent + "_cal";
084:
085:                SFormattedTextField fTextField = component
086:                        .getFormattedTextField();
087:                SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
088:                dateFormat.setTimeZone(component.getTimeZone());
089:
090:                device.print("<table");
091:                Utils.writeAllAttributes(device, component);
092:                device.print("><tr><td class=\"tf\" width=\"*\"");
093:                int oversizePadding = Utils.calculateHorizontalOversize(
094:                        fTextField, true);
095:                if (oversizePadding != 0)
096:                    Utils.optAttribute(device, "oversize", oversizePadding);
097:                device.print('>');
098:
099:                SDimension preferredSize = component.getPreferredSize();
100:                if (preferredSize != null && preferredSize.getWidth() != null
101:                        && "auto".equals(preferredSize.getWidth()))
102:                    fTextField.setPreferredSize(SDimension.FULLWIDTH);
103:                fTextField.setEnabled(component.isEnabled());
104:                fTextField.write(device);
105:
106:                device.print("\n</td><td class=\"bu\" width=\"1\">\n");
107:
108:                device.print("<input type=\"hidden\" id=\"").print(idValue)
109:                        .print("\" name=\"").print(idValue)
110:                        .print("\" value=\"").print(
111:                                format(dateFormat, component.getDate())).print(
112:                                "\">\n");
113:                device.print("<img id=\"").print(idButton).print("\" src=\"")
114:                        .print(component.getEditIcon().getURL()).print(
115:                                "\" />\n");
116:                device
117:                        .print("<div class=\"container\" id=\"")
118:                        .print(idContainer)
119:                        .print(
120:                                "\"><div class=\"hd\"></div><div class=\"bd\"><div class=\"calendar\" id=\"")
121:                        .print(idCalendar).print("\"></div></div></div></td>");
122:
123:                writeTableSuffix(device, component);
124:
125:                if (component.isEnabled()) {
126:                    SimpleDateFormat format_months_long = new SimpleDateFormat(
127:                            "MMMMM");
128:                    format_months_long.setTimeZone(component.getTimeZone());
129:                    SimpleDateFormat format_weekdays_short = new SimpleDateFormat(
130:                            "EE");
131:                    format_weekdays_short.setTimeZone(component.getTimeZone());
132:
133:                    SStringBuilder script = new SStringBuilder(
134:                            "new wingS.calendar.XCalendar(")
135:                            .append('"')
136:                            .append(component.getName())
137:                            .append("\",\"")
138:                            .append(component.getParentFrame().getName())
139:                            .append("\", {iframe:false,")
140:                            .append("months_long:")
141:                            .append(createMonthsString(format_months_long))
142:                            .append(',')
143:                            .append("weekdays_short:")
144:                            .append(createWeekdaysString(format_weekdays_short))
145:                            .append(',')
146:                            .append("start_weekday:")
147:                            .append(
148:                                    (Calendar.getInstance().getFirstDayOfWeek() - 1))
149:                            .append("}").append(");");
150:
151:                    ScriptManager.getInstance().addScriptListener(
152:                            new OnHeadersLoadedScript(script.toString(), true));
153:                }
154:
155:            }
156:
157:            private String createMonthsString(Format format) {
158:                SStringBuilder stringBuilder = new SStringBuilder();
159:                stringBuilder.append('[');
160:                Calendar cal = new GregorianCalendar();
161:                cal.set(Calendar.MONTH, Calendar.JANUARY);
162:                for (int x = 0, y = 12; x < y; x++) {
163:                    stringBuilder.append('"');
164:                    stringBuilder.append(format.format(cal.getTime()));
165:                    stringBuilder.append("\",");
166:                    cal.add(Calendar.MONTH, 1);
167:                }
168:                stringBuilder.deleteCharAt(stringBuilder.length() - 1);
169:                stringBuilder.append(']');
170:                return stringBuilder.toString();
171:            }
172:
173:            private String createWeekdaysString(Format format) {
174:                SStringBuilder stringBuilder = new SStringBuilder();
175:                stringBuilder.append('[');
176:                Calendar cal = new GregorianCalendar();
177:                cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
178:                for (int x = 0, y = 7; x < y; x++) {
179:                    stringBuilder.append('"');
180:                    stringBuilder.append(format.format(cal.getTime()));
181:                    stringBuilder.append("\",");
182:                    cal.add(Calendar.DAY_OF_WEEK, 1);
183:                }
184:                stringBuilder.deleteCharAt(stringBuilder.length() - 1);
185:                stringBuilder.append(']');
186:                return stringBuilder.toString();
187:            }
188:
189:            private String format(DateFormat dateFormat, Date date) {
190:                return date != null ? dateFormat.format(date) : "";
191:            }
192:
193:            public Update getHiddenUpdate(XCalendar cal, Date date) {
194:                return new HiddenUpdate(cal, date);
195:            }
196:
197:            protected static class HiddenUpdate extends
198:                    AbstractUpdate<XCalendar> {
199:
200:                private Date date;
201:                private SimpleDateFormat format;
202:
203:                public HiddenUpdate(XCalendar cal, Date date) {
204:                    super (cal);
205:                    this .date = date;
206:                    this .format = new SimpleDateFormat("MM/dd/yyyy");
207:                }
208:
209:                public Handler getHandler() {
210:                    UpdateHandler handler = new UpdateHandler("value");
211:                    handler.addParameter(component.getName() + "val");
212:                    handler.addParameter(date == null ? "" : format
213:                            .format(date));
214:                    return handler;
215:                }
216:            }
217:
218:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.