• Views
  • Iteration Report
  • My Iteration Report
  •  
OMERO.clients
  • Login
  • Help/Guide
  • About Trac
  • Preferences
  • Wiki
  • Timeline
  • Roadmap
  • Browse Source
  • View Tickets
  • Search

Context Navigation

  • ← Previous Change
  • Next Change →

Changeset 4628 for trunk/SRC

Show
Ignore:
Timestamp:
11/30/06 12:10:23 (2 years ago)
Author:
jburel
Message:

add code to allow the user to magnify the thumbnail

Location:
trunk/SRC/org/openmicroscopy/shoola
Files:
10 modified

  • agents/hiviewer/util/RollOverCanvas.java (modified) (3 diffs)
  • agents/hiviewer/util/RollOverWin.java (modified) (6 diffs)
  • env/ui/tdialog/BorderListener.java (modified) (2 diffs)
  • env/ui/tdialog/DialogControl.java (modified) (4 diffs)
  • env/ui/tdialog/ScreenControl.java (modified) (1 diff)
  • env/ui/tdialog/ThumbnailCanvas.java (modified) (3 diffs)
  • env/ui/tdialog/TinyDialog.java (modified) (5 diffs)
  • env/ui/tdialog/TinyDialogUI.java (modified) (2 diffs)
  • util/image/geom/Factory.java (modified) (2 diffs)
  • util/ui/lens/LensController.java (modified) (1 diff)

Legend:

Unmodified
Added
Removed
  • trunk/SRC/org/openmicroscopy/shoola/agents/hiviewer/util/RollOverCanvas.java

    r4600 r4628  
    4141import java.awt.event.MouseAdapter; 
    4242import java.awt.event.MouseEvent; 
     43import java.awt.event.MouseWheelEvent; 
     44import java.awt.event.MouseWheelListener; 
    4345import javax.swing.BorderFactory; 
    4446import javax.swing.ImageIcon; 
    … …  
    100102    private Rectangle           classifiedRectangle; 
    101103 
     104 
    102105    /** 
    103106     * Creates a new instance.  
    … …  
    129132            } 
    130133        }); 
     134        addMouseWheelListener(new MouseWheelListener() { 
     135                        public void mouseWheelMoved(MouseWheelEvent e) { 
     136                                model.magnifyImage(e.getWheelRotation()); 
     137                        } 
     138                }); 
    131139    } 
    132140     
  • trunk/SRC/org/openmicroscopy/shoola/agents/hiviewer/util/RollOverWin.java

    r4585 r4628  
    5353import org.openmicroscopy.shoola.agents.hiviewer.browser.Thumbnail; 
    5454import org.openmicroscopy.shoola.agents.hiviewer.cmd.ViewCmd; 
     55import org.openmicroscopy.shoola.util.image.geom.Factory; 
    5556 
    5657import pojos.DataObject; 
    … …  
    7677{ 
    7778 
     79    /** The minimum magnification value. */ 
     80    final static int            MINIMUM_ZOOM = 1; 
     81     
     82    /** The maximum magnification value. */ 
     83    final static int            MAXIMUM_ZOOM = 2; 
     84     
    7885    /** ImageNode displayed. */ 
    79     public ImageNode        node; 
     86    private ImageNode        node; 
    8087     
    8188    /** The image to display. */ 
    8289    private BufferedImage   image; 
    8390     
     91    /** The image to display. */ 
     92    private BufferedImage   originalImage; 
     93     
    8494    /** The canvas hosting the image. */ 
    8595    private RollOverCanvas  canvas; 
    … …  
    8898    private Browser         browser; 
    8999     
     100    /** The magnification factor. */ 
     101    private float                       zoomFactor; 
     102 
    90103    /** Sets the property of the dialog window. */  
    91104    private void setProperties() 
    … …  
    94107        setResizable(false); 
    95108        setUndecorated(true); 
     109        zoomFactor = MINIMUM_ZOOM; 
    96110    } 
    97111     
    … …  
    137151    } 
    138152     
     153    /** 
     154     * Magnifies the displayed image. 
     155     *  
     156     * @param tick The number of "clicks" the mouse wheel was rotated. 
     157     */ 
     158    void magnifyImage(int tick) 
     159    { 
     160                zoomFactor -= 0.1f*tick; 
     161                zoomFactor = Math.round(zoomFactor*10)/10.0f; 
     162                if (zoomFactor < RollOverWin.MINIMUM_ZOOM) 
     163                        zoomFactor = RollOverWin.MINIMUM_ZOOM; 
     164                if (zoomFactor > RollOverWin.MAXIMUM_ZOOM) 
     165                        zoomFactor = RollOverWin.MAXIMUM_ZOOM; 
     166                image = Factory.magnifyImage(zoomFactor, originalImage); 
     167                makeComponentsSize(image.getWidth(), image.getHeight()); 
     168                pack(); 
     169    } 
     170     
     171 
    139172    /** Pins the thumbnail. */ 
    140173    void pinThumbnail() { browser.setThumbSelected(true, node); } 
    … …  
    184217        if (full != null)  { 
    185218            image = full; 
     219            originalImage = full; 
    186220            makeComponentsSize(image.getWidth(), image.getHeight()); 
    187221            canvas.repaint(); 
  • trunk/SRC/org/openmicroscopy/shoola/env/ui/tdialog/BorderListener.java

    r3096 r4628  
    7070    /** Reference to the model. */ 
    7171    private TinyDialog  model; 
    72      
    7372 
    7473    /**  
    … …  
    9493        this.model = model; 
    9594    } 
    96  
    9795     
    9896    /** 
  • trunk/SRC/org/openmicroscopy/shoola/env/ui/tdialog/DialogControl.java

    r3096 r4628  
    3737import java.awt.event.MouseListener; 
    3838import java.awt.event.MouseMotionListener; 
     39import java.awt.event.MouseWheelEvent; 
     40import java.awt.event.MouseWheelListener; 
     41import java.awt.image.BufferedImage; 
    3942import java.beans.PropertyChangeEvent; 
    4043import java.beans.PropertyChangeListener; 
    4144 
     45 
    4246//Third-party libraries 
    4347 
    4448//Application-internal dependencies 
     49import org.openmicroscopy.shoola.util.image.geom.Factory; 
    4550 
    4651/**  
    … …  
    6469class DialogControl 
    6570    implements  
    66     PropertyChangeListener, ActionListener, MouseListener, MouseMotionListener 
     71    PropertyChangeListener, ActionListener, MouseListener, MouseMotionListener, 
     72    MouseWheelListener 
    6773{ 
    6874     
    69     /** Action command ID. */ 
    70     static final int        SIZE = 0, CLOSE = 1; 
     75    /** Action command ID to modify the size of the component. */ 
     76    static final int        SIZE = 0; 
     77     
     78    /** Action command ID to modify the close of the component. */ 
     79    static final int            CLOSE = 1; 
    7180     
    7281    /** The window this controller is for. */ 
    … …  
    7887    /** The mouse events controller. */ 
    7988    private ScreenControl   sControl; 
    80      
     89 
    8190    /** 
    8291     * Creates a new instance to control a given {@link TinyDialog} and 
    8392     * notify its View. 
    8493     *  
    85      * @param model The window. Mustn't be <code>null</code>. 
    86      * @param view The window's UI. Mustn't be <code>null</code>. 
     94     * @param model     The window. Mustn't be <code>null</code>. 
     95     * @param view      The window's UI. Mustn't be <code>null</code>. 
    8796     */ 
    8897    DialogControl(TinyDialog model, TinyDialogUI view) 
    … …  
    147156 
    148157    /**  
     158     * Modifies the magnification factor depending on the number of "clicks" 
     159     * the mouse wheel was rotated. 
     160     *  
     161     * @see MouseWheelListener#mouseWheelMoved(MouseWheelEvent) 
     162     */ 
     163        public void mouseWheelMoved(MouseWheelEvent e) 
     164        { 
     165                float zoomFactor = model.getZoomFactor(); 
     166                zoomFactor -= 0.1f*e.getWheelRotation(); 
     167                zoomFactor = Math.round(zoomFactor*10)/10.0f; 
     168                if (zoomFactor < TinyDialog.MINIMUM_ZOOM) 
     169                        zoomFactor = TinyDialog.MINIMUM_ZOOM; 
     170                if (zoomFactor > TinyDialog.MAXIMUM_ZOOM) 
     171                        zoomFactor = TinyDialog.MAXIMUM_ZOOM; 
     172                model.setZoomFactor(zoomFactor); 
     173                BufferedImage img = Factory.magnifyImage(zoomFactor,  
     174                                                                                model.getOriginalImage()); 
     175                view.setImage(img); 
     176        } 
     177         
     178    /**  
    149179     * Forward event to the <code>Screen control</code>.  
    150180     * @see MouseListener#mousePressed(MouseEvent) 
  • trunk/SRC/org/openmicroscopy/shoola/env/ui/tdialog/ScreenControl.java

    r3096 r4628  
    6464{ 
    6565     
    66     /** MousePressed location in absolute coordinate system .*/ 
    67     private int             xAbs, yAbs; 
     66    /**  
     67     * The x-coordinate of mouse in absolute coordinate system  
     68     * when the mouse is pressed. 
     69     */ 
     70    private int             xAbs; 
    6871     
    69     /** MousePressed location in source view's coordinate system .*/ 
    70     private int             xView, yView; 
    71  
     72    /**  
     73     * The y-coordinate of mouse in absolute coordinate system  
     74     * when the mouse is pressed. 
     75     */ 
     76    private int                         yAbs; 
     77     
     78    /**  
     79     * The y-coordinate of mouse in source view's coordinate system  
     80     * when the mouse is pressed. 
     81     */ 
     82    private int             xView; 
     83     
     84    /**  
     85     * The y-coordinate of mouse in source view's coordinate system  
     86     * when the mouse is pressed. 
     87     */ 
     88    private int             yView; 
     89     
    7290    /** Dragging control. */ 
    7391    private boolean         dragging; 
  • trunk/SRC/org/openmicroscopy/shoola/env/ui/tdialog/ThumbnailCanvas.java

    r3929 r4628  
    6363 
    6464    /** The {@link BufferedImage} to paint. */ 
    65     private BufferedImage   image; 
     65    private BufferedImage       image; 
    6666     
    6767    /** 
    … …  
    7676    } 
    7777     
     78    /**  
     79     * Sets the image to paint. 
     80     *  
     81     * @param image The {@link BufferedImage} to paint.  
     82     */ 
     83    void setImage(BufferedImage image) { this.image = image; } 
     84         
    7885    /** 
    79      * Overriden to paint the thumbnail. 
     86     * Overridden to paint the thumbnail. 
    8087     * @see JComponent#paintComponent(Graphics) 
    8188     */ 
    … …  
    8996        }   
    9097    } 
     98 
    9199     
    92100} 
  • trunk/SRC/org/openmicroscopy/shoola/env/ui/tdialog/TinyDialog.java

    r3929 r4628  
    7474    public final static String TITLE_PROPERTY = "title"; 
    7575     
     76    /** The minimum magnification value. */ 
     77    final static int            MINIMUM_ZOOM = 1; 
     78     
     79    /** The maximum magnification value. */ 
     80    final static int            MAXIMUM_ZOOM = 2; 
     81     
    7682    /** The size of the frame before the last collapse request. */ 
    7783    private Dimension       restoreSize; 
    … …  
    9197    /** Tells if the close button is displayed. */ 
    9298    private boolean         closedButton; 
     99     
     100    /** The image to display. */ 
     101    private BufferedImage       originalImage; 
     102     
     103    /** The magnification factor. */ 
     104    private float                       zoomFactor; 
    93105     
    94106    /** The title displayed in this window's title bar. */ 
    … …  
    102114        setUndecorated(true); 
    103115        setRestoreSize(new Dimension(getWidth(), getHeight())); 
    104     } 
     116        zoomFactor = MINIMUM_ZOOM; 
     117    } 
     118     
     119    /**  
     120     * Returns the original image to display. 
     121     *  
     122     * @return Se above 
     123     */ 
     124    BufferedImage getOriginalImage() { return originalImage; } 
     125     
     126    /** 
     127     * Returns the magnification factor. 
     128     *  
     129     * @return See above. 
     130     */ 
     131    float getZoomFactor() { return zoomFactor; } 
     132     
     133    /** 
     134     * Sets the magnification factor. 
     135     *  
     136     * @param v The value to set. 
     137     */ 
     138    void setZoomFactor(float v) { zoomFactor = v; } 
    105139     
    106140    /** 
    … …  
    153187        if (image == null) throw new NullPointerException("No image."); 
    154188        this.title = title; 
     189        originalImage = image; 
     190        zoomFactor = MINIMUM_ZOOM; 
    155191        closedButton = true; 
    156192        //Create the View and the Controller. 
    157193        uiDelegate = new TinyDialogUI(this, image); 
    158194        controller = new DialogControl(this, uiDelegate); 
     195        uiDelegate.attachMouseWheelListener(controller); 
    159196    } 
    160197     
    … …  
    330367    } 
    331368 
    332  
    333  
    334369} 
  • trunk/SRC/org/openmicroscopy/shoola/env/ui/tdialog/TinyDialogUI.java

    r3929 r4628  
    4242import java.awt.event.MouseListener; 
    4343import java.awt.event.MouseMotionListener; 
     44import java.awt.event.MouseWheelListener; 
    4445import java.awt.image.BufferedImage; 
    4546import javax.swing.BorderFactory; 
    … …  
    251252        makeBorders(); 
    252253        buildUI(); 
     254    } 
     255     
     256    /** 
     257     * Sets the image to paint if the canvas is an instance of  
     258     * <code>ThumbnailCanvas</code>. 
     259     *  
     260     * @param image The image to paint. 
     261     */ 
     262    void setImage(BufferedImage image) 
     263    { 
     264        if (canvas instanceof ThumbnailCanvas) { 
     265                makeComponentsSize(image.getWidth(), image.getHeight());  
     266                ((ThumbnailCanvas) canvas).setImage(image); 
     267                //window.getContentPane().removeAll(); 
     268                //buildUI(); 
     269                window.pack(); 
     270        } 
     271    } 
     272     
     273    /** 
     274     * Adds a {@link MouseWheelListener} to the canvas if the canvas is  
     275     * an instance of <code>ThumbnailCanvas</code>. 
     276     *  
     277     * @param controller The listener to add. 
     278     */ 
     279    void attachMouseWheelListener(MouseWheelListener controller) 
     280    { 
     281        if (canvas instanceof ThumbnailCanvas)  
     282                canvas.addMouseWheelListener(controller); 
    253283    } 
    254284     
  • trunk/SRC/org/openmicroscopy/shoola/util/image/geom/Factory.java

    r3780 r4628  
    8989    private static final int            BORDER = 2; 
    9090     
     91    /** The default message for the default thumbnail. */ 
    9192    private static final String         DEFAULT_TEXT = "No thumbnail"; 
    9293     
    … …  
    102103            0.1f, 0.2f, 0.1f, 
    103104            0.1f, 0.1f, 0.1f}; 
     105 
     106    /**  
     107     * Magnifies the specified image. 
     108     *  
     109     * @param f the magnification factor. 
     110     * @param img The image to magnify. 
     111     *  
     112     * @return The magnified image. 
     113     */ 
     114    public static BufferedImage magnifyImage(double f, BufferedImage img) 
     115    { 
     116        if (img == null) return null; 
     117        int width = img.getWidth(), height = img.getHeight(); 
     118        AffineTransform at = new AffineTransform(); 
     119        at.scale(f, f); 
     120        BufferedImageOp biop = new AffineTransformOp(at,  
     121            AffineTransformOp.TYPE_BILINEAR);  
     122        BufferedImage rescaleBuff = new BufferedImage((int) (width*f),  
     123                        (int) (height*f), img.getType()); 
     124        biop.filter(img, rescaleBuff); 
     125        return rescaleBuff; 
     126    } 
    104127     
    105128    /** 
  • trunk/SRC/org/openmicroscopy/shoola/util/ui/lens/LensController.java

    r4627 r4628  
    250250         
    251251        /** 
    252          * MouseWheelMoved event 
    253          *  
    254          * @param tick 
     252         * Magnifies the image. 
     253         *  
     254         * @param tick The number of "clicks" the mouse wheel was rotated. 
    255255         */ 
    256256        void lensMouseWheelMoved(int tick) 

Download in other formats:

  • Unified Diff
  • Zip Archive

Trac Powered

Powered by Trac 0.11
By Edgewall Software.

Visit the Trac open source project at
http://trac.edgewall.org/