Coverage Report - wjhk.jupload2.gui.image.PictureDialog
 
Classes in this File Line Coverage Branch Coverage Complexity
PictureDialog
0 %
0/30
0 %
0/2
1,167
 
 1  
 //
 2  
 // $Id: PictureDialog.java 298 2007-07-12 10:17:32 +0000 (jeu., 12 juil. 2007)
 3  
 // etienne_sf $
 4  
 //
 5  
 // jupload - A file upload applet.
 6  
 // Copyright 2007 The JUpload Team
 7  
 //
 8  
 // Created: 2006-07-10
 9  
 // Creator: etienne_sf
 10  
 // Last modified: $Date: 2010-01-08 23:21:44 +0100 (ven., 08 janv. 2010) $
 11  
 //
 12  
 // This program is free software; you can redistribute it and/or modify it under
 13  
 // the terms of the GNU General Public License as published by the Free Software
 14  
 // Foundation; either version 2 of the License, or (at your option) any later
 15  
 // version. This program is distributed in the hope that it will be useful, but
 16  
 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 17  
 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 18  
 // details. You should have received a copy of the GNU General Public License
 19  
 // along with this program; if not, write to the Free Software Foundation, Inc.,
 20  
 // 675 Mass Ave, Cambridge, MA 02139, USA.
 21  
 
 22  
 package wjhk.jupload2.gui.image;
 23  
 
 24  
 import java.awt.BorderLayout;
 25  
 import java.awt.Cursor;
 26  
 import java.awt.Dimension;
 27  
 import java.awt.Frame;
 28  
 import java.awt.Toolkit;
 29  
 import java.awt.event.ActionEvent;
 30  
 import java.awt.event.ActionListener;
 31  
 import java.awt.event.ComponentEvent;
 32  
 import java.awt.event.ComponentListener;
 33  
 
 34  
 import javax.swing.JButton;
 35  
 import javax.swing.JDialog;
 36  
 
 37  
 import wjhk.jupload2.filedata.PictureFileData;
 38  
 import wjhk.jupload2.policies.UploadPolicy;
 39  
 
 40  
 /**
 41  
  * A maximized modal dialog box, that display the selected picture.
 42  
  * 
 43  
  * @author etienne_sf
 44  
  */
 45  
 public class PictureDialog extends JDialog implements ActionListener,
 46  
         ComponentListener {
 47  
 
 48  
     /** A generated serialVersionUID, to avoid warning during compilation */
 49  
     private static final long serialVersionUID = 7802205907550854333L;
 50  
 
 51  
     JButton buttonClose;
 52  
 
 53  0
     PictureFileData pictureFileData = null;
 54  
 
 55  0
     PicturePanel picturePanel = null;
 56  
 
 57  0
     UploadPolicy uploadPolicy = null;
 58  
 
 59  
     /**
 60  
      * Creates a new instance.
 61  
      * 
 62  
      * @param owner The parent frame.
 63  
      * @param pictureFileData The picture to manage.
 64  
      * @param uploadPolicy The upload policy which applies.
 65  
      */
 66  
     public PictureDialog(Frame owner, PictureFileData pictureFileData,
 67  
             UploadPolicy uploadPolicy) {
 68  0
         super(owner, pictureFileData.getFileName(), true);
 69  
 
 70  0
         this.uploadPolicy = uploadPolicy;
 71  0
         this.pictureFileData = pictureFileData;
 72  
 
 73  
         // This will be a long operation. The cursor will set back to normal in
 74  
         // componentShown, see below
 75  0
         setCursor(new Cursor(Cursor.WAIT_CURSOR));
 76  
 
 77  
         // Creation of the image area
 78  0
         this.picturePanel = new DialogPicturePanel(this, uploadPolicy,
 79  
                 pictureFileData);
 80  
 
 81  
         // Creation of the buttonClose button.
 82  0
         this.buttonClose = new JButton(uploadPolicy
 83  0
                 .getLocalizedString("buttonClose"));
 84  0
         this.buttonClose.setMaximumSize(new Dimension(100, 100));
 85  0
         this.buttonClose.addActionListener(this);
 86  
 
 87  0
         getContentPane().add(this.buttonClose, BorderLayout.SOUTH);
 88  0
         getContentPane().add(this.picturePanel);
 89  
 
 90  0
         pack();
 91  
         // Correction given by
 92  
         // setSize(getMaximumSize()); generate very high number under MAC OSX ->
 93  
         // Applet Crash
 94  0
         Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
 95  0
         setBounds(0, 0, screenSize.width, screenSize.height);
 96  
 
 97  
         // The dialog is modal: the next line will return when the DialogPicture
 98  
         // is hidden (to be closed, in our case)
 99  
         // But we want to know when it will becom visible, to clear the wait
 100  
         // cursor.
 101  0
         addComponentListener(this);
 102  0
         setVisible(true);
 103  
 
 104  
         // MEMORY LEAK CORRECTION :
 105  
 
 106  
         // Let's free some memory.
 107  
         // This is necessary, as the finalize method is not called (if anyone
 108  
         // has an explanation...).
 109  
         // So, I have to manually free the memory consummed to display the
 110  
         // image, here.
 111  0
         this.picturePanel.setPictureFile(null, null, null);
 112  0
     }
 113  
 
 114  
     /**
 115  
      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
 116  
      */
 117  
     public void actionPerformed(ActionEvent event) {
 118  0
         if (event.getActionCommand() == this.buttonClose.getActionCommand()) {
 119  0
             this.uploadPolicy.displayDebug(
 120  
                     "[PictureDialog] Before this.dispose()", 10);
 121  0
             this.dispose();
 122  
         }
 123  0
     }
 124  
 
 125  
     /** {@inheritDoc} */
 126  
     public void componentHidden(ComponentEvent arg0) {
 127  
         // No action
 128  0
     }
 129  
 
 130  
     /** {@inheritDoc} */
 131  
     public void componentMoved(ComponentEvent arg0) {
 132  
         // No action
 133  0
     }
 134  
 
 135  
     /** {@inheritDoc} */
 136  
     public void componentResized(ComponentEvent arg0) {
 137  
         // No action
 138  0
     }
 139  
 
 140  
     /** {@inheritDoc} */
 141  
     public void componentShown(ComponentEvent arg0) {
 142  
         // We set the cursor back to normal
 143  0
         setCursor(new Cursor(Cursor.HAND_CURSOR));
 144  0
     }
 145  
 
 146  
 }