Java Code Examples for sun.swing.SwingUtilities2#checkAccess()

The following examples show how to use sun.swing.SwingUtilities2#checkAccess() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultFormatter.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Converts the passed in String into an instance of
 * <code>getValueClass</code> by way of the constructor that
 * takes a String argument. If <code>getValueClass</code>
 * returns null, the Class of the current value in the
 * <code>JFormattedTextField</code> will be used. If this is null, a
 * String will be returned. If the constructor throws an exception, a
 * <code>ParseException</code> will be thrown. If there is no single
 * argument String constructor, <code>string</code> will be returned.
 *
 * @throws ParseException if there is an error in the conversion
 * @param string String to convert
 * @return Object representation of text
 */
public Object stringToValue(String string) throws ParseException {
    Class<?> vc = getValueClass();
    JFormattedTextField ftf = getFormattedTextField();

    if (vc == null && ftf != null) {
        Object value = ftf.getValue();

        if (value != null) {
            vc = value.getClass();
        }
    }
    if (vc != null) {
        Constructor cons;

        try {
            ReflectUtil.checkPackageAccess(vc);
            SwingUtilities2.checkAccess(vc.getModifiers());
            cons = vc.getConstructor(new Class[]{String.class});

        } catch (NoSuchMethodException nsme) {
            cons = null;
        }

        if (cons != null) {
            try {
                SwingUtilities2.checkAccess(cons.getModifiers());
                return cons.newInstance(new Object[] { string });
            } catch (Throwable ex) {
                throw new ParseException("Error creating instance", 0);
            }
        }
    }
    return string;
}
 
Example 2
Source File: DefaultFormatter.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Converts the passed in String into an instance of
 * <code>getValueClass</code> by way of the constructor that
 * takes a String argument. If <code>getValueClass</code>
 * returns null, the Class of the current value in the
 * <code>JFormattedTextField</code> will be used. If this is null, a
 * String will be returned. If the constructor throws an exception, a
 * <code>ParseException</code> will be thrown. If there is no single
 * argument String constructor, <code>string</code> will be returned.
 *
 * @throws ParseException if there is an error in the conversion
 * @param string String to convert
 * @return Object representation of text
 */
public Object stringToValue(String string) throws ParseException {
    Class<?> vc = getValueClass();
    JFormattedTextField ftf = getFormattedTextField();

    if (vc == null && ftf != null) {
        Object value = ftf.getValue();

        if (value != null) {
            vc = value.getClass();
        }
    }
    if (vc != null) {
        Constructor cons;

        try {
            ReflectUtil.checkPackageAccess(vc);
            SwingUtilities2.checkAccess(vc.getModifiers());
            cons = vc.getConstructor(new Class[]{String.class});

        } catch (NoSuchMethodException nsme) {
            cons = null;
        }

        if (cons != null) {
            try {
                SwingUtilities2.checkAccess(cons.getModifiers());
                return cons.newInstance(new Object[] { string });
            } catch (Throwable ex) {
                throw new ParseException("Error creating instance", 0);
            }
        }
    }
    return string;
}
 
Example 3
Source File: DefaultFormatter.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Converts the passed in String into an instance of
 * <code>getValueClass</code> by way of the constructor that
 * takes a String argument. If <code>getValueClass</code>
 * returns null, the Class of the current value in the
 * <code>JFormattedTextField</code> will be used. If this is null, a
 * String will be returned. If the constructor throws an exception, a
 * <code>ParseException</code> will be thrown. If there is no single
 * argument String constructor, <code>string</code> will be returned.
 *
 * @throws ParseException if there is an error in the conversion
 * @param string String to convert
 * @return Object representation of text
 */
public Object stringToValue(String string) throws ParseException {
    Class<?> vc = getValueClass();
    JFormattedTextField ftf = getFormattedTextField();

    if (vc == null && ftf != null) {
        Object value = ftf.getValue();

        if (value != null) {
            vc = value.getClass();
        }
    }
    if (vc != null) {
        Constructor cons;

        try {
            ReflectUtil.checkPackageAccess(vc);
            SwingUtilities2.checkAccess(vc.getModifiers());
            cons = vc.getConstructor(new Class[]{String.class});

        } catch (NoSuchMethodException nsme) {
            cons = null;
        }

        if (cons != null) {
            try {
                SwingUtilities2.checkAccess(cons.getModifiers());
                return cons.newInstance(new Object[] { string });
            } catch (Throwable ex) {
                throw new ParseException("Error creating instance", 0);
            }
        }
    }
    return string;
}
 
Example 4
Source File: DefaultFormatter.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Converts the passed in String into an instance of
 * <code>getValueClass</code> by way of the constructor that
 * takes a String argument. If <code>getValueClass</code>
 * returns null, the Class of the current value in the
 * <code>JFormattedTextField</code> will be used. If this is null, a
 * String will be returned. If the constructor throws an exception, a
 * <code>ParseException</code> will be thrown. If there is no single
 * argument String constructor, <code>string</code> will be returned.
 *
 * @throws ParseException if there is an error in the conversion
 * @param string String to convert
 * @return Object representation of text
 */
public Object stringToValue(String string) throws ParseException {
    Class<?> vc = getValueClass();
    JFormattedTextField ftf = getFormattedTextField();

    if (vc == null && ftf != null) {
        Object value = ftf.getValue();

        if (value != null) {
            vc = value.getClass();
        }
    }
    if (vc != null) {
        Constructor cons;

        try {
            ReflectUtil.checkPackageAccess(vc);
            SwingUtilities2.checkAccess(vc.getModifiers());
            cons = vc.getConstructor(new Class[]{String.class});

        } catch (NoSuchMethodException nsme) {
            cons = null;
        }

        if (cons != null) {
            try {
                SwingUtilities2.checkAccess(cons.getModifiers());
                return cons.newInstance(new Object[] { string });
            } catch (Throwable ex) {
                throw new ParseException("Error creating instance", 0);
            }
        }
    }
    return string;
}
 
Example 5
Source File: DefaultFormatter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Converts the passed in String into an instance of
 * <code>getValueClass</code> by way of the constructor that
 * takes a String argument. If <code>getValueClass</code>
 * returns null, the Class of the current value in the
 * <code>JFormattedTextField</code> will be used. If this is null, a
 * String will be returned. If the constructor throws an exception, a
 * <code>ParseException</code> will be thrown. If there is no single
 * argument String constructor, <code>string</code> will be returned.
 *
 * @throws ParseException if there is an error in the conversion
 * @param string String to convert
 * @return Object representation of text
 */
public Object stringToValue(String string) throws ParseException {
    Class<?> vc = getValueClass();
    JFormattedTextField ftf = getFormattedTextField();

    if (vc == null && ftf != null) {
        Object value = ftf.getValue();

        if (value != null) {
            vc = value.getClass();
        }
    }
    if (vc != null) {
        Constructor<?> cons;

        try {
            ReflectUtil.checkPackageAccess(vc);
            SwingUtilities2.checkAccess(vc.getModifiers());
            cons = vc.getConstructor(new Class<?>[]{String.class});

        } catch (NoSuchMethodException nsme) {
            cons = null;
        }

        if (cons != null) {
            try {
                SwingUtilities2.checkAccess(cons.getModifiers());
                return cons.newInstance(new Object[] { string });
            } catch (Throwable ex) {
                throw new ParseException("Error creating instance", 0);
            }
        }
    }
    return string;
}
 
Example 6
Source File: DefaultFormatter.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Converts the passed in String into an instance of
 * <code>getValueClass</code> by way of the constructor that
 * takes a String argument. If <code>getValueClass</code>
 * returns null, the Class of the current value in the
 * <code>JFormattedTextField</code> will be used. If this is null, a
 * String will be returned. If the constructor throws an exception, a
 * <code>ParseException</code> will be thrown. If there is no single
 * argument String constructor, <code>string</code> will be returned.
 *
 * @throws ParseException if there is an error in the conversion
 * @param string String to convert
 * @return Object representation of text
 */
public Object stringToValue(String string) throws ParseException {
    Class<?> vc = getValueClass();
    JFormattedTextField ftf = getFormattedTextField();

    if (vc == null && ftf != null) {
        Object value = ftf.getValue();

        if (value != null) {
            vc = value.getClass();
        }
    }
    if (vc != null) {
        Constructor cons;

        try {
            ReflectUtil.checkPackageAccess(vc);
            SwingUtilities2.checkAccess(vc.getModifiers());
            cons = vc.getConstructor(new Class[]{String.class});

        } catch (NoSuchMethodException nsme) {
            cons = null;
        }

        if (cons != null) {
            try {
                SwingUtilities2.checkAccess(cons.getModifiers());
                return cons.newInstance(new Object[] { string });
            } catch (Throwable ex) {
                throw new ParseException("Error creating instance", 0);
            }
        }
    }
    return string;
}
 
Example 7
Source File: DefaultFormatter.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Converts the passed in String into an instance of
 * <code>getValueClass</code> by way of the constructor that
 * takes a String argument. If <code>getValueClass</code>
 * returns null, the Class of the current value in the
 * <code>JFormattedTextField</code> will be used. If this is null, a
 * String will be returned. If the constructor throws an exception, a
 * <code>ParseException</code> will be thrown. If there is no single
 * argument String constructor, <code>string</code> will be returned.
 *
 * @throws ParseException if there is an error in the conversion
 * @param string String to convert
 * @return Object representation of text
 */
public Object stringToValue(String string) throws ParseException {
    Class<?> vc = getValueClass();
    JFormattedTextField ftf = getFormattedTextField();

    if (vc == null && ftf != null) {
        Object value = ftf.getValue();

        if (value != null) {
            vc = value.getClass();
        }
    }
    if (vc != null) {
        Constructor cons;

        try {
            ReflectUtil.checkPackageAccess(vc);
            SwingUtilities2.checkAccess(vc.getModifiers());
            cons = vc.getConstructor(new Class[]{String.class});

        } catch (NoSuchMethodException nsme) {
            cons = null;
        }

        if (cons != null) {
            try {
                SwingUtilities2.checkAccess(cons.getModifiers());
                return cons.newInstance(new Object[] { string });
            } catch (Throwable ex) {
                throw new ParseException("Error creating instance", 0);
            }
        }
    }
    return string;
}
 
Example 8
Source File: DefaultFormatter.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Converts the passed in String into an instance of
 * <code>getValueClass</code> by way of the constructor that
 * takes a String argument. If <code>getValueClass</code>
 * returns null, the Class of the current value in the
 * <code>JFormattedTextField</code> will be used. If this is null, a
 * String will be returned. If the constructor throws an exception, a
 * <code>ParseException</code> will be thrown. If there is no single
 * argument String constructor, <code>string</code> will be returned.
 *
 * @throws ParseException if there is an error in the conversion
 * @param string String to convert
 * @return Object representation of text
 */
public Object stringToValue(String string) throws ParseException {
    Class<?> vc = getValueClass();
    JFormattedTextField ftf = getFormattedTextField();

    if (vc == null && ftf != null) {
        Object value = ftf.getValue();

        if (value != null) {
            vc = value.getClass();
        }
    }
    if (vc != null) {
        Constructor cons;

        try {
            ReflectUtil.checkPackageAccess(vc);
            SwingUtilities2.checkAccess(vc.getModifiers());
            cons = vc.getConstructor(new Class[]{String.class});

        } catch (NoSuchMethodException nsme) {
            cons = null;
        }

        if (cons != null) {
            try {
                SwingUtilities2.checkAccess(cons.getModifiers());
                return cons.newInstance(new Object[] { string });
            } catch (Throwable ex) {
                throw new ParseException("Error creating instance", 0);
            }
        }
    }
    return string;
}
 
Example 9
Source File: NumberFormatter.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Invoked to toggle the sign. For this to work the value class
 * must have a single arg constructor that takes a String.
 */
private Object toggleSign(boolean positive) throws ParseException {
    Object value = stringToValue(getFormattedTextField().getText());

    if (value != null) {
        // toString isn't localized, so that using +/- should work
        // correctly.
        String string = value.toString();

        if (string != null && string.length() > 0) {
            if (positive) {
                if (string.charAt(0) == '-') {
                    string = string.substring(1);
                }
            }
            else {
                if (string.charAt(0) == '+') {
                    string = string.substring(1);
                }
                if (string.length() > 0 && string.charAt(0) != '-') {
                    string = "-" + string;
                }
            }
            if (string != null) {
                Class<?> valueClass = getValueClass();

                if (valueClass == null) {
                    valueClass = value.getClass();
                }
                try {
                    ReflectUtil.checkPackageAccess(valueClass);
                    SwingUtilities2.checkAccess(valueClass.getModifiers());
                    Constructor cons = valueClass.getConstructor(
                                          new Class[] { String.class });
                    if (cons != null) {
                        SwingUtilities2.checkAccess(cons.getModifiers());
                        return cons.newInstance(new Object[]{string});
                    }
                } catch (Throwable ex) { }
            }
        }
    }
    return null;
}
 
Example 10
Source File: NumberFormatter.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Invoked to toggle the sign. For this to work the value class
 * must have a single arg constructor that takes a String.
 */
private Object toggleSign(boolean positive) throws ParseException {
    Object value = stringToValue(getFormattedTextField().getText());

    if (value != null) {
        // toString isn't localized, so that using +/- should work
        // correctly.
        String string = value.toString();

        if (string != null && string.length() > 0) {
            if (positive) {
                if (string.charAt(0) == '-') {
                    string = string.substring(1);
                }
            }
            else {
                if (string.charAt(0) == '+') {
                    string = string.substring(1);
                }
                if (string.length() > 0 && string.charAt(0) != '-') {
                    string = "-" + string;
                }
            }
            if (string != null) {
                Class<?> valueClass = getValueClass();

                if (valueClass == null) {
                    valueClass = value.getClass();
                }
                try {
                    ReflectUtil.checkPackageAccess(valueClass);
                    SwingUtilities2.checkAccess(valueClass.getModifiers());
                    Constructor cons = valueClass.getConstructor(
                                          new Class[] { String.class });
                    if (cons != null) {
                        SwingUtilities2.checkAccess(cons.getModifiers());
                        return cons.newInstance(new Object[]{string});
                    }
                } catch (Throwable ex) { }
            }
        }
    }
    return null;
}
 
Example 11
Source File: NumberFormatter.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Invoked to toggle the sign. For this to work the value class
 * must have a single arg constructor that takes a String.
 */
private Object toggleSign(boolean positive) throws ParseException {
    Object value = stringToValue(getFormattedTextField().getText());

    if (value != null) {
        // toString isn't localized, so that using +/- should work
        // correctly.
        String string = value.toString();

        if (string != null && string.length() > 0) {
            if (positive) {
                if (string.charAt(0) == '-') {
                    string = string.substring(1);
                }
            }
            else {
                if (string.charAt(0) == '+') {
                    string = string.substring(1);
                }
                if (string.length() > 0 && string.charAt(0) != '-') {
                    string = "-" + string;
                }
            }
            if (string != null) {
                Class<?> valueClass = getValueClass();

                if (valueClass == null) {
                    valueClass = value.getClass();
                }
                try {
                    ReflectUtil.checkPackageAccess(valueClass);
                    SwingUtilities2.checkAccess(valueClass.getModifiers());
                    Constructor<?> cons = valueClass.getConstructor(
                                          new Class<?>[] { String.class });
                    if (cons != null) {
                        SwingUtilities2.checkAccess(cons.getModifiers());
                        return cons.newInstance(new Object[]{string});
                    }
                } catch (Throwable ex) { }
            }
        }
    }
    return null;
}
 
Example 12
Source File: NumberFormatter.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Invoked to toggle the sign. For this to work the value class
 * must have a single arg constructor that takes a String.
 */
private Object toggleSign(boolean positive) throws ParseException {
    Object value = stringToValue(getFormattedTextField().getText());

    if (value != null) {
        // toString isn't localized, so that using +/- should work
        // correctly.
        String string = value.toString();

        if (string != null && string.length() > 0) {
            if (positive) {
                if (string.charAt(0) == '-') {
                    string = string.substring(1);
                }
            }
            else {
                if (string.charAt(0) == '+') {
                    string = string.substring(1);
                }
                if (string.length() > 0 && string.charAt(0) != '-') {
                    string = "-" + string;
                }
            }
            if (string != null) {
                Class<?> valueClass = getValueClass();

                if (valueClass == null) {
                    valueClass = value.getClass();
                }
                try {
                    ReflectUtil.checkPackageAccess(valueClass);
                    SwingUtilities2.checkAccess(valueClass.getModifiers());
                    Constructor cons = valueClass.getConstructor(
                                          new Class[] { String.class });
                    if (cons != null) {
                        SwingUtilities2.checkAccess(cons.getModifiers());
                        return cons.newInstance(new Object[]{string});
                    }
                } catch (Throwable ex) { }
            }
        }
    }
    return null;
}
 
Example 13
Source File: NumberFormatter.java    From Java8CN with Apache License 2.0 4 votes vote down vote up
/**
 * Invoked to toggle the sign. For this to work the value class
 * must have a single arg constructor that takes a String.
 */
private Object toggleSign(boolean positive) throws ParseException {
    Object value = stringToValue(getFormattedTextField().getText());

    if (value != null) {
        // toString isn't localized, so that using +/- should work
        // correctly.
        String string = value.toString();

        if (string != null && string.length() > 0) {
            if (positive) {
                if (string.charAt(0) == '-') {
                    string = string.substring(1);
                }
            }
            else {
                if (string.charAt(0) == '+') {
                    string = string.substring(1);
                }
                if (string.length() > 0 && string.charAt(0) != '-') {
                    string = "-" + string;
                }
            }
            if (string != null) {
                Class<?> valueClass = getValueClass();

                if (valueClass == null) {
                    valueClass = value.getClass();
                }
                try {
                    ReflectUtil.checkPackageAccess(valueClass);
                    SwingUtilities2.checkAccess(valueClass.getModifiers());
                    Constructor cons = valueClass.getConstructor(
                                          new Class[] { String.class });
                    if (cons != null) {
                        SwingUtilities2.checkAccess(cons.getModifiers());
                        return cons.newInstance(new Object[]{string});
                    }
                } catch (Throwable ex) { }
            }
        }
    }
    return null;
}
 
Example 14
Source File: NumberFormatter.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Invoked to toggle the sign. For this to work the value class
 * must have a single arg constructor that takes a String.
 */
private Object toggleSign(boolean positive) throws ParseException {
    Object value = stringToValue(getFormattedTextField().getText());

    if (value != null) {
        // toString isn't localized, so that using +/- should work
        // correctly.
        String string = value.toString();

        if (string != null && string.length() > 0) {
            if (positive) {
                if (string.charAt(0) == '-') {
                    string = string.substring(1);
                }
            }
            else {
                if (string.charAt(0) == '+') {
                    string = string.substring(1);
                }
                if (string.length() > 0 && string.charAt(0) != '-') {
                    string = "-" + string;
                }
            }
            if (string != null) {
                Class<?> valueClass = getValueClass();

                if (valueClass == null) {
                    valueClass = value.getClass();
                }
                try {
                    ReflectUtil.checkPackageAccess(valueClass);
                    SwingUtilities2.checkAccess(valueClass.getModifiers());
                    Constructor cons = valueClass.getConstructor(
                                          new Class[] { String.class });
                    if (cons != null) {
                        SwingUtilities2.checkAccess(cons.getModifiers());
                        return cons.newInstance(new Object[]{string});
                    }
                } catch (Throwable ex) { }
            }
        }
    }
    return null;
}
 
Example 15
Source File: NumberFormatter.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Invoked to toggle the sign. For this to work the value class
 * must have a single arg constructor that takes a String.
 */
private Object toggleSign(boolean positive) throws ParseException {
    Object value = stringToValue(getFormattedTextField().getText());

    if (value != null) {
        // toString isn't localized, so that using +/- should work
        // correctly.
        String string = value.toString();

        if (string != null && string.length() > 0) {
            if (positive) {
                if (string.charAt(0) == '-') {
                    string = string.substring(1);
                }
            }
            else {
                if (string.charAt(0) == '+') {
                    string = string.substring(1);
                }
                if (string.length() > 0 && string.charAt(0) != '-') {
                    string = "-" + string;
                }
            }
            if (string != null) {
                Class<?> valueClass = getValueClass();

                if (valueClass == null) {
                    valueClass = value.getClass();
                }
                try {
                    ReflectUtil.checkPackageAccess(valueClass);
                    SwingUtilities2.checkAccess(valueClass.getModifiers());
                    Constructor cons = valueClass.getConstructor(
                                          new Class[] { String.class });
                    if (cons != null) {
                        SwingUtilities2.checkAccess(cons.getModifiers());
                        return cons.newInstance(new Object[]{string});
                    }
                } catch (Throwable ex) { }
            }
        }
    }
    return null;
}
 
Example 16
Source File: NumberFormatter.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Invoked to toggle the sign. For this to work the value class
 * must have a single arg constructor that takes a String.
 */
private Object toggleSign(boolean positive) throws ParseException {
    Object value = stringToValue(getFormattedTextField().getText());

    if (value != null) {
        // toString isn't localized, so that using +/- should work
        // correctly.
        String string = value.toString();

        if (string != null && string.length() > 0) {
            if (positive) {
                if (string.charAt(0) == '-') {
                    string = string.substring(1);
                }
            }
            else {
                if (string.charAt(0) == '+') {
                    string = string.substring(1);
                }
                if (string.length() > 0 && string.charAt(0) != '-') {
                    string = "-" + string;
                }
            }
            if (string != null) {
                Class<?> valueClass = getValueClass();

                if (valueClass == null) {
                    valueClass = value.getClass();
                }
                try {
                    ReflectUtil.checkPackageAccess(valueClass);
                    SwingUtilities2.checkAccess(valueClass.getModifiers());
                    Constructor cons = valueClass.getConstructor(
                                          new Class[] { String.class });
                    if (cons != null) {
                        SwingUtilities2.checkAccess(cons.getModifiers());
                        return cons.newInstance(new Object[]{string});
                    }
                } catch (Throwable ex) { }
            }
        }
    }
    return null;
}
 
Example 17
Source File: NumberFormatter.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Invoked to toggle the sign. For this to work the value class
 * must have a single arg constructor that takes a String.
 */
private Object toggleSign(boolean positive) throws ParseException {
    Object value = stringToValue(getFormattedTextField().getText());

    if (value != null) {
        // toString isn't localized, so that using +/- should work
        // correctly.
        String string = value.toString();

        if (string != null && string.length() > 0) {
            if (positive) {
                if (string.charAt(0) == '-') {
                    string = string.substring(1);
                }
            }
            else {
                if (string.charAt(0) == '+') {
                    string = string.substring(1);
                }
                if (string.length() > 0 && string.charAt(0) != '-') {
                    string = "-" + string;
                }
            }
            if (string != null) {
                Class<?> valueClass = getValueClass();

                if (valueClass == null) {
                    valueClass = value.getClass();
                }
                try {
                    ReflectUtil.checkPackageAccess(valueClass);
                    SwingUtilities2.checkAccess(valueClass.getModifiers());
                    Constructor cons = valueClass.getConstructor(
                                          new Class[] { String.class });
                    if (cons != null) {
                        SwingUtilities2.checkAccess(cons.getModifiers());
                        return cons.newInstance(new Object[]{string});
                    }
                } catch (Throwable ex) { }
            }
        }
    }
    return null;
}
 
Example 18
Source File: NumberFormatter.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Invoked to toggle the sign. For this to work the value class
 * must have a single arg constructor that takes a String.
 */
private Object toggleSign(boolean positive) throws ParseException {
    Object value = stringToValue(getFormattedTextField().getText());

    if (value != null) {
        // toString isn't localized, so that using +/- should work
        // correctly.
        String string = value.toString();

        if (string != null && string.length() > 0) {
            if (positive) {
                if (string.charAt(0) == '-') {
                    string = string.substring(1);
                }
            }
            else {
                if (string.charAt(0) == '+') {
                    string = string.substring(1);
                }
                if (string.length() > 0 && string.charAt(0) != '-') {
                    string = "-" + string;
                }
            }
            if (string != null) {
                Class<?> valueClass = getValueClass();

                if (valueClass == null) {
                    valueClass = value.getClass();
                }
                try {
                    ReflectUtil.checkPackageAccess(valueClass);
                    SwingUtilities2.checkAccess(valueClass.getModifiers());
                    Constructor cons = valueClass.getConstructor(
                                          new Class[] { String.class });
                    if (cons != null) {
                        SwingUtilities2.checkAccess(cons.getModifiers());
                        return cons.newInstance(new Object[]{string});
                    }
                } catch (Throwable ex) { }
            }
        }
    }
    return null;
}
 
Example 19
Source File: NumberFormatter.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Invoked to toggle the sign. For this to work the value class
 * must have a single arg constructor that takes a String.
 */
private Object toggleSign(boolean positive) throws ParseException {
    Object value = stringToValue(getFormattedTextField().getText());

    if (value != null) {
        // toString isn't localized, so that using +/- should work
        // correctly.
        String string = value.toString();

        if (string != null && string.length() > 0) {
            if (positive) {
                if (string.charAt(0) == '-') {
                    string = string.substring(1);
                }
            }
            else {
                if (string.charAt(0) == '+') {
                    string = string.substring(1);
                }
                if (string.length() > 0 && string.charAt(0) != '-') {
                    string = "-" + string;
                }
            }
            if (string != null) {
                Class<?> valueClass = getValueClass();

                if (valueClass == null) {
                    valueClass = value.getClass();
                }
                try {
                    ReflectUtil.checkPackageAccess(valueClass);
                    SwingUtilities2.checkAccess(valueClass.getModifiers());
                    Constructor cons = valueClass.getConstructor(
                                          new Class[] { String.class });
                    if (cons != null) {
                        SwingUtilities2.checkAccess(cons.getModifiers());
                        return cons.newInstance(new Object[]{string});
                    }
                } catch (Throwable ex) { }
            }
        }
    }
    return null;
}
 
Example 20
Source File: NumberFormatter.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Invoked to toggle the sign. For this to work the value class
 * must have a single arg constructor that takes a String.
 */
private Object toggleSign(boolean positive) throws ParseException {
    Object value = stringToValue(getFormattedTextField().getText());

    if (value != null) {
        // toString isn't localized, so that using +/- should work
        // correctly.
        String string = value.toString();

        if (string != null && string.length() > 0) {
            if (positive) {
                if (string.charAt(0) == '-') {
                    string = string.substring(1);
                }
            }
            else {
                if (string.charAt(0) == '+') {
                    string = string.substring(1);
                }
                if (string.length() > 0 && string.charAt(0) != '-') {
                    string = "-" + string;
                }
            }
            if (string != null) {
                Class<?> valueClass = getValueClass();

                if (valueClass == null) {
                    valueClass = value.getClass();
                }
                try {
                    ReflectUtil.checkPackageAccess(valueClass);
                    SwingUtilities2.checkAccess(valueClass.getModifiers());
                    Constructor cons = valueClass.getConstructor(
                                          new Class[] { String.class });
                    if (cons != null) {
                        SwingUtilities2.checkAccess(cons.getModifiers());
                        return cons.newInstance(new Object[]{string});
                    }
                } catch (Throwable ex) { }
            }
        }
    }
    return null;
}