1 16 17 package org.mc4j.console.swing.editor; 18 19 import java.awt.Component ; 20 import java.awt.Graphics ; 21 import java.awt.Rectangle ; 22 import java.beans.PropertyChangeListener ; 23 import java.beans.PropertyEditor ; 24 import java.lang.reflect.Array ; 25 26 29 public class ArrayEditor implements PropertyEditor 30 { 31 public final static Class [] SUPPORTED_TYPES = new Class [] { 32 Double [].class, 33 double[].class, 34 Integer [].class, 35 int[].class, 36 Float [].class, 37 float[].class, 38 Long [].class, 39 long[].class, 40 Short [].class, 41 short[].class, 42 Character [].class, 43 char[].class, 44 Boolean [].class, 45 boolean[].class 46 }; 47 48 private Object value; 49 50 public void setValue( Object value ) 51 { 52 this.value = value; 53 } 54 55 public Object getValue() 56 { 57 return value; 58 } 59 60 public String getAsText() 61 { 62 String result = null; 63 64 if( value.getClass().isArray() ) 65 { 66 result = getArrayText(); 67 } 68 69 return result; 70 } 71 72 private String getArrayText() 73 { 74 StringBuffer result = new StringBuffer (); 75 76 int length = Array.getLength( value ); 77 78 for( int i = 0; i < length; i++ ) 79 { 80 result.append( Array.get( value, i) ); 81 82 if( i != length - 1 ) 83 { 84 result.append( ',' ); 85 } 86 } 87 88 return result.toString(); 89 } 90 91 93 public void setAsText( String text ) throws IllegalArgumentException 94 { 95 throw new IllegalArgumentException ( "setAsText not implemented" ); 96 } 97 98 public String getJavaInitializationString() 99 { 100 return null; 102 } 103 104 public String [] getTags() 105 { 106 return null; 108 } 109 110 public Component getCustomEditor() 111 { 112 return null; 114 } 115 116 public boolean supportsCustomEditor() 117 { 118 return false; 119 } 120 121 public void addPropertyChangeListener( PropertyChangeListener listener ) 122 { 123 } 125 126 public void removePropertyChangeListener( PropertyChangeListener listener ) 127 { 128 } 130 131 public boolean isPaintable() 132 { 133 return false; 134 } 135 136 public void paintValue( Graphics gfx, Rectangle box ) 137 { 138 } 140 } 141 | Popular Tags |