149137ca02da385726dc3f4f56cb539f7ebb4184
[sdk/emulator/qemu.git] / tizen / src / skin / client / src / org / tizen / emulator / skin / EmulatorSdlSkin.java
1 /**
2  * Emulator Skin Process
3  *
4  * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact:
7  * GiWoong Kim <giwoong.kim@samsung.com>
8  * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
9  *
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.
14  *
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.
19  *
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.
23  *
24  * Contributors:
25  * - S-Core Co., Ltd
26  *
27  */
28
29 package org.tizen.emulator.skin;
30
31 import java.lang.reflect.Field;
32 import java.util.logging.Level;
33 import java.util.logging.Logger;
34
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;
44
45 public class EmulatorSdlSkin extends EmulatorSkin {
46         private Logger logger = SkinLogger.getSkinLogger(
47                         EmulatorSdlSkin.class).getLogger();
48
49         /**
50          *  Constructor
51          */
52         public EmulatorSdlSkin(EmulatorSkinState state, EmulatorFingers finger,
53                         EmulatorConfig config, SkinInformation skinInfo, boolean isOnTop) {
54                 super(state, finger, config, skinInfo, SWT.EMBEDDED, isOnTop);
55         }
56
57         public long initLayout() {
58                 super.initLayout();
59
60                 /* sdl uses this handle ID */
61                 return getWindowHandleId();
62         }
63
64         private long getWindowHandleId() {
65                 long windowHandleId = 0;
66
67                 /* org.eclipse.swt.widgets.Widget */
68                 if (SwtUtil.isLinuxPlatform()) {
69
70                         try {
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);
76                                 shutdown();
77                         } catch (IllegalAccessException e ) {
78                                 logger.log(Level.SEVERE, e.getMessage(), e);
79                                 shutdown();
80                         } catch (SecurityException e ) {
81                                 logger.log(Level.SEVERE, e.getMessage(), e);
82                                 shutdown();
83                         } catch (NoSuchFieldException e) {
84                                 logger.log(Level.SEVERE, e.getMessage(), e);
85                                 shutdown();
86                         }
87
88                 } else if (SwtUtil.isWindowsPlatform()) {
89
90                         try {
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);
96                                 shutdown();
97                         } catch (IllegalAccessException e) {
98                                 logger.log(Level.SEVERE, e.getMessage(), e);
99                                 shutdown();
100                         } catch (SecurityException e) {
101                                 logger.log(Level.SEVERE, e.getMessage(), e);
102                                 shutdown();
103                         } catch (NoSuchFieldException e) {
104                                 logger.log(Level.SEVERE, e.getMessage(), e);
105                                 shutdown();
106                         }
107
108                 } else if (SwtUtil.isMacPlatform()) {
109
110                         // not supported
111                         windowHandleId = 0;
112
113                 } else {
114                         logger.severe("Not Supported OS platform:" + SWT.getPlatform());
115                         System.exit(-1);
116                 }
117
118                 return windowHandleId;
119         }
120
121         @Override
122         public void displayOn() {
123                 logger.info("display on");
124                 /* do nothing */
125         }
126
127         @Override
128         public void displayOff() {
129                 logger.info("display off");
130                 /* do nothing */
131         }
132
133         @Override
134         protected void openScreenShotWindow() {
135                 if (screenShotDialog != null) {
136                         logger.info("screenshot window was already opened");
137                         return;
138                 }
139
140                 try {
141                         screenShotDialog = new SdlScreenShotWindow(shell, communicator, this, config,
142                                         imageRegistry.getIcon(IconName.SCREENSHOT));
143                         screenShotDialog.open();
144
145                 } catch (ScreenShotException ex) {
146                         screenShotDialog = null;
147                         logger.log(Level.SEVERE, ex.getMessage(), ex);
148
149                         SkinUtil.openMessage(shell, null,
150                                         "Fail to create a screen shot.", SWT.ICON_ERROR, config);
151                 } catch (Exception ex) {
152                         screenShotDialog = null;
153                         logger.log(Level.SEVERE, ex.getMessage(), ex);
154
155                         SkinUtil.openMessage(shell, null, "ScreenShot is not ready.\n" +
156                                         "Please wait until the emulator is completely boot up.",
157                                         SWT.ICON_WARNING, config);
158                 }
159         }
160
161 }