KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mc4j > console > swing > editor > ArrayEditor


1 /*
2  * Copyright 2002-2004 Greg Hinkle
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.mc4j.console.swing.editor;
18
19 import java.awt.Component JavaDoc;
20 import java.awt.Graphics JavaDoc;
21 import java.awt.Rectangle JavaDoc;
22 import java.beans.PropertyChangeListener JavaDoc;
23 import java.beans.PropertyEditor JavaDoc;
24 import java.lang.reflect.Array JavaDoc;
25
26 /**
27  * @author Andrew Couchman & Dima Samsonoff
28  */

29 public class ArrayEditor implements PropertyEditor JavaDoc
30 {
31     public final static Class JavaDoc[] SUPPORTED_TYPES = new Class JavaDoc [] {
32             Double JavaDoc[].class,
33             double[].class,
34             Integer JavaDoc[].class,
35             int[].class,
36             Float JavaDoc[].class,
37             float[].class,
38             Long JavaDoc[].class,
39             long[].class,
40             Short JavaDoc[].class,
41             short[].class,
42             Character JavaDoc[].class,
43             char[].class,
44             Boolean JavaDoc[].class,
45             boolean[].class
46         };
47     
48     private Object JavaDoc value;
49     
50     public void setValue( Object JavaDoc value )
51     {
52         this.value = value;
53     }
54
55     public Object JavaDoc getValue()
56     {
57         return value;
58     }
59
60     public String JavaDoc getAsText()
61     {
62         String JavaDoc result = null;
63         
64         if( value.getClass().isArray() )
65         {
66             result = getArrayText();
67         }
68         
69         return result;
70     }
71
72     private String JavaDoc getArrayText()
73     {
74         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
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 // NOT IMPLEMENTED!!
92

93     public void setAsText( String JavaDoc text ) throws IllegalArgumentException JavaDoc
94     {
95         throw new IllegalArgumentException JavaDoc( "setAsText not implemented" );
96     }
97
98     public String JavaDoc getJavaInitializationString()
99     {
100         // not implemented
101
return null;
102     }
103
104     public String JavaDoc[] getTags()
105     {
106         // not implemented
107
return null;
108     }
109
110     public Component JavaDoc getCustomEditor()
111     {
112         // not implemented
113
return null;
114     }
115
116     public boolean supportsCustomEditor()
117     {
118         return false;
119     }
120
121     public void addPropertyChangeListener( PropertyChangeListener JavaDoc listener )
122     {
123         // not implemented
124
}
125
126     public void removePropertyChangeListener( PropertyChangeListener JavaDoc listener )
127     {
128         // not implemented
129
}
130     
131     public boolean isPaintable()
132     {
133         return false;
134     }
135
136     public void paintValue( Graphics JavaDoc gfx, Rectangle JavaDoc box )
137     {
138         // not implemented
139
}
140 }
141
Popular Tags