Java Code Examples for java.text.Format.Field

The following are top voted examples for showing how to use java.text.Format.Field. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: OpenJSharp   File: AquaSpinnerUI.java   View source code 6 votes vote down vote up
/**
 * 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) {}
}
 
Example 2
Project: OpenJSharp   File: AquaSpinnerUI.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 3
Project: jdk8u-jdk   File: AquaSpinnerUI.java   View source code 6 votes vote down vote up
/**
 * 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) {}
}
 
Example 4
Project: jdk8u-jdk   File: AquaSpinnerUI.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 5
Project: openjdk-jdk10   File: AquaSpinnerUI.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 6
Project: openjdk9   File: AquaSpinnerUI.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 7
Project: jdk8u_jdk   File: AquaSpinnerUI.java   View source code 6 votes vote down vote up
/**
 * 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) {}
}
 
Example 8
Project: jdk8u_jdk   File: AquaSpinnerUI.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 9
Project: lookaside_java-1.8.0-openjdk   File: AquaSpinnerUI.java   View source code 6 votes vote down vote up
/**
 * 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) {}
}
 
Example 10
Project: lookaside_java-1.8.0-openjdk   File: AquaSpinnerUI.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 11
Project: infobip-open-jdk-8   File: AquaSpinnerUI.java   View source code 6 votes vote down vote up
/**
 * 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) {}
}
 
Example 12
Project: infobip-open-jdk-8   File: AquaSpinnerUI.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 13
Project: jdk8u-dev-jdk   File: AquaSpinnerUI.java   View source code 6 votes vote down vote up
/**
 * 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) {}
}
 
Example 14
Project: jdk8u-dev-jdk   File: AquaSpinnerUI.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 15
Project: OLD-OpenJDK8   File: AquaSpinnerUI.java   View source code 6 votes vote down vote up
/**
 * 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) {}
}
 
Example 16
Project: OLD-OpenJDK8   File: AquaSpinnerUI.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 17
Project: openjdk-jdk7u-jdk   File: AquaSpinnerUI.java   View source code 6 votes vote down vote up
/**
 * 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) {}
}
 
Example 18
Project: openjdk-jdk7u-jdk   File: AquaSpinnerUI.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 19
Project: openjdk-icedtea7   File: AquaSpinnerUI.java   View source code 6 votes vote down vote up
/**
 * 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) {}
}
 
Example 20
Project: openjdk-icedtea7   File: AquaSpinnerUI.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 21
Project: OpenJSharp   File: AquaSpinnerUI.java   View source code 5 votes vote down vote up
/**
 * 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;
}
 
Example 22
Project: jdk8u-jdk   File: AquaSpinnerUI.java   View source code 5 votes vote down vote up
/**
 * 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;
}
 
Example 23
Project: openjdk-jdk10   File: AquaSpinnerUI.java   View source code 5 votes vote down vote up
/**
 * 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) {
    }
}
 
Example 24
Project: openjdk-jdk10   File: AquaSpinnerUI.java   View source code 5 votes vote down vote up
/**
 * 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;
}
 
Example 25
Project: openjdk9   File: AquaSpinnerUI.java   View source code 5 votes vote down vote up
/**
 * 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) {
    }
}
 
Example 26
Project: openjdk9   File: AquaSpinnerUI.java   View source code 5 votes vote down vote up
/**
 * 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;
}
 
Example 27
Project: jdk8u_jdk   File: AquaSpinnerUI.java   View source code 5 votes vote down vote up
/**
 * 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;
}
 
Example 28
Project: lookaside_java-1.8.0-openjdk   File: AquaSpinnerUI.java   View source code 5 votes vote down vote up
/**
 * 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;
}
 
Example 29
Project: NoMobileData   File: NetworkCheckReceiver.java   View source code 5 votes vote down vote up
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);
}
 
Example 30
Project: infobip-open-jdk-8   File: AquaSpinnerUI.java   View source code 5 votes vote down vote up
/**
 * 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;
}
 
Example 31
Project: jdk8u-dev-jdk   File: AquaSpinnerUI.java   View source code 5 votes vote down vote up
/**
 * 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;
}
 
Example 32
Project: OLD-OpenJDK8   File: AquaSpinnerUI.java   View source code 5 votes vote down vote up
/**
 * 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;
}
 
Example 33
Project: openjdk-jdk7u-jdk   File: AquaSpinnerUI.java   View source code 5 votes vote down vote up
/**
 * 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;
}
 
Example 34
Project: openjdk-icedtea7   File: AquaSpinnerUI.java   View source code 5 votes vote down vote up
/**
 * 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;
}
 
Example 35
Project: fitnotifications   File: UFieldPosition.java   View source code 4 votes vote down vote up
/**
 * @internal
 * @deprecated This API is ICU internal only.
 */
@Deprecated
public UFieldPosition(Field attribute, int fieldID) {
    super(attribute, fieldID);
}
 
Example 36
Project: fitnotifications   File: UFieldPosition.java   View source code 4 votes vote down vote up
/**
 * @internal
 * @deprecated This API is ICU internal only.
 */
@Deprecated
public UFieldPosition(Field attribute) {
    super(attribute);
}