-// $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.
*/
import org.eclipse.ui.forms.widgets.TableWrapData;
import eu.etaxonomy.cdm.common.UriUtils;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
/**
- * <p>ImageElement class.</p>
- *
* @author n.hoffmann
* @created Sep 24, 2010
* @version 1.0
private URI imageUri;
private Image image;
-
+
private Composite container;
- /**
- * <p>Constructor for ImageElement.</p>
- *
- * @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.
- */
+ private final Runnable postRunnable = new Runnable(){
+ @Override
+ public void run() {
+ AbstractUtility.reflowDetailsViewer();
+ AbstractUtility.reflowSupplementalViewer();
+ }
+ };
+
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);
}
- /**
- * <p>Setter for the field <code>imageUri</code>.</p>
- *
- * @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);
}
-
-
- /**
- * <p>Getter for the field <code>imageUri</code>.</p>
- *
- * @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);
} 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) {
+ public void unloadImage() {
Job job = new Job("Unloading image") {
-
+
@Override
protected IStatus run(IProgressMonitor monitor) {
IRunnableWithProgress runnable = getLoadImageRunnable(postRunnable);
} 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
public void run() {
- if(! getLayoutComposite().isDisposed()){
+ if(! getLayoutComposite().isDisposed() && container!=null){
Event untypedEvent = new Event();
untypedEvent.widget = container;
PaintEvent event = new PaintEvent(untypedEvent);
}
}
});
-
+
// 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);
}
+ public void dispose(){
+ if(image!=null){
+ image.dispose();
+ image = null;
+ }
+ imageUri = null;
+ if(container!=null){
+ container.dispose();
+ container = null;
+ }
+ }
- /* (non-Javadoc)
- * @see org.eclipse.swt.events.PaintListener#paintControl(org.eclipse.swt.events.PaintEvent)
- */
/** {@inheritDoc} */
@Override
public void paintControl(PaintEvent e) {