1 19 20 package org.netbeans.beaninfo.editors; 21 22 import java.text.MessageFormat ; 23 import org.netbeans.core.UIExceptions; 24 25 import org.openide.util.Lookup; 26 import org.openide.util.NbBundle; 27 28 31 public class ClassEditor extends java.beans.PropertyEditorSupport { 32 33 44 public String getJavaInitializationString() { 45 Class clazz = (Class )getValue(); 46 if (clazz == null) return "null"; return "Class.forName (\"" + clazz.getName () + "\")"; } 49 50 52 58 public String getAsText() { 59 Class clazz = (Class )getValue(); 60 if (clazz == null) return "null"; return clazz.getName (); 62 } 63 64 70 public void setAsText(String text) throws java.lang.IllegalArgumentException { 71 try { 72 ClassLoader loader = Lookup.getDefault().lookup(ClassLoader .class); 73 setValue (loader.loadClass (text)); 74 } catch (ClassNotFoundException e) { 75 IllegalArgumentException iae = new IllegalArgumentException (e.getMessage()); 76 String msg = MessageFormat.format( 77 NbBundle.getMessage( 78 ClassEditor.class, "FMT_EXC_CANT_LOAD_CLASS"), new Object [] {text}); UIExceptions.annotateUser(iae, e.getMessage(), msg, e, 80 new java.util.Date ()); 81 throw iae; 82 } 83 } 84 } 85 | Popular Tags |