AquaSpinnerUI.java 文件源码

java
阅读 27 收藏 0 点赞 0 评论 0

项目:infobip-open-jdk-8 作者:
/**
 * Returns the calendarField under the start of the selection, or
 * -1 if there is no valid calendar field under the selection (or
 * the spinner isn't editing dates.
 */
private int getCalendarField(final JSpinner spinnerComponent) {
    final JComponent editor = spinnerComponent.getEditor();
    if (!(editor instanceof JSpinner.DateEditor)) return -1;

    final JSpinner.DateEditor dateEditor = (JSpinner.DateEditor)editor;
    final JFormattedTextField ftf = dateEditor.getTextField();
    final int start = ftf.getSelectionStart();
    final JFormattedTextField.AbstractFormatter formatter = ftf.getFormatter();
    if (!(formatter instanceof InternationalFormatter)) return -1;

    final Format.Field[] fields = ((InternationalFormatter)formatter).getFields(start);
    for (final Field element : fields) {
        if (!(element instanceof DateFormat.Field)) continue;
        int calendarField;

        if (element == DateFormat.Field.HOUR1) {
            calendarField = Calendar.HOUR;
        } else {
            calendarField = ((DateFormat.Field)element).getCalendarField();
        }

        if (calendarField != -1) {
            return calendarField;
        }
    }
    return -1;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号