229 * String will be returned. If the constructor throws an exception, a 230 * <code>ParseException</code> will be thrown. If there is no single 231 * argument String constructor, <code>string</code> will be returned. 232 * 233 * @throws ParseException if there is an error in the conversion 234 * @param string String to convert 235 * @return Object representation of text 236 */ 237 public Object stringToValue(String string) throws ParseException { 238 Class<?> vc = getValueClass(); 239 JFormattedTextField ftf = getFormattedTextField(); 240 241 if (vc == null && ftf != null) { 242 Object value = ftf.getValue(); 243 244 if (value != null) { 245 vc = value.getClass(); 246 } 247 } 248 if (vc != null) { 249 Constructor cons; 250 251 try { 252 ReflectUtil.checkPackageAccess(vc); 253 SwingUtilities2.checkAccess(vc.getModifiers()); 254 cons = vc.getConstructor(new Class[]{String.class}); 255 256 } catch (NoSuchMethodException nsme) { 257 cons = null; 258 } 259 260 if (cons != null) { 261 try { 262 SwingUtilities2.checkAccess(cons.getModifiers()); 263 return cons.newInstance(new Object[] { string }); 264 } catch (Throwable ex) { 265 throw new ParseException("Error creating instance", 0); 266 } 267 } 268 } 269 return string; 270 } 271 272 /** 273 * Converts the passed in Object into a String by way of the 274 * <code>toString</code> method. | 229 * String will be returned. If the constructor throws an exception, a 230 * <code>ParseException</code> will be thrown. If there is no single 231 * argument String constructor, <code>string</code> will be returned. 232 * 233 * @throws ParseException if there is an error in the conversion 234 * @param string String to convert 235 * @return Object representation of text 236 */ 237 public Object stringToValue(String string) throws ParseException { 238 Class<?> vc = getValueClass(); 239 JFormattedTextField ftf = getFormattedTextField(); 240 241 if (vc == null && ftf != null) { 242 Object value = ftf.getValue(); 243 244 if (value != null) { 245 vc = value.getClass(); 246 } 247 } 248 if (vc != null) { 249 Constructor<?> cons; 250 251 try { 252 ReflectUtil.checkPackageAccess(vc); 253 SwingUtilities2.checkAccess(vc.getModifiers()); 254 cons = vc.getConstructor(new Class<?>[]{String.class}); 255 256 } catch (NoSuchMethodException nsme) { 257 cons = null; 258 } 259 260 if (cons != null) { 261 try { 262 SwingUtilities2.checkAccess(cons.getModifiers()); 263 return cons.newInstance(new Object[] { string }); 264 } catch (Throwable ex) { 265 throw new ParseException("Error creating instance", 0); 266 } 267 } 268 } 269 return string; 270 } 271 272 /** 273 * Converts the passed in Object into a String by way of the 274 * <code>toString</code> method. |