2 * Emulator Skin Process
4 * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
7 * GiWoong Kim <giwoong.kim@samsung.com>
8 * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29 package org.tizen.emulator.skin;
31 import java.lang.reflect.Field;
32 import java.util.logging.Level;
33 import java.util.logging.Logger;
35 import org.eclipse.swt.SWT;
36 import org.tizen.emulator.skin.config.EmulatorConfig;
37 import org.tizen.emulator.skin.exception.ScreenShotException;
38 import org.tizen.emulator.skin.image.ImageRegistry.IconName;
39 import org.tizen.emulator.skin.info.SkinInformation;
40 import org.tizen.emulator.skin.log.SkinLogger;
41 import org.tizen.emulator.skin.screenshot.SdlScreenShotWindow;
42 import org.tizen.emulator.skin.util.SkinUtil;
43 import org.tizen.emulator.skin.util.SwtUtil;
45 public class EmulatorSdlSkin extends EmulatorSkin {
46 private Logger logger = SkinLogger.getSkinLogger(
47 EmulatorSdlSkin.class).getLogger();
52 public EmulatorSdlSkin(EmulatorSkinState state, EmulatorFingers finger,
53 EmulatorConfig config, SkinInformation skinInfo, boolean isOnTop) {
54 super(state, finger, config, skinInfo, SWT.EMBEDDED, isOnTop);
57 public long initLayout() {
60 /* sdl uses this handle ID */
61 return getWindowHandleId();
64 private long getWindowHandleId() {
65 long windowHandleId = 0;
67 /* org.eclipse.swt.widgets.Widget */
68 if (SwtUtil.isLinuxPlatform()) {
71 Field field = lcdCanvas.getClass().getField("embeddedHandle");
72 windowHandleId = field.getLong(lcdCanvas);
73 logger.info("lcdCanvas.embeddedHandle:" + windowHandleId);
74 } catch (IllegalArgumentException e) {
75 logger.log(Level.SEVERE, e.getMessage(), e);
77 } catch (IllegalAccessException e ) {
78 logger.log(Level.SEVERE, e.getMessage(), e);
80 } catch (SecurityException e ) {
81 logger.log(Level.SEVERE, e.getMessage(), e);
83 } catch (NoSuchFieldException e) {
84 logger.log(Level.SEVERE, e.getMessage(), e);
88 } else if (SwtUtil.isWindowsPlatform()) {
91 Field field = lcdCanvas.getClass().getField("handle");
92 windowHandleId = field.getLong(lcdCanvas);
93 logger.info("lcdCanvas.handle:" + windowHandleId);
94 } catch (IllegalArgumentException e) {
95 logger.log(Level.SEVERE, e.getMessage(), e);
97 } catch (IllegalAccessException e) {
98 logger.log(Level.SEVERE, e.getMessage(), e);
100 } catch (SecurityException e) {
101 logger.log(Level.SEVERE, e.getMessage(), e);
103 } catch (NoSuchFieldException e) {
104 logger.log(Level.SEVERE, e.getMessage(), e);
108 } else if (SwtUtil.isMacPlatform()) {
114 logger.severe("Not Supported OS platform:" + SWT.getPlatform());
118 return windowHandleId;
122 protected void openScreenShotWindow() {
123 if (screenShotDialog != null) {
124 logger.info("screenshot window was already opened");
129 screenShotDialog = new SdlScreenShotWindow(shell, communicator, this, config,
130 imageRegistry.getIcon(IconName.SCREENSHOT));
131 screenShotDialog.open();
133 } catch (ScreenShotException ex) {
134 screenShotDialog = null;
135 logger.log(Level.SEVERE, ex.getMessage(), ex);
137 SkinUtil.openMessage(shell, null,
138 "Fail to create a screen shot.", SWT.ICON_ERROR, config);
139 } catch (Exception ex) {
140 screenShotDialog = null;
141 logger.log(Level.SEVERE, ex.getMessage(), ex);
143 SkinUtil.openMessage(shell, null, "ScreenShot is not ready.\n" +
144 "Please wait until the emulator is completely boot up.",
145 SWT.ICON_WARNING, config);