当前位置: 首页>>代码示例>>Java>>正文


Java Field类代码示例

本文整理汇总了Java中java.text.Format.Field的典型用法代码示例。如果您正苦于以下问题:Java Field类的具体用法?Java Field怎么用?Java Field使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Field类属于java.text.Format包,在下文中一共展示了Field类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: select

import java.text.Format.Field; //导入依赖的package包/类
/**
 * 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) {}
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:26,代码来源:AquaSpinnerUI.java

示例2: select

import java.text.Format.Field; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:AquaSpinnerUI.java

示例3: getCalendarField

import java.text.Format.Field; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:33,代码来源:AquaSpinnerUI.java

示例4: getCalendarField

import java.text.Format.Field; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:39,代码来源:AquaSpinnerUI.java

示例5: setMobileDataEnabled

import java.text.Format.Field; //导入依赖的package包/类
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);
}
 
开发者ID:KlwntSingh,项目名称:NoMobileData,代码行数:14,代码来源:NetworkCheckReceiver.java

示例6: UFieldPosition

import java.text.Format.Field; //导入依赖的package包/类
/**
 * @internal
 * @deprecated This API is ICU internal only.
 */
@Deprecated
public UFieldPosition(Field attribute, int fieldID) {
    super(attribute, fieldID);
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:9,代码来源:UFieldPosition.java


注:本文中的java.text.Format.Field类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。