<?xml version="1.0" standalone="yes"?>
<project name="emulator-skin" basedir="." default="linux-jar">
-
- <property name="jar.file" value="emulator-skin.jar" />
- <property name="mainclass" value="org.tizen.emulator.skin.EmulatorSkinMain" />
-
- <property name="swt.file" value="swt.jar" />
- <path id="linux-classpath">
- <fileset dir="lib/swt/gtk-linux" includes="swt.jar" />
- </path>
- <path id="windows-classpath">
- <fileset dir="lib/swt/win32-win32" includes="swt.jar" />
- </path>
- <path id="mac-classpath">
- <fileset dir="lib/swt/cocoa-macosx" includes="swt.jar" />
- </path>
+ <property name="jar.file" value="emulator-skin.jar" />
+ <property name="mainclass" value="org.tizen.emulator.skin.EmulatorSkinMain" />
- <target name="clean">
- <echo message="cleaning..." />
- <delete dir="bin"/>
- <delete file="${jar.file}" />
- </target>
+ <property name="swt.file" value="swt.jar" />
+
+ <path id="linux-classpath">
+ <fileset dir="lib/swt/gtk-linux" includes="swt.jar" />
+ </path>
+ <path id="windows-classpath">
+ <fileset dir="lib/swt/win32-win32" includes="swt.jar" />
+ </path>
+ <path id="mac-classpath">
+ <fileset dir="lib/swt/cocoa-macosx" includes="swt.jar" />
+ </path>
+
+ <target name="clean">
+ <echo message="cleaning..." />
+ <delete dir="bin" />
+ <delete file="${jar.file}" />
+ </target>
<target name="make-properties">
- <echo message="Make properties..." />
+ <echo message="Make properties..." />
<tstamp>
<format property="build_time" pattern="MM/dd/yyyy hh:mm aa" timezone="GMT" locale="en" />
</tstamp>
<arg value="--short" />
<arg value="HEAD" />
</exec>
-
- <propertyfile file="src/about.properties"
- comment="Auto-generated properties - DO NOT EDIT">
+
+ <propertyfile file="src/about.properties" comment="Auto-generated properties - DO NOT EDIT">
<entry key="version" value="${version}" />
<entry key="build_time" value="${build_time}" />
<entry key="build_git_commit" value="${build_git_commit}" />
</propertyfile>
</target>
-
- <target name="linux-compile" depends="make-properties, clean">
- <echo message="compiling..." />
- <mkdir dir="bin" />
- <javac encoding="UTF-8" fork="true" srcdir="src" destdir="bin" debug="on" memorymaximumsize="128m">
- <classpath refid="linux-classpath" />
- </javac>
- </target>
- <target name="windows-compile" depends="make-properties, clean">
- <echo message="compiling..." />
- <mkdir dir="bin" />
- <javac encoding="UTF-8" fork="true" srcdir="src" destdir="bin" debug="on" memorymaximumsize="128m">
- <classpath refid="windows-classpath" />
- </javac>
- </target>
+ <target name="linux-compile" depends="make-properties, clean">
+ <echo message="compiling..." />
+ <mkdir dir="bin" />
+ <javac encoding="UTF-8" fork="true" srcdir="src" destdir="bin" debug="on" memorymaximumsize="128m">
+ <classpath refid="linux-classpath" />
+ </javac>
+ </target>
- <target name="mac-compile" depends="make-properties, clean">
- <echo message="compiling..." />
- <mkdir dir="bin" />
- <javac encoding="UTF-8" fork="true" srcdir="src" destdir="bin" debug="on" memorymaximumsize="128m">
- <classpath refid="mac-classpath" />
- </javac>
- </target>
+ <target name="windows-compile" depends="make-properties, clean">
+ <echo message="compiling..." />
+ <mkdir dir="bin" />
+ <javac encoding="UTF-8" fork="true" srcdir="src" destdir="bin" debug="on" memorymaximumsize="128m">
+ <classpath refid="windows-classpath" />
+ </javac>
+ </target>
- <target name="linux-jar" depends="linux-compile">
- <echo message="creating jar..." />
- <jar jarfile="${jar.file}" basedir="bin" duplicate="add">
+ <target name="mac-compile" depends="make-properties, clean">
+ <echo message="compiling..." />
+ <mkdir dir="bin" />
+ <javac encoding="UTF-8" fork="true" srcdir="src" destdir="bin" debug="on" memorymaximumsize="128m">
+ <classpath refid="mac-classpath" />
+ </javac>
+ </target>
+
+ <target name="linux-jar" depends="linux-compile">
+ <echo message="creating jar..." />
+ <delete dir="dist" />
+ <mkdir dir="dist" />
+ <mkdir dir="dist/icons" />
+ <copy todir="dist">
+ <fileset dir="bin" />
+ </copy>
+ <copy todir="dist/icons">
+ <fileset dir="icons" />
+ </copy>
+ <jar jarfile="${jar.file}" basedir="dist" duplicate="add">
<fileset file="src/about.properties" />
- <manifest>
- <attribute name="Main-Class" value="${mainclass}"/>
- <attribute name="Class-path" value="lib/swt/gtk-linux/${swt.file}"/>
- </manifest>
- </jar>
- </target>
+ <manifest>
+ <attribute name="Main-Class" value="${mainclass}" />
+ <attribute name="Class-path" value="lib/swt/gtk-linux/${swt.file}" />
+ </manifest>
+ </jar>
+ <delete dir="dist" />
+ </target>
- <target name="windows-jar" depends="windows-compile">
- <echo message="creating jar..." />
- <jar jarfile="${jar.file}" basedir="bin" duplicate="add">
+ <target name="windows-jar" depends="windows-compile">
+ <echo message="creating jar..." />
+ <delete dir="dist" />
+ <mkdir dir="dist" />
+ <mkdir dir="dist/icons" />
+ <copy todir="dist">
+ <fileset dir="bin" />
+ </copy>
+ <copy todir="dist/icons">
+ <fileset dir="icons" />
+ </copy>
+ <jar jarfile="${jar.file}" basedir="dist" duplicate="add">
<fileset file="src/about.properties" />
- <manifest>
- <attribute name="Main-Class" value="${mainclass}"/>
- <attribute name="Class-path" value="lib/swt/win32-win32/${swt.file}"/>
- </manifest>
- </jar>
- </target>
+ <manifest>
+ <attribute name="Main-Class" value="${mainclass}" />
+ <attribute name="Class-path" value="lib/swt/win32-win32/${swt.file}" />
+ </manifest>
+ </jar>
+ <delete dir="dist" />
+ </target>
- <target name="mac-jar" depends="mac-compile">
- <echo message="creating jar..." />
- <jar jarfile="${jar.file}" basedir="bin" duplicate="add">
+ <target name="mac-jar" depends="mac-compile">
+ <echo message="creating jar..." />
+ <delete dir="dist" />
+ <mkdir dir="dist" />
+ <mkdir dir="dist/icons" />
+ <copy todir="dist">
+ <fileset dir="bin" />
+ </copy>
+ <copy todir="dist/icons">
+ <fileset dir="icons" />
+ </copy>
+ <jar jarfile="${jar.file}" basedir="dist" duplicate="add">
<fileset file="src/about.properties" />
- <manifest>
- <attribute name="Main-Class" value="${mainclass}"/>
- <attribute name="Class-path" value="lib/swt/cocoa-macosx/${swt.file}"/>
- </manifest>
- </jar>
- </target>
+ <manifest>
+ <attribute name="Main-Class" value="${mainclass}" />
+ <attribute name="Class-path" value="lib/swt/cocoa-macosx/${swt.file}" />
+ </manifest>
+ </jar>
+ <delete dir="dist" />
+ </target>
</project>
\ No newline at end of file
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.RGB;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.graphics.Region;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.tizen.emulator.skin.config.EmulatorConfig.ArgsConstants;
import org.tizen.emulator.skin.config.EmulatorConfig.PropertiesConstants;
import org.tizen.emulator.skin.dbi.ColorsType;
-import org.tizen.emulator.skin.dbi.EventInfoType;
-import org.tizen.emulator.skin.dbi.KeyMapType;
-import org.tizen.emulator.skin.dbi.LcdType;
-import org.tizen.emulator.skin.dbi.RegionType;
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.image.ImageRegistry;
+import org.tizen.emulator.skin.image.ImageRegistry.IconName;
import org.tizen.emulator.skin.image.ImageRegistry.ImageType;
import org.tizen.emulator.skin.log.SkinLogger;
import org.tizen.emulator.skin.screenshot.ScreenShotDialog;
import org.tizen.emulator.skin.util.SkinRegion;
import org.tizen.emulator.skin.util.SkinRotation;
-import org.tizen.emulator.skin.util.SkinUtil;
import org.tizen.emulator.skin.util.SkinRotation.RotationInfo;
+import org.tizen.emulator.skin.util.SkinUtil;
/**
*
private int currentAngle;
private int currentLcdWidth;
private int currentLcdHeight;
+ private SkinRegion currentHoverRegion;
private int pressedMouseX;
private int pressedMouseY;
private boolean isMousePressed;
private boolean isDragStartedInLCD;
private boolean isHoverState;
- private SkinRegion currentHoverRegion;
private boolean isShutdownRequested;
private SocketCommunicator communicator;
private int windowHandleId;
- private ScheduledExecutorService canvasExecutor = Executors.newSingleThreadScheduledExecutor();
-
protected EmulatorSkin( EmulatorConfig config ) {
this.config = config;
this.shell = new Shell( new Display(), SWT.NO_TRIM );
String emulatorName = SkinUtil.makeEmulatorName( config );
shell.setText( emulatorName );
-
- this.lcdCanvas = new Canvas( shell, SWT.EMBEDDED | SWT.NO_BACKGROUND );
+
+ if( SkinUtil.isWindowsPlatform() ) {
+ shell.setImage( imageRegistry.getIcon( IconName.EMULATOR_TITLE_ICO ) );
+ }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 = config.getPropertyInt( PropertiesConstants.WINDOW_SCALE, 50 );
- //TODO:
- if (scale != 100 && scale != 75 && scale != 50 && scale != 25 ) {
- scale = 50;
- }
+
+ int scale = SkinUtil.getValidScale( config );
short rotationId = config.getPropertyShort( PropertiesConstants.WINDOW_DIRECTION, (short) 0 );
arrangeSkin( lcdWidth, lcdHeight, scale, (short) rotationId );
+ decideHoverColor();
Menu menu = new Menu( shell );
addMenuItems( menu );
shell.setMenu( menu );
- ColorsType colors = config.getDbiContents().getColors();
- if ( null != colors ) {
- RgbType hoverRgb = colors.getHoverColor();
- if ( null != hoverRgb ) {
- Long r = hoverRgb.getR();
- Long g = hoverRgb.getG();
- Long b = hoverRgb.getB();
- if ( null != r && null != g && null != b ) {
- hoverColor = new Color( shell.getDisplay(), new RGB( r.intValue(), g.intValue(), b.intValue() ) );
- isDefaultHoverColor = false;
- }
- }
- }
+ // sdl uses this handle id.
+ windowHandleId = getWindowHandleId( lcdCanvas );
+
+ addLCDListener( lcdCanvas );
+ addShellListener( shell );
- if( isDefaultHoverColor ) {
- hoverColor = shell.getDisplay().getSystemColor( SWT.COLOR_WHITE );
- }
+ return windowHandleId;
- // sdl uses this handle id.
- String platform = SWT.getPlatform();
- if( "gtk".equalsIgnoreCase( platform ) ) {
+ }
+
+ private int getWindowHandleId( Canvas lcdCanvas ) {
+
+ int windowHandleId = 0;
+
+ if( SkinUtil.isLinuxPlatform() ) {
+
try {
Field field = lcdCanvas.getClass().getField( "embeddedHandle" );
windowHandleId = field.getInt( lcdCanvas );
} catch ( IllegalArgumentException e ) {
logger.log( Level.SEVERE, e.getMessage(), e );
shutdown();
- return windowHandleId;
} catch ( IllegalAccessException e ) {
logger.log( Level.SEVERE, e.getMessage(), e );
shutdown();
- return windowHandleId;
} catch ( SecurityException e ) {
logger.log( Level.SEVERE, e.getMessage(), e );
shutdown();
- return windowHandleId;
} catch ( NoSuchFieldException e ) {
logger.log( Level.SEVERE, e.getMessage(), e );
shutdown();
- return windowHandleId;
}
- }else if( "win32".equalsIgnoreCase( platform ) ) {
+
+ }else if( SkinUtil.isWindowsPlatform() ) {
+
logger.info( "lcdCanvas.handle:" + lcdCanvas.handle );
windowHandleId = lcdCanvas.handle;
- }else if( "cocoa".equalsIgnoreCase( platform ) ) {
+
+ }else if( SkinUtil.isMacPlatform() ) {
+
//TODO
+
}else {
- logger.severe( "Not Supported OS platform:" + platform );
+ logger.severe( "Not Supported OS platform:" + SWT.getPlatform() );
System.exit( -1 );
}
-
- addLCDListener( lcdCanvas );
- addShellListener( shell );
return windowHandleId;
-
+
}
+
+ private void decideHoverColor() {
+
+ ColorsType colors = config.getDbiContents().getColors();
+ if ( null != colors ) {
+ RgbType hoverRgb = colors.getHoverColor();
+ if ( null != hoverRgb ) {
+ Long r = hoverRgb.getR();
+ Long g = hoverRgb.getG();
+ Long b = hoverRgb.getB();
+ if ( null != r && null != g && null != b ) {
+ hoverColor = new Color( shell.getDisplay(), new RGB( r.intValue(), g.intValue(), b.intValue() ) );
+ isDefaultHoverColor = false;
+ }
+ }
+ }
+
+ if( isDefaultHoverColor ) {
+ hoverColor = shell.getDisplay().getSystemColor( SWT.COLOR_WHITE );
+ }
+ }
+
public void open() {
if ( null == this.communicator ) {
currentKeyPressedImage.dispose();
}
- currentImage = createScaledImage( rotationId, scale, ImageType.IMG_TYPE_MAIN );
- currentKeyPressedImage = createScaledImage( rotationId, scale, ImageType.IMG_TYPE_PRESSED );
+ currentImage = SkinUtil.createScaledImage( imageRegistry, shell, rotationId, scale, ImageType.IMG_TYPE_MAIN );
+ currentKeyPressedImage = SkinUtil.createScaledImage( imageRegistry, shell, rotationId, scale,
+ ImageType.IMG_TYPE_PRESSED );
- trimSkin( currentImage );
- adjustLcdGeometry( lcdCanvas, scale, rotationId );
+ SkinUtil.trimShell( shell, currentImage );
+ SkinUtil.adjustLcdGeometry( lcdCanvas, scale, rotationId );
ImageData imageData = currentImage.getImageData();
shell.setMinimumSize( imageData.width, imageData.height );
}
- private Image createScaledImage( short rotationId, int scale, ImageType type ) {
-
- ImageData originalImageData = imageRegistry.getImageData( rotationId, type );
-
- ImageData imageData = (ImageData) originalImageData.clone();
- int width = (int) ( originalImageData.width * (((float)scale) / 100) );
- int height = (int) ( originalImageData.height * (((float)scale) / 100) );
- imageData = imageData.scaledTo( width, height );
-
- Image image = new Image( shell.getDisplay(), imageData );
- return image;
-
- }
-
- private void trimSkin( Image image ) {
-
- // trim transparent pixels in image. especially, corner round areas.
-
- ImageData imageData = image.getImageData();
-
- int width = imageData.width;
- int height = imageData.height;
-
- Region region = new Region();
- region.add( new Rectangle( 0, 0, width, height ) );
-
- for ( int i = 0; i < width; i++ ) {
- for ( int j = 0; j < height; j++ ) {
- int alpha = imageData.getAlpha( i, j );
- if ( 0 == alpha ) {
- region.subtract( i, j, 1, 1 );
- }
- }
- }
-
- shell.setRegion( region );
-
- }
-
- private void adjustLcdGeometry( Canvas lcdCanvas, int scale, short rotationId ) {
-
- RotationType rotation = SkinRotation.getRotation( rotationId );
-
- LcdType lcd = rotation.getLcd();
- RegionType region = lcd.getRegion();
-
- Integer left = region.getLeft();
- Integer top = region.getTop();
- Integer width = region.getWidth();
- Integer height = region.getHeight();
-
- int l = (int) ( left * (((float)scale) / 100) );
- int t = (int) ( top * (((float)scale) / 100) );
- int w = (int) ( width * (((float)scale) / 100) );
- int h = (int) ( height * (((float)scale) / 100) );
-
- lcdCanvas.setBounds( l, t, w, h );
-
- }
-
- private SkinRegion getHardKeyArea( int currentX, int currentY ) {
-
- RotationType rotation = SkinRotation.getRotation( currentRotationId );
-
- List<KeyMapType> keyMapList = rotation.getKeyMapList().getKeyMap();
-
- for ( KeyMapType keyMap : keyMapList ) {
-
- RegionType region = keyMap.getRegion();
-
- int scaledX = (int) ( region.getLeft() * (((float)currentScale) / 100) );
- int scaledY = (int) ( region.getTop() * (((float)currentScale) / 100) );
- int scaledWidth = (int) ( region.getWidth() * (((float)currentScale) / 100) );
- int scaledHeight = (int) ( region.getHeight() * (((float)currentScale) / 100) );
-
- if ( isInGeometry( currentX, currentY, scaledX, scaledY, scaledWidth, scaledHeight ) ) {
- return new SkinRegion( scaledX, scaledY, scaledWidth, scaledHeight );
- }
-
- }
-
- return null;
-
- }
-
- private int getHardKeyCode( int currentX, int currentY ) {
-
- RotationType rotation = SkinRotation.getRotation( currentRotationId );
-
- List<KeyMapType> keyMapList = rotation.getKeyMapList().getKeyMap();
-
- for ( KeyMapType keyMap : keyMapList ) {
- RegionType region = keyMap.getRegion();
-
- int scaledX = (int) ( region.getLeft() * (((float)currentScale) / 100) );
- int scaledY = (int) ( region.getTop() * (((float)currentScale) / 100) );
- int scaledWidth = (int) ( region.getWidth() * (((float)currentScale) / 100) );
- int scaledHeight = (int) ( region.getHeight() * (((float)currentScale) / 100) );
-
- if ( isInGeometry( currentX, currentY, scaledX, scaledY, scaledWidth, scaledHeight ) ) {
- EventInfoType eventInfo = keyMap.getEventInfo();
- return eventInfo.getKeyCode();
- }
- }
-
- return EmulatorConstants.UNKNOWN_KEYCODE;
-
- }
-
- private boolean isInGeometry( int currentX, int currentY, int targetX, int targetY, int targetWidth,
- int targetHeight ) {
-
- if ( ( currentX >= targetX ) && ( currentY >= targetY ) ) {
- if ( ( currentX <= ( targetX + targetWidth ) ) && ( currentY <= ( targetY + targetHeight ) ) ) {
- return true;
- }
- }
-
- return false;
-
- }
-
- private int[] convertMouseGeometry( int originalX, int originalY ) {
-
- int x = (int) ( originalX * ( 1 / (((float)currentScale) / 100) ) );
- int y = (int) ( originalY * ( 1 / (((float)currentScale) / 100) ) );
-
- int rotatedX = x;
- int rotatedY = y;
-
- if ( RotationInfo.LANDSCAPE.angle() == currentAngle ) {
- rotatedX = currentLcdWidth - y;
- rotatedY = x;
- }else if ( RotationInfo.REVERSE_PORTRAIT.angle() == currentAngle ) {
- rotatedX = currentLcdWidth - x;
- rotatedY = currentLcdHeight - y;
- }else if ( RotationInfo.REVERSE_LANDSCAPE.angle() == currentAngle ) {
- rotatedX = y;
- rotatedY = currentLcdHeight - x;
- }
-
- return new int[] { rotatedX, rotatedY };
-
- }
-
private void addShellListener( final Shell shell ) {
shell.addListener( SWT.Close, new Listener() {
if ( EmulatorSkin.this.isMousePressed ) {
if ( 0 == e.button ) { // left button
- SkinRegion hardkeyRegion = getHardKeyArea( e.x, e.y );
+ SkinRegion hardkeyRegion = SkinUtil.getHardKeyArea( e.x, e.y, currentRotationId, currentScale );
if ( null == hardkeyRegion ) {
Point previouseLocation = shell.getLocation();
}
} else {
- SkinRegion region = getHardKeyArea( e.x, e.y );
+ SkinRegion region = SkinUtil.getHardKeyArea( e.x, e.y, currentRotationId, currentScale );
if ( null == region ) {
if( isHoverState ) {
EmulatorSkin.this.pressedMouseY = 0;
EmulatorSkin.this.isMousePressed = false;
- int keyCode = getHardKeyCode( e.x, e.y );
+ int keyCode = SkinUtil.getHardKeyCode( e.x, e.y, currentRotationId, currentScale );
if ( EmulatorConstants.UNKNOWN_KEYCODE != keyCode ) {
if (currentHoverRegion.width == 0 && currentHoverRegion.height == 0) {
EmulatorSkin.this.isMousePressed = true;
- int keyCode = getHardKeyCode( e.x, e.y );
+ int keyCode = SkinUtil.getHardKeyCode( e.x, e.y, currentRotationId, currentScale );
if ( EmulatorConstants.UNKNOWN_KEYCODE != keyCode ) {
// draw the button region as the cropped keyPressed image area
- SkinRegion region = getHardKeyArea( e.x, e.y );
+ SkinRegion region = SkinUtil.getHardKeyArea( e.x, e.y, currentRotationId, currentScale );
if ( null != currentKeyPressedImage ) {
GC gc = new GC( shell );
EmulatorSkin.this.isDragStartedInLCD = false;
}
- int[] geometry = convertMouseGeometry( e.x, e.y );
+ 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 );
}
public void mouseUp( MouseEvent e ) {
if ( 1 == e.button ) { // left button
- int[] geometry = convertMouseGeometry( e.x, e.y );
+ int[] geometry = SkinUtil.convertMouseGeometry( e.x, e.y, currentLcdWidth, currentLcdHeight,
+ currentScale, currentAngle );
+
logger.info( "mouseUp in LCD" + " x:" + geometry[0] + " y:" + geometry[1] );
MouseEventData mouseEventData = new MouseEventData( MouseEventType.UP.value(), geometry[0],
geometry[1], 0 );
@Override
public void mouseDown( MouseEvent e ) {
if ( 1 == e.button ) { // left button
- int[] geometry = convertMouseGeometry( e.x, e.y );
+
+ int[] geometry = SkinUtil.convertMouseGeometry( e.x, e.y, currentLcdWidth, currentLcdHeight,
+ currentScale, currentAngle );
+
logger.info( "mouseDown in LCD" + " x:" + geometry[0] + " y:" + geometry[1] );
MouseEventData mouseEventData = new MouseEventData( MouseEventType.DOWN.value(), geometry[0],
geometry[1], 0 );
private void addMenuItems( final Menu menu ) {
- final MenuItem infoItem = new MenuItem( menu, SWT.PUSH );
+ final MenuItem deviceInfoItem = new MenuItem( menu, SWT.PUSH );
String emulatorName = SkinUtil.makeEmulatorName( config );
- infoItem.setText( emulatorName );
+ deviceInfoItem.setText( emulatorName );
+ deviceInfoItem.setImage( imageRegistry.getIcon( IconName.DEVICE_INFO ) );
//FIXME
- infoItem.setEnabled( false );
- infoItem.addSelectionListener( new SelectionAdapter() {
+// deviceInfoItem.setEnabled( false );
+ deviceInfoItem.addSelectionListener( new SelectionAdapter() {
@Override
public void widgetSelected( SelectionEvent e ) {
logger.fine( "Selected Info." );
final MenuItem rotateItem = new MenuItem( menu, SWT.CASCADE );
rotateItem.setText( "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 ) );
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 ) );
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.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.addSelectionListener( new SelectionAdapter() {
@Override
public void widgetSelected( SelectionEvent e ) {
final List<MenuItem> rotationList = new ArrayList<MenuItem>();
- final short storedDirectionId = config.getPropertyShort( PropertiesConstants.WINDOW_DIRECTION, (short) 0 );
+ final short storedDirectionId = config.getPropertyShort( PropertiesConstants.WINDOW_DIRECTION,
+ (short) RotationInfo.PORTRAIT.id() );
Iterator<Entry<Short, RotationType>> iterator = SkinRotation.getRotationIterator();
break;
}
}
- // ////////
+ ///////////
MessageBox messageBox = new MessageBox( shell );
messageBox.setMessage( "Rotation is not ready." );
scaleOneQtrItem.setData( 25 );
scaleList.add( scaleOneQtrItem );
- int storedScale = config.getPropertyInt( PropertiesConstants.WINDOW_SCALE, 100 );
- //TODO:
- if (storedScale != 100 && storedScale != 75 && storedScale != 50 && storedScale != 25 ) {
- storedScale = 50;
- }
-
SelectionAdapter selectionAdapter = new SelectionAdapter() {
@Override
}
};
+ int storedScale = SkinUtil.getValidScale( config );
+
for ( MenuItem menuItem : scaleList ) {
int scale = (Integer) menuItem.getData();
final MenuItem screenshotItem = new MenuItem( menu, SWT.PUSH );
screenshotItem.setText( "Screen Shot" );
- //FIXME
- screenshotItem.setEnabled( false );
-
+ screenshotItem.setImage( imageRegistry.getIcon( IconName.SCREENSHOT ) );
screenshotItem.addSelectionListener( new SelectionAdapter() {
+ private boolean isOpen;
@Override
public void widgetSelected( SelectionEvent e ) {
- ScreenShotDialog dialog = new ScreenShotDialog( shell, lcdCanvas );
- dialog.open();
-// Display display = shell.getDisplay();
-// final Image image = new Image( display, lcdCanvas.getBounds() );
-//
-// GC gc = null;
-//
-// try {
-// gc = new GC( lcdCanvas );
-// gc.copyArea( image, 0, 0 );
-// } finally {
-// if ( null != gc ) {
-// gc.dispose();
-// }
-// }
-//
-// Shell popup = new Shell( shell, SWT.DIALOG_TRIM );
-// popup.setLayout( new FillLayout() );
-// popup.setText( "Screen Shot" );
-// popup.setBounds( 0, 0, lcdCanvas.getSize().x + 50, lcdCanvas.getSize().y + 50 );
-//
-// popup.addListener( SWT.Close, new Listener() {
-// @Override
-// public void handleEvent( Event event ) {
-// image.dispose();
-// }
-// } );
-//
-// ScrolledComposite composite = new ScrolledComposite( popup, SWT.V_SCROLL | SWT.H_SCROLL );
-//
-// Canvas canvas = new Canvas( composite, SWT.NONE );
-// composite.setContent( canvas );
-// canvas.setBounds( popup.getBounds() );
-//
-// canvas.addPaintListener( new PaintListener() {
-// public void paintControl( PaintEvent e ) {
-// e.gc.drawImage( image, 0, 0 );
-// }
-// } );
-//
-// // FileOutputStream fos = null;
-// //
-// // try {
-// //
-// // fos = new FileOutputStream( "./screenshot-" + System.currentTimeMillis() + ".png", false );
-// //
-// // ImageLoader loader = new ImageLoader();
-// // loader.data = new ImageData[] { image.getImageData() };
-// // loader.save( fos, SWT.IMAGE_PNG );
-// //
-// // } catch ( IOException ex ) {
-// // ex.printStackTrace();
-// // } finally {
-// // IOUtil.close( fos );
-// // }
-//
-// popup.open();
-
+ if( !isOpen ) {
+ isOpen = true;
+ ScreenShotDialog dialog = new ScreenShotDialog( shell, lcdCanvas );
+ dialog.open();
+ isOpen = false;
+ }
}
} );
final MenuItem usbKeyboardItem = new MenuItem( menu, SWT.CASCADE );
usbKeyboardItem.setText( "USB Keyboard" );
-
+ usbKeyboardItem.setImage( imageRegistry.getIcon( IconName.USB_KEBOARD ) );
+
Menu usbKeyBoardMenu = new Menu( shell, SWT.DROP_DOWN );
final MenuItem usbOnItem = new MenuItem( usbKeyBoardMenu, SWT.RADIO );
final MenuItem aboutItem = new MenuItem( menu, SWT.PUSH );
aboutItem.setText( "About" );
+ aboutItem.setImage( imageRegistry.getIcon( IconName.ABOUT ) );
aboutItem.addSelectionListener( new SelectionAdapter() {
private boolean isOpen;
@Override
isShutdownRequested = true;
- canvasExecutor.shutdownNow();
-
if ( !this.shell.isDisposed() ) {
this.shell.getDisplay().asyncExec( new Runnable() {
@Override
package org.tizen.emulator.skin.image;
import java.io.File;
+import java.io.InputStream;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.logging.Logger;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.tizen.emulator.skin.dbi.ImageListType;
import org.tizen.emulator.skin.dbi.RotationType;
import org.tizen.emulator.skin.dbi.RotationsType;
+import org.tizen.emulator.skin.log.SkinLogger;
+import org.tizen.emulator.skin.util.IOUtil;
import org.tizen.emulator.skin.util.SkinRotation;
*
*/
public class ImageRegistry {
+
+ private Logger logger = SkinLogger.getSkinLogger( ImageRegistry.class ).getLogger();
public static final String SKIN_FOLDER = "skins";
public static final String IMAGE_FOLDER_PREFIX = "emul_";
public enum IconName {
+ DEVICE_INFO( "device_info.png" ),
+ ROTATE( "rotate.png" ),
+ SCALING( "scaling.png" ),
+ SHELL( "shell.png" ),
+ ADVANCED( "advanced.png" ),
+ CLOSE( "close.png" ),
+ SCREENSHOT( "screenshot.png" ),
+ USB_KEBOARD( "keypad.png" ),
+ ABOUT( "about.png" ),
+
+ EMULATOR_TITLE( "Emulator_20x20.png" ),
+ EMULATOR_TITLE_ICO( "Emulator.ico" );
+
+ private String name;
+
+ private IconName( String name ) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
}
private Display display;
private int resolutionHeight;
private EmulatorUI dbiContents;
- private Map<String, Image> imageMap;
+ private Map<String, Image> skinImageMap;
+ private Map<String, Image> iconMap;
public ImageRegistry(Display display, EmulatorConfig config ) {
this.resolutionWidth = lcdWidth;
this.resolutionHeight = lcdHeight;
this.dbiContents = config.getDbiContents();
- this.imageMap = new HashMap<String, Image>();
+ this.skinImageMap = new HashMap<String, Image>();
+ this.iconMap = new HashMap<String, Image>();
init();
String skinPath = ".." + File.separator + SKIN_FOLDER + File.separator + IMAGE_FOLDER_PREFIX + lcdWidth + "x" + lcdHeight;
return skinPath;
}
-
+
private void init() {
String skinPath = getSkinPath( resolutionWidth, resolutionHeight );
if ( entry.getValue().getName().value().equals( rotation.getName().value() ) ) {
String mainKey = makeKey( entry.getKey(), ImageType.IMG_TYPE_MAIN );
- imageMap.put( mainKey, new Image( display, skinPath + File.separator + mainImage ) );
+ skinImageMap.put( mainKey, new Image( display, skinPath + File.separator + mainImage ) );
String pressedKey = makeKey( entry.getKey(), ImageType.IMG_TYPE_PRESSED );
- imageMap.put( pressedKey, new Image( display, skinPath + File.separator + keyPressedImage ) );
+ skinImageMap.put( pressedKey, new Image( display, skinPath + File.separator + keyPressedImage ) );
}
}
}
+
+ ClassLoader classLoader = this.getClass().getClassLoader();
+ IconName[] values = IconName.values();
+
+ for ( IconName iconName : values ) {
+
+ String name = iconName.getName();
+
+ String iconPath = ICON_FOLDER + "/" + name;
+
+ InputStream is = null;
+ try {
+ is = classLoader.getResourceAsStream( iconPath );
+ if( null != is ) {
+ logger.info( "load icon:" + iconPath );
+ iconMap.put( name, new Image( display, is ) );
+ }else {
+ logger.severe( "missing icon:" + iconPath );
+ }
+ } finally {
+ IOUtil.close( is );
+ }
+
+ }
}
-// public Image getImage( Short id, ImageType imageType ) {
-// Image image = imageMap.get( makeKey(id, imageType) );
-// return image;
-// }
-
- public ImageData getImageData( Short id, ImageType imageType ) {
- Image image = imageMap.get( makeKey(id, imageType) );
+ public ImageData getSkinImageData( Short id, ImageType imageType ) {
+ Image image = skinImageMap.get( makeKey(id, imageType) );
if( null != image ) {
return image.getImageData();
}else {
return id + ":" + imageType.ordinal();
}
+ public Image getIcon( IconName name ) {
+ return iconMap.get( name.getName() );
+ }
+
public void dispose() {
-
- Collection<Image> images = imageMap.values();
-
- Iterator<Image> iterator = images.iterator();
-
- while(iterator.hasNext()) {
- Image image = iterator.next();
+
+ Collection<Image> images = skinImageMap.values();
+
+ Iterator<Image> imageIterator = images.iterator();
+
+ while ( imageIterator.hasNext() ) {
+ Image image = imageIterator.next();
image.dispose();
}
-
+
+ Collection<Image> icons = iconMap.values();
+
+ Iterator<Image> iconIterator = icons.iterator();
+
+ while ( iconIterator.hasNext() ) {
+ Image image = iconIterator.next();
+ image.dispose();
+ }
+
}
}
package org.tizen.emulator.skin.util;
+import java.io.File;
+import java.lang.reflect.Field;
+import java.util.List;
+import java.util.logging.Level;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.graphics.Region;
+import org.eclipse.swt.widgets.Canvas;
+import org.eclipse.swt.widgets.Shell;
+import org.tizen.emulator.skin.EmulatorConstants;
import org.tizen.emulator.skin.config.EmulatorConfig;
import org.tizen.emulator.skin.config.EmulatorConfig.ArgsConstants;
+import org.tizen.emulator.skin.config.EmulatorConfig.PropertiesConstants;
+import org.tizen.emulator.skin.dbi.EventInfoType;
+import org.tizen.emulator.skin.dbi.KeyMapType;
+import org.tizen.emulator.skin.dbi.LcdType;
+import org.tizen.emulator.skin.dbi.RegionType;
+import org.tizen.emulator.skin.dbi.RotationType;
+import org.tizen.emulator.skin.image.ImageRegistry;
+import org.tizen.emulator.skin.image.ImageRegistry.ImageType;
+import org.tizen.emulator.skin.util.SkinRotation.RotationInfo;
/**
*/
public class SkinUtil {
+ public static final int SCALE_CONVERTER = 100;
public static final String EMULATOR_PREFIX = "emulator";
-
+
private SkinUtil() {
}
+
+ public static boolean isLinuxPlatform() {
+ return "gtk".equalsIgnoreCase( SWT.getPlatform() );
+ }
+
+ public static boolean isWindowsPlatform() {
+ return "win32".equalsIgnoreCase( SWT.getPlatform() );
+ }
+
+ public static boolean isMacPlatform() {
+ return "cocoa".equalsIgnoreCase( SWT.getPlatform() );
+ }
+
+ public static String getVmName( EmulatorConfig config ) {
+
+ String vmPath = config.getArg( ArgsConstants.VM_PATH );
+ String[] split = StringUtil.nvl( vmPath ).split( File.separator );
+ String vmName = split[split.length - 1];
+
+ return vmName;
+
+ }
public static String makeEmulatorName( EmulatorConfig config ) {
-
+
+ String vmName = getVmName( config );
+
+ if ( StringUtil.isEmpty( vmName ) ) {
+ vmName = EMULATOR_PREFIX;
+ }
+
String portNumber = StringUtil.nvl( config.getArg( ArgsConstants.NET_BASE_PORT ) );
+
+ if ( StringUtil.isEmpty( portNumber ) ) {
+ return vmName;
+ } else {
+ return vmName + ":" + portNumber;
+ }
+
+ }
+
+ public static void adjustLcdGeometry( Canvas lcdCanvas, int scale, short rotationId ) {
+
+ RotationType rotation = SkinRotation.getRotation( rotationId );
+
+ LcdType lcd = rotation.getLcd();
+ RegionType region = lcd.getRegion();
+
+ Integer left = region.getLeft();
+ Integer top = region.getTop();
+ Integer width = region.getWidth();
+ Integer height = region.getHeight();
+
+ float convertedScale = convertScale( scale );
+
+ int l = (int) ( left * convertedScale );
+ int t = (int) ( top * convertedScale );
+ int w = (int) ( width * convertedScale );
+ int h = (int) ( height * convertedScale );
+
+ lcdCanvas.setBounds( l, t, w, h );
+
+ }
+
+ public static SkinRegion getHardKeyArea( int currentX, int currentY, short rotationId, int scale ) {
+
+ float convertedScale = convertScale( scale );
+
+ RotationType rotation = SkinRotation.getRotation( rotationId );
+
+ List<KeyMapType> keyMapList = rotation.getKeyMapList().getKeyMap();
+
+ for ( KeyMapType keyMap : keyMapList ) {
+
+ RegionType region = keyMap.getRegion();
+
+ int scaledX = (int) ( region.getLeft() * convertedScale );
+ int scaledY = (int) ( region.getTop() * convertedScale );
+ int scaledWidth = (int) ( region.getWidth() * convertedScale );
+ int scaledHeight = (int) ( region.getHeight() * convertedScale );
+
+ if ( isInGeometry( currentX, currentY, scaledX, scaledY, scaledWidth, scaledHeight ) ) {
+ return new SkinRegion( scaledX, scaledY, scaledWidth, scaledHeight );
+ }
+
+ }
+
+ return null;
+
+ }
+
+ public static int getHardKeyCode( int currentX, int currentY, short rotationId, int scale ) {
+
+ float convertedScale = convertScale( scale );
+
+ RotationType rotation = SkinRotation.getRotation( rotationId );
+
+ List<KeyMapType> keyMapList = rotation.getKeyMapList().getKeyMap();
+
+ for ( KeyMapType keyMap : keyMapList ) {
+ RegionType region = keyMap.getRegion();
+
+ int scaledX = (int) ( region.getLeft() * convertedScale );
+ int scaledY = (int) ( region.getTop() * convertedScale );
+ int scaledWidth = (int) ( region.getWidth() * convertedScale );
+ int scaledHeight = (int) ( region.getHeight() * convertedScale );
+
+ if ( isInGeometry( currentX, currentY, scaledX, scaledY, scaledWidth, scaledHeight ) ) {
+ EventInfoType eventInfo = keyMap.getEventInfo();
+ return eventInfo.getKeyCode();
+ }
+ }
+
+ return EmulatorConstants.UNKNOWN_KEYCODE;
+
+ }
+
+ public static boolean isInGeometry( int currentX, int currentY, int targetX, int targetY, int targetWidth,
+ int targetHeight ) {
+
+ if ( ( currentX >= targetX ) && ( currentY >= targetY ) ) {
+ if ( ( currentX <= ( targetX + targetWidth ) ) && ( currentY <= ( targetY + targetHeight ) ) ) {
+ return true;
+ }
+ }
+
+ return false;
+
+ }
+
+ public static void trimShell( Shell shell, Image image ) {
+
+ // trim transparent pixels in image. especially, corner round areas.
+
+ ImageData imageData = image.getImageData();
+
+ int width = imageData.width;
+ int height = imageData.height;
+
+ Region region = new Region();
+ region.add( new Rectangle( 0, 0, width, height ) );
+
+ for ( int i = 0; i < width; i++ ) {
+ for ( int j = 0; j < height; j++ ) {
+ int alpha = imageData.getAlpha( i, j );
+ if ( 0 == alpha ) {
+ region.subtract( i, j, 1, 1 );
+ }
+ }
+ }
+
+ shell.setRegion( region );
+
+ }
+
+ public static int[] convertMouseGeometry( int originalX, int originalY, int lcdWidth, int lcdHeight, int scale,
+ int angle ) {
+
+ float convertedScale = convertScale( scale );
+
+ int x = (int) ( originalX * ( 1 / convertedScale ) );
+ int y = (int) ( originalY * ( 1 / convertedScale ) );
+
+ int rotatedX = x;
+ int rotatedY = y;
+
+ if ( RotationInfo.LANDSCAPE.angle() == angle ) {
+ rotatedX = lcdWidth - y;
+ rotatedY = x;
+ } else if ( RotationInfo.REVERSE_PORTRAIT.angle() == angle ) {
+ rotatedX = lcdWidth - x;
+ rotatedY = lcdHeight - y;
+ } else if ( RotationInfo.REVERSE_LANDSCAPE.angle() == angle ) {
+ rotatedX = y;
+ rotatedY = lcdHeight - x;
+ }
+
+ return new int[] { rotatedX, rotatedY };
+
+ }
+
+ public static Image createScaledImage( ImageRegistry imageRegistry, Shell shell, short rotationId, int scale,
+ ImageType type ) {
+
+ ImageData originalImageData = imageRegistry.getSkinImageData( rotationId, type );
+
+ ImageData imageData = (ImageData) originalImageData.clone();
+
+ float convertedScale = convertScale( scale );
+
+ int width = (int) ( originalImageData.width * convertedScale );
+ int height = (int) ( originalImageData.height * convertedScale );
+ imageData = imageData.scaledTo( width, height );
+
+ Image image = new Image( shell.getDisplay(), imageData );
+ return image;
+
+ }
+
+ public static float convertScale( int scale ) {
+ return (float) scale / SCALE_CONVERTER;
+ }
+
+ public static int getValidScale( EmulatorConfig config ) {
+
+ int lcdHeight = Integer.parseInt( config.getArg( ArgsConstants.RESOLUTION_HEIGHT ) );
+ int defaultScale = SkinUtil.getDefaultScale( lcdHeight );
+
+ int storedScale = config.getPropertyInt( PropertiesConstants.WINDOW_SCALE, defaultScale );
- if( StringUtil.isEmpty( portNumber ) ) {
- return EMULATOR_PREFIX;
+ if ( !SkinUtil.isValidScale( storedScale ) ) {
+ return defaultScale;
}else {
- return EMULATOR_PREFIX + "-" + portNumber;
+ return storedScale;
}
}
-
+
+ public static int getDefaultScale( int lcdHeight ) {
+ int defaultScale = 100;
+ if ( 800 < lcdHeight ) {
+ defaultScale = 50;
+ }
+ return defaultScale;
+ }
+
+ public static boolean isValidScale( int scale ) {
+ if ( 100 == scale || 75 == scale || 50 == scale || 25 == scale ) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
}