⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 minutespropertyeditor.java

📁 Java 敏捷开发--使用Spring Hibernate 和 Eclipse源码
💻 JAVA
字号:
package com.visualpatterns.timex.controller;

import java.beans.PropertyEditorSupport;
import java.text.DecimalFormat;

/**
 * Property editor for the Enter Hours screen; registered in 
 * the EnterHoursController class.
 * @author anil
 * @see com.visualpatterns.timex.controller.EnterHoursController
 */
public class MinutesPropertyEditor extends PropertyEditorSupport
{
    private final double ALTER_BY = 60.0; // 60 seconds
    DecimalFormat decimalFormat = new DecimalFormat("#.00");

    /**
     * Divides value by 60 and returns result
     */
    public String getAsText()
    {
        Integer value = (Integer) getValue();
        if (value == null) return "";

        float newValue = (float) value.intValue() / (float) ALTER_BY;
        return decimalFormat.format(newValue);
    }

    /**
     * Multiplies value by 60 and returns result
     */
    public void setAsText(String text) throws IllegalArgumentException
    {
        try
        {
            Float newValue = new Float(Float.valueOf(text).floatValue()
                    * ALTER_BY);
            setValue(new Integer(newValue.intValue()));
        }
        catch (NumberFormatException ex)
        {
            throw new IllegalArgumentException("Invalid number: " + text);
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -