Пример #1
0
  protected void handleAsClassWithArg(String str) {
    String[] args = str.split("\\|");
    if (args.length == 2) {
      Class<?> iconClass = null;
      try {
        iconClass = ImagePropertyEditor.class.getClassLoader().loadClass(args[0]);
      } catch (ClassNotFoundException e) {
        throw illegalValue(str, Image.class, e);
      }

      Constructor<?> constructor = null;
      try {
        constructor = iconClass.getConstructor(String.class);
      } catch (NoSuchMethodException e) {
        throw illegalValue(str, Image.class, e);
      }

      try {
        Object o = constructor.newInstance(args[1]);
        if (o instanceof Image) {
          super.setValueInternal(o);
        } else if (o instanceof ImageView) {
          super.setValueInternal(((ImageView) o).getImage());
        } else {
          throw illegalValue(str, Image.class);
        }
      } catch (InstantiationException | InvocationTargetException | IllegalAccessException e) {
        throw illegalValue(str, Image.class, e);
      }
    } else {
      throw illegalValue(str, Image.class);
    }
  }
  protected void handleAsMap(Map<?, ?> map) {
    if (map.isEmpty()) {
      super.setValueInternal(null);
      return;
    }

    double x = getMapValue(map, "x", 0);
    double y = getMapValue(map, "y", 0);
    double w = getMapValue(map, "width", 0);
    double h = getMapValue(map, "height", 0);
    super.setValueInternal(new Rectangle2D(x, y, w, h));
  }
 protected void setValueInternal(Object value) {
   if (null == value) {
     super.setValueInternal(null);
   } else if (value instanceof CharSequence) {
     handleAsString(String.valueOf(value));
   } else if (value instanceof List) {
     handleAsList((List) value);
   } else if (value instanceof Map) {
     handleAsMap((Map) value);
   } else if (value instanceof Rectangle2D) {
     super.setValueInternal(value);
   } else {
     throw illegalValue(value, Rectangle2D.class);
   }
 }
Пример #4
0
 protected void handleAsInputStream(InputStream stream) {
   try {
     super.setValueInternal(new Image(stream));
   } catch (Exception e) {
     throw illegalValue(stream, URL.class, e);
   }
 }
Пример #5
0
 protected void handleAsURL(URL url) {
   try {
     super.setValueInternal(new Image(url.toString()));
   } catch (Exception e) {
     throw illegalValue(url, URL.class, e);
   }
 }
Пример #6
0
 protected void handleAsString(String str) {
   if (isBlank(str)) {
     super.setValueInternal(null);
   } else if (str.contains("|")) {
     handleAsClassWithArg(str);
   } else {
     handleAsURL(getClass().getClassLoader().getResource(str));
   }
 }
  protected void handleAsList(List<?> list) {
    if (list.isEmpty()) {
      super.setValueInternal(null);
      return;
    }

    switch (list.size()) {
      case 4:
        double x = parseValue(list.get(0));
        double y = parseValue(list.get(1));
        double w = parseValue(list.get(2));
        double h = parseValue(list.get(3));
        super.setValueInternal(new Rectangle2D(x, y, w, h));
        break;
      default:
        throw illegalValue(list, Rectangle2D.class);
    }
  }
Пример #8
0
 protected void setValueInternal(Object value) {
   if (null == value) {
     super.setValueInternal(null);
   } else if (value instanceof CharSequence) {
     handleAsString(String.valueOf(value));
   } else if (value instanceof File) {
     handleAsFile((File) value);
   } else if (value instanceof URL) {
     handleAsURL((URL) value);
   } else if (value instanceof URI) {
     handleAsURI((URI) value);
   } else if (value instanceof InputStream) {
     handleAsInputStream((InputStream) value);
   } else if (value instanceof Image) {
     super.setValueInternal(value);
   } else {
     throw illegalValue(value, Image.class);
   }
 }
  protected void handleAsString(String str) {
    if (isBlank(str)) {
      super.setValueInternal(null);
      return;
    }

    String[] parts = str.split(",");
    switch (parts.length) {
      case 4:
        double x = parseValue(parts[0]);
        double y = parseValue(parts[1]);
        double w = parseValue(parts[2]);
        double h = parseValue(parts[3]);
        super.setValueInternal(new Rectangle2D(x, y, w, h));
        break;
      default:
        throw illegalValue(str, Rectangle2D.class);
    }
  }