1 18 19 package org.objectweb.jac.aspects.gui.swing; 20 21 22 23 import java.awt.Dimension ; 24 import java.lang.reflect.Array ; 25 import java.util.Collection ; 26 import java.util.StringTokenizer ; 27 import java.util.Vector ; 28 import javax.swing.JTextPane ; 29 import org.objectweb.jac.aspects.gui.Length; 30 31 34 35 public class ArrayEditor extends JTextPane 36 { 38 39 41 42 Class type; 43 public ArrayEditor(Class type) { 44 setPreferredSize(new Dimension ( 200, 200 )); 45 this.type = type; 46 } 47 48 52 53 public Object getValue() { 54 String s = getText(); 55 Collection c = null; 56 if ( type.isArray() ) { 57 c = new Vector (); 58 } else { 59 try { 60 c = (Collection ) type.newInstance(); 61 } catch ( Exception e ) { e.printStackTrace(); } 62 } 63 StringTokenizer st = new StringTokenizer ( s, "\n" ); 64 while ( st.hasMoreTokens() ) { 65 c.add( st.nextToken() ); 66 } 67 if ( type.isArray() ) { 68 Object [] a = c.toArray(); 69 Object array = Array.newInstance( type.getComponentType(), c.size() ); 70 for ( int j = 0; j < c.size(); j++ ) { 71 Array.set( array, j, a[j] ); 72 } 73 return array; 74 } else { 75 return c; 76 } 77 } 78 79 82 83 public void setValue(Object value) {} 84 85 public void setSize(Length width, Length height) { 86 SwingUtils.setSize(this, width, height); 87 } 88 89 public void onClose() {} 90 } 91 | Popular Tags |