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;
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() {
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 );
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 ) {
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 ) {
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;
@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 );
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;
}
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;
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;
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;
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 ) );
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();
-
}
-
+
}
}
try {
clickShutter();
} catch ( ScreenShotException e ) {
- if( !shell.isDisposed() ) {
+ if ( !shell.isDisposed() ) {
shell.close();
}
throw e;
}
-
+
shell.pack();
-
+
}
private void clickShutter() throws ScreenShotException {
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();
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 );
}
scrollComposite.setMinSize( width, height );
-
+
rotation = getCurrentRotation();
if ( !currentRotation.equals( rotation ) ) {
}
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 );
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 ) {
}
} );
-
+
}
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() ) {
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" ) ) {
} 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();
public void open() {
- if( shell.isDisposed() ) {
+ if ( shell.isDisposed() ) {
return;
}
-
+
shell.open();
while ( !shell.isDisposed() ) {
}
}
-
+
+ public void close() {
+ if ( null != shell ) {
+ shell.close();
+ }
+ }
+
}
\ No newline at end of file