Tizen 2.1 base
[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.log.SkinLogger;
56 import org.tizen.emulator.skin.util.IOUtil;
57 import org.tizen.emulator.skin.util.StringUtil;
58 import org.tizen.emulator.skin.util.SwtUtil;
59
60 public class AboutDialog extends SkinDialog {
61
62         public static final String ABOUT_PROP_FILENAME = "about.properties";
63
64         public static final String PROP_KEY_VERSION = "version";
65         public static final String PROP_KEY_BUILD_TIME = "build_time";
66         public static final String PROP_KEY_GIT_VERSION = "build_git_commit";
67
68         public static final String URL_TIZEN_ORG = "https://developer.tizen.org";
69
70         private Image aboutImage;
71
72         private Logger logger = SkinLogger.getSkinLogger(AboutDialog.class).getLogger();
73
74         public AboutDialog(Shell parent) {
75                 super(parent, "About Tizen Emulator", SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
76         }
77
78         private GridLayout getNopaddedGridLayout(int numColumns, boolean makeColumnEqualWidth) {
79                 GridLayout layout = new GridLayout(numColumns, makeColumnEqualWidth);
80                 layout.marginLeft = layout.marginRight = 0;
81                 layout.marginTop = layout.marginBottom = 0;
82                 layout.marginWidth = layout.marginHeight = 0;
83                 layout.horizontalSpacing = layout.verticalSpacing = 0;
84
85                 return layout;
86         }
87
88         @Override
89         protected void createComposite() {
90                 Composite parent = new Composite(shell, SWT.NONE);
91                 parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
92                 GridLayout gridLayout = getNopaddedGridLayout(1, true);
93                 parent.setLayout(gridLayout);
94
95                 Composite area = createArea(parent);
96                 if (null == area) {
97                         return;
98                 }
99
100                 /* bottom side */
101                 buttonComposite = new Composite(parent, SWT.NONE);
102                 buttonComposite.setLayoutData(new GridData(SWT.RIGHT, SWT.BOTTOM, true, true));
103                 buttonComposite.setLayout(new GridLayout(1, false));
104
105                 createButtons(buttonComposite);
106         }
107
108         @Override
109         protected Composite createArea(Composite parent) {
110                 Composite composite = displayInfo(parent);
111                 return composite;
112         }
113
114         private Composite displayInfo(Composite parent) {
115                 Composite compositeBase = new Composite(parent, SWT.BORDER);
116                 compositeBase.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
117                 compositeBase.setLayout(getNopaddedGridLayout(2, false));
118                 Color white = Display.getCurrent().getSystemColor(SWT.COLOR_WHITE);
119                 compositeBase.setBackground(white);
120
121                 /* left side */
122                 Composite compositeLeft = new Composite(compositeBase, SWT.BORDER);
123                 compositeLeft.setLayout(getNopaddedGridLayout(1, false));
124
125                 Label imageLabel = new Label(compositeLeft, SWT.NONE);
126                 aboutImage = new Image(shell.getDisplay(),
127                                 this.getClass().getClassLoader().getResourceAsStream("images/about_Tizen_SDK.png"));
128                 imageLabel.setImage(aboutImage);
129
130                 /* right side */
131                 Composite compositeRight = new Composite(compositeBase, SWT.NONE);
132                 compositeRight.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
133                 GridLayout layout = getNopaddedGridLayout(1, true);
134                 layout.marginLeft = layout.marginRight = 6;
135                 compositeRight.setLayout(layout);
136                 compositeRight.setBackground(white);
137
138                 /* SDK name */
139                 Label titleLabel = new Label(compositeRight, SWT.NONE);
140                 /*GridData gridData = new GridData();
141                 gridData.grabExcessHorizontalSpace = true;
142                 gridData.horizontalAlignment = SWT.CENTER;
143                 titleLabel.setLayoutData(gridData);*/
144                 titleLabel.setText("\nTizen SDK\n");
145                 /*Font systemFont = shell.getDisplay().getSystemFont();
146                 FontData[] fontData = systemFont.getFontData();
147                 fontData[0].setStyle(SWT.BOLD);
148                 fontData[0].setHeight(16);
149                 Font font = new Font(shell.getDisplay(), fontData[0]);
150                 titleLabel.setFont(font);
151                 font.dispose();*/
152                 titleLabel.setBackground(white);
153
154                 if (SwtUtil.isWindowsPlatform()) {
155                         Label space = new Label(compositeRight, SWT.NONE);
156                         space.setText("\n");
157                 }
158
159                 Properties properties = getProperties();
160
161                 /* SDK version */
162                 Text versionText = new Text(compositeRight, SWT.NONE);
163                 String version = getValue(properties, PROP_KEY_VERSION);
164                 if (version.isEmpty()) {
165                         version = "Not identified";
166                 }
167                 versionText.setText("Version : " + version);
168                 versionText.setEditable(false);
169                 versionText.setBackground(white);
170
171                 /* build id */
172                 Text buildText = new Text(compositeRight, SWT.NONE);
173                 String time = getValue(properties, PROP_KEY_BUILD_TIME);
174                 if (time.isEmpty()) {
175                         time = "Not identified";
176                 }
177                 buildText.setText("Build id : " + time);
178                 buildText.setEditable(false);
179                 buildText.setBackground(white);
180
181                 /*Text gitText = new Text(compositeRight, SWT.NONE);
182                 String gitVersion = getValue(properties, PROP_KEY_GIT_VERSION);
183                 gitText.setText("Git version" + " : " + gitVersion);
184                 gitText.setEditable(false);
185                 gitText.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));*/
186
187                 /* link to URL */
188                 Link visit = new Link(compositeRight, SWT.NONE);
189                 visit.setText("\n\n Visit <a>" + URL_TIZEN_ORG + "</a>");
190                 visit.setBackground(white);
191                 visit.addSelectionListener(new SelectionListener() {
192                         @Override
193                         public void widgetDefaultSelected(SelectionEvent arg0) {
194                                 //do nothing
195                         }
196
197                         @Override
198                         public void widgetSelected(SelectionEvent arg0) {
199                                 try {
200                                         Program.launch(URL_TIZEN_ORG);
201                                 } catch (Throwable e) {
202                                         e.printStackTrace();
203                                         return;
204                                 }
205                         }
206
207                 });
208
209                 return compositeBase;
210         }
211
212         private String getValue(Properties properties, String key) {
213                 if (null != properties) {
214
215                         String property = properties.getProperty(key);
216
217                         if (!StringUtil.isEmpty(property)) {
218
219                                 if (!property.contains(key)) {
220                                         return property;
221                                 } else {
222                                         // ex) '${build_git_commit}' is default
223                                         // expression in build.xml
224                                         return "Not identified";
225                                 }
226
227                         } else {
228                                 return "Not identified";
229                         }
230
231                 } else {
232                         return "Not identified";
233                 }
234         }
235
236         @Override
237         protected void createButtons(Composite parent) {
238                 super.createButtons(parent);
239
240                 Composite composite = new Composite(parent, SWT.NONE);
241                 FillLayout fillLayout = new FillLayout(SWT.HORIZONTAL);
242                 composite.setLayout(fillLayout);
243
244                 Button licenseButton = createButton(composite, "License");
245
246                 licenseButton.addSelectionListener(new SelectionAdapter() {
247                         private boolean isOpen;
248
249                         @Override
250                         public void widgetSelected(SelectionEvent e) {
251                                 if (!isOpen) {
252                                         isOpen = true;
253                                         LicenseDialog licenseDialog = new LicenseDialog(shell, "License");
254                                         licenseDialog.open();
255                                         isOpen = false;
256                                 }
257                         }
258                 });
259
260                 createOKButton(composite, true);
261         }
262
263         private Properties getProperties() {
264                 InputStream is = null;
265                 Properties properties = null;
266
267                 try {
268                         is = this.getClass().getClassLoader().getResourceAsStream(ABOUT_PROP_FILENAME);
269                         if (null == is) {
270                                 logger.severe("about properties file is null.");
271                                 return null;
272                         }
273
274                         properties = new Properties();
275                         properties.load(is);
276
277                 } catch (IOException e) {
278                         logger.log(Level.SEVERE, e.getMessage(), e);
279                         return null;
280                 } finally {
281                         IOUtil.close(is);
282                 }
283
284                 return properties;
285         }
286
287         protected void setShellSize() {
288                 shell.setSize(436, shell.getSize().y);
289         }
290
291         protected void close() {
292                 logger.info("close the about dialog");
293                 aboutImage.dispose();
294         }
295 }