super(config, skinInfo, isOnTop);
}
- public long compose() {
- super.compose();
+ public long initLayout() {
+ super.initLayout();
// sdl uses this handle id.
windowHandleId = getWindowHandleId();
pollThread.stopRequest();
}
- public long compose() {
- super.compose();
+ public long initLayout() {
+ super.initLayout();
/* initialize shared memory */
int result = shmget(
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
-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.layout.FormAttachment;
-import org.eclipse.swt.layout.FormData;
-import org.eclipse.swt.layout.FormLayout;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Decorations;
import org.tizen.emulator.skin.config.EmulatorConfig.ArgsConstants;
import org.tizen.emulator.skin.config.EmulatorConfig.SkinPropertiesConstants;
import org.tizen.emulator.skin.dbi.ColorsType;
-import org.tizen.emulator.skin.dbi.KeyMapType;
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.dialog.RamdumpDialog;
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.info.SkinInformation;
+import org.tizen.emulator.skin.layout.GeneralPurposeSkinComposer;
+import org.tizen.emulator.skin.layout.ISkinComposer;
+import org.tizen.emulator.skin.layout.PhoneShapeSkinComposer;
import org.tizen.emulator.skin.log.SkinLogger;
import org.tizen.emulator.skin.screenshot.ScreenShotDialog;
import org.tizen.emulator.skin.util.SkinRegion;
protected Shell shell;
protected ImageRegistry imageRegistry;
protected Canvas lcdCanvas;
- private SkinInformation skinInfo;
- private Image currentImage;
- private Image currentKeyPressedImage;
+ protected SkinInformation skinInfo;
+ protected ISkinComposer skinComposer;
private Color hoverColor;
private boolean isDefaultHoverColor;
private SkinWindow controlPanel;
protected ScreenShotDialog screenShotDialog;
private Menu contextMenu;
- private Button foldingButton; //TODO:
- private Decorations decoration; //TODO:
protected SocketCommunicator communicator;
protected long windowHandleId;
if (skinInfo.isPhoneShape() == false) {
style = SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.BORDER;
}
-
this.shell = new Shell(Display.getDefault(), style);
this.currentState = new EmulatorSkinState();
this.communicator = communicator;
}
- public long compose() {
- shell.setLayout(new FormLayout());
-
- this.lcdCanvas = new Canvas(shell, SWT.EMBEDDED); //TODO:
-
- int x = config.getSkinPropertyInt(SkinPropertiesConstants.WINDOW_X,
- EmulatorConfig.DEFAULT_WINDOW_X);
- int y = config.getSkinPropertyInt(SkinPropertiesConstants.WINDOW_Y,
- EmulatorConfig.DEFAULT_WINDOW_Y);
-
- currentState.setCurrentResolutionWidth(
- config.getArgInt(ArgsConstants.RESOLUTION_WIDTH));
- currentState.setCurrentResolutionHeight(
- config.getArgInt(ArgsConstants.RESOLUTION_HEIGHT));
-
- int scale = SkinUtil.getValidScale(config);
-// int rotationId = config.getPropertyShort( PropertiesConstants.WINDOW_ROTATION,
-// EmulatorConfig.DEFAULT_WINDOW_ROTATION );
- // has to be portrait mode at first booting time
- short rotationId = EmulatorConfig.DEFAULT_WINDOW_ROTATION;
-
- composeInternal(lcdCanvas, x, y, scale, rotationId, false);
- logger.info("resolution : " + currentState.getCurrentResolution() +
- ", scale : " + scale);
-
- return 0;
- }
-
- private void composeInternal(Canvas lcdCanvas,
- int x, int y, int scale, short rotationId, boolean isOnKbd) {
-
- //shell.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_BLACK));
- shell.setLocation(x, y);
-
- String emulatorName = SkinUtil.makeEmulatorName(config);
- shell.setText(emulatorName);
-
- lcdCanvas.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_BLACK));
-
+ public long initLayout() {
imageRegistry = ImageRegistry.getInstance();
- if (SwtUtil.isWindowsPlatform()) {
- shell.setImage(imageRegistry.getIcon(IconName.EMULATOR_TITLE_ICO));
- } else {
- shell.setImage(imageRegistry.getIcon(IconName.EMULATOR_TITLE));
- }
-
- arrangeSkin(scale, rotationId);
- if (skinInfo.isPhoneShape() && null == currentImage) {
- logger.severe("Failed to load initial skin image file. Kill this skin process.");
- SkinUtil.openMessage(shell, null,
- "Failed to load Skin image file.", SWT.ICON_ERROR, config);
- System.exit(-1);
+ if (skinInfo.isPhoneShape() == true) {
+ skinComposer = new PhoneShapeSkinComposer(config, shell,
+ currentState, imageRegistry);
+ } else {
+ skinComposer = new GeneralPurposeSkinComposer(config, shell,
+ currentState, imageRegistry, communicator);
}
+ lcdCanvas = skinComposer.compose();
seteHoverColor();
- this.isOnKbd = isOnKbd;
+ addShellListener(shell);
+ addCanvasListener(shell, lcdCanvas);
+
+ this.isOnKbd = false;
setMenu();
+
+ return 0;
}
private void setMenu() {
addMenuItems(shell, contextMenu);
- addShellListener(shell);
- addCanvasListener(shell, lcdCanvas);
-
shell.setMenu(contextMenu);
}
}
-// private void rearrangeSkin() {
-// logger.info("rearrange the skin (" + skinInfo.getSkinOption() + ")");
-// arrangeSkin(currentScale, currentRotationId);
-// }
-
- private void arrangeSkin(int scale, short rotationId) {
- currentState.setCurrentScale(scale);
- currentState.setCurrentRotationId(rotationId);
- currentState.setCurrentAngle(SkinRotation.getAngle(rotationId));
-
- /* arrange the lcd */
- Rectangle lcdBounds = SkinUtil.adjustLcdGeometry(lcdCanvas,
- currentState.getCurrentResolutionWidth(),
- currentState.getCurrentResolutionHeight(), scale, rotationId,
- skinInfo.isPhoneShape());
-
- if (lcdBounds == null) {
- logger.severe("Failed to lcd information for phone shape skin.");
- SkinUtil.openMessage(shell, null,
- "Failed to read lcd information for phone shape skin.\n" +
- "Check the contents of skin dbi file.",
- SWT.ICON_ERROR, config);
- System.exit(-1);
- }
- logger.info("lcd bounds : " + lcdBounds);
-
- FormData dataCanvas = new FormData();
- dataCanvas.left = new FormAttachment(0, lcdBounds.x);
- dataCanvas.top = new FormAttachment(0, lcdBounds.y);
- dataCanvas.width = lcdBounds.width;
- dataCanvas.height = lcdBounds.height;
- lcdCanvas.setLayoutData(dataCanvas);
-
- if (skinInfo.isPhoneShape() == false) {
-// /* folding button */
-// if (foldingButton == null) {
-// foldingButton = new Button(shell, SWT.PUSH);
-// foldingButton.setText(">");
-//
-// foldingButton.addMouseListener(new MouseListener() {
-// @Override
-// public void mouseDown(MouseEvent e) {
-// /* do nothing */
-// }
-//
-// @Override
-// public void mouseUp(MouseEvent e) {
-// if (skinInfo.getSkinOption() == 0) {
-// skinInfo.setSkinOption(1);
-// foldingButton.setText("<");
-// } else {
-// skinInfo.setSkinOption(0);
-// foldingButton.setText(">");
-// }
-//
-// shell.getDisplay().syncExec(new Runnable() {
-// public void run() {
-// rearrangeSkin();
-// }
-// });
-// }
-//
-// @Override
-// public void mouseDoubleClick(MouseEvent e) {
-// /* do nothing */
-// }
-// });
-//
-// shell.pack();
-// }
-//
-// FormData dataFoldingButton = new FormData();
-// dataFoldingButton.left = new FormAttachment(lcdCanvas, 0);
-// dataFoldingButton.top = new FormAttachment(
-// 0, (lcdBounds.height / 2) - (foldingButton.getSize().y / 2));
-// foldingButton.setLayoutData(dataFoldingButton);
-//
-// if (skinInfo.getSkinOption() == 0) {
-// /* HW keys region */
-// if (decoration == null) {
- decoration = new Decorations(shell, SWT.BORDER);
- decoration.setLayout(new GridLayout(1, true));
-
- RotationType rotation =
- SkinRotation.getRotation(currentState.getCurrentRotationId());
- List<KeyMapType> keyMapList = rotation.getKeyMapList().getKeyMap();
-
- // TODO: function
- if (keyMapList != null && keyMapList.isEmpty() == false) {
- for (KeyMapType keyEntry : keyMapList) {
- Button hardKeyButton = new Button(decoration, SWT.FLAT);
- hardKeyButton.setText(keyEntry.getEventInfo().getKeyName());
- hardKeyButton.setToolTipText(keyEntry.getTooltip());
-
- hardKeyButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
-
- final int keycode = keyEntry.getEventInfo().getKeyCode();
- hardKeyButton.addMouseListener(new MouseListener() {
- @Override
- public void mouseDown(MouseEvent e) {
- KeyEventData keyEventData = new KeyEventData(
- KeyEventType.PRESSED.value(), keycode, 0, 0);
- communicator.sendToQEMU(SendCommand.SEND_HARD_KEY_EVENT, keyEventData);
- }
-
- @Override
- public void mouseUp(MouseEvent e) {
- KeyEventData keyEventData = new KeyEventData(
- KeyEventType.RELEASED.value(), keycode, 0, 0);
- communicator.sendToQEMU(SendCommand.SEND_HARD_KEY_EVENT, keyEventData);
- }
-
- @Override
- public void mouseDoubleClick(MouseEvent e) {
- /* do nothing */
- }
- });
- }
- }
-
- FormData dataDecoration = new FormData();
- dataDecoration.left = new FormAttachment(lcdCanvas, 0);
- dataDecoration.top = new FormAttachment(0, 0);
- decoration.setLayoutData(dataDecoration);
-// }
-// } else {
-// if (decoration != null) {
-// decoration.dispose();
-// decoration = null;
-// }
-// }
-
- } else {
- Image tempImage = null;
- Image tempKeyPressedImage = null;
-
- if (null != currentImage) {
- tempImage = currentImage;
- }
- if (null != currentKeyPressedImage) {
- tempKeyPressedImage = currentKeyPressedImage;
- }
-
- currentImage = SkinUtil.createScaledImage(
- imageRegistry, shell, rotationId, scale, ImageType.IMG_TYPE_MAIN);
- currentKeyPressedImage = SkinUtil.createScaledImage(
- imageRegistry, shell, rotationId, scale, ImageType.IMG_TYPE_PRESSED);
-
- if (tempImage != null) {
- tempImage.dispose();
- }
- if (tempKeyPressedImage != null) {
- tempKeyPressedImage.dispose();
- }
-
- /* custom window shape */
- SkinUtil.trimShell(shell, currentImage);
- }
-
- /* set window size */
- if (null != currentImage) {
- ImageData imageData = currentImage.getImageData();
- shell.setMinimumSize(imageData.width, imageData.height);
- shell.setSize(imageData.width, imageData.height);
- }
-
- shell.redraw();
- shell.pack();
- }
-
protected void skinFinalize() {
//TODO:
}
config.saveSkinProperties();
}
- if ( null != currentImage ) {
- currentImage.dispose();
+ if (currentState.getCurrentImage() != null) {
+ currentState.getCurrentImage().dispose();
}
- if ( null != currentKeyPressedImage ) {
- currentKeyPressedImage.dispose();
+ if (currentState.getCurrentKeyPressedImage() != null) {
+ currentState.getCurrentKeyPressedImage().dispose();
}
if ( !isDefaultHoverColor ) {
@Override
public void paintControl( final PaintEvent e ) {
-
// general shell does not support native transparency, so draw image with GC.
- if ( null != currentImage ) {
- e.gc.drawImage( currentImage, 0, 0 );
+ if (currentState.getCurrentImage() != null) {
+ e.gc.drawImage(currentState.getCurrentImage(), 0, 0);
}
}
SkinRegion region = SkinUtil.getHardKeyArea(e.x, e.y,
currentState.getCurrentRotationId(), currentState.getCurrentScale());
if (keyCode != 101) { // TODO: not necessary for home key
- SkinUtil.trimShell(shell, currentImage,
+ SkinUtil.trimShell(shell, currentState.getCurrentImage(),
region.x, region.y, region.width, region.height);
}
}
currentPressedRegion.width != 0 && currentPressedRegion.height != 0) {
shell.getDisplay().syncExec(new Runnable() {
public void run() {
- if ( null != currentKeyPressedImage ) {
+ if (currentState.getCurrentKeyPressedImage() != null) {
GC gc = new GC( shell );
if (gc != null) {
/* button */
- gc.drawImage(currentKeyPressedImage,
+ gc.drawImage(currentState.getCurrentKeyPressedImage(),
currentPressedRegion.x + 1, currentPressedRegion.y + 1,
currentPressedRegion.width - 1, currentPressedRegion.height - 1, //src
currentPressedRegion.x + 1, currentPressedRegion.y + 1,
gc.dispose();
if (keyCode != 101) { // TODO: not necessary for home key
- SkinUtil.trimShell(shell, currentKeyPressedImage,
+ SkinUtil.trimShell(shell, currentState.getCurrentKeyPressedImage(),
currentPressedRegion.x, currentPressedRegion.y,
currentPressedRegion.width, currentPressedRegion.height);
}
if ( !communicator.isSensorDaemonStarted() ) {
- // reset selection.
+ /* roll back a selection */
item.setSelection( false );
for ( MenuItem m : rotationList ) {
}
}
- SkinUtil.openMessage( shell, null, "Rotation is not ready.\nPlease, wait.", SWT.ICON_WARNING,
- config );
-
+ SkinUtil.openMessage(shell, null,
+ "Rotation is not ready.\nPlease wait until the emulator is completely boot up.",
+ SWT.ICON_WARNING, config);
return;
-
}
- short rotationId = ( (Short) item.getData() );
+ short rotationId = ((Short) item.getData());
+
+ skinComposer.arrangeSkin(currentState.getCurrentScale(), rotationId);
- arrangeSkin(currentState.getCurrentScale(), rotationId);
LcdStateData lcdStateData =
new LcdStateData(currentState.getCurrentScale(), rotationId);
communicator.sendToQEMU(SendCommand.CHANGE_LCD_STATE, lcdStateData);
return;
}
- int scale = ( (Scale) item.getData() ).value();
+ int scale = ((Scale) item.getData()).value();
+
+ skinComposer.arrangeSkin(scale, currentState.getCurrentRotationId());
- arrangeSkin(scale, currentState.getCurrentRotationId());
LcdStateData lcdStateData =
new LcdStateData(scale, currentState.getCurrentRotationId());
communicator.sendToQEMU(SendCommand.CHANGE_LCD_STATE, lcdStateData);
SkinPropertiesConstants.WINDOW_ONTOP, Boolean.FALSE.toString());
boolean isOnTop = Boolean.parseBoolean(onTopVal);
- /* create skin */
+ /* create a skin */
EmulatorSkin skin;
if (SwtUtil.isMacPlatform()) {
skin = new EmulatorShmSkin(config, skinInfo, isOnTop);
skin = new EmulatorSdlSkin(config, skinInfo, isOnTop);
}
- long windowHandleId = skin.compose();
+ /* create a qemu communicator */
+ int uid = config.getArgInt(ArgsConstants.UID);
+ communicator = new SocketCommunicator(config, uid, skin);
+ skin.setCommunicator(communicator);
- int uid = config.getArgInt( ArgsConstants.UID );
- communicator = new SocketCommunicator( config, uid, windowHandleId, skin );
-
- skin.setCommunicator( communicator );
+ /* initialize a skin layout */
+ long windowHandleId = skin.initLayout();
+ communicator.setInitialData(windowHandleId);
Socket commSocket = communicator.getSocket();
- if ( null != commSocket ) {
+ if (null != commSocket) {
Runtime.getRuntime().addShutdownHook( new EmulatorShutdownhook( communicator ) );
package org.tizen.emulator.skin;
+import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.tizen.emulator.skin.comm.ICommunicator.RotationInfo;
private int currentScale;
private short currentRotationId;
private int currentAngle;
-
+
+ private Image currentImage;
+ private Image currentKeyPressedImage;
+
public EmulatorSkinState() {
this.currentResolution = new Point(480, 800);
this.currentScale = 50;
public synchronized Point getCurrentResolution() {
return currentResolution;
}
+
public synchronized int getCurrentResolutionWidth() {
return currentResolution.x;
}
+
public synchronized int getCurrentResolutionHeight() {
return currentResolution.y;
}
+
public synchronized void setCurrentResolution(Point resolution) {
setCurrentResolutionWidth(resolution.x);
setCurrentResolutionHeight(resolution.y);
}
+
public synchronized void setCurrentResolutionWidth(int width) {
if (width < 0) {
width = 0;
}
this.currentResolution.x = width;
}
+
public synchronized void setCurrentResolutionHeight(int height) {
if (height < 0) {
height = 0;
public synchronized int getCurrentScale() {
return currentScale;
}
+
public synchronized void setCurrentScale(int scale) {
this.currentScale = scale;
}
public synchronized short getCurrentRotationId() {
return currentRotationId;
}
+
public synchronized void setCurrentRotationId(short rotationId) {
this.currentRotationId = rotationId;
}
public synchronized int getCurrentAngle() {
return currentAngle;
}
+
public synchronized void setCurrentAngle(int angle) {
this.currentAngle = angle;
- };
+ }
+
+ /* skin image */
+ public Image getCurrentImage() {
+ return currentImage;
+ }
+
+ public void setCurrentImage(Image image) {
+ this.currentImage = image;
+ }
+
+ public Image getCurrentKeyPressedImage() {
+ return currentKeyPressedImage;
+ }
+
+ public void setCurrentKeyPressedImag(Image keyPressedImage) {
+ this.currentKeyPressedImage = keyPressedImage;
+ }
}
private EmulatorConfig config;
private int uId;
- private long windowHandleId;
+ private long initialData;
private EmulatorSkin skin;
private Socket socket;
private Thread sendThread;
private LinkedList<SkinSendData> sendQueue;
- public SocketCommunicator( EmulatorConfig config, int uId, long windowHandleId, EmulatorSkin skin ) {
+ public SocketCommunicator(EmulatorConfig config, int uId, EmulatorSkin skin) {
this.config = config;
this.uId = uId;
- this.windowHandleId = windowHandleId;
this.skin = skin;
this.screenShotDataTransfer = new DataTranfer();
}
+ public void setInitialData(long data) {
+ this.initialData = data;
+ }
+
@Override
public void run() {
// EmulatorConfig.DEFAULT_WINDOW_ROTATION );
// has to be portrait mode at first booting time
short rotation = EmulatorConfig.DEFAULT_WINDOW_ROTATION;
- StartData startData = new StartData( windowHandleId, width, height, scale, rotation );
+ StartData startData = new StartData(initialData, width, height, scale, rotation);
logger.info("StartData" + startData);
sendToQEMU( SendCommand.SEND_START, startData );
--- /dev/null
+/**
+ *
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * GiWoong Kim <giwoong.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.emulator.skin.layout;
+
+import java.util.List;
+import java.util.logging.Logger;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Canvas;
+import org.eclipse.swt.widgets.Decorations;
+import org.eclipse.swt.widgets.Shell;
+import org.tizen.emulator.skin.EmulatorSkinState;
+import org.tizen.emulator.skin.comm.ICommunicator.KeyEventType;
+import org.tizen.emulator.skin.comm.ICommunicator.SendCommand;
+import org.tizen.emulator.skin.comm.sock.SocketCommunicator;
+import org.tizen.emulator.skin.comm.sock.data.KeyEventData;
+import org.tizen.emulator.skin.config.EmulatorConfig;
+import org.tizen.emulator.skin.config.EmulatorConfig.ArgsConstants;
+import org.tizen.emulator.skin.config.EmulatorConfig.SkinPropertiesConstants;
+import org.tizen.emulator.skin.dbi.KeyMapType;
+import org.tizen.emulator.skin.dbi.RotationType;
+import org.tizen.emulator.skin.image.ImageRegistry;
+import org.tizen.emulator.skin.image.ImageRegistry.IconName;
+import org.tizen.emulator.skin.log.SkinLogger;
+import org.tizen.emulator.skin.util.SkinRotation;
+import org.tizen.emulator.skin.util.SkinUtil;
+import org.tizen.emulator.skin.util.SwtUtil;
+
+public class GeneralPurposeSkinComposer implements ISkinComposer {
+ private Logger logger = SkinLogger.getSkinLogger(
+ GeneralPurposeSkinComposer.class).getLogger();
+
+ private EmulatorConfig config;
+ private Shell shell;
+ private Canvas lcdCanvas;
+ private EmulatorSkinState currentState;
+
+ private ImageRegistry imageRegistry;
+ private SocketCommunicator communicator;
+
+ public GeneralPurposeSkinComposer(EmulatorConfig config, Shell shell,
+ EmulatorSkinState currentState, ImageRegistry imageRegistry, SocketCommunicator communicator) {
+ this.config = config;
+ this.shell = shell;
+ this.currentState = currentState;
+ this.imageRegistry = imageRegistry;
+ this.communicator = communicator;
+ }
+
+ @Override
+ public Canvas compose() {
+ shell.setLayout(new FormLayout());
+
+ lcdCanvas = new Canvas(shell, SWT.EMBEDDED); //TODO:
+
+ int x = config.getSkinPropertyInt(SkinPropertiesConstants.WINDOW_X,
+ EmulatorConfig.DEFAULT_WINDOW_X);
+ int y = config.getSkinPropertyInt(SkinPropertiesConstants.WINDOW_Y,
+ EmulatorConfig.DEFAULT_WINDOW_Y);
+
+ currentState.setCurrentResolutionWidth(
+ config.getArgInt(ArgsConstants.RESOLUTION_WIDTH));
+ currentState.setCurrentResolutionHeight(
+ config.getArgInt(ArgsConstants.RESOLUTION_HEIGHT));
+
+ int scale = SkinUtil.getValidScale(config);
+ short rotationId = EmulatorConfig.DEFAULT_WINDOW_ROTATION;
+
+ composeInternal(lcdCanvas, x, y, scale, rotationId, false);
+ logger.info("resolution : " + currentState.getCurrentResolution() +
+ ", scale : " + scale);
+
+ return lcdCanvas;
+ }
+
+ @Override
+ public void composeInternal(Canvas lcdCanvas,
+ int x, int y, int scale, short rotationId, boolean isOnKbd) {
+
+ //shell.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_BLACK));
+ shell.setLocation(x, y);
+
+ String emulatorName = SkinUtil.makeEmulatorName(config);
+ shell.setText(emulatorName);
+
+ lcdCanvas.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_BLACK));
+
+ if (SwtUtil.isWindowsPlatform()) {
+ shell.setImage(imageRegistry.getIcon(IconName.EMULATOR_TITLE_ICO));
+ } else {
+ shell.setImage(imageRegistry.getIcon(IconName.EMULATOR_TITLE));
+ }
+
+ arrangeSkin(scale, rotationId);
+ }
+
+ @Override
+ public void arrangeSkin(int scale, short rotationId) {
+ currentState.setCurrentScale(scale);
+ currentState.setCurrentRotationId(rotationId);
+ currentState.setCurrentAngle(SkinRotation.getAngle(rotationId));
+
+ /* arrange the lcd */
+ Rectangle lcdBounds = SkinUtil.adjustLcdGeometry(lcdCanvas,
+ currentState.getCurrentResolutionWidth(),
+ currentState.getCurrentResolutionHeight(), scale, rotationId,
+ false);
+
+ if (lcdBounds == null) {
+ logger.severe("Failed to lcd information for phone shape skin.");
+ SkinUtil.openMessage(shell, null,
+ "Failed to read lcd information for phone shape skin.\n" +
+ "Check the contents of skin dbi file.",
+ SWT.ICON_ERROR, config);
+ System.exit(-1);
+ }
+ logger.info("lcd bounds : " + lcdBounds);
+
+ FormData dataCanvas = new FormData();
+ dataCanvas.left = new FormAttachment(0, lcdBounds.x);
+ dataCanvas.top = new FormAttachment(0, lcdBounds.y);
+ dataCanvas.width = lcdBounds.width;
+ dataCanvas.height = lcdBounds.height;
+ lcdCanvas.setLayoutData(dataCanvas);
+
+ Decorations decoration = new Decorations(shell, SWT.BORDER);
+ decoration.setLayout(new GridLayout(1, true));
+
+ RotationType rotation =
+ SkinRotation.getRotation(currentState.getCurrentRotationId());
+ List<KeyMapType> keyMapList = rotation.getKeyMapList().getKeyMap();
+
+ // TODO: function
+ if (keyMapList != null && keyMapList.isEmpty() == false) {
+ for (KeyMapType keyEntry : keyMapList) {
+ Button hardKeyButton = new Button(decoration, SWT.FLAT);
+ hardKeyButton.setText(keyEntry.getEventInfo().getKeyName());
+ hardKeyButton.setToolTipText(keyEntry.getTooltip());
+
+ hardKeyButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+
+ final int keycode = keyEntry.getEventInfo().getKeyCode();
+ hardKeyButton.addMouseListener(new MouseListener() {
+ @Override
+ public void mouseDown(MouseEvent e) {
+ KeyEventData keyEventData = new KeyEventData(
+ KeyEventType.PRESSED.value(), keycode, 0, 0);
+ communicator.sendToQEMU(SendCommand.SEND_HARD_KEY_EVENT, keyEventData);
+ }
+
+ @Override
+ public void mouseUp(MouseEvent e) {
+ KeyEventData keyEventData = new KeyEventData(
+ KeyEventType.RELEASED.value(), keycode, 0, 0);
+ communicator.sendToQEMU(SendCommand.SEND_HARD_KEY_EVENT, keyEventData);
+ }
+
+ @Override
+ public void mouseDoubleClick(MouseEvent e) {
+ /* do nothing */
+ }
+ });
+ }
+ }
+
+ FormData dataDecoration = new FormData();
+ dataDecoration.left = new FormAttachment(lcdCanvas, 0);
+ dataDecoration.top = new FormAttachment(0, 0);
+ decoration.setLayoutData(dataDecoration);
+
+ shell.redraw();
+ shell.pack();
+ }
+
+}
--- /dev/null
+/**
+ *
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * GiWoong Kim <giwoong.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.emulator.skin.layout;
+
+import org.eclipse.swt.widgets.Canvas;
+
+public interface ISkinComposer {
+ public abstract Canvas compose();
+ public abstract void composeInternal(Canvas lcdCanvas,
+ int x, int y, int scale, short rotationId, boolean isOnKbd);
+ public abstract void arrangeSkin(int scale, short rotationId);
+}
--- /dev/null
+/**
+ *
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * GiWoong Kim <giwoong.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.emulator.skin.layout;
+
+import java.util.logging.Logger;
+
+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.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Canvas;
+import org.eclipse.swt.widgets.Shell;
+import org.tizen.emulator.skin.EmulatorSkin;
+import org.tizen.emulator.skin.EmulatorSkinState;
+import org.tizen.emulator.skin.config.EmulatorConfig;
+import org.tizen.emulator.skin.config.EmulatorConfig.ArgsConstants;
+import org.tizen.emulator.skin.config.EmulatorConfig.SkinPropertiesConstants;
+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.util.SkinRotation;
+import org.tizen.emulator.skin.util.SkinUtil;
+import org.tizen.emulator.skin.util.SwtUtil;
+
+public class PhoneShapeSkinComposer implements ISkinComposer {
+ private Logger logger = SkinLogger.getSkinLogger(
+ PhoneShapeSkinComposer.class).getLogger();
+
+ private EmulatorConfig config;
+ private Shell shell;
+ private Canvas lcdCanvas;
+ private EmulatorSkinState currentState;
+
+ private ImageRegistry imageRegistry;
+
+ public PhoneShapeSkinComposer(EmulatorConfig config, Shell shell,
+ EmulatorSkinState currentState, ImageRegistry imageRegistry) {
+ this.config = config;
+ this.shell = shell;
+ this.currentState = currentState;
+ this.imageRegistry = imageRegistry;
+ }
+
+ @Override
+ public Canvas compose() {
+ lcdCanvas = new Canvas(shell, SWT.EMBEDDED); //TODO:
+
+ int x = config.getSkinPropertyInt(SkinPropertiesConstants.WINDOW_X,
+ EmulatorConfig.DEFAULT_WINDOW_X);
+ int y = config.getSkinPropertyInt(SkinPropertiesConstants.WINDOW_Y,
+ EmulatorConfig.DEFAULT_WINDOW_Y);
+
+ currentState.setCurrentResolutionWidth(
+ config.getArgInt(ArgsConstants.RESOLUTION_WIDTH));
+ currentState.setCurrentResolutionHeight(
+ config.getArgInt(ArgsConstants.RESOLUTION_HEIGHT));
+
+ int scale = SkinUtil.getValidScale(config);
+// int rotationId = config.getPropertyShort( PropertiesConstants.WINDOW_ROTATION,
+// EmulatorConfig.DEFAULT_WINDOW_ROTATION );
+ // has to be portrait mode at first booting time
+ short rotationId = EmulatorConfig.DEFAULT_WINDOW_ROTATION;
+
+ composeInternal(lcdCanvas, x, y, scale, rotationId, false);
+ logger.info("resolution : " + currentState.getCurrentResolution() +
+ ", scale : " + scale);
+
+ return lcdCanvas;
+ }
+
+ @Override
+ public void composeInternal(Canvas lcdCanvas,
+ int x, int y, int scale, short rotationId, boolean isOnKbd) {
+
+ //shell.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_BLACK));
+ shell.setLocation(x, y);
+
+ String emulatorName = SkinUtil.makeEmulatorName(config);
+ shell.setText(emulatorName);
+
+ lcdCanvas.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_BLACK));
+
+ if (SwtUtil.isWindowsPlatform()) {
+ shell.setImage(imageRegistry.getIcon(IconName.EMULATOR_TITLE_ICO));
+ } else {
+ shell.setImage(imageRegistry.getIcon(IconName.EMULATOR_TITLE));
+ }
+
+ arrangeSkin(scale, rotationId);
+
+ if (/*skinInfo.isPhoneShape() &&*/ currentState.getCurrentImage() == null) {
+ logger.severe("Failed to load initial skin image file. Kill this skin process.");
+ SkinUtil.openMessage(shell, null,
+ "Failed to load Skin image file.", SWT.ICON_ERROR, config);
+ System.exit(-1);
+ }
+ }
+
+ @Override
+ public void arrangeSkin(int scale, short rotationId) {
+ currentState.setCurrentScale(scale);
+ currentState.setCurrentRotationId(rotationId);
+ currentState.setCurrentAngle(SkinRotation.getAngle(rotationId));
+
+ /* arrange the lcd */
+ Rectangle lcdBounds = SkinUtil.adjustLcdGeometry(lcdCanvas,
+ currentState.getCurrentResolutionWidth(),
+ currentState.getCurrentResolutionHeight(), scale, rotationId,
+ true);
+
+ if (lcdBounds == null) {
+ logger.severe("Failed to lcd information for phone shape skin.");
+ SkinUtil.openMessage(shell, null,
+ "Failed to read lcd information for phone shape skin.\n" +
+ "Check the contents of skin dbi file.",
+ SWT.ICON_ERROR, config);
+ System.exit(-1);
+ }
+ logger.info("lcd bounds : " + lcdBounds);
+
+ /* arrange the skin image */
+ Image tempImage = null;
+ Image tempKeyPressedImage = null;
+
+ if (currentState.getCurrentImage() != null) {
+ tempImage = currentState.getCurrentImage();
+ }
+ if (currentState.getCurrentKeyPressedImage() != null) {
+ tempKeyPressedImage = currentState.getCurrentKeyPressedImage();
+ }
+
+ currentState.setCurrentImage(SkinUtil.createScaledImage(
+ imageRegistry, shell, rotationId, scale, ImageType.IMG_TYPE_MAIN));
+ currentState.setCurrentKeyPressedImag(SkinUtil.createScaledImage(
+ imageRegistry, shell, rotationId, scale, ImageType.IMG_TYPE_PRESSED));
+
+ if (tempImage != null) {
+ tempImage.dispose();
+ }
+ if (tempKeyPressedImage != null) {
+ tempKeyPressedImage.dispose();
+ }
+
+ /* custom window shape */
+ SkinUtil.trimShell(shell, currentState.getCurrentImage());
+
+ /* set window size */
+ if (currentState.getCurrentImage() != null) {
+ ImageData imageData = currentState.getCurrentImage().getImageData();
+ shell.setMinimumSize(imageData.width, imageData.height);
+ shell.setSize(imageData.width, imageData.height);
+ }
+
+ shell.redraw();
+ shell.pack();
+
+ lcdCanvas.setBounds(lcdBounds);
+ }
+}