Commit 62414e92 authored by Valérie Maquil's avatar Valérie Maquil

added a width and height to the image coronas

parent b7a7f650
......@@ -29,6 +29,8 @@ import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.widget.corona.Image;
import lu.list.itis.dkd.tui.widget.corona.TextBox;
import com.google.common.base.Strings;
import org.jdom2.Element;
import java.io.File;
......@@ -53,6 +55,8 @@ public abstract class BaseImageBuilder<B extends BaseImageBuilder<B>> extends Co
/** Field holding an {@link InformationProvider} instances to draw information from. */
@Nullable
public InformationProvider<java.awt.Image> informationProvider = null;
public int width;
public int height;
/**
* Constructor setting the centre of the corona.
......@@ -79,11 +83,30 @@ public abstract class BaseImageBuilder<B extends BaseImageBuilder<B>> extends Co
protected BaseImageBuilder(Element rootElement) throws BuildException {
super(rootElement);
try {
Element imageNode = rootElement.getChild(Externalization.IMAGE_ELEMENT);
if (null != imageNode) {
java.lang.System.out.println(imageNode.getText());
image = ImageIO.read(new File(imageNode.getText()));
String w = rootElement.getChildText(Externalization.WIDTH_NODE);
String h = rootElement.getChildText(Externalization.HEIGHT_NODE);
if (Strings.isNullOrEmpty(w) || Strings.isNullOrEmpty(h)) {
image = ImageIO.read(new File(imageNode.getText()));
} else {
width = Integer.parseInt(w);
height = Integer.parseInt(h);
java.awt.Image inputImage = ImageIO.read(new File(imageNode.getText()));
image = inputImage.getScaledInstance(width, height, java.awt.Image.SCALE_AREA_AVERAGING);
}
}
} catch (NullPointerException npe) {
throw new BuildException("The provided image path may not be empty. To add no image, remove the \"image\" element!", npe); //$NON-NLS-1$
} catch (IllegalArgumentException iae) {
......
......@@ -37,6 +37,8 @@ import org.jdom2.Element;
*/
@NonNullByDefault
public final class ImageBuilder extends BaseImageBuilder<ImageBuilder> {
/**
* Constructor setting the centre of the corona.
*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment