import org.eclipse.swt.events.DragDetectListener;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.events.MenuAdapter;
import org.eclipse.swt.events.MenuDetectEvent;
import org.eclipse.swt.events.MenuDetectListener;
+import org.eclipse.swt.events.MenuEvent;
+import org.eclipse.swt.events.MenuListener;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.events.MouseTrackAdapter;
+import org.eclipse.swt.events.MouseTrackListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.SelectionAdapter;
*/
public class EmulatorSkin {
+ public class SkinReopenPolicy {
+
+ private EmulatorSkin reopenSkin;
+ private boolean reopen;
+
+ private SkinReopenPolicy( EmulatorSkin reopenSkin, boolean reopen ) {
+ this.reopenSkin = reopenSkin;
+ this.reopen = reopen;
+ }
+
+ public EmulatorSkin getReopenSkin() {
+ return reopenSkin;
+ }
+
+ public boolean isReopen() {
+ return reopen;
+ }
+
+ }
+
private Logger logger = SkinLogger.getSkinLogger( EmulatorSkin.class ).getLogger();
+ private static final String MENU_ITEM_IMAGE = "ITEM_IMAGE";
+
private EmulatorConfig config;
private Shell shell;
private ImageRegistry imageRegistry;
private Image currentKeyPressedImage;
private Color hoverColor;
private boolean isDefaultHoverColor;
-
+
private int currentScale;
private short currentRotationId;
private int currentAngle;
private boolean isDragStartedInLCD;
private boolean isHoverState;
private boolean isShutdownRequested;
-
+ private boolean isAboutToReopen;
+ private boolean isOnTop;
+ private boolean isScreenShotOpened;
+
+ private ScreenShotDialog screenShotDialog;
+
private SocketCommunicator communicator;
private int windowHandleId;
- protected EmulatorSkin( EmulatorConfig config ) {
+ private Listener shellCloseListener;
+ private PaintListener shellPaintListener;
+ private MouseTrackListener shellMouseTrackListener;
+ private MouseMoveListener shellMouseMoveListener;
+ private MouseListener shellMouseListener;
+
+ private DragDetectListener canvasDragDetectListener;
+ private MouseMoveListener canvasMouseMoveListener;
+ private MouseListener canvasMouseListener;
+ private KeyListener canvasKeyListener;
+ private MenuDetectListener canvasMenuDetectListener;
+
+ private MenuListener menuListener;
+
+ private EmulatorSkin reopenSkin;
+
+ protected EmulatorSkin( EmulatorConfig config, boolean isOnTop ) {
this.config = config;
- this.shell = new Shell( new Display(), SWT.NO_TRIM );
this.isDefaultHoverColor = true;
+
+ this.isOnTop = isOnTop;
+
+ int style = SWT.NO_TRIM;
+ if ( isOnTop ) {
+ style |= SWT.ON_TOP;
+ }
+ this.shell = new Shell( Display.getDefault(), style );
+
}
public void setCommunicator( SocketCommunicator communicator ) {
public int compose() {
- imageRegistry = new ImageRegistry( shell.getDisplay(), config );
-
- shell.setBackground( shell.getDisplay().getSystemColor( SWT.COLOR_BLACK ) );
+ this.lcdCanvas = new Canvas( shell, SWT.EMBEDDED );
int x = config.getSkinPropertyInt( SkinPropertiesConstants.WINDOW_X, 50 );
int y = config.getSkinPropertyInt( SkinPropertiesConstants.WINDOW_Y, 50 );
+ int lcdWidth = Integer.parseInt( config.getArg( ArgsConstants.RESOLUTION_WIDTH ) );
+ int lcdHeight = Integer.parseInt( config.getArg( ArgsConstants.RESOLUTION_HEIGHT ) );
+ int scale = SkinUtil.getValidScale( config );
+ // int rotationId = config.getPropertyShort( PropertiesConstants.WINDOW_ROTATION, RotationInfo.PORTRAIT.id() );
+ // has to be portrait mode at first booting time
+ short rotationId = RotationInfo.PORTRAIT.id();
+
+ composeInternal( lcdCanvas, x, y, lcdWidth, lcdHeight, scale, rotationId );
+
+ // sdl uses this handle id.
+ windowHandleId = getWindowHandleId();
+
+ return windowHandleId;
+
+ }
+
+ private void composeInternal( Canvas lcdCanvas, int x, int y, int lcdWidth, int lcdHeight, int scale,
+ short rotationId ) {
+
+ lcdCanvas.setBackground( shell.getDisplay().getSystemColor( SWT.COLOR_BLACK ) );
+
+ imageRegistry = ImageRegistry.getInstance();
+
+ shell.setBackground( shell.getDisplay().getSystemColor( SWT.COLOR_BLACK ) );
+
shell.setLocation( x, y );
String emulatorName = SkinUtil.makeEmulatorName( config );
shell.setText( emulatorName );
-
- if( SkinUtil.isWindowsPlatform() ) {
+
+ if ( SkinUtil.isWindowsPlatform() ) {
shell.setImage( imageRegistry.getIcon( IconName.EMULATOR_TITLE_ICO ) );
- }else {
+ } else {
shell.setImage( imageRegistry.getIcon( IconName.EMULATOR_TITLE ) );
}
-
- this.lcdCanvas = new Canvas( shell, SWT.EMBEDDED );
- lcdCanvas.setBackground( shell.getDisplay().getSystemColor( SWT.COLOR_BLACK ) );
-
- int lcdWidth = Integer.parseInt( config.getArg( ArgsConstants.RESOLUTION_WIDTH ) );
- int lcdHeight = Integer.parseInt( config.getArg( ArgsConstants.RESOLUTION_HEIGHT ) );
-
- int scale = SkinUtil.getValidScale( config );
-
-// short rotationId = config.getPropertyShort( PropertiesConstants.WINDOW_ROTATION, RotationInfo.PORTRAIT.id() );
- // has to be portrait mode at first booting time
- arrangeSkin( lcdWidth, lcdHeight, scale, RotationInfo.PORTRAIT.id() );
-
- decideHoverColor();
- Menu menu = new Menu( shell );
- addMenuItems( menu );
- shell.setMenu( menu );
-
- addLCDListener( lcdCanvas );
+ arrangeSkin( lcdWidth, lcdHeight, scale, rotationId );
+
+ seteHoverColor();
+
+ setMenu();
+
+ }
+
+ private void setMenu() {
+
+ Menu contextMenu = new Menu( shell );
+
+ menuListener = new MenuAdapter() {
+ @Override
+ public void menuShown( MenuEvent e ) {
+
+ Menu menu = (Menu) e.getSource();
+ MenuItem[] items = menu.getItems();
+
+ for ( MenuItem menuItem : items ) {
+
+ Image image = (Image) menuItem.getData( MENU_ITEM_IMAGE );
+ if ( null != image ) {
+ menuItem.setImage( image );
+ }
+
+ Menu subMenu = menuItem.getMenu();
+ if ( null != subMenu ) {
+ subMenu.removeMenuListener( menuListener );
+ subMenu.addMenuListener( menuListener );
+ }
+
+ }
+
+ }
+
+ };
+
+ contextMenu.addMenuListener( menuListener );
+
+ addMenuItems( shell, contextMenu );
+
addShellListener( shell );
+ addCanvasListener( shell, lcdCanvas );
- // sdl uses this handle id.
- windowHandleId = getWindowHandleId( lcdCanvas );
+ shell.setMenu( contextMenu );
- return windowHandleId;
+ }
+
+ private void readyToReopen( EmulatorSkin sourceSkin, boolean isOnTop ) {
+
+ logger.info( "Start Changing AlwaysOnTop status" );
+
+ sourceSkin.reopenSkin = new EmulatorSkin( sourceSkin.config, isOnTop );
+
+ sourceSkin.reopenSkin.lcdCanvas = sourceSkin.lcdCanvas;
+ Point previousLocation = sourceSkin.shell.getLocation();
+
+ sourceSkin.reopenSkin.composeInternal( sourceSkin.lcdCanvas, previousLocation.x, previousLocation.y,
+ sourceSkin.currentLcdWidth, sourceSkin.currentLcdHeight, sourceSkin.currentScale,
+ sourceSkin.currentRotationId );
+
+ sourceSkin.reopenSkin.windowHandleId = sourceSkin.windowHandleId;
+
+ sourceSkin.reopenSkin.communicator = sourceSkin.communicator;
+ sourceSkin.reopenSkin.communicator.resetSkin( reopenSkin );
+
+ sourceSkin.isAboutToReopen = true;
+ sourceSkin.isShutdownRequested = true;
+
+ if ( sourceSkin.isScreenShotOpened && ( null != sourceSkin.screenShotDialog ) ) {
+ sourceSkin.screenShotDialog.setReserveImage( true );
+ sourceSkin.screenShotDialog.setEmulatorSkin( reopenSkin );
+ reopenSkin.isScreenShotOpened = true;
+ reopenSkin.screenShotDialog = sourceSkin.screenShotDialog;
+ // see open() method to know next logic for screenshot dialog.
+ }
+
+ sourceSkin.lcdCanvas.setParent( reopenSkin.shell );
+ sourceSkin.shell.close();
}
-
- private int getWindowHandleId( Canvas lcdCanvas ) {
-
+
+ private int getWindowHandleId() {
+
int windowHandleId = 0;
-
- if( SkinUtil.isLinuxPlatform() ) {
-
+
+ if ( SkinUtil.isLinuxPlatform() ) {
+
try {
Field field = lcdCanvas.getClass().getField( "embeddedHandle" );
windowHandleId = field.getInt( lcdCanvas );
logger.log( Level.SEVERE, e.getMessage(), e );
shutdown();
}
-
- }else if( SkinUtil.isWindowsPlatform() ) {
-
+
+ } else if ( SkinUtil.isWindowsPlatform() ) {
+
logger.info( "lcdCanvas.handle:" + lcdCanvas.handle );
windowHandleId = lcdCanvas.handle;
-
- }else if( SkinUtil.isMacPlatform() ) {
-
- //TODO
-
- }else {
+
+ } else if ( SkinUtil.isMacPlatform() ) {
+
+ // TODO
+
+ } else {
logger.severe( "Not Supported OS platform:" + SWT.getPlatform() );
System.exit( -1 );
}
return windowHandleId;
-
+
}
-
- private void decideHoverColor() {
-
+
+ private void seteHoverColor() {
+
ColorsType colors = config.getDbiContents().getColors();
if ( null != colors ) {
RgbType hoverRgb = colors.getHoverColor();
}
}
- if( isDefaultHoverColor ) {
- hoverColor = shell.getDisplay().getSystemColor( SWT.COLOR_WHITE );
+ if ( isDefaultHoverColor ) {
+ hoverColor = shell.getDisplay().getSystemColor( SWT.COLOR_WHITE );
}
}
-
- public void open() {
+
+ public SkinReopenPolicy open() {
if ( null == this.communicator ) {
logger.severe( "communicator is null." );
- shell.close();
- return;
+ return null;
}
Display display = this.shell.getDisplay();
this.shell.open();
+ // logic only for reopen case ///////
+ if ( isScreenShotOpened && ( null != screenShotDialog ) ) {
+ try {
+ screenShotDialog.setReserveImage( false );
+ screenShotDialog.open();
+ } finally {
+ isScreenShotOpened = false;
+ }
+ }
+ // ///////////////////////////////////
+
while ( !shell.isDisposed() ) {
if ( !display.readAndDispatch() ) {
display.sleep();
}
}
- display.dispose();
+ return new SkinReopenPolicy( reopenSkin, isAboutToReopen );
}
}
private void addShellListener( final Shell shell ) {
-
- shell.addListener( SWT.Close, new Listener() {
+
+ shellCloseListener = new Listener() {
@Override
public void handleEvent( Event event ) {
if ( isShutdownRequested ) {
- config.setSkinProperty( SkinPropertiesConstants.WINDOW_X, shell.getLocation().x );
- config.setSkinProperty( SkinPropertiesConstants.WINDOW_Y, shell.getLocation().y );
- config.setSkinProperty( SkinPropertiesConstants.WINDOW_SCALE, currentScale );
- config.setSkinProperty( SkinPropertiesConstants.WINDOW_ROTATION, currentRotationId );
+ removeShellListeners();
+ removeCanvasListeners();
+
+ if ( !isAboutToReopen ) {
- config.saveSkinProperties();
+ if ( isScreenShotOpened && ( null != screenShotDialog ) ) {
+ Shell scShell = screenShotDialog.getShell();
+ if ( !scShell.isDisposed() ) {
+ scShell.close();
+ }
+ }
+
+ // save config only for emulator close
+ config.setSkinProperty( SkinPropertiesConstants.WINDOW_X, shell.getLocation().x );
+ config.setSkinProperty( SkinPropertiesConstants.WINDOW_Y, shell.getLocation().y );
+ config.setSkinProperty( SkinPropertiesConstants.WINDOW_SCALE, currentScale );
+ config.setSkinProperty( SkinPropertiesConstants.WINDOW_ROTATION, currentRotationId );
+ config.setSkinProperty( SkinPropertiesConstants.WINDOW_ONTOP, Boolean.toString( isOnTop ) );
+ config.saveSkinProperties();
+
+ }
if ( null != currentImage ) {
currentImage.dispose();
currentKeyPressedImage.dispose();
}
- imageRegistry.dispose();
-
- if( !isDefaultHoverColor ) {
+ if ( !isDefaultHoverColor ) {
hoverColor.dispose();
}
}
}
- } );
+ };
- shell.addPaintListener( new PaintListener() {
+ shell.addListener( SWT.Close, shellCloseListener );
+
+ shellPaintListener = new PaintListener() {
@Override
public void paintControl( final PaintEvent e ) {
}
}
- } );
+ };
+
+ shell.addPaintListener( shellPaintListener );
- shell.addMouseTrackListener( new MouseTrackAdapter() {
+ shellMouseTrackListener = new MouseTrackAdapter() {
@Override
public void mouseExit( MouseEvent e ) {
// MouseMoveListener of shell does not receive event only with MouseMoveListener
// in case that : hover hardkey -> mouse move into LCD area
- if( isHoverState ) {
- if (currentHoverRegion.width == 0 && currentHoverRegion.height == 0) {
+ if ( isHoverState ) {
+ if ( currentHoverRegion.width == 0 && currentHoverRegion.height == 0 ) {
shell.redraw();
} else {
- shell.redraw( currentHoverRegion.x, currentHoverRegion.y,
- currentHoverRegion.width + 1, currentHoverRegion.height + 1, false );
+ shell.redraw( currentHoverRegion.x, currentHoverRegion.y, currentHoverRegion.width + 1,
+ currentHoverRegion.height + 1, false );
}
isHoverState = false;
currentHoverRegion.width = currentHoverRegion.height = 0;
}
}
-
- } );
-
- shell.addMouseMoveListener( new MouseMoveListener() {
+
+ };
+
+ shell.addMouseTrackListener( shellMouseTrackListener );
+
+ shellMouseMoveListener = new MouseMoveListener() {
@Override
public void mouseMove( MouseEvent e ) {
SkinRegion region = SkinUtil.getHardKeyArea( e.x, e.y, currentRotationId, currentScale );
if ( null == region ) {
- if( isHoverState ) {
- if (currentHoverRegion.width == 0 && currentHoverRegion.height == 0) {
+ if ( isHoverState ) {
+ if ( currentHoverRegion.width == 0 && currentHoverRegion.height == 0 ) {
shell.redraw();
} else {
- shell.redraw( currentHoverRegion.x, currentHoverRegion.y,
- currentHoverRegion.width + 1, currentHoverRegion.height + 1, false );
+ shell.redraw( currentHoverRegion.x, currentHoverRegion.y, currentHoverRegion.width + 1,
+ currentHoverRegion.height + 1, false );
}
isHoverState = false;
currentHoverRegion.width = currentHoverRegion.height = 0;
}
}
- } );
+ };
- shell.addMouseListener( new MouseListener() {
+ shell.addMouseMoveListener( shellMouseMoveListener );
+
+ shellMouseListener = new MouseListener() {
@Override
public void mouseUp( MouseEvent e ) {
int keyCode = SkinUtil.getHardKeyCode( e.x, e.y, currentRotationId, currentScale );
if ( EmulatorConstants.UNKNOWN_KEYCODE != keyCode ) {
- if (currentHoverRegion.width == 0 && currentHoverRegion.height == 0) {
+ if ( currentHoverRegion.width == 0 && currentHoverRegion.height == 0 ) {
shell.redraw();
} else {
- shell.redraw( currentHoverRegion.x, currentHoverRegion.y,
- currentHoverRegion.width + 1, currentHoverRegion.height + 1, false );
+ shell.redraw( currentHoverRegion.x, currentHoverRegion.y, currentHoverRegion.width + 1,
+ currentHoverRegion.height + 1, false );
}
KeyEventData keyEventData = new KeyEventData( KeyEventType.RELEASED.value(), keyCode );
communicator.sendToQEMU( SendCommand.SEND_HARD_KEY_EVENT, keyEventData );
}
-
+
}
}
if ( null != currentKeyPressedImage ) {
GC gc = new GC( shell );
- gc.drawImage( currentKeyPressedImage,
- region.x + 1, region.y + 1, region.width - 1, region.height - 1, //src
- region.x + 1, region.y + 1, region.width - 1, region.height - 1 ); //dst
+ gc.drawImage( currentKeyPressedImage, region.x + 1, region.y + 1, region.width - 1,
+ region.height - 1, // src
+ region.x + 1, region.y + 1, region.width - 1, region.height - 1 ); // dst
gc.dispose();
}
@Override
public void mouseDoubleClick( MouseEvent e ) {
}
- } );
+ };
+
+ shell.addMouseListener( shellMouseListener );
+
+ }
+
+ private void removeShellListeners() {
+
+ if ( null != shellCloseListener ) {
+ shell.removeListener( SWT.Close, shellCloseListener );
+ }
+ if ( null != shellPaintListener ) {
+ shell.removePaintListener( shellPaintListener );
+ }
+ if ( null != shellMouseTrackListener ) {
+ shell.removeMouseTrackListener( shellMouseTrackListener );
+ }
+ if ( null != shellMouseMoveListener ) {
+ shell.removeMouseMoveListener( shellMouseMoveListener );
+ }
+ if ( null != shellMouseListener ) {
+ shell.removeMouseListener( shellMouseListener );
+ }
}
- private void addLCDListener( final Canvas canvas ) {
+ private void addCanvasListener( final Shell shell, final Canvas canvas ) {
- // remove 'input method' menu item
- canvas.addMenuDetectListener( new MenuDetectListener() {
+ canvasMenuDetectListener = new MenuDetectListener() {
@Override
public void menuDetected( MenuDetectEvent e ) {
Menu menu = shell.getMenu();
menu.setVisible( true );
e.doit = false;
}
- } );
+ };
- canvas.addDragDetectListener( new DragDetectListener() {
+ // remove 'input method' menu item ( avoid bug )
+ canvas.addMenuDetectListener( canvasMenuDetectListener );
+
+ canvasDragDetectListener = new DragDetectListener() {
@Override
public void dragDetected( DragDetectEvent e ) {
- if( logger.isLoggable( Level.FINE ) ) {
+ if ( logger.isLoggable( Level.FINE ) ) {
logger.fine( "dragDetected e.button:" + e.button );
}
if ( 1 == e.button && // left button
e.x > 0 && e.x < canvas.getSize().x && e.y > 0 && e.y < canvas.getSize().y ) {
- if( logger.isLoggable( Level.FINE ) ) {
+ if ( logger.isLoggable( Level.FINE ) ) {
logger.fine( "dragDetected in LCD" );
}
EmulatorSkin.this.isDragStartedInLCD = true;
}
}
- } );
+ };
+
+ canvas.addDragDetectListener( canvasDragDetectListener );
- canvas.addMouseMoveListener( new MouseMoveListener() {
+ canvasMouseMoveListener = new MouseMoveListener() {
@Override
public void mouseMove( MouseEvent e ) {
int[] geometry = SkinUtil.convertMouseGeometry( e.x, e.y, currentLcdWidth, currentLcdHeight,
currentScale, currentAngle );
-
+
MouseEventData mouseEventData = new MouseEventData( eventType, geometry[0], geometry[1], 0 );
communicator.sendToQEMU( SendCommand.SEND_MOUSE_EVENT, mouseEventData );
}
}
- } );
+ };
+
+ canvas.addMouseMoveListener( canvasMouseMoveListener );
- canvas.addMouseListener( new MouseListener() {
+ canvasMouseListener = new MouseListener() {
@Override
public void mouseUp( MouseEvent e ) {
@Override
public void mouseDoubleClick( MouseEvent e ) {
}
- } );
+ };
+
+ canvas.addMouseListener( canvasMouseListener );
- canvas.addKeyListener( new KeyListener() {
+ canvasKeyListener = new KeyListener() {
@Override
public void keyReleased( KeyEvent e ) {
communicator.sendToQEMU( SendCommand.SEND_KEY_EVENT, keyEventData );
}
- } );
+ };
+
+ canvas.addKeyListener( canvasKeyListener );
+
+ }
+
+ private void removeCanvasListeners() {
+
+ if ( null != canvasDragDetectListener ) {
+ lcdCanvas.removeDragDetectListener( canvasDragDetectListener );
+ }
+ if ( null != canvasMouseMoveListener ) {
+ lcdCanvas.removeMouseMoveListener( canvasMouseMoveListener );
+ }
+ if ( null != canvasMouseListener ) {
+ lcdCanvas.removeMouseListener( canvasMouseListener );
+ }
+ if ( null != canvasKeyListener ) {
+ lcdCanvas.removeKeyListener( canvasKeyListener );
+ }
+ if ( null != canvasMenuDetectListener ) {
+ lcdCanvas.removeMenuDetectListener( canvasMenuDetectListener );
+ }
}
- private void addMenuItems( final Menu menu ) {
+ private void addMenuItems( final Shell shell, final Menu menu ) {
final MenuItem deviceInfoItem = new MenuItem( menu, SWT.PUSH );
String emulatorName = SkinUtil.makeEmulatorName( config );
deviceInfoItem.setText( emulatorName );
-// deviceInfoItem.setImage( imageRegistry.getIcon( IconName.DEVICE_INFO ) );
- //FIXME
- deviceInfoItem.setEnabled( false );
+ deviceInfoItem.setData( MENU_ITEM_IMAGE, imageRegistry.getIcon( IconName.DETAIL_INFO ) );
deviceInfoItem.addSelectionListener( new SelectionAdapter() {
@Override
public void widgetSelected( SelectionEvent e ) {
- if( logger.isLoggable( Level.FINE ) ) {
+ if ( logger.isLoggable( Level.FINE ) ) {
logger.fine( "Open device info" );
}
}
} );
- deviceInfoItem.addListener( SWT.PaintItem, new Listener() {
- @Override
- public void handleEvent( Event event ) {
- event.gc.drawImage( imageRegistry.getIcon( IconName.DEVICE_INFO ), 0, 0 );
- }
- } );
-
new MenuItem( menu, SWT.SEPARATOR );
- final MenuItem aotItem = new MenuItem( menu, SWT.CHECK );
- aotItem.setText( "Always On Top" );
- //FIXME
- aotItem.setEnabled( false );
- aotItem.addSelectionListener( new SelectionAdapter() {
- private boolean isTop;
+ final MenuItem onTopItem = new MenuItem( menu, SWT.CHECK );
+ onTopItem.setText( "Always On Top" );
+ onTopItem.setSelection( isOnTop );
+
+ onTopItem.addSelectionListener( new SelectionAdapter() {
@Override
public void widgetSelected( SelectionEvent e ) {
- if( logger.isLoggable( Level.FINE ) ) {
- logger.fine( "Select Always On Top. : " + aotItem.getSelection() );
+
+ final boolean isOnTop = onTopItem.getSelection();
+
+ if ( logger.isLoggable( Level.FINE ) ) {
+ logger.fine( "Select Always On Top. : " + isOnTop );
}
- isTop = !isTop;
- //TODO
+
+ readyToReopen( EmulatorSkin.this, isOnTop );
+
}
} );
final MenuItem rotateItem = new MenuItem( menu, SWT.CASCADE );
rotateItem.setText( "Rotate" );
-// rotateItem.setImage( imageRegistry.getIcon( IconName.ROTATE ) );
+ rotateItem.setData( MENU_ITEM_IMAGE, 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.setData( MENU_ITEM_IMAGE, imageRegistry.getIcon( IconName.SCALE ) );
+
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.setData( MENU_ITEM_IMAGE, 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.setData( MENU_ITEM_IMAGE, imageRegistry.getIcon( IconName.SHELL ) );
+
shellItem.addSelectionListener( new SelectionAdapter() {
@Override
public void widgetSelected( SelectionEvent e ) {
}
String sdbPath = SkinUtil.getSdbPath();
- String portNumber = StringUtil.nvl(config.getArg( ArgsConstants.NET_BASE_PORT ));
+ String portNumber = StringUtil.nvl( config.getArg( ArgsConstants.NET_BASE_PORT ) );
- if (!StringUtil.isEmpty(portNumber) && !StringUtil.isEmpty(portNumber)) {
- int portSdb = Integer.parseInt(portNumber) + 1;
+ if ( !StringUtil.isEmpty( portNumber ) && !StringUtil.isEmpty( portNumber ) ) {
+ int portSdb = Integer.parseInt( portNumber ) + 1;
- ProcessBuilder procConnect = new ProcessBuilder(sdbPath, "connect", "localhost:" + portSdb);
+ ProcessBuilder procConnect = new ProcessBuilder( sdbPath, "connect", "localhost:" + portSdb );
ProcessBuilder procSdb = new ProcessBuilder();
- if (SkinUtil.isLinuxPlatform()) {
- procSdb.command("/usr/bin/gnome-terminal", "--disable-factory",
- "--title=" + SkinUtil.makeEmulatorName(config), "-x",
- sdbPath, "-s", "localhost:" + portSdb, "shell");
- } else if (SkinUtil.isWindowsPlatform()) {
- procSdb.command("cmd.exe", "/c", "start",
- sdbPath, "-s", "localhost:" + portSdb, "shell");
+ if ( SkinUtil.isLinuxPlatform() ) {
+ procSdb.command( "/usr/bin/gnome-terminal", "--disable-factory",
+ "--title=" + SkinUtil.makeEmulatorName( config ), "-x", sdbPath, "-s", "localhost:"
+ + portSdb, "shell" );
+ } else if ( SkinUtil.isWindowsPlatform() ) {
+ procSdb.command( "cmd.exe", "/c", "start", sdbPath, "-s", "localhost:" + portSdb, "shell" );
}
try {
- procConnect.start(); //connect with sdb
- procSdb.start(); //open sdb shell
- } catch (Exception ee) {
- logger.log(Level.SEVERE, ee.getMessage(), ee);
+ procConnect.start(); // connect with sdb
+ procSdb.start(); // open sdb shell
+ } catch ( Exception ee ) {
+ logger.log( Level.SEVERE, ee.getMessage(), ee );
SkinUtil.openMessage( shell, null, "Fail to open Shell.", SWT.ICON_ERROR, config );
}
}
MenuItem closeItem = new MenuItem( menu, SWT.PUSH );
closeItem.setText( "Close" );
-// closeItem.setImage( imageRegistry.getIcon( IconName.CLOSE ) );
+ closeItem.setData( MENU_ITEM_IMAGE, imageRegistry.getIcon( IconName.CLOSE ) );
closeItem.addSelectionListener( new SelectionAdapter() {
@Override
public void widgetSelected( SelectionEvent e ) {
final List<MenuItem> rotationList = new ArrayList<MenuItem>();
-// final short storedDirectionId = config.getPropertyShort( PropertiesConstants.WINDOW_ROTATION,
-// (short) RotationInfo.PORTRAIT.id() );
- final short storedDirectionId = RotationInfo.PORTRAIT.id();
-
Iterator<Entry<Short, RotationType>> iterator = SkinRotation.getRotationIterator();
while ( iterator.hasNext() ) {
final MenuItem menuItem = new MenuItem( menu, SWT.RADIO );
menuItem.setText( section.getName().value() );
menuItem.setData( rotationId );
- if ( storedDirectionId == rotationId ) {
- menuItem.setSelection( true );
- }
- if ( RotationInfo.PORTRAIT.id() == rotationId ) {
+ if ( currentRotationId == rotationId ) {
menuItem.setSelection( true );
}
break;
}
}
- ///////////
-
- SkinUtil.openMessage( shell, null, "Rotation is not ready.\nPlease, wait.", SWT.ICON_WARNING, config );
+ // /////////
+
+ SkinUtil.openMessage( shell, null, "Rotation is not ready.\nPlease, wait.", SWT.ICON_WARNING,
+ config );
return;
private Menu createAdvancedMenu( final Shell shell ) {
- Menu menu = new Menu( shell, SWT.DROP_DOWN );
+ final Menu menu = new Menu( shell, SWT.DROP_DOWN );
final MenuItem screenshotItem = new MenuItem( menu, SWT.PUSH );
screenshotItem.setText( "Screen Shot" );
-// screenshotItem.setImage( imageRegistry.getIcon( IconName.SCREENSHOT ) );
+ screenshotItem.setData( MENU_ITEM_IMAGE, imageRegistry.getIcon( IconName.SCREENSHOT ) );
screenshotItem.addSelectionListener( new SelectionAdapter() {
-
- private boolean isOpen;
-
+
@Override
public void widgetSelected( SelectionEvent e ) {
-
- ScreenShotDialog dialog = null;
-
+
+ if ( isScreenShotOpened ) {
+ return;
+ }
+
try {
-
- if( !isOpen ) {
- isOpen = true;
- dialog = new ScreenShotDialog( shell, communicator, EmulatorSkin.this, config );
- dialog.open();
- }
-
+
+ isScreenShotOpened = true;
+
+ screenShotDialog = new ScreenShotDialog( shell, communicator, EmulatorSkin.this, config );
+ screenShotDialog.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 ) {
-
+
// 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;
+ isScreenShotOpened = false;
}
-
+
}
} );
final MenuItem usbKeyboardItem = new MenuItem( menu, SWT.CASCADE );
usbKeyboardItem.setText( "USB Keyboard" );
-// usbKeyboardItem.setImage( imageRegistry.getIcon( IconName.USB_KEBOARD ) );
-
+ usbKeyboardItem.setData( MENU_ITEM_IMAGE, imageRegistry.getIcon( IconName.USB_KEBOARD ) );
+
Menu usbKeyBoardMenu = new Menu( shell, SWT.DROP_DOWN );
final MenuItem usbOnItem = new MenuItem( usbKeyBoardMenu, SWT.RADIO );
final MenuItem usbOffItem = new MenuItem( usbKeyBoardMenu, SWT.RADIO );
usbOffItem.setText( "Off" );
usbOffItem.setSelection( true );
-
+
SelectionAdapter usbSelectionAdaptor = new SelectionAdapter() {
@Override
public void widgetSelected( SelectionEvent e ) {
final MenuItem aboutItem = new MenuItem( menu, SWT.PUSH );
aboutItem.setText( "About" );
-// aboutItem.setImage( imageRegistry.getIcon( IconName.ABOUT ) );
+ aboutItem.setData( MENU_ITEM_IMAGE, imageRegistry.getIcon( IconName.ABOUT ) );
+
aboutItem.addSelectionListener( new SelectionAdapter() {
private boolean isOpen;
+
@Override
public void widgetSelected( SelectionEvent e ) {
- if( !isOpen ) {
+ if ( !isOpen ) {
isOpen = true;
- AboutDialog dialog = new AboutDialog( shell, SWT.DIALOG_TRIM );
+ AboutDialog dialog = new AboutDialog( shell );
dialog.open();
isOpen = false;
}
/* disconnect with sdb */
String sdbPath = SkinUtil.getSdbPath();
- String portNumber = StringUtil.nvl(config.getArg( ArgsConstants.NET_BASE_PORT ));
+ String portNumber = StringUtil.nvl( config.getArg( ArgsConstants.NET_BASE_PORT ) );
- if (!StringUtil.isEmpty(portNumber) && !StringUtil.isEmpty(portNumber)) {
- int portSdb = Integer.parseInt(portNumber) + 1;
+ if ( !StringUtil.isEmpty( portNumber ) && !StringUtil.isEmpty( portNumber ) ) {
+ int portSdb = Integer.parseInt( portNumber ) + 1;
- ProcessBuilder procDisconnect = new ProcessBuilder(sdbPath, "connect", "localhost:" + portSdb);
+ ProcessBuilder procDisconnect = new ProcessBuilder( sdbPath, "connect", "localhost:" + portSdb );
try {
procDisconnect.start();
- } catch (IOException e) {
- logger.log(Level.SEVERE, e.getMessage(), e);
+ } catch ( IOException e ) {
+ logger.log( Level.SEVERE, e.getMessage(), e );
}
}
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.ImageLoader;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Canvas;
-import org.eclipse.swt.widgets.Dialog;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Listener;
import org.tizen.emulator.skin.config.EmulatorConfig;
import org.tizen.emulator.skin.config.EmulatorConfig.ArgsConstants;
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.log.SkinLogger;
import org.tizen.emulator.skin.util.IOUtil;
import org.tizen.emulator.skin.util.SkinUtil;
import org.tizen.emulator.skin.util.StringUtil;
-public class ScreenShotDialog extends Dialog {
+public class ScreenShotDialog {
public final static String DEFAULT_FILE_EXTENSION = "png";
private Image image;
private Canvas imageCanvas;
private Shell shell;
- private Shell parent;
private ScrolledComposite scrollComposite;
private SocketCommunicator communicator;
private RotationInfo currentRotation;
private boolean needToStoreRotatedImage;
+ private boolean reserveImage;
- public ScreenShotDialog( Shell parent, SocketCommunicator commuicator, EmulatorSkin emulatorSkin,
+ public ScreenShotDialog( Shell parent, SocketCommunicator communicator, EmulatorSkin emulatorSkin,
EmulatorConfig config ) throws ScreenShotException {
- super( parent, SWT.DIALOG_TRIM | SWT.RESIZE );
-
- this.parent = parent;
- this.communicator = commuicator;
+ this.communicator = communicator;
this.emulatorSkin = emulatorSkin;
this.config = config;
this.needToStoreRotatedImage = true;
- shell = new Shell( parent, SWT.DIALOG_TRIM | SWT.RESIZE );
+ shell = new Shell( Display.getDefault(), SWT.DIALOG_TRIM | SWT.RESIZE );
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 ) {
- image.dispose();
+ if( !reserveImage ) {
+ image.dispose();
+ }
}
}
} );
GridLayout gridLayout = new GridLayout();
- gridLayout.marginWidth = 2;
+ gridLayout.marginWidth = 0;
gridLayout.marginHeight = 0;
gridLayout.horizontalSpacing = 0;
gridLayout.verticalSpacing = 0;
} else {
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;
-
+ drawRotatedImage( e.gc, width, height );
needToStoreRotatedImage = false;
-
}else {
//just redraw rotated image
e.gc.drawImage( image, CANVAS_MARGIN, CANVAS_MARGIN );
}
shell.pack();
-
+
}
+
+ private void drawRotatedImage( GC gc, int width, int height ) {
+
+ 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;
+ }
+
+ gc.setTransform( transform );
+
+ 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 );
+ gc.copyArea( rotatedImage, CANVAS_MARGIN, CANVAS_MARGIN );
+ image.dispose();
+ image = rotatedImage;
+
+ }
+
private void clickShutter() throws ScreenShotException {
capture();
arrageImageLayout();
int height = Integer.parseInt( config.getArg( ArgsConstants.RESOLUTION_HEIGHT ) );
ImageData imageData = new ImageData( width, height, COLOR_DEPTH, paletteData, 1, receivedData );
- this.image = new Image( parent.getDisplay(), imageData );
+ this.image = new Image( Display.getDefault(), imageData );
needToStoreRotatedImage = true;
imageCanvas.redraw();
}
private RotationInfo getCurrentRotation() {
- short currentRotationId = ScreenShotDialog.this.emulatorSkin.getCurrentRotationId();
+ short currentRotationId = emulatorSkin.getCurrentRotationId();
RotationInfo rotationInfo = RotationInfo.getValue( currentRotationId );
return rotationInfo;
}
ToolBar toolBar = new ToolBar( shell, SWT.HORIZONTAL );
GridData gridData = new GridData( GridData.FILL_HORIZONTAL );
toolBar.setLayoutData( gridData );
-
+
ToolItem saveItem = new ToolItem( toolBar, SWT.FLAT );
- // FIXME icon
- // saveItem.setImage( null );
- saveItem.setText( "Save" );
- saveItem.setToolTipText( "Save" );
-
+ saveItem.setImage( ImageRegistry.getInstance().getIcon( IconName.SAVE_SCREEN_SHOT ) );
+ saveItem.setToolTipText( "Save to file" );
+
saveItem.addSelectionListener( new SelectionAdapter() {
@Override
public void widgetSelected( SelectionEvent e ) {
}
} );
-
+
ToolItem copyItem = new ToolItem( toolBar, SWT.FLAT );
- // FIXME icon
- // refreshItem.setImage( null );
- copyItem.setText( "Copy" );
+ copyItem.setImage( ImageRegistry.getInstance().getIcon( IconName.COPY_SCREEN_SHOT ) );
copyItem.setToolTipText( "Copy to clipboard" );
copyItem.addSelectionListener( new SelectionAdapter() {
} );
ToolItem refreshItem = new ToolItem( toolBar, SWT.FLAT );
- // FIXME icon
- // refreshItem.setImage( null );
- refreshItem.setText( "Refresh" );
- refreshItem.setToolTipText( "Refresh" );
+ refreshItem.setImage( ImageRegistry.getInstance().getIcon( IconName.REFRESH_SCREEN_SHOT ) );
+ refreshItem.setToolTipText( "Refresh image" );
refreshItem.addSelectionListener( new SelectionAdapter() {
@Override
while ( !shell.isDisposed() ) {
if ( !shell.getDisplay().readAndDispatch() ) {
- shell.getDisplay().sleep();
+ if( reserveImage ) {
+ break;
+ }else {
+ shell.getDisplay().sleep();
+ }
}
}
-
+
}
- public void close() {
- if ( null != shell ) {
- shell.close();
- }
+ public void setEmulatorSkin( EmulatorSkin emulatorSkin ) {
+ this.emulatorSkin = emulatorSkin;
}
+ public void setReserveImage( boolean reserveImage ) {
+ this.reserveImage = reserveImage;
+ }
+
+ public Shell getShell() {
+ return shell;
+ }
+
}
\ No newline at end of file