[Title] refactoring java skin source, add icons
authorSon Hyunjun <hj79.son@samsung.com>
Fri, 23 Mar 2012 01:08:12 +0000 (10:08 +0900)
committerSon Hyunjun <hj79.son@samsung.com>
Fri, 23 Mar 2012 01:08:12 +0000 (10:08 +0900)
[Type] Feature
[Module]
[Priority] Minor
[CQ#]
[Redmine#]
[Problem]
[Cause]
[Solution]

Change-Id: I0d40cad4ad88b8c9a41368519f67bde2874f9f59

tizen/src/skin/client/build.xml
tizen/src/skin/client/icons/properties.png [deleted file]
tizen/src/skin/client/icons/scaling.png [new file with mode: 0644]
tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkin.java
tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkinMain.java
tizen/src/skin/client/src/org/tizen/emulator/skin/comm/ICommunicator.java
tizen/src/skin/client/src/org/tizen/emulator/skin/comm/sock/SocketCommunicator.java
tizen/src/skin/client/src/org/tizen/emulator/skin/dialog/SkinDialog.java
tizen/src/skin/client/src/org/tizen/emulator/skin/image/ImageRegistry.java
tizen/src/skin/client/src/org/tizen/emulator/skin/log/SkinLogger.java
tizen/src/skin/client/src/org/tizen/emulator/skin/util/SkinUtil.java

index 00a849030189591fdc60849b239b0db77d3677ec..3f3276d18fad9f2590e2a48883670cb26ec1270c 100644 (file)
@@ -1,29 +1,29 @@
 <?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
diff --git a/tizen/src/skin/client/icons/properties.png b/tizen/src/skin/client/icons/properties.png
deleted file mode 100644 (file)
index 5a8114b..0000000
Binary files a/tizen/src/skin/client/icons/properties.png and /dev/null differ
diff --git a/tizen/src/skin/client/icons/scaling.png b/tizen/src/skin/client/icons/scaling.png
new file mode 100644 (file)
index 0000000..5a8114b
Binary files /dev/null and b/tizen/src/skin/client/icons/scaling.png differ
index bfa9cb3ef1b2592b3eef2eb9826b6f515ce615b9..86526cdf3357497bdc8a0fe485c302b19dbd413b 100644 (file)
@@ -34,8 +34,6 @@ import java.util.ArrayList;
 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;
 
@@ -60,8 +58,6 @@ import org.eclipse.swt.graphics.Image;
 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;
@@ -82,21 +78,18 @@ 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.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;
 
 /**
  * 
@@ -120,20 +113,18 @@ public class EmulatorSkin {
        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 );
@@ -156,47 +147,45 @@ public class EmulatorSkin {
 
                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 );
@@ -204,37 +193,57 @@ public class EmulatorSkin {
                        } 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 ) {
@@ -272,11 +281,12 @@ public class EmulatorSkin {
                        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 );
@@ -284,151 +294,6 @@ public class EmulatorSkin {
 
        }
 
-       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() {
@@ -506,7 +371,7 @@ public class EmulatorSkin {
                                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();
@@ -519,7 +384,7 @@ public class EmulatorSkin {
                                        }
                                } else {
 
-                                       SkinRegion region = getHardKeyArea( e.x, e.y );
+                                       SkinRegion region = SkinUtil.getHardKeyArea( e.x, e.y, currentRotationId, currentScale );
 
                                        if ( null == region ) {
                                                if( isHoverState ) {
@@ -557,7 +422,7 @@ public class EmulatorSkin {
                                        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) {
@@ -582,11 +447,11 @@ public class EmulatorSkin {
 
                                        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 );
@@ -665,7 +530,9 @@ public class EmulatorSkin {
                                                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 );
                                }
@@ -678,7 +545,9 @@ public class EmulatorSkin {
                        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 );
@@ -692,7 +561,10 @@ public class EmulatorSkin {
                        @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 );
@@ -730,13 +602,14 @@ public class EmulatorSkin {
 
        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." );
@@ -762,12 +635,14 @@ public class EmulatorSkin {
 
                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 );
 
@@ -775,11 +650,13 @@ public class EmulatorSkin {
 
                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 ) {
@@ -801,6 +678,7 @@ public class EmulatorSkin {
 
                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 ) {
@@ -816,7 +694,8 @@ public class EmulatorSkin {
 
                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();
 
@@ -861,7 +740,7 @@ public class EmulatorSkin {
                                                        break;
                                                }
                                        }
-                                       // ////////
+                                       ///////////
 
                                        MessageBox messageBox = new MessageBox( shell );
                                        messageBox.setMessage( "Rotation is not ready." );
@@ -913,12 +792,6 @@ public class EmulatorSkin {
                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
@@ -941,6 +814,8 @@ public class EmulatorSkin {
                        }
                };
 
+               int storedScale = SkinUtil.getValidScale( config );
+
                for ( MenuItem menuItem : scaleList ) {
 
                        int scale = (Integer) menuItem.getData();
@@ -962,76 +837,24 @@ public class EmulatorSkin {
 
                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 );
@@ -1061,6 +884,7 @@ public class EmulatorSkin {
 
                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
@@ -1082,8 +906,6 @@ public class EmulatorSkin {
 
                isShutdownRequested = true;
 
-               canvasExecutor.shutdownNow();
-
                if ( !this.shell.isDisposed() ) {
                        this.shell.getDisplay().asyncExec( new Runnable() {
                                @Override
index 0d1ad657efd976f68ea5619cf6b0745381e46d3f..ef19709457962b891fc3d526365591cc7f79b9ff 100644 (file)
@@ -57,11 +57,11 @@ import org.tizen.emulator.skin.util.StringUtil;
  */
 public class EmulatorSkinMain {
 
-       private static Logger logger;
-
        public static final String PROPERTIES_FILE_NAME = ".skin.properties";
        public static final String DBI_FILE_NAME = "default.dbi";
 
+       private static Logger logger;
+       
        /**
         * @param args
         */
@@ -94,8 +94,8 @@ public class EmulatorSkinMain {
                        EmulatorSkin skin = new EmulatorSkin( config );
                        int windowHandleId = skin.compose();
 
-                       int pid = Integer.parseInt( config.getArg( ArgsConstants.UID ) );
-                       SocketCommunicator communicator = new SocketCommunicator( config, pid, windowHandleId, skin );
+                       int uid = Integer.parseInt( config.getArg( ArgsConstants.UID ) );
+                       SocketCommunicator communicator = new SocketCommunicator( config, uid, windowHandleId, skin );
 
                        skin.setCommunicator( communicator );
 
@@ -132,8 +132,11 @@ public class EmulatorSkinMain {
 
                String logLevel = "";
                String vmPath = "";
+               
                for ( int i = 0; i < args.length; i++ ) {
+                       
                        String[] split = args[i].split( "=" );
+                       
                        if ( split[0].trim().equalsIgnoreCase( ArgsConstants.LOG_LEVEL ) ) {
                                if ( !StringUtil.isEmpty( split[1].trim() ) ) {
                                        logLevel = split[1].trim();
@@ -141,18 +144,22 @@ public class EmulatorSkinMain {
                        }else if ( split[0].trim().equalsIgnoreCase( ArgsConstants.VM_PATH ) ) {
                                vmPath = split[1].trim();
                        }
+                       
                }
 
-               SkinLogLevel skinLogLevel = SkinLogLevel.DEBUG;
+               SkinLogLevel skinLogLevel = SkinLogLevel.WARN;
                
                if( !StringUtil.isEmpty( logLevel ) ) {
+                       
                        SkinLogLevel[] values = SkinLogLevel.values();
+                       
                        for ( SkinLogLevel level : values ) {
                                if ( level.value().equalsIgnoreCase( logLevel ) ) {
                                        skinLogLevel = level;
                                        break;
                                }
                        }
+                       
                }
 
                SkinLogger.init( skinLogLevel, vmPath );
index 70d3ce5a7e28cf30d9c9e82ecb6a7d91cceb518a..d0aecab8b7d722076f8d2c7d537a3ceeb8f8270a 100644 (file)
@@ -37,45 +37,6 @@ import org.tizen.emulator.skin.comm.sock.data.ISendData;
  */
 public interface ICommunicator extends Runnable {
 
-//     public enum Scale {
-//             ONE( (short)1, (float)1.0 ),
-//             THREE_QUARTERS( (short)2, (float)0.75 ),
-//             HALF( (short)3, (float)0.5 ),
-//             ONE_QUARTER( (short)4, (float)0.25 );
-//             
-//             private short value;
-//             private float ratio;
-//             Scale( short value, float ratio ) {
-//                     this.value = value;
-//                     this.ratio = ratio;
-//             }
-//             public short value() {
-//                     return this.value;
-//             }
-//             public float ratio() {
-//                     return this.ratio;
-//             }
-//             public static Scale getValue( String val ) {
-//                     Scale[] values = Scale.values();
-//                     for (int i = 0; i < values.length; i++) {
-//                             if( values[i].value == Integer.parseInt( val ) ) {
-//                                     return values[i];
-//                             }
-//                     }
-//                     throw new IllegalArgumentException( val );
-//             }
-//             public static Scale getValue( short val ) {
-//                     Scale[] values = Scale.values();
-//                     for (int i = 0; i < values.length; i++) {
-//                             if( values[i].value == val ) {
-//                                     return values[i];
-//                             }
-//                     }
-//                     throw new IllegalArgumentException( Integer.toString(val) );
-//             }
-//
-//     }
-
        public enum MouseEventType {
                DOWN( (short)1 ),
                UP( (short)2 ),
index 918787abdeb6c1d813d60123be0bbfa0babb2591..9b8a4f3c501250ad766c5d06d34362c377e6117a 100644 (file)
@@ -53,6 +53,7 @@ import org.tizen.emulator.skin.config.EmulatorConfig.ArgsConstants;
 import org.tizen.emulator.skin.config.EmulatorConfig.PropertiesConstants;
 import org.tizen.emulator.skin.log.SkinLogger;
 import org.tizen.emulator.skin.util.IOUtil;
+import org.tizen.emulator.skin.util.SkinUtil;
 
 
 /**
@@ -112,11 +113,8 @@ public class SocketCommunicator implements ICommunicator {
                        dis = new DataInputStream(socket.getInputStream());
                        dos = new DataOutputStream(socket.getOutputStream());
                        
-                       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 rotation = config.getPropertyShort( PropertiesConstants.WINDOW_DIRECTION, (short) 0 );
                        
                        sendToQEMU(SendCommand.SEND_START,
index 35677f499ad6780d4482de9a0154a847c38a34a2..64ed86cb993efb0a5a38ac8e0758db1ea4703eb9 100644 (file)
@@ -71,8 +71,10 @@ public abstract class SkinDialog extends Dialog {
        public void open() {
 
                shell = new Shell( parent, style );
-               shell.setLocation( parent.getLocation().x + 30, parent.getLocation().y + 100 );
+               shell.setLocation( parent.getLocation().x + 50, parent.getLocation().y + 50 );
                shell.setText( title );
+               shell.setImage( parent.getImage() );
+               
                shell.setLayout( new GridLayout( 1, true ) );
 
                Composite parent = new Composite( shell, SWT.NONE );
index fb6545faf6db0c553f80aa481434c451e6aa7f66..04209e12879e57eb1f4f0f6bb829001985ed64a9 100644 (file)
 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;
@@ -46,6 +48,8 @@ import org.tizen.emulator.skin.dbi.EmulatorUI;
 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;
 
 
@@ -54,6 +58,8 @@ 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_";
@@ -66,6 +72,29 @@ public class ImageRegistry {
        
        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;
@@ -73,7 +102,8 @@ public class ImageRegistry {
        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 ) {
                
@@ -85,7 +115,8 @@ public class ImageRegistry {
                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();
                
@@ -95,7 +126,7 @@ public class ImageRegistry {
                String skinPath = ".." + File.separator + SKIN_FOLDER + File.separator + IMAGE_FOLDER_PREFIX + lcdWidth + "x" + lcdHeight;
                return skinPath;
        }
-       
+
        private void init() {
 
                String skinPath = getSkinPath( resolutionWidth, resolutionHeight );
@@ -122,25 +153,44 @@ public class ImageRegistry {
                                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 {
@@ -152,17 +202,30 @@ public class ImageRegistry {
                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();
+               }
+
        }
        
 }
index 335a1b9806f2b344d6de915a3692547e94af98b6..df22f901b4753ffb9d8ae58c9519eee9f4819ed4 100644 (file)
@@ -138,6 +138,8 @@ public class SkinLogger {
                        
                        fileHandler.setLevel( logLevel.level() );
                        
+                       System.out.println( "[SkinLog]SkinLogger level:" + logLevel.value() );
+                       
                }
                
        }
index 9142274271b3248bb3750fba0684095743b29a9a..1c68ba2c5d5d7f6fa98fe4e0fe5115500aee79f8 100644 (file)
 
 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;
 
 
 /**
@@ -39,21 +61,243 @@ import org.tizen.emulator.skin.config.EmulatorConfig.ArgsConstants;
  */
 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;
+               }
+       }
+
 }