/** @noRefGuide */ private int prepareImage() { long t0 = time(); printf("ImageColorMap.prepareImage()\n"); Object imageSource = mp_imageSource.getValue(); if (imageSource == null) throw new RuntimeException("imageSource is null"); if (imageSource instanceof String) { try { m_imageData = new ImageColor(ImageIO.read(new File((String) imageSource))); } catch (IOException e) { printf("Can't find file: %s\n", imageSource); // empty 1x1 image m_imageData = new ImageColor(1, 1); throw new RuntimeException(e); } } else if (imageSource instanceof Text2D) { m_imageData = new ImageColor(((Text2D) imageSource).getImage()); } else if (imageSource instanceof FormattedText2D) { m_imageData = new ImageColor(((FormattedText2D) imageSource).getImage()); } else if (imageSource instanceof BufferedImage) { m_imageData = new ImageColor((BufferedImage) imageSource); } else if (imageSource instanceof ImageWrapper) { m_imageData = new ImageColor(((ImageWrapper) imageSource).getImage()); } if (m_imageData == null) { // Cast to String for now, not sure how to really handle this String file = imageSource.toString(); printf("Converted to string: " + file); try { m_imageData = new ImageColor(ImageIO.read(new File(file))); } catch (IOException e) { // empty 1x1 image m_imageData = new ImageColor(1, 1); throw new RuntimeException(e); } } if (m_imageData == null) { m_imageData = new ImageColor(1, 1); throw new IllegalArgumentException( "Unhandled imageSource: " + imageSource + " class: " + imageSource.getClass()); } return ResultCodes.RESULT_OK; }
/** Removes all picked elements. */ public final void removeAllElements() { LinkedHashSet<String> elements = (LinkedHashSet<String>) selection.getValue(); elements.clear(); markDirty(); }
/** * Removes the given element id from the picked element list * * @param id a valid element id */ public final void removeElement(String id) { LinkedHashSet<String> elements = (LinkedHashSet<String>) selection.getValue(); elements.remove(id); markDirty(); }
private final void copySelection(HashSet<String> newSelection) { HashSet<String> _selection = (HashSet<String>) selection.getValue(); _selection.clear(); _selection.addAll(newSelection); markDirty(); }
/** * Sets the selection parameter. Note that in order to take effect the parameter value should be * of type {@link LinkedHashSet} (to keep adding order). The <code>HashSet</code> should contain * the {@link Element} ids of the picked elements. * * @param selection */ public final void setSelection(ObjectParameter selection) { // this.selection = selection; Object value = selection.getValue(); if (value instanceof HashSet) copySelection((HashSet<String>) value); getSelection().bind(subset); }
/** * Get the source image * * @return */ public Object getImage() { return mp_imageSource.getValue(); }