scalingeditor.java

来自「程序练习中包括书中实例程序代码和练习中要用到的代码,是压缩文件」· Java 代码 · 共 48 行

JAVA
48
字号
package examples.beans;
import java.beans.*;
/** This class provides the editing support for the
  * scaling property of the ImageBean3 class.
  */
public class ScalingEditor extends PropertyEditorSupport {
   /** Provide the names of the allowable values.
     * Don't put spaces in these tags - the Sun
     * BeanBox chokes on them.  
     * @return An array of strings containing the
     *         allowable values
     */
   public String[] getTags() {
      return new String[] { "original_size",
                            "scaled_to_fit" };
   }
   /** Convert a tag string into a tag name into a
     * value.  The default is to set the value to
     * the ORIGINAL_SIZE value.
     * @param s The tag string
     */
   public void setAsText( String s ) {
      if ( s.equals( "scaled_to_fit" ) ) {
         setValue( new Integer(
                       ImageBean3.SCALED_TO_FIT) );
      } else {
         setValue( new Integer(
                       ImageBean3.ORIGINAL_SIZE) );
      }
   }
   /** For a given property value, return a string
     * that can be used for code generation.  The
     * default value returned is the string for the
     * ORIGINAL_SIZE value.
     * @return The string put into the generated code
     */
   public String getJavaInitializationString() {
      switch( ( (Number) getValue() ).intValue() ) {
         default:
         case ImageBean3.ORIGINAL_SIZE:
            return "examples.beans.ImageBean3."
                   +"ORIGINAL_SIZE";
         case ImageBean3.SCALED_TO_FIT:
            return "examples.beans.ImageBean3."
                   +"SCALED_TO_FIT";
      }
   }
}

⌨️ 快捷键说明

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