All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jdesktop.swingx.editors.PropertyEditorUtil Maven / Gradle / Ivy

Go to download

Contains extensions to the Swing GUI toolkit, including new and enhanced components that provide functionality commonly required by rich client applications.

The newest version!
/*
 * PropertyEditorUtil.java
 *
 * Created on August 16, 2006, 7:09 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package org.jdesktop.swingx.editors;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 *
 * @author joshy
 */
public class PropertyEditorUtil {
    //the text could be in many different formats. All of the supported formats are as follows:
    //(where x and y are doubles of some form)
    //[x,y]
    //[x y]
    //x,y]
    //[x,y
    //[ x , y ] or any other arbitrary whitespace
    // x , y ] or any other arbitrary whitespace
    //[ x , y  or any other arbitrary whitespace
    //x,y
    // x , y (or any other arbitrary whitespace)
    //x y
    // (empty space)
    //null
    //[]
    //[ ]
    //any other value throws an IllegalArgumentException
    public static Object createValueFromString(String text, int count, Class objectClass, Class paramClass) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
        // strip all extra whitespace
        text = text.replaceAll("[\\[|,| |\\]]"," ");
        text = text.replaceAll("\\s+"," ");
        text = text.trim();
//        u.p("text = " + text);
        if (text == null || text.equals("") || text.equals("null")) {
            return null;
        }
        // split by spaces
        String[] strs = text.split(" ");
//        u.p("split:");
//        u.p(strs);
//        u.p("len = " + strs.length);
        if(strs.length != count) {
            return null;
        }
        Object[] params = new Object[count];
        Class[] paramClasses = new Class[count];
        for(int i=0; i-->
            
    
            


© 2015 - 2024 Weber Informatics LLC | Privacy Policy