Package org.jdesktop.application.ResourceConverter

Examples of org.jdesktop.application.ResourceConverter.ResourceConverterException


        throws ResourceConverterException
    {
  String rPath = resourcePath(s, resourceMap);
  if (rPath == null) {
      String msg = String.format("invalid image/icon path \"%s\"", s);
      throw new ResourceConverterException(msg, s);
  }
  URL url = resourceMap.getClassLoader().getResource(rPath);
  if (url != null) {
      return new ImageIcon(url);
  }
  else {
      String msg = String.format("couldn't find Icon resource \"%s\"", s);
      throw new ResourceConverterException(msg, s);
  }
    }
View Full Code Here


     * of the numbers is specified by Double.valueOf().
     */
    private static List<Double> parseDoubles(final String s, final int n, final String errorMsg) throws ResourceConverterException {
        String[] doubleStrings = s.split(",", n + 1);
        if (doubleStrings.length != n) {
            throw new ResourceConverterException(errorMsg, s);
        }
        else {
            List<Double> doubles = new ArrayList<Double>(n);
            for(String doubleString : doubleStrings) {
                try {
                    doubles.add(Double.valueOf(doubleString));
                }
                catch(NumberFormatException e) {
                    throw new ResourceConverterException(errorMsg, s, e);
                }
            }
            return doubles;
        }
    }
View Full Code Here

    private static class ColorStringConverter extends ResourceConverter {
  ColorStringConverter() {
      super(Color.class);
  }
  private void error(final String msg, final String s, final Exception e) throws ResourceConverterException  {
      throw new ResourceConverterException(msg, s, e);
  }
View Full Code Here

        int alpha = Integer.decode(s.substring(0, 3));
        int rgb = Integer.decode("#" + s.substring(3));
        color = new Color(alpha << 24 | rgb, true);
        break;
    default:
        throw new ResourceConverterException("invalid #RRGGBB or #AARRGGBB color string", s);
    }
      }
      else {
    String[] parts = s.split(",");
    if (parts.length < 3 || parts.length > 4) {
        throw new ResourceConverterException("invalid R, G, B[, A] color string", s);
    }
    try {
        // with alpha component
        if (parts.length == 4) {
      int r = Integer.parseInt(parts[0].trim());
      int g = Integer.parseInt(parts[1].trim());
      int b = Integer.parseInt(parts[2].trim());
      int a = Integer.parseInt(parts[3].trim());
      color = new Color(r, g, b, a);
        } else {
      int r = Integer.parseInt(parts[0].trim());
      int g = Integer.parseInt(parts[1].trim());
      int b = Integer.parseInt(parts[2].trim());
      color = new Color(r, g, b);
        }
    }
    catch (NumberFormatException e) {
        throw new ResourceConverterException("invalid R, G, B[, A] color string", s, e);
    }
      }
      return color;
  }
View Full Code Here

        throws ResourceConverterException
    {
  String rPath = resourcePath(s, resourceMap);
  if (rPath == null) {
      String msg = String.format("invalid image/icon path \"%s\"", s);
      throw new ResourceConverterException(msg, s);
  }
  URL url = resourceMap.getClassLoader().getResource(rPath);
  if (url != null) {
      return new ImageIcon(url);
  }
  else {
      String msg = String.format("couldn't find Icon resource \"%s\"", s);
      throw new ResourceConverterException(msg, s);
  }
    }
View Full Code Here

     * of the numbers is specified by Double.valueOf().
     */
    private static List<Double> parseDoubles(final String s, final int n, final String errorMsg) throws ResourceConverterException {
        String[] doubleStrings = s.split(",", n + 1);
        if (doubleStrings.length != n) {
            throw new ResourceConverterException(errorMsg, s);
        }
        else {
            List<Double> doubles = new ArrayList<Double>(n);
            for(String doubleString : doubleStrings) {
                try {
                    doubles.add(Double.valueOf(doubleString));
                }
                catch(NumberFormatException e) {
                    throw new ResourceConverterException(errorMsg, s, e);
                }
            }
            return doubles;
        }
    }
View Full Code Here

    private static class ColorStringConverter extends ResourceConverter {
  ColorStringConverter() {
      super(Color.class);
  }
  private void error(final String msg, final String s, final Exception e) throws ResourceConverterException  {
      throw new ResourceConverterException(msg, s, e);
  }
View Full Code Here

        int alpha = Integer.decode(s.substring(0, 3));
        int rgb = Integer.decode("#" + s.substring(3));
        color = new Color(alpha << 24 | rgb, true);
        break;
    default:
        throw new ResourceConverterException("invalid #RRGGBB or #AARRGGBB color string", s);
    }
      }
      else {
    String[] parts = s.split(",");
    if (parts.length < 3 || parts.length > 4) {
        throw new ResourceConverterException("invalid R, G, B[, A] color string", s);
    }
    try {
        // with alpha component
        if (parts.length == 4) {
      int r = Integer.parseInt(parts[0].trim());
      int g = Integer.parseInt(parts[1].trim());
      int b = Integer.parseInt(parts[2].trim());
      int a = Integer.parseInt(parts[3].trim());
      color = new Color(r, g, b, a);
        } else {
      int r = Integer.parseInt(parts[0].trim());
      int g = Integer.parseInt(parts[1].trim());
      int b = Integer.parseInt(parts[2].trim());
      color = new Color(r, g, b);
        }
    }
    catch (NumberFormatException e) {
        throw new ResourceConverterException("invalid R, G, B[, A] color string", s, e);
    }
      }
      return color;
  }
View Full Code Here

TOP

Related Classes of org.jdesktop.application.ResourceConverter.ResourceConverterException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.