update source for tizen_2.1
[sdk/emulator/qemu.git] / tizen / src / skin / client / src / org / tizen / emulator / skin / dialog / AboutDialog.java
1 /**
2  * 
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  * HyunJun Son
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
24  *
25  * Contributors:
26  * - S-Core Co., Ltd
27  *
28  */
29
30 package org.tizen.emulator.skin.dialog;
31
32 import java.io.IOException;
33 import java.io.InputStream;
34 import java.util.Properties;
35 import java.util.logging.Level;
36 import java.util.logging.Logger;
37
38 import org.eclipse.swt.SWT;
39 import org.eclipse.swt.events.SelectionAdapter;
40 import org.eclipse.swt.events.SelectionEvent;
41 import org.eclipse.swt.events.SelectionListener;
42 import org.eclipse.swt.graphics.Color;
43 import org.eclipse.swt.graphics.Image;
44 import org.eclipse.swt.layout.FillLayout;
45 import org.eclipse.swt.layout.GridData;
46 import org.eclipse.swt.layout.GridLayout;
47 import org.eclipse.swt.program.Program;
48 import org.eclipse.swt.widgets.Button;
49 import org.eclipse.swt.widgets.Composite;
50 import org.eclipse.swt.widgets.Display;
51 import org.eclipse.swt.widgets.Label;
52 import org.eclipse.swt.widgets.Link;
53 import org.eclipse.swt.widgets.Shell;
54 import org.eclipse.swt.widgets.Text;
55 import org.tizen.emulator.skin.config.EmulatorConfig;
56 import org.tizen.emulator.skin.log.SkinLogger;
57 import org.tizen.emulator.skin.util.IOUtil;
58 import org.tizen.emulator.skin.util.StringUtil;
59 import org.tizen.emulator.skin.util.SwtUtil;
60
61 public class AboutDialog extends SkinDialog {
62
63         public static final String ABOUT_PROP_FILENAME = "about.properties";
64
65         public static final String PROP_KEY_VERSION = "version";
66         public static final String PROP_KEY_BUILD_TIME = "build_time";
67         public static final String PROP_KEY_GIT_VERSION = "build_git_commit";
68
69         public static final String URL_TIZEN_ORG = "https://developer.tizen.org";
70
71         private Logger logger =
72                         SkinLogger.getSkinLogger(AboutDialog.class).getLogger();
73
74         private Image aboutImage;
75         private EmulatorConfig config;
76
77
78         public AboutDialog(Shell parent, EmulatorConfig config) {
79                 super(parent, "About Tizen Emulator", SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
80
81                 this.config = config;
82         }
83
84         private GridLayout getNopaddedGridLayout(int numColumns, boolean makeColumnEqualWidth) {
85                 GridLayout layout = new GridLayout(numColumns, makeColumnEqualWidth);
86                 layout.marginLeft = layout.marginRight = 0;
87                 layout.marginTop = layout.marginBottom = 0;
88                 layout.marginWidth = layout.marginHeight = 0;
89                 layout.horizontalSpacing = layout.verticalSpacing = 0;
90
91                 return layout;
92         }
93
94         @Override
95         protected void createComposite() {
96                 Composite parent = new Composite(shell, SWT.NONE);
97                 parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
98                 GridLayout gridLayout = getNopaddedGridLayout(1, true);
99                 parent.setLayout(gridLayout);
100
101                 Composite area = createArea(parent);
102                 if (null == area) {
103                         return;
104                 }
105
106                 /* bottom side */
107                 buttonComposite = new Composite(parent, SWT.NONE);
108                 buttonComposite.setLayoutData(new GridData(SWT.RIGHT, SWT.BOTTOM, true, true));
109                 buttonComposite.setLayout(new GridLayout(1, false));
110
111                 createButtons(buttonComposite);
112         }
113
114         @Override
115         protected Composite createArea(Composite parent) {
116                 Composite composite = displayInfo(parent);
117                 return composite;
118         }
119
120         private Composite displayInfo(Composite parent) {
121                 Composite compositeBase = new Composite(parent, SWT.BORDER);
122                 compositeBase.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
123                 compositeBase.setLayout(getNopaddedGridLayout(2, false));
124                 Color white = Display.getCurrent().getSystemColor(SWT.COLOR_WHITE);
125                 compositeBase.setBackground(white);
126
127                 /* left side */
128                 Composite compositeLeft = new Composite(compositeBase, SWT.BORDER);
129                 compositeLeft.setLayout(getNopaddedGridLayout(1, false));
130
131                 Label imageLabel = new Label(compositeLeft, SWT.NONE);
132                 aboutImage = new Image(shell.getDisplay(),
133                                 this.getClass().getClassLoader().getResourceAsStream("images/about_Tizen_SDK.png"));
134                 imageLabel.setImage(aboutImage);
135
136                 /* right side */
137                 Composite compositeRight = new Composite(compositeBase, SWT.NONE);
138                 compositeRight.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
139                 GridLayout layout = getNopaddedGridLayout(1, true);
140                 layout.marginLeft = layout.marginRight = 6;
141                 compositeRight.setLayout(layout);
142                 compositeRight.setBackground(white);
143
144                 /* SDK name */
145                 Label titleLabel = new Label(compositeRight, SWT.NONE);
146                 /*GridData gridData = new GridData();
147                 gridData.grabExcessHorizontalSpace = true;
148                 gridData.horizontalAlignment = SWT.CENTER;
149                 titleLabel.setLayoutData(gridData);*/
150                 titleLabel.setText("\nTizen SDK\n");
151                 /*Font systemFont = shell.getDisplay().getSystemFont();
152                 FontData[] fontData = systemFont.getFontData();
153                 fontData[0].setStyle(SWT.BOLD);
154                 fontData[0].setHeight(16);
155                 Font font = new Font(shell.getDisplay(), fontData[0]);
156                 titleLabel.setFont(font);
157                 font.dispose();*/
158                 titleLabel.setBackground(white);
159
160                 if (SwtUtil.isWindowsPlatform()) {
161                         Label space = new Label(compositeRight, SWT.NONE);
162                         space.setText("\n");
163                 }
164
165                 Properties properties = getProperties();
166
167                 /* SDK version */
168                 Text versionText = new Text(compositeRight, SWT.NONE);
169                 /*String version = getValue(properties, PROP_KEY_VERSION);
170                 if (version.isEmpty()) {
171                         version = "Not identified";
172                 }*/
173                 String version = config.getSkinProperty(
174                                 EmulatorConfig.SkinInfoConstants.SDK_VERSION_NAME);
175
176                 versionText.setText("Version : " + version);
177                 versionText.setEditable(false);
178                 versionText.setBackground(white);
179
180                 /* build id */
181                 Text buildText = new Text(compositeRight, SWT.NONE);
182                 String time = getValue(properties, PROP_KEY_BUILD_TIME);
183                 if (time.isEmpty()) {
184                         time = "Not identified";
185                 }
186                 buildText.setText("Build id : " + time);
187                 buildText.setEditable(false);
188                 buildText.setBackground(white);
189
190                 /*Text gitText = new Text(compositeRight, SWT.NONE);
191                 String gitVersion = getValue(properties, PROP_KEY_GIT_VERSION);
192                 gitText.setText("Git version" + " : " + gitVersion);
193                 gitText.setEditable(false);
194                 gitText.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));*/
195
196                 /* link to URL */
197                 Link visit = new Link(compositeRight, SWT.NONE);
198                 visit.setText("\n\n Visit <a>" + URL_TIZEN_ORG + "</a>");
199                 visit.setBackground(white);
200                 visit.addSelectionListener(new SelectionListener() {
201                         @Override
202                         public void widgetDefaultSelected(SelectionEvent arg0) {
203                                 //do nothing
204                         }
205
206                         @Override
207                         public void widgetSelected(SelectionEvent arg0) {
208                                 try {
209                                         Program.launch(URL_TIZEN_ORG);
210                                 } catch (Throwable e) {
211                                         e.printStackTrace();
212                                         return;
213                                 }
214                         }
215
216                 });
217
218                 return compositeBase;
219         }
220
221         private String getValue(Properties properties, String key) {
222                 if (null != properties) {
223
224                         String property = properties.getProperty(key);
225
226                         if (!StringUtil.isEmpty(property)) {
227
228                                 if (!property.contains(key)) {
229                                         return property;
230                                 } else {
231                                         // ex) '${build_git_commit}' is default
232                                         // expression in build.xml
233                                         return "Not identified";
234                                 }
235
236                         } else {
237                                 return "Not identified";
238                         }
239
240                 } else {
241                         return "Not identified";
242                 }
243         }
244
245         @Override
246         protected void createButtons(Composite parent) {
247                 super.createButtons(parent);
248
249                 Composite composite = new Composite(parent, SWT.NONE);
250                 FillLayout fillLayout = new FillLayout(SWT.HORIZONTAL);
251                 composite.setLayout(fillLayout);
252
253                 Button licenseButton = createButton(composite, "License");
254
255                 licenseButton.addSelectionListener(new SelectionAdapter() {
256                         private boolean isOpen;
257
258                         @Override
259                         public void widgetSelected(SelectionEvent e) {
260                                 if (!isOpen) {
261                                         isOpen = true;
262                                         LicenseDialog licenseDialog = new LicenseDialog(shell, "License");
263                                         licenseDialog.open();
264                                         isOpen = false;
265                                 }
266                         }
267                 });
268
269                 createOKButton(composite, true);
270         }
271
272         private Properties getProperties() {
273                 InputStream is = null;
274                 Properties properties = null;
275
276                 try {
277                         is = this.getClass().getClassLoader().getResourceAsStream(ABOUT_PROP_FILENAME);
278                         if (null == is) {
279                                 logger.severe("about properties file is null.");
280                                 return null;
281                         }
282
283                         properties = new Properties();
284                         properties.load(is);
285
286                 } catch (IOException e) {
287                         logger.log(Level.SEVERE, e.getMessage(), e);
288                         return null;
289                 } finally {
290                         IOUtil.close(is);
291                 }
292
293                 return properties;
294         }
295
296         protected void setShellSize() {
297                 shell.setSize(436, shell.getSize().y);
298         }
299
300         protected void close() {
301                 logger.info("close the about dialog");
302                 aboutImage.dispose();
303         }
304 }