java类java.text.Format.Field的实例源码

AquaSpinnerUI.java 文件源码 项目:OpenJSharp 阅读 24 收藏 0 点赞 0 评论 0
/**
 * If the spinner's editor is a DateEditor, this selects the field
 * associated with the value that is being incremented.
 */
private void select(final JSpinner spinnerComponent) {
    final JComponent editor = spinnerComponent.getEditor();
    if (!(editor instanceof JSpinner.DateEditor)) return;

    final JSpinner.DateEditor dateEditor = (JSpinner.DateEditor)editor;
    final JFormattedTextField ftf = dateEditor.getTextField();
    final Format format = dateEditor.getFormat();
    Object value;
    if (format == null || (value = spinnerComponent.getValue()) == null) return;

    final SpinnerDateModel model = dateEditor.getModel();
    final DateFormat.Field field = DateFormat.Field.ofCalendarField(model.getCalendarField());
    if (field == null) return;

    try {
        final AttributedCharacterIterator iterator = format.formatToCharacterIterator(value);
        if (!select(ftf, iterator, field) && field == DateFormat.Field.HOUR0) {
            select(ftf, iterator, DateFormat.Field.HOUR1);
        }
    } catch (final IllegalArgumentException iae) {}
}
AquaSpinnerUI.java 文件源码 项目:OpenJSharp 阅读 29 收藏 0 点赞 0 评论 0
/**
 * Selects the passed in field, returning true if it is found,
 * false otherwise.
 */
private boolean select(final JFormattedTextField ftf, final AttributedCharacterIterator iterator, final DateFormat.Field field) {
    final int max = ftf.getDocument().getLength();

    iterator.first();
    do {
        final Map<Attribute,Object> attrs = iterator.getAttributes();
        if (attrs == null || !attrs.containsKey(field)) continue;

        final int start = iterator.getRunStart(field);
        final int end = iterator.getRunLimit(field);
        if (start != -1 && end != -1 && start <= max && end <= max) {
            ftf.select(start, end);
        }

        return true;
    } while (iterator.next() != CharacterIterator.DONE);
    return false;
}
AquaSpinnerUI.java 文件源码 项目:jdk8u-jdk 阅读 31 收藏 0 点赞 0 评论 0
/**
 * If the spinner's editor is a DateEditor, this selects the field
 * associated with the value that is being incremented.
 */
private void select(final JSpinner spinnerComponent) {
    final JComponent editor = spinnerComponent.getEditor();
    if (!(editor instanceof JSpinner.DateEditor)) return;

    final JSpinner.DateEditor dateEditor = (JSpinner.DateEditor)editor;
    final JFormattedTextField ftf = dateEditor.getTextField();
    final Format format = dateEditor.getFormat();
    Object value;
    if (format == null || (value = spinnerComponent.getValue()) == null) return;

    final SpinnerDateModel model = dateEditor.getModel();
    final DateFormat.Field field = DateFormat.Field.ofCalendarField(model.getCalendarField());
    if (field == null) return;

    try {
        final AttributedCharacterIterator iterator = format.formatToCharacterIterator(value);
        if (!select(ftf, iterator, field) && field == DateFormat.Field.HOUR0) {
            select(ftf, iterator, DateFormat.Field.HOUR1);
        }
    } catch (final IllegalArgumentException iae) {}
}
AquaSpinnerUI.java 文件源码 项目:jdk8u-jdk 阅读 29 收藏 0 点赞 0 评论 0
/**
 * Selects the passed in field, returning true if it is found,
 * false otherwise.
 */
private boolean select(final JFormattedTextField ftf, final AttributedCharacterIterator iterator, final DateFormat.Field field) {
    final int max = ftf.getDocument().getLength();

    iterator.first();
    do {
        final Map<Attribute,Object> attrs = iterator.getAttributes();
        if (attrs == null || !attrs.containsKey(field)) continue;

        final int start = iterator.getRunStart(field);
        final int end = iterator.getRunLimit(field);
        if (start != -1 && end != -1 && start <= max && end <= max) {
            ftf.select(start, end);
        }

        return true;
    } while (iterator.next() != CharacterIterator.DONE);
    return false;
}
AquaSpinnerUI.java 文件源码 项目:openjdk-jdk10 阅读 37 收藏 0 点赞 0 评论 0
/**
 * Selects the passed in field, returning true if it is found, false
 * otherwise.
 */
private boolean select(final JFormattedTextField ftf, final AttributedCharacterIterator iterator, final DateFormat.Field field) {
    final int max = ftf.getDocument().getLength();

    iterator.first();
    do {
        final Map<Attribute, Object> attrs = iterator.getAttributes();
        if (attrs == null || !attrs.containsKey(field)) {
            continue;
        }

        final int start = iterator.getRunStart(field);
        final int end = iterator.getRunLimit(field);
        if (start != -1 && end != -1 && start <= max && end <= max) {
            ftf.select(start, end);
        }

        return true;
    } while (iterator.next() != CharacterIterator.DONE);
    return false;
}
AquaSpinnerUI.java 文件源码 项目:openjdk9 阅读 32 收藏 0 点赞 0 评论 0
/**
 * Selects the passed in field, returning true if it is found, false
 * otherwise.
 */
private boolean select(final JFormattedTextField ftf, final AttributedCharacterIterator iterator, final DateFormat.Field field) {
    final int max = ftf.getDocument().getLength();

    iterator.first();
    do {
        final Map<Attribute, Object> attrs = iterator.getAttributes();
        if (attrs == null || !attrs.containsKey(field)) {
            continue;
        }

        final int start = iterator.getRunStart(field);
        final int end = iterator.getRunLimit(field);
        if (start != -1 && end != -1 && start <= max && end <= max) {
            ftf.select(start, end);
        }

        return true;
    } while (iterator.next() != CharacterIterator.DONE);
    return false;
}
AquaSpinnerUI.java 文件源码 项目:jdk8u_jdk 阅读 29 收藏 0 点赞 0 评论 0
/**
 * If the spinner's editor is a DateEditor, this selects the field
 * associated with the value that is being incremented.
 */
private void select(final JSpinner spinnerComponent) {
    final JComponent editor = spinnerComponent.getEditor();
    if (!(editor instanceof JSpinner.DateEditor)) return;

    final JSpinner.DateEditor dateEditor = (JSpinner.DateEditor)editor;
    final JFormattedTextField ftf = dateEditor.getTextField();
    final Format format = dateEditor.getFormat();
    Object value;
    if (format == null || (value = spinnerComponent.getValue()) == null) return;

    final SpinnerDateModel model = dateEditor.getModel();
    final DateFormat.Field field = DateFormat.Field.ofCalendarField(model.getCalendarField());
    if (field == null) return;

    try {
        final AttributedCharacterIterator iterator = format.formatToCharacterIterator(value);
        if (!select(ftf, iterator, field) && field == DateFormat.Field.HOUR0) {
            select(ftf, iterator, DateFormat.Field.HOUR1);
        }
    } catch (final IllegalArgumentException iae) {}
}
AquaSpinnerUI.java 文件源码 项目:jdk8u_jdk 阅读 24 收藏 0 点赞 0 评论 0
/**
 * Selects the passed in field, returning true if it is found,
 * false otherwise.
 */
private boolean select(final JFormattedTextField ftf, final AttributedCharacterIterator iterator, final DateFormat.Field field) {
    final int max = ftf.getDocument().getLength();

    iterator.first();
    do {
        final Map<Attribute,Object> attrs = iterator.getAttributes();
        if (attrs == null || !attrs.containsKey(field)) continue;

        final int start = iterator.getRunStart(field);
        final int end = iterator.getRunLimit(field);
        if (start != -1 && end != -1 && start <= max && end <= max) {
            ftf.select(start, end);
        }

        return true;
    } while (iterator.next() != CharacterIterator.DONE);
    return false;
}
AquaSpinnerUI.java 文件源码 项目:lookaside_java-1.8.0-openjdk 阅读 29 收藏 0 点赞 0 评论 0
/**
 * If the spinner's editor is a DateEditor, this selects the field
 * associated with the value that is being incremented.
 */
private void select(final JSpinner spinnerComponent) {
    final JComponent editor = spinnerComponent.getEditor();
    if (!(editor instanceof JSpinner.DateEditor)) return;

    final JSpinner.DateEditor dateEditor = (JSpinner.DateEditor)editor;
    final JFormattedTextField ftf = dateEditor.getTextField();
    final Format format = dateEditor.getFormat();
    Object value;
    if (format == null || (value = spinnerComponent.getValue()) == null) return;

    final SpinnerDateModel model = dateEditor.getModel();
    final DateFormat.Field field = DateFormat.Field.ofCalendarField(model.getCalendarField());
    if (field == null) return;

    try {
        final AttributedCharacterIterator iterator = format.formatToCharacterIterator(value);
        if (!select(ftf, iterator, field) && field == DateFormat.Field.HOUR0) {
            select(ftf, iterator, DateFormat.Field.HOUR1);
        }
    } catch (final IllegalArgumentException iae) {}
}
AquaSpinnerUI.java 文件源码 项目:lookaside_java-1.8.0-openjdk 阅读 30 收藏 0 点赞 0 评论 0
/**
 * Selects the passed in field, returning true if it is found,
 * false otherwise.
 */
private boolean select(final JFormattedTextField ftf, final AttributedCharacterIterator iterator, final DateFormat.Field field) {
    final int max = ftf.getDocument().getLength();

    iterator.first();
    do {
        final Map<Attribute,Object> attrs = iterator.getAttributes();
        if (attrs == null || !attrs.containsKey(field)) continue;

        final int start = iterator.getRunStart(field);
        final int end = iterator.getRunLimit(field);
        if (start != -1 && end != -1 && start <= max && end <= max) {
            ftf.select(start, end);
        }

        return true;
    } while (iterator.next() != CharacterIterator.DONE);
    return false;
}
AquaSpinnerUI.java 文件源码 项目:infobip-open-jdk-8 阅读 28 收藏 0 点赞 0 评论 0
/**
 * If the spinner's editor is a DateEditor, this selects the field
 * associated with the value that is being incremented.
 */
private void select(final JSpinner spinnerComponent) {
    final JComponent editor = spinnerComponent.getEditor();
    if (!(editor instanceof JSpinner.DateEditor)) return;

    final JSpinner.DateEditor dateEditor = (JSpinner.DateEditor)editor;
    final JFormattedTextField ftf = dateEditor.getTextField();
    final Format format = dateEditor.getFormat();
    Object value;
    if (format == null || (value = spinnerComponent.getValue()) == null) return;

    final SpinnerDateModel model = dateEditor.getModel();
    final DateFormat.Field field = DateFormat.Field.ofCalendarField(model.getCalendarField());
    if (field == null) return;

    try {
        final AttributedCharacterIterator iterator = format.formatToCharacterIterator(value);
        if (!select(ftf, iterator, field) && field == DateFormat.Field.HOUR0) {
            select(ftf, iterator, DateFormat.Field.HOUR1);
        }
    } catch (final IllegalArgumentException iae) {}
}
AquaSpinnerUI.java 文件源码 项目:infobip-open-jdk-8 阅读 28 收藏 0 点赞 0 评论 0
/**
 * Selects the passed in field, returning true if it is found,
 * false otherwise.
 */
private boolean select(final JFormattedTextField ftf, final AttributedCharacterIterator iterator, final DateFormat.Field field) {
    final int max = ftf.getDocument().getLength();

    iterator.first();
    do {
        final Map<Attribute,Object> attrs = iterator.getAttributes();
        if (attrs == null || !attrs.containsKey(field)) continue;

        final int start = iterator.getRunStart(field);
        final int end = iterator.getRunLimit(field);
        if (start != -1 && end != -1 && start <= max && end <= max) {
            ftf.select(start, end);
        }

        return true;
    } while (iterator.next() != CharacterIterator.DONE);
    return false;
}
AquaSpinnerUI.java 文件源码 项目:jdk8u-dev-jdk 阅读 25 收藏 0 点赞 0 评论 0
/**
 * If the spinner's editor is a DateEditor, this selects the field
 * associated with the value that is being incremented.
 */
private void select(final JSpinner spinnerComponent) {
    final JComponent editor = spinnerComponent.getEditor();
    if (!(editor instanceof JSpinner.DateEditor)) return;

    final JSpinner.DateEditor dateEditor = (JSpinner.DateEditor)editor;
    final JFormattedTextField ftf = dateEditor.getTextField();
    final Format format = dateEditor.getFormat();
    Object value;
    if (format == null || (value = spinnerComponent.getValue()) == null) return;

    final SpinnerDateModel model = dateEditor.getModel();
    final DateFormat.Field field = DateFormat.Field.ofCalendarField(model.getCalendarField());
    if (field == null) return;

    try {
        final AttributedCharacterIterator iterator = format.formatToCharacterIterator(value);
        if (!select(ftf, iterator, field) && field == DateFormat.Field.HOUR0) {
            select(ftf, iterator, DateFormat.Field.HOUR1);
        }
    } catch (final IllegalArgumentException iae) {}
}
AquaSpinnerUI.java 文件源码 项目:jdk8u-dev-jdk 阅读 27 收藏 0 点赞 0 评论 0
/**
 * Selects the passed in field, returning true if it is found,
 * false otherwise.
 */
private boolean select(final JFormattedTextField ftf, final AttributedCharacterIterator iterator, final DateFormat.Field field) {
    final int max = ftf.getDocument().getLength();

    iterator.first();
    do {
        final Map<Attribute,Object> attrs = iterator.getAttributes();
        if (attrs == null || !attrs.containsKey(field)) continue;

        final int start = iterator.getRunStart(field);
        final int end = iterator.getRunLimit(field);
        if (start != -1 && end != -1 && start <= max && end <= max) {
            ftf.select(start, end);
        }

        return true;
    } while (iterator.next() != CharacterIterator.DONE);
    return false;
}
AquaSpinnerUI.java 文件源码 项目:OLD-OpenJDK8 阅读 30 收藏 0 点赞 0 评论 0
/**
 * If the spinner's editor is a DateEditor, this selects the field
 * associated with the value that is being incremented.
 */
private void select(final JSpinner spinnerComponent) {
    final JComponent editor = spinnerComponent.getEditor();
    if (!(editor instanceof JSpinner.DateEditor)) return;

    final JSpinner.DateEditor dateEditor = (JSpinner.DateEditor)editor;
    final JFormattedTextField ftf = dateEditor.getTextField();
    final Format format = dateEditor.getFormat();
    Object value;
    if (format == null || (value = spinnerComponent.getValue()) == null) return;

    final SpinnerDateModel model = dateEditor.getModel();
    final DateFormat.Field field = DateFormat.Field.ofCalendarField(model.getCalendarField());
    if (field == null) return;

    try {
        final AttributedCharacterIterator iterator = format.formatToCharacterIterator(value);
        if (!select(ftf, iterator, field) && field == DateFormat.Field.HOUR0) {
            select(ftf, iterator, DateFormat.Field.HOUR1);
        }
    } catch (final IllegalArgumentException iae) {}
}
AquaSpinnerUI.java 文件源码 项目:OLD-OpenJDK8 阅读 35 收藏 0 点赞 0 评论 0
/**
 * Selects the passed in field, returning true if it is found,
 * false otherwise.
 */
private boolean select(final JFormattedTextField ftf, final AttributedCharacterIterator iterator, final DateFormat.Field field) {
    final int max = ftf.getDocument().getLength();

    iterator.first();
    do {
        final Map<Attribute,Object> attrs = iterator.getAttributes();
        if (attrs == null || !attrs.containsKey(field)) continue;

        final int start = iterator.getRunStart(field);
        final int end = iterator.getRunLimit(field);
        if (start != -1 && end != -1 && start <= max && end <= max) {
            ftf.select(start, end);
        }

        return true;
    } while (iterator.next() != CharacterIterator.DONE);
    return false;
}
AquaSpinnerUI.java 文件源码 项目:openjdk-jdk7u-jdk 阅读 23 收藏 0 点赞 0 评论 0
/**
 * If the spinner's editor is a DateEditor, this selects the field
 * associated with the value that is being incremented.
 */
private void select(final JSpinner spinnerComponent) {
    final JComponent editor = spinnerComponent.getEditor();
    if (!(editor instanceof JSpinner.DateEditor)) return;

    final JSpinner.DateEditor dateEditor = (JSpinner.DateEditor)editor;
    final JFormattedTextField ftf = dateEditor.getTextField();
    final Format format = dateEditor.getFormat();
    Object value;
    if (format == null || (value = spinnerComponent.getValue()) == null) return;

    final SpinnerDateModel model = dateEditor.getModel();
    final DateFormat.Field field = DateFormat.Field.ofCalendarField(model.getCalendarField());
    if (field == null) return;

    try {
        final AttributedCharacterIterator iterator = format.formatToCharacterIterator(value);
        if (!select(ftf, iterator, field) && field == DateFormat.Field.HOUR0) {
            select(ftf, iterator, DateFormat.Field.HOUR1);
        }
    } catch (final IllegalArgumentException iae) {}
}
AquaSpinnerUI.java 文件源码 项目:openjdk-jdk7u-jdk 阅读 30 收藏 0 点赞 0 评论 0
/**
 * Selects the passed in field, returning true if it is found,
 * false otherwise.
 */
private boolean select(final JFormattedTextField ftf, final AttributedCharacterIterator iterator, final DateFormat.Field field) {
    final int max = ftf.getDocument().getLength();

    iterator.first();
    do {
        final Map<Attribute,Object> attrs = iterator.getAttributes();
        if (attrs == null || !attrs.containsKey(field)) continue;

        final int start = iterator.getRunStart(field);
        final int end = iterator.getRunLimit(field);
        if (start != -1 && end != -1 && start <= max && end <= max) {
            ftf.select(start, end);
        }

        return true;
    } while (iterator.next() != CharacterIterator.DONE);
    return false;
}
AquaSpinnerUI.java 文件源码 项目:openjdk-icedtea7 阅读 27 收藏 0 点赞 0 评论 0
/**
 * If the spinner's editor is a DateEditor, this selects the field
 * associated with the value that is being incremented.
 */
private void select(final JSpinner spinnerComponent) {
    final JComponent editor = spinnerComponent.getEditor();
    if (!(editor instanceof JSpinner.DateEditor)) return;

    final JSpinner.DateEditor dateEditor = (JSpinner.DateEditor)editor;
    final JFormattedTextField ftf = dateEditor.getTextField();
    final Format format = dateEditor.getFormat();
    Object value;
    if (format == null || (value = spinnerComponent.getValue()) == null) return;

    final SpinnerDateModel model = dateEditor.getModel();
    final DateFormat.Field field = DateFormat.Field.ofCalendarField(model.getCalendarField());
    if (field == null) return;

    try {
        final AttributedCharacterIterator iterator = format.formatToCharacterIterator(value);
        if (!select(ftf, iterator, field) && field == DateFormat.Field.HOUR0) {
            select(ftf, iterator, DateFormat.Field.HOUR1);
        }
    } catch (final IllegalArgumentException iae) {}
}
AquaSpinnerUI.java 文件源码 项目:openjdk-icedtea7 阅读 28 收藏 0 点赞 0 评论 0
/**
 * Selects the passed in field, returning true if it is found,
 * false otherwise.
 */
private boolean select(final JFormattedTextField ftf, final AttributedCharacterIterator iterator, final DateFormat.Field field) {
    final int max = ftf.getDocument().getLength();

    iterator.first();
    do {
        final Map<Attribute,Object> attrs = iterator.getAttributes();
        if (attrs == null || !attrs.containsKey(field)) continue;

        final int start = iterator.getRunStart(field);
        final int end = iterator.getRunLimit(field);
        if (start != -1 && end != -1 && start <= max && end <= max) {
            ftf.select(start, end);
        }

        return true;
    } while (iterator.next() != CharacterIterator.DONE);
    return false;
}
AquaSpinnerUI.java 文件源码 项目:OpenJSharp 阅读 21 收藏 0 点赞 0 评论 0
/**
 * 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;
}
AquaSpinnerUI.java 文件源码 项目:jdk8u-jdk 阅读 23 收藏 0 点赞 0 评论 0
/**
 * 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;
}
AquaSpinnerUI.java 文件源码 项目:openjdk-jdk10 阅读 25 收藏 0 点赞 0 评论 0
/**
 * If the spinner's editor is a DateEditor, this selects the field
 * associated with the value that is being incremented.
 */
private void select(final JSpinner spinnerComponent) {
    final JComponent editor = spinnerComponent.getEditor();
    if (!(editor instanceof JSpinner.DateEditor)) {
        return;
    }

    final JSpinner.DateEditor dateEditor = (JSpinner.DateEditor) editor;
    final JFormattedTextField ftf = dateEditor.getTextField();
    final Format format = dateEditor.getFormat();
    Object value;
    if (format == null || (value = spinnerComponent.getValue()) == null) {
        return;
    }

    final SpinnerDateModel model = dateEditor.getModel();
    final DateFormat.Field field = DateFormat.Field.ofCalendarField(model.getCalendarField());
    if (field == null) {
        return;
    }

    try {
        final AttributedCharacterIterator iterator = format.formatToCharacterIterator(value);
        if (!select(ftf, iterator, field) && field == DateFormat.Field.HOUR0) {
            select(ftf, iterator, DateFormat.Field.HOUR1);
        }
    } catch (final IllegalArgumentException iae) {
    }
}
AquaSpinnerUI.java 文件源码 项目:openjdk-jdk10 阅读 44 收藏 0 点赞 0 评论 0
/**
 * 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;
}
AquaSpinnerUI.java 文件源码 项目:openjdk9 阅读 37 收藏 0 点赞 0 评论 0
/**
 * If the spinner's editor is a DateEditor, this selects the field
 * associated with the value that is being incremented.
 */
private void select(final JSpinner spinnerComponent) {
    final JComponent editor = spinnerComponent.getEditor();
    if (!(editor instanceof JSpinner.DateEditor)) {
        return;
    }

    final JSpinner.DateEditor dateEditor = (JSpinner.DateEditor) editor;
    final JFormattedTextField ftf = dateEditor.getTextField();
    final Format format = dateEditor.getFormat();
    Object value;
    if (format == null || (value = spinnerComponent.getValue()) == null) {
        return;
    }

    final SpinnerDateModel model = dateEditor.getModel();
    final DateFormat.Field field = DateFormat.Field.ofCalendarField(model.getCalendarField());
    if (field == null) {
        return;
    }

    try {
        final AttributedCharacterIterator iterator = format.formatToCharacterIterator(value);
        if (!select(ftf, iterator, field) && field == DateFormat.Field.HOUR0) {
            select(ftf, iterator, DateFormat.Field.HOUR1);
        }
    } catch (final IllegalArgumentException iae) {
    }
}
AquaSpinnerUI.java 文件源码 项目:openjdk9 阅读 27 收藏 0 点赞 0 评论 0
/**
 * 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;
}
AquaSpinnerUI.java 文件源码 项目:jdk8u_jdk 阅读 23 收藏 0 点赞 0 评论 0
/**
 * 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;
}
AquaSpinnerUI.java 文件源码 项目:lookaside_java-1.8.0-openjdk 阅读 40 收藏 0 点赞 0 评论 0
/**
 * 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;
}
NetworkCheckReceiver.java 文件源码 项目:NoMobileData 阅读 19 收藏 0 点赞 0 评论 0
public void setMobileDataEnabled(Context context, boolean enabled) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
    final ConnectivityManager conman = (ConnectivityManager)  context.getSystemService(Context.CONNECTIVITY_SERVICE);
    final Class conmanClass = Class.forName(conman.getClass().getName());
    final java.lang.reflect.Field connectivityManagerField = conmanClass.getDeclaredField("mService");
    connectivityManagerField.setAccessible(true);

    final Object connectivityManager = connectivityManagerField.get(conman);
    final Class connectivityManagerClass =  Class.forName(connectivityManager.getClass().getName());
    final Method setMobileDataEnabledMethod = connectivityManagerClass.getDeclaredMethod("setMobileDataEnabled", Boolean.TYPE);
    setMobileDataEnabledMethod.setAccessible(true);

    setMobileDataEnabledMethod.invoke(connectivityManager, enabled);
}
AquaSpinnerUI.java 文件源码 项目:infobip-open-jdk-8 阅读 27 收藏 0 点赞 0 评论 0
/**
 * 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;
}


问题


面经


文章

微信
公众号

扫码关注公众号