[Title] merge ScreeenShot dialog from develop branch
authorSon Hyunjun <hj79.son@samsung.com>
Mon, 26 Mar 2012 12:42:39 +0000 (21:42 +0900)
committerSon Hyunjun <hj79.son@samsung.com>
Mon, 26 Mar 2012 12:42:39 +0000 (21:42 +0900)
[Type] Feature
[Module]
[Priority] Major
[CQ#]
[Redmine#]
[Problem]
[Cause]
[Solution]

package/pkginfo.manifest
tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkin.java
tizen/src/skin/client/src/org/tizen/emulator/skin/dialog/AboutDialog.java
tizen/src/skin/client/src/org/tizen/emulator/skin/screenshot/ScreenShotDialog.java

index a4a695cf14ca9f419e8d2bdaf4f18dec0f9bef4d..4000fc29e30c6793066da8f635a0dfbee62b9b1f 100644 (file)
@@ -1,5 +1,5 @@
 Package: emulator
-Version: 1.2.48
+Version: 1.2.49
 OS: linux
 Build-host-os: linux
 Maintainer: Yeong-Kyoon Lee<yeongkyoon.lee@samsung.com>
@@ -8,7 +8,7 @@ Source: emulator
 Description: Tizen Emulator
 
 Package: emulator
-Version: 1.2.48
+Version: 1.2.49
 OS: windows
 Build-host-os: windows
 Maintainer: Yeong-Kyoon Lee<yeongkyoon.lee@samsung.com>
index 3feb87fccbf53a445df62d2c0c9a31b3405e29f9..afd4b31345e1183f637e5b5d3a78fa7a198b8f0a 100644 (file)
@@ -82,6 +82,7 @@ import org.tizen.emulator.skin.dbi.ColorsType;
 import org.tizen.emulator.skin.dbi.RgbType;
 import org.tizen.emulator.skin.dbi.RotationType;
 import org.tizen.emulator.skin.dialog.AboutDialog;
+import org.tizen.emulator.skin.exception.ScreenShotException;
 import org.tizen.emulator.skin.image.ImageRegistry;
 import org.tizen.emulator.skin.image.ImageRegistry.IconName;
 import org.tizen.emulator.skin.image.ImageRegistry.ImageType;
@@ -616,7 +617,7 @@ public class EmulatorSkin {
 
                String emulatorName = SkinUtil.makeEmulatorName( config );
                deviceInfoItem.setText( emulatorName );
-               deviceInfoItem.setImage( imageRegistry.getIcon( IconName.DEVICE_INFO ) );
+//             deviceInfoItem.setImage( imageRegistry.getIcon( IconName.DEVICE_INFO ) );
                //FIXME
                deviceInfoItem.setEnabled( false );
                deviceInfoItem.addSelectionListener( new SelectionAdapter() {
@@ -656,14 +657,14 @@ public class EmulatorSkin {
 
                final MenuItem rotateItem = new MenuItem( menu, SWT.CASCADE );
                rotateItem.setText( "Rotate" );
-               rotateItem.setImage( imageRegistry.getIcon( IconName.ROTATE ) );
+//             rotateItem.setImage( imageRegistry.getIcon( IconName.ROTATE ) );
 
                Menu rotateMenu = createRotateMenu( menu.getShell() );
                rotateItem.setMenu( rotateMenu );
 
                final MenuItem scaleItem = new MenuItem( menu, SWT.CASCADE );
                scaleItem.setText( "Scale" );
-               scaleItem.setImage( imageRegistry.getIcon( IconName.SCALING ) );
+//             scaleItem.setImage( imageRegistry.getIcon( IconName.SCALING ) );
                Menu scaleMenu = createScaleMenu( menu.getShell() );
                scaleItem.setMenu( scaleMenu );
 
@@ -671,13 +672,13 @@ public class EmulatorSkin {
 
                final MenuItem advancedItem = new MenuItem( menu, SWT.CASCADE );
                advancedItem.setText( "Advanced" );
-               advancedItem.setImage( imageRegistry.getIcon( IconName.ADVANCED ) );
+//             advancedItem.setImage( imageRegistry.getIcon( IconName.ADVANCED ) );
                Menu advancedMenu = createAdvancedMenu( menu.getShell() );
                advancedItem.setMenu( advancedMenu );
 
                final MenuItem shellItem = new MenuItem( menu, SWT.PUSH );
                shellItem.setText( "Shell" );
-               shellItem.setImage( imageRegistry.getIcon( IconName.SHELL ) );
+//             shellItem.setImage( imageRegistry.getIcon( IconName.SHELL ) );
                shellItem.addSelectionListener( new SelectionAdapter() {
                        @Override
                        public void widgetSelected( SelectionEvent e ) {
@@ -717,7 +718,7 @@ public class EmulatorSkin {
 
                MenuItem closeItem = new MenuItem( menu, SWT.PUSH );
                closeItem.setText( "Close" );
-               closeItem.setImage( imageRegistry.getIcon( IconName.CLOSE ) );
+//             closeItem.setImage( imageRegistry.getIcon( IconName.CLOSE ) );
                closeItem.addSelectionListener( new SelectionAdapter() {
                        @Override
                        public void widgetSelected( SelectionEvent e ) {
@@ -879,7 +880,7 @@ public class EmulatorSkin {
 
                final MenuItem screenshotItem = new MenuItem( menu, SWT.PUSH );
                screenshotItem.setText( "Screen Shot" );
-               screenshotItem.setImage( imageRegistry.getIcon( IconName.SCREENSHOT ) );
+//             screenshotItem.setImage( imageRegistry.getIcon( IconName.SCREENSHOT ) );
                screenshotItem.addSelectionListener( new SelectionAdapter() {
                        
                        private boolean isOpen;
@@ -887,26 +888,41 @@ public class EmulatorSkin {
                        @Override
                        public void widgetSelected( SelectionEvent e ) {
                                
+                               ScreenShotDialog dialog = null;
+                               
                                try {
                                        
                                        if( !isOpen ) {
                                                isOpen = true;
-                                               ScreenShotDialog dialog = new ScreenShotDialog( shell, communicator, EmulatorSkin.this, config );
+                                               dialog = new ScreenShotDialog( shell, communicator, EmulatorSkin.this, config );
                                                dialog.open();
                                        }
                                        
+                               } catch ( ScreenShotException ex ) {
+                                       
+                                       logger.log( Level.SEVERE, ex.getMessage(), ex );
+                                       SkinUtil.openMessage( shell, null, "Fail to create a screen shot.", SWT.ICON_ERROR, config );
+                                       
                                } catch ( Exception ex ) {
-                                       logger.log( Level.SEVERE, "Fail to create a screen shot.", ex );
-                                       SkinUtil.openMessage( shell, null, "Fail to create a screen shot.", SWT.ERROR, config );
+                                       
+                                       // defense exception handling.
+                                       logger.log( Level.SEVERE, ex.getMessage(), ex );
+                                       String errorMessage = "Internal Error.\n[" + ex.getMessage() + "]";
+                                       SkinUtil.openMessage( shell, null, errorMessage, SWT.ICON_ERROR, config );
+                                       if( null != dialog ) {
+                                               dialog.close();
+                                       }
+                                       
                                } finally {
                                        isOpen = false;
                                }
+                               
                        }
                } );
 
                final MenuItem usbKeyboardItem = new MenuItem( menu, SWT.CASCADE );
                usbKeyboardItem.setText( "USB Keyboard" );
-               usbKeyboardItem.setImage( imageRegistry.getIcon( IconName.USB_KEBOARD ) );
+//             usbKeyboardItem.setImage( imageRegistry.getIcon( IconName.USB_KEBOARD ) );
                
                Menu usbKeyBoardMenu = new Menu( shell, SWT.DROP_DOWN );
 
@@ -937,14 +953,14 @@ public class EmulatorSkin {
 
                final MenuItem aboutItem = new MenuItem( menu, SWT.PUSH );
                aboutItem.setText( "About" );
-               aboutItem.setImage( imageRegistry.getIcon( IconName.ABOUT ) );
+//             aboutItem.setImage( imageRegistry.getIcon( IconName.ABOUT ) );
                aboutItem.addSelectionListener( new SelectionAdapter() {
                        private boolean isOpen;
                        @Override
                        public void widgetSelected( SelectionEvent e ) {
                                if( !isOpen ) {
                                        isOpen = true;
-                                       AboutDialog dialog = new AboutDialog( shell, "Tizen Emulator Info", SWT.DIALOG_TRIM );
+                                       AboutDialog dialog = new AboutDialog( shell, SWT.DIALOG_TRIM );
                                        dialog.open();
                                        isOpen = false;
                                }
index 5306da4623fae20a8064c34d83457ddd88cd9c11..807d9b8ab966a93a0f973426e637ef0844412418 100644 (file)
@@ -57,8 +57,8 @@ public class AboutDialog extends SkinDialog {
        
        private Logger logger = SkinLogger.getSkinLogger( AboutDialog.class ).getLogger();
 
-       public AboutDialog( Shell parent, String title, int style ) {
-               super( parent, title, style );
+       public AboutDialog( Shell parent, int style ) {
+               super( parent, "About Tizen Emulator", style );
        }
 
        @Override
index 7b84881d196535b7d80d33007ee35ee0974d573e..c2cf1ce43e4f7854ab9931d21fbfca74294009c4 100644 (file)
@@ -29,6 +29,8 @@
 
 package org.tizen.emulator.skin.screenshot;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
@@ -39,6 +41,9 @@ import java.util.logging.Logger;
 
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.ScrolledComposite;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.ImageTransfer;
+import org.eclipse.swt.dnd.Transfer;
 import org.eclipse.swt.events.PaintEvent;
 import org.eclipse.swt.events.PaintListener;
 import org.eclipse.swt.events.SelectionAdapter;
@@ -74,10 +79,10 @@ import org.tizen.emulator.skin.util.StringUtil;
 public class ScreenShotDialog extends Dialog {
 
        public final static String DEFAULT_FILE_EXTENSION = "png";
-       
+
        public final static int SCREENSHOT_WAIT_INTERVAL = 3; // milli-seconds
        public final static int SCREENSHOT_WAIT_LIMIT = 3000; // milli-seconds
-       
+
        public final static int RED_MASK = 0x0000FF00;
        public final static int GREEN_MASK = 0x00FF0000;
        public final static int BLUE_MASK = 0xFF000000;
@@ -93,54 +98,55 @@ public class ScreenShotDialog extends Dialog {
        private Shell shell;
        private Shell parent;
        private ScrolledComposite scrollComposite;
-       
+
        private SocketCommunicator communicator;
        private EmulatorSkin emulatorSkin;
        private EmulatorConfig config;
 
        private RotationInfo currentRotation;
+       private boolean needToStoreRotatedImage;
+       
+       public ScreenShotDialog( Shell parent, SocketCommunicator commuicator, EmulatorSkin emulatorSkin,
+                       EmulatorConfig config ) throws ScreenShotException {
 
-
-       public ScreenShotDialog( Shell parent, SocketCommunicator commuicator, EmulatorSkin emulatorSkin, EmulatorConfig config )
-                       throws ScreenShotException {
-               
                super( parent, SWT.DIALOG_TRIM | SWT.RESIZE );
 
                this.parent = parent;
                this.communicator = commuicator;
                this.emulatorSkin = emulatorSkin;
                this.config = config;
-
+               this.needToStoreRotatedImage = true;
+               
                shell = new Shell( parent, SWT.DIALOG_TRIM | SWT.RESIZE );
-               shell.setText( "Screen Shot - " + SkinUtil.getVmName( config ) );
+               shell.setText( "Screen Shot - " + SkinUtil.makeEmulatorName( config ) );
                shell.setLocation( parent.getLocation().x + parent.getSize().x + 30, parent.getLocation().y );
                shell.addListener( SWT.Close, new Listener() {
                        @Override
                        public void handleEvent( Event event ) {
-                               if( null != image ) {
+                               if ( null != image ) {
                                        image.dispose();
                                }
                        }
                } );
-               
+
                GridLayout gridLayout = new GridLayout();
-               gridLayout.marginWidth = 0;
+               gridLayout.marginWidth = 2;
                gridLayout.marginHeight = 0;
                gridLayout.horizontalSpacing = 0;
                gridLayout.verticalSpacing = 0;
                shell.setLayout( gridLayout );
-               
+
                makeMenuBar( shell );
-               
+
                scrollComposite = new ScrolledComposite( shell, SWT.V_SCROLL | SWT.H_SCROLL );
                GridData gridData = new GridData( SWT.FILL, SWT.FILL, true, true );
                scrollComposite.setLayoutData( gridData );
-               
+
                scrollComposite.setExpandHorizontal( true );
                scrollComposite.setExpandVertical( true );
-               
+
                currentRotation = getCurrentRotation();
-               
+
                final int width = Integer.parseInt( config.getArg( ArgsConstants.RESOLUTION_WIDTH ) );
                final int height = Integer.parseInt( config.getArg( ArgsConstants.RESOLUTION_HEIGHT ) );
 
@@ -152,37 +158,65 @@ public class ScreenShotDialog extends Dialog {
                                
                                logger.info( "capture screen." );
 
-                               if( null != image && !image.isDisposed() ) {
-                                       
-                                       RotationInfo rotation = getCurrentRotation();
-                                       
-                                       if( RotationInfo.PORTRAIT.equals( rotation ) ) {
-                                               
-                                               e.gc.drawImage( image, CANVAS_MARGIN, CANVAS_MARGIN );
-                                               
-                                       }else {
+                               if ( null != image && !image.isDisposed() ) {
+
+                                       if ( RotationInfo.PORTRAIT.equals( currentRotation ) ) {
 
-                                               float angle = rotation.angle();
+                                               e.gc.drawImage( image, CANVAS_MARGIN, CANVAS_MARGIN );
+                                               needToStoreRotatedImage = false;
                                                
-                                               Transform transform = new Transform( shell.getDisplay() );
+                                       } else {
                                                
-                                               transform.rotate( angle );
-
-                                               if ( RotationInfo.LANDSCAPE.equals( rotation ) ) {
-                                                       transform.translate( -width - ( 2 * CANVAS_MARGIN ), 0 );
-                                               } else if ( RotationInfo.REVERSE_PORTRAIT.equals( rotation ) ) {
-                                                       transform.translate( -width - ( 2 * CANVAS_MARGIN ), -height - ( 2 * CANVAS_MARGIN ) );
-                                               } else if ( RotationInfo.REVERSE_LANDSCAPE.equals( rotation ) ) {
-                                                       transform.translate( 0, -height - ( 2 * CANVAS_MARGIN ) );
+                                               if( needToStoreRotatedImage ) {
+                                                       
+                                                       Transform transform = new Transform( shell.getDisplay() );
+
+                                                       float angle = currentRotation.angle();
+                                                       transform.rotate( angle );
+
+                                                       int w = 0;
+                                                       int h = 0;
+                                                       ImageData imageData = image.getImageData();
+
+                                                       if ( RotationInfo.LANDSCAPE.equals( currentRotation ) ) {
+                                                               transform.translate( -width - ( 2 * CANVAS_MARGIN ), 0 );
+                                                               w = imageData.height;
+                                                               h = imageData.width;
+                                                       } else if ( RotationInfo.REVERSE_PORTRAIT.equals( currentRotation ) ) {
+                                                               transform.translate( -width - ( 2 * CANVAS_MARGIN ), -height - ( 2 * CANVAS_MARGIN ) );
+                                                               w = imageData.width;
+                                                               h = imageData.height;
+                                                       } else if ( RotationInfo.REVERSE_LANDSCAPE.equals( currentRotation ) ) {
+                                                               transform.translate( 0, -height - ( 2 * CANVAS_MARGIN ) );
+                                                               w = imageData.height;
+                                                               h = imageData.width;
+                                                       } else {
+                                                               w = imageData.width;
+                                                               h = imageData.height;
+                                                       }
+
+                                                       e.gc.setTransform( transform );
+
+                                                       e.gc.drawImage( image, CANVAS_MARGIN, CANVAS_MARGIN );
+
+                                                       transform.dispose();
+
+                                                       // 'gc.drawImage' is only for the showing without changing image data,
+                                                       // so change image data fully to support the roated image in a saved file and a pasted image.
+                                                       Image rotatedImage = new Image( shell.getDisplay(), w, h );
+                                                       e.gc.copyArea( rotatedImage, CANVAS_MARGIN, CANVAS_MARGIN );
+                                                       image.dispose();
+                                                       image = rotatedImage;
+
+                                                       needToStoreRotatedImage = false;
+
+                                               }else {
+                                                       //just redraw rotated image
+                                                       e.gc.drawImage( image, CANVAS_MARGIN, CANVAS_MARGIN );
                                                }
 
-                                               e.gc.setTransform( transform );
-                                               e.gc.drawImage( image, CANVAS_MARGIN, CANVAS_MARGIN );
-
-                                               transform.dispose();
-
                                        }
-                                       
+
                                }
 
                        }
@@ -195,14 +229,14 @@ public class ScreenShotDialog extends Dialog {
                try {
                        clickShutter();
                } catch ( ScreenShotException e ) {
-                       if( !shell.isDisposed() ) {
+                       if ( !shell.isDisposed() ) {
                                shell.close();
                        }
                        throw e;
                }
-               
+
                shell.pack();
-               
+
        }
 
        private void clickShutter() throws ScreenShotException {
@@ -219,57 +253,58 @@ public class ScreenShotDialog extends Dialog {
                boolean isFail = false;
                byte[] receivedData = null;
                int limitCount = SCREENSHOT_WAIT_LIMIT / SCREENSHOT_WAIT_INTERVAL;
-               
+
                synchronized ( dataTranfer ) {
-                       
-                       while( dataTranfer.isTransferState() ) {
-                               
-                               if( limitCount < count ) {
+
+                       while ( dataTranfer.isTransferState() ) {
+
+                               if ( limitCount < count ) {
                                        isFail = true;
                                        break;
                                }
-                               
+
                                try {
                                        dataTranfer.wait( SCREENSHOT_WAIT_INTERVAL );
                                } catch ( InterruptedException e ) {
                                        logger.log( Level.SEVERE, e.getMessage(), e );
                                }
-                               
+
                                count++;
                                logger.info( "wait image data... count:" + count );
-                               
+
                        }
-                       
+
                        receivedData = dataTranfer.getReceivedData();
-                       
+
                }
-               
-               if( !isFail ) {
 
-                       if( null != receivedData ) {
-                               
-                               if( null != this.image ) {
+               if ( !isFail ) {
+
+                       if ( null != receivedData ) {
+
+                               if ( null != this.image ) {
                                        this.image.dispose();
                                }
 
                                int width = Integer.parseInt( config.getArg( ArgsConstants.RESOLUTION_WIDTH ) );
                                int height = Integer.parseInt( config.getArg( ArgsConstants.RESOLUTION_HEIGHT ) );
-                               ImageData imageData = new ImageData(width, height, COLOR_DEPTH, paletteData, 1, receivedData );
-                               
+                               ImageData imageData = new ImageData( width, height, COLOR_DEPTH, paletteData, 1, receivedData );
+
                                this.image = new Image( parent.getDisplay(), imageData );
-                               
+
+                               needToStoreRotatedImage = true;
                                imageCanvas.redraw();
-                               
-                       }else {
+
+                       } else {
                                throw new ScreenShotException( "Received image data is null." );
                        }
-                       
-               }else {
+
+               } else {
                        throw new ScreenShotException( "Fail to received image data." );
                }
                
        }
-       
+
        private void arrageImageLayout() {
 
                ImageData imageData = image.getImageData();
@@ -277,7 +312,7 @@ public class ScreenShotDialog extends Dialog {
 
                int width = 0;
                int height = 0;
-               
+
                if ( RotationInfo.PORTRAIT.equals( rotation ) || RotationInfo.REVERSE_PORTRAIT.equals( rotation ) ) {
                        width = imageData.width + ( 2 * CANVAS_MARGIN );
                        height = imageData.height + ( 2 * CANVAS_MARGIN );
@@ -287,7 +322,7 @@ public class ScreenShotDialog extends Dialog {
                }
 
                scrollComposite.setMinSize( width, height );
-               
+
                rotation = getCurrentRotation();
 
                if ( !currentRotation.equals( rotation ) ) {
@@ -295,35 +330,34 @@ public class ScreenShotDialog extends Dialog {
                }
 
                currentRotation = rotation;
-               
+
        }
-       
+
        private RotationInfo getCurrentRotation() {
                short currentRotationId = ScreenShotDialog.this.emulatorSkin.getCurrentRotationId();
                RotationInfo rotationInfo = RotationInfo.getValue( currentRotationId );
                return rotationInfo;
        }
-       
+
        private void makeMenuBar( final Shell shell ) {
-               
+
                ToolBar toolBar = new ToolBar( shell, SWT.HORIZONTAL );
                GridData gridData = new GridData( GridData.FILL_HORIZONTAL );
                toolBar.setLayoutData( gridData );
-               
-               ToolItem saveItem = new ToolItem( toolBar, SWT.PUSH );
-               //FIXME icon
-//             saveItem.setImage( shell.getDisplay().getSystemImage( SWT.ICON_QUESTION ) );
+
+               ToolItem saveItem = new ToolItem( toolBar, SWT.FLAT );
+               // FIXME icon
+               // saveItem.setImage( null );
                saveItem.setText( "Save" );
                saveItem.setToolTipText( "Save" );
-               saveItem.setSelection( false );
-               
+
                saveItem.addSelectionListener( new SelectionAdapter() {
                        @Override
                        public void widgetSelected( SelectionEvent e ) {
-                               
+
                                FileDialog fileDialog = new FileDialog( shell, SWT.SAVE );
                                fileDialog.setText( "Save Image" );
-                               
+
                                String[] filter = { "*.png;*.PNG;*.jpg;*.JPG;*.jpeg;*.JPEG;*.bmp;*.BMP" };
                                fileDialog.setFilterExtensions( filter );
 
@@ -333,33 +367,66 @@ public class ScreenShotDialog extends Dialog {
                                String vmName = SkinUtil.getVmName( config );
                                SimpleDateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd-hhmmss" );
                                String dateString = formatter.format( new Date( System.currentTimeMillis() ) );
-                               
+
                                fileDialog.setFileName( vmName + "-" + dateString + "." + DEFAULT_FILE_EXTENSION );
 
                                String userHome = System.getProperty( "user.home" );
-                               if( !StringUtil.isEmpty( userHome ) ) {
+                               if ( !StringUtil.isEmpty( userHome ) ) {
                                        fileDialog.setFilterPath( userHome );
-                               }else {
+                               } else {
                                        logger.warning( "Cannot find user home path int java System properties." );
                                }
-                               
+
                                String filePath = fileDialog.open();
                                saveFile( filePath, fileDialog );
-                               
+
                        }
 
                } );
-               
-               ToolItem refreshItem = new ToolItem( toolBar, SWT.PUSH );
-               //FIXME icon
-//             refreshItem.setImage( shell.getDisplay().getSystemImage( SWT.ICON_INFORMATION ) );
+
+               ToolItem copyItem = new ToolItem( toolBar, SWT.FLAT );
+               // FIXME icon
+               // refreshItem.setImage( null );
+               copyItem.setText( "Copy" );
+               copyItem.setToolTipText( "Copy to clipboard" );
+
+               copyItem.addSelectionListener( new SelectionAdapter() {
+                       @Override
+                       public void widgetSelected( SelectionEvent e ) {
+
+                               if ( null == image || image.isDisposed() ) {
+                                       SkinUtil.openMessage( shell, null, "Fail to copy to clipboard.", SWT.ICON_ERROR, config );
+                                       return;
+                               }
+
+                               ImageLoader loader = new ImageLoader();
+                               loader.data = new ImageData[] { image.getImageData() };
+
+                               ByteArrayOutputStream bao = new ByteArrayOutputStream();
+                               loader.save( bao, SWT.IMAGE_PNG );
+
+                               ImageData imageData = new ImageData( new ByteArrayInputStream( bao.toByteArray() ) );
+                               Object[] imageObject = new Object[] { imageData };
+
+                               Transfer[] transfer = new Transfer[] { ImageTransfer.getInstance() };
+
+                               Clipboard clipboard = new Clipboard( shell.getDisplay() );
+                               clipboard.setContents( imageObject, transfer );
+
+                       }
+
+               } );
+
+               ToolItem refreshItem = new ToolItem( toolBar, SWT.FLAT );
+               // FIXME icon
+               // refreshItem.setImage( null );
                refreshItem.setText( "Refresh" );
                refreshItem.setToolTipText( "Refresh" );
-               refreshItem.setSelection( false );
-               
+
                refreshItem.addSelectionListener( new SelectionAdapter() {
                        @Override
                        public void widgetSelected( SelectionEvent e ) {
+
                                try {
                                        clickShutter();
                                } catch ( ScreenShotException ex ) {
@@ -369,20 +436,20 @@ public class ScreenShotDialog extends Dialog {
                        }
 
                } );
-               
+
        }
 
        private void saveFile( String fileFullPath, FileDialog fileDialog ) {
-               
+
                if ( null == fileFullPath ) {
                        return;
                }
 
                String format = "";
                String[] split = fileFullPath.split( "\\." );
-               
-               if( 1 < split.length ) {
-                       
+
+               if ( 1 < split.length ) {
+
                        format = split[split.length - 1];
 
                        if ( new File( split[split.length - 2] ).isDirectory() ) {
@@ -392,26 +459,26 @@ public class ScreenShotDialog extends Dialog {
                                saveFile( path, fileDialog );
 
                        }
-                       
+
                }
-               
+
                FileOutputStream fos = null;
-               
+
                try {
-                       
-                       if( StringUtil.isEmpty( format ) ) {
-                               if( fileFullPath.endsWith( "." ) ) {
+
+                       if ( StringUtil.isEmpty( format ) ) {
+                               if ( fileFullPath.endsWith( "." ) ) {
                                        fileFullPath += DEFAULT_FILE_EXTENSION;
-                               }else {
+                               } else {
                                        fileFullPath += "." + DEFAULT_FILE_EXTENSION;
                                }
                        }
-                       
+
                        fos = new FileOutputStream( fileFullPath, false );
-                       
+
                        ImageLoader loader = new ImageLoader();
                        loader.data = new ImageData[] { image.getImageData() };
-                       
+
                        if ( StringUtil.isEmpty( format ) || format.equalsIgnoreCase( "png" ) ) {
                                loader.save( fos, SWT.IMAGE_PNG );
                        } else if ( format.equalsIgnoreCase( "jpg" ) || format.equalsIgnoreCase( "jpeg" ) ) {
@@ -419,23 +486,23 @@ public class ScreenShotDialog extends Dialog {
                        } else if ( format.equalsIgnoreCase( "bmp" ) ) {
                                loader.save( fos, SWT.IMAGE_BMP );
                        } else {
-                               
+
                                SkinUtil.openMessage( shell, null, "Use the specified image formats. ( PNG / JPG / JPEG / BMP )",
                                                SWT.ICON_WARNING, config );
                                String path = fileDialog.open();
                                saveFile( path, fileDialog );
-                               
+
                        }
-                       
+
                } catch ( FileNotFoundException ex ) {
-                       
+
                        logger.log( Level.WARNING, "Use correct file name.", ex );
                        SkinUtil.openMessage( shell, null, "Use correct file name.", SWT.ICON_WARNING, config );
                        String path = fileDialog.open();
                        saveFile( path, fileDialog );
 
                } catch ( Exception ex ) {
-                       
+
                        logger.log( Level.SEVERE, "Fail to save this image file.", ex );
                        SkinUtil.openMessage( shell, null, "Fail to save this image file.", SWT.ERROR, config );
                        String path = fileDialog.open();
@@ -449,10 +516,10 @@ public class ScreenShotDialog extends Dialog {
        
        public void open() {
 
-               if( shell.isDisposed() ) {
+               if ( shell.isDisposed() ) {
                        return;
                }
-               
+
                shell.open();
 
                while ( !shell.isDisposed() ) {
@@ -462,5 +529,11 @@ public class ScreenShotDialog extends Dialog {
                }
 
        }
-               
+
+       public void close() {
+               if ( null != shell ) {
+                       shell.close();
+               }
+       }
+
 }
\ No newline at end of file