From 96755ebc406ef4861500429082fc975db2c9200d Mon Sep 17 00:00:00 2001
From: Patrick Plitzner
Date: Wed, 28 Oct 2015 18:44:30 +0100
Subject: [PATCH 1/1] Trim code
---
.../taxeditor/ui/element/ImageElement.java | 84 ++++++-------------
1 file changed, 27 insertions(+), 57 deletions(-)
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/ImageElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/ImageElement.java
index 090413bb9..92ab62f7f 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/ImageElement.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/ImageElement.java
@@ -1,9 +1,9 @@
// $Id$
/**
* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
+* European Distributed Institute of Taxonomy
* http://www.e-taxonomy.eu
-*
+*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* See LICENSE.TXT at the top of this package for the full license terms.
*/
@@ -35,8 +35,6 @@ import eu.etaxonomy.cdm.common.UriUtils;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
/**
- * ImageElement class.
- *
* @author n.hoffmann
* @created Sep 24, 2010
* @version 1.0
@@ -45,59 +43,37 @@ public class ImageElement extends AbstractCdmFormElement implements PaintListene
private URI imageUri;
private Image image;
-
+
private Composite container;
- /**
- * Constructor for ImageElement.
- *
- * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
- * @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
- * @param imageUri a {@link java.net.URI} object.
- * @param style a int.
- */
protected ImageElement(CdmFormFactory formFactory, ICdmFormElement parentElement, URI imageUri, int style) {
super(formFactory, parentElement);
-
+
container = new Composite(getLayoutComposite(), style);
container.setLayoutData(LayoutConstants.FILL(2, 1));
-
+
container.addPaintListener(this);
}
- /**
- * Setter for the field imageUri
.
- *
- * @param uri a {@link java.net.URI} object.
- * @throws HttpException
- * @throws IOException
- */
public void initImageUri(URI uri) throws IOException, HttpException {
this.imageUri = uri;
InputStream imageStream = UriUtils.getInputStream(imageUri);
image = new Image(Display.getCurrent(), imageStream);
}
-
-
- /**
- * Getter for the field imageUri
.
- *
- * @return the imageUri
- */
+
+
public URI getImageUri() {
return imageUri;
}
-
+
public void loadImage(){
loadImage(null);
}
-
-
-
+
public void loadImage(final Runnable postRunnable){
if(getImageUri() != null){
Job job = new Job("Loading image") {
-
+
@Override
protected IStatus run(IProgressMonitor monitor) {
IRunnableWithProgress runnable = getLoadImageRunnable(postRunnable);
@@ -106,19 +82,17 @@ public class ImageElement extends AbstractCdmFormElement implements PaintListene
} catch (Exception e) {
MessagingUtils.messageDialog("Could not load image", getClass(), e.getMessage() + ": " + getImageUri(), e);
}
-
+
return Status.OK_STATUS;
}
};
job.schedule();
}
}
-
-
public void unloadImage(final Runnable postRunnable) {
Job job = new Job("Unloading image") {
-
+
@Override
protected IStatus run(IProgressMonitor monitor) {
IRunnableWithProgress runnable = getLoadImageRunnable(postRunnable);
@@ -127,24 +101,24 @@ public class ImageElement extends AbstractCdmFormElement implements PaintListene
} catch (Exception e) {
MessagingUtils.messageDialog("Could not unload image", getClass(), e.getMessage() + ": " + getImageUri(), e);
}
-
+
return Status.OK_STATUS;
}
};
job.schedule();
-
+
}
-
+
public IRunnableWithProgress getLoadImageRunnable(final Runnable postRunnable){
-
- final Display display = getLayoutComposite().getDisplay();
-
+
+ final Display display = getLayoutComposite().getDisplay();
+
IRunnableWithProgress runnable = new IRunnableWithProgress(){
-
+
@Override
public void run(IProgressMonitor monitor) {
monitor.beginTask("Loading: " + getImageUri(), IProgressMonitor.UNKNOWN);
-
+
// redraw the image container
display.asyncExec(new Runnable(){
@Override
@@ -159,37 +133,33 @@ public class ImageElement extends AbstractCdmFormElement implements PaintListene
}
}
});
-
+
// execute the external runnable
if(postRunnable != null){
display.asyncExec(postRunnable);
}
- monitor.done();
+ monitor.done();
}
};
-
+
return runnable;
}
-
+
private Rectangle calculateImageBounds(Image image, Control control){
Rectangle imageBounds = image.getBounds();
Rectangle containerBounds = control.getBounds();
-
+
Integer imgWidth = imageBounds.width;
Integer imgHeight = imageBounds.height;
-
+
Float ratio = imgHeight.floatValue()/imgWidth.floatValue();
Integer width = containerBounds.width;
Integer height = ((Float) (width * ratio)).intValue();
-
+
return new Rectangle(containerBounds.x, containerBounds.y, width, height);
}
-
- /* (non-Javadoc)
- * @see org.eclipse.swt.events.PaintListener#paintControl(org.eclipse.swt.events.PaintEvent)
- */
/** {@inheritDoc} */
@Override
public void paintControl(PaintEvent e) {
--
2.34.1