📄 datepicker.java
字号:
* Append javascript to the initialization function for the YUI widget. Can be used by * subclasses to conveniently extend configuration without having to write a separate * contribution. * * @param markupId * The markup id of the calendar component * @param javascriptId * the non-name spaced javascript id of the widget * @param javascriptWidgetId * the name space id of the widget * @param b * the buffer to append the script to */ protected void appendToInit(String markupId, String javascriptId, String javascriptWidgetId, StringBuffer b) { } /** * Gives overriding classes the option of adding (or even changing/ removing) configuration * properties for the javascript widget. See <a * href="http://developer.yahoo.com/yui/calendar/">the widget's documentation</a> for the * available options. If you want to override/ remove properties, you should call * {@link super#setWidgetProperties(Properties)} first. If you don't call that, be aware that * you will have to call {@link #localize(Map)} manually if you like localized strings to be * added. * * @param widgetProperties * the current widget properties */ protected void configure(Map widgetProperties) { widgetProperties.put("close", Boolean.TRUE); // localize date fields localize(widgetProperties); Object modelObject = component.getModelObject(); // null and cast check if (modelObject instanceof Date) { Date date = (Date)modelObject; widgetProperties.put("selected", FORMAT_DATE.format(date)); widgetProperties.put("pagedate", FORMAT_PAGEDATE.format(date)); } } /** * @deprecated Please use {@link #configure(Map)} instead. */ // TODO remove this very ugly named method protected final void configureWidgetProperties(Map widgetProperties) { throw new UnsupportedOperationException(""); } /** * Filter all empty elements (workaround for {@link DateFormatSymbols} returning arrays with * empty elements). * * @param array * array to filter * @return filtered array (without null or empty string elements) */ protected final String[] filterEmpty(String[] array) { if (array == null) { return null; } List l = new ArrayList(array.length); for (int i = 0; i < array.length; i++) { if (!Strings.isEmpty(array[i])) { l.add(array[i]); } } return (String[])l.toArray(new String[l.size()]); } /** * Gets the id of the component that the calendar widget will get attached to. * * @return The DOM id of the component */ protected final String getComponentMarkupId() { return component.getMarkupId(); } /** * Gets the date pattern to use for putting selected values in the coupled component. * * @return The date pattern */ protected String getDatePattern() { String format = null; if (component instanceof ITextFormatProvider) { format = ((ITextFormatProvider)component).getTextFormat(); // it is possible that components implement ITextFormatProvider but // don't provide a format } if (format == null) { IConverter converter = component.getConverter(DateTime.class); if (!(converter instanceof DateConverter)) { converter = component.getConverter(Date.class); } format = ((SimpleDateFormat)((DateConverter)converter).getDateFormat(component .getLocale())).toPattern(); } return format; } /** * Gets the escaped DOM id that the calendar widget will get attached to. All non word * characters (\W) will be removed from the string. * * @return The DOM id of the calendar widget - same as the component's markup id + 'Dp'} */ protected final String getEscapedComponentMarkupId() { return component.getMarkupId().replaceAll("\\W", ""); } /** * Gets the id of the icon that triggers the popup. * * @return The id of the icon */ protected final String getIconId() { return getEscapedComponentMarkupId() + "Icon"; } /** * Gets the style of the icon that triggers the popup. * * @return The style of the icon, e.g. 'cursor: point' etc. */ protected String getIconStyle() { return "cursor: pointer; border: none;"; } /** * Gets the url for the popup button. Users can override to provide their own icon URL. * * @return the url to use for the popup button/ icon */ protected CharSequence getIconUrl() { return RequestCycle.get().urlFor(new ResourceReference(DatePicker.class, "icon1.gif")); } /** * Gets the locale that should be used to configure this widget. * * @return By default the locale of the bound component. */ protected Locale getLocale() { return component.getLocale(); } /** * Configure the localized strings for the datepicker widget. This implementation uses * {@link DateFormatSymbols} and some slight string manupilation to get the strings for months * and week days. Also, the first week day is set according to the {@link Locale} returned by * {@link #getLocale()}. It should work well for most locales. * <p> * This method is called from {@link #configureWidgetProperties(Map)} and can be overridden if * you want to customize setting up the localized strings but are happy with the rest of * {@link #configureWidgetProperties(Map)}'s behavior. Note that you can call (overridable) * method {@link #getLocale()} to get the locale that should be used for setting up the widget. * </p> * <p> * See YUI Calendar's <a href="http://developer.yahoo.com/yui/examples/calendar/germany/1.html"> * German</a> and <a * href="http://developer.yahoo.com/yui/examples/calendar/japan/1.html">Japanese</a> examples * for more info. * </p> * * @param widgetProperties * the current widget properties */ protected void localize(Map widgetProperties) { DateFormatSymbols dfSymbols = new DateFormatSymbols(getLocale()); if (Locale.SIMPLIFIED_CHINESE.equals(getLocale())) { dfSymbols.setShortWeekdays(new String[] { "", "\u65E5", "\u4E00", "\u4E8C", "\u4E09", "\u56DB", "\u4E94", "\u516D" }); } setWidgetProperty(widgetProperties, "MONTHS_SHORT", filterEmpty(dfSymbols.getShortMonths())); setWidgetProperty(widgetProperties, "MONTHS_LONG", filterEmpty(dfSymbols.getMonths())); setWidgetProperty(widgetProperties, "WEEKDAYS_1CHAR", filterEmpty(substring(dfSymbols .getShortWeekdays(), 1))); setWidgetProperty(widgetProperties, "WEEKDAYS_SHORT", filterEmpty(substring(dfSymbols .getShortWeekdays(), 2))); setWidgetProperty(widgetProperties, "WEEKDAYS_MEDIUM", filterEmpty(dfSymbols .getShortWeekdays())); setWidgetProperty(widgetProperties, "WEEKDAYS_LONG", filterEmpty(dfSymbols.getWeekdays())); widgetProperties.put("START_WEEKDAY", new Integer(Calendar.getInstance(getLocale()) .getFirstDayOfWeek() - 1)); } /** * Whether to notify the associated component when a date is selected. Notifying is done by * calling the associated component's onchange Javascript event handler. You can for instance * attach an {@link AjaxEventBehavior} to that component to get a call back to the server. The * default is true. * * @return if true, notifies the associated component when a date is selected */ protected boolean notifyComponentOnDateSelected() { return true; } /** * Makes a copy of the provided array and for each element copy the substring 0..len to the new * array * * @param array * array to copy from * @param len * size of substring for each element to copy * @return copy of the array filled with substrings. */ protected final String[] substring(String[] array, int len) { if (array != null) { String[] copy = new String[array.length]; for (int i = 0; i < array.length; i++) { String el = array[i]; if (el != null) { if (el.length() > len) { copy[i] = el.substring(0, len); } else { copy[i] = el; } } } return copy; } return null; } /** * Indicates whether plain text is rendered or two select boxes are used to allow direct * selection of month and year. * * @return <code>true</code> if select boxes should be rendered to allow month and year * selection.<br/><code>false</code> to render just plain text. */ protected boolean enableMonthYearSelection() { return false; } /** * Indicates whether the calendar should be hidden after a date was selected. * * @return <code>true</code> (default) if the calendar should be hidden after the date * selection <br/><code>false</code> if the calendar should remain visible after the * date selection. */ protected boolean hideOnSelect() { return true; } /** * Indicates whether the calendar should be rendered after it has been loaded. * * @return <code>true</code> if the calendar should be rendered after it has been loaded.<br/><code>false</code> * (default) if it's initially hidden. */ protected boolean renderOnLoad() { return false; } /** * Override this method to further customize the YUI Calendar with additional Javascript code. * The code returned by this method is executed right after the Calendar has been constructed * and initialized. To refer to the actual Calendar DOM object, use <code>${calendar}</code> * in your code.<br/>See <a href="http://developer.yahoo.com/yui/calendar/">the widget's * documentation</a> for more information about the YUI Calendar.<br/> Example: * * <pre> * protected String getAdditionalJavascript() * { * return "${calendar}.addRenderer(\"10/3\", ${calendar}.renderCellStyleHighlight1);"; * } * </pre> * * @return a String containing additional Javascript code * */ protected String getAdditionalJavascript() { return ""; } /** * @see org.apache.wicket.behavior.AbstractBehavior#isEnabled(org.apache.wicket.Component) */ public boolean isEnabled(Component component) { return component.isEnabled() && component.isEnableAllowed(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -