Trim code
authorPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 28 Oct 2015 17:44:30 +0000 (18:44 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Thu, 29 Oct 2015 10:04:49 +0000 (11:04 +0100)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/ImageElement.java

index 090413bb9fe20aea585212bfe59d5cfc7b5bce54..92ab62f7f7b61e0d6a505bd9aa7beba3fd552549 100644 (file)
@@ -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;
 
 /**
- * <p>ImageElement class.</p>
- *
  * @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;
 
-       /**
-        * <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.
-        */
        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);
@@ -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) {