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>
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.
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.
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.
30 package org.tizen.emulator.skin.dialog;
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;
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;
60 public class AboutDialog extends SkinDialog {
62 public static final String ABOUT_PROP_FILENAME = "about.properties";
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";
68 public static final String URL_TIZEN_ORG = "https://developer.tizen.org";
70 private Image aboutImage;
72 private Logger logger = SkinLogger.getSkinLogger(AboutDialog.class).getLogger();
74 public AboutDialog(Shell parent) {
75 super(parent, "About Tizen Emulator", SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
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;
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);
95 Composite area = createArea(parent);
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));
105 createButtons(buttonComposite);
109 protected Composite createArea(Composite parent) {
110 Composite composite = displayInfo(parent);
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);
122 Composite compositeLeft = new Composite(compositeBase, SWT.BORDER);
123 compositeLeft.setLayout(getNopaddedGridLayout(1, false));
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);
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);
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);
152 titleLabel.setBackground(white);
154 if (SwtUtil.isWindowsPlatform()) {
155 Label space = new Label(compositeRight, SWT.NONE);
159 Properties properties = getProperties();
162 Text versionText = new Text(compositeRight, SWT.NONE);
163 String version = getValue(properties, PROP_KEY_VERSION);
164 if (version.isEmpty()) {
165 version = "Not identified";
167 versionText.setText("Version : " + version);
168 versionText.setEditable(false);
169 versionText.setBackground(white);
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";
177 buildText.setText("Build id : " + time);
178 buildText.setEditable(false);
179 buildText.setBackground(white);
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));*/
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() {
193 public void widgetDefaultSelected(SelectionEvent arg0) {
198 public void widgetSelected(SelectionEvent arg0) {
200 Program.launch(URL_TIZEN_ORG);
201 } catch (Throwable e) {
209 return compositeBase;
212 private String getValue(Properties properties, String key) {
213 if (null != properties) {
215 String property = properties.getProperty(key);
217 if (!StringUtil.isEmpty(property)) {
219 if (!property.contains(key)) {
222 // ex) '${build_git_commit}' is default
223 // expression in build.xml
224 return "Not identified";
228 return "Not identified";
232 return "Not identified";
237 protected void createButtons(Composite parent) {
238 super.createButtons(parent);
240 Composite composite = new Composite(parent, SWT.NONE);
241 FillLayout fillLayout = new FillLayout(SWT.HORIZONTAL);
242 composite.setLayout(fillLayout);
244 Button licenseButton = createButton(composite, "License");
246 licenseButton.addSelectionListener(new SelectionAdapter() {
247 private boolean isOpen;
250 public void widgetSelected(SelectionEvent e) {
253 LicenseDialog licenseDialog = new LicenseDialog(shell, "License");
254 licenseDialog.open();
260 createOKButton(composite, true);
263 private Properties getProperties() {
264 InputStream is = null;
265 Properties properties = null;
268 is = this.getClass().getClassLoader().getResourceAsStream(ABOUT_PROP_FILENAME);
270 logger.severe("about properties file is null.");
274 properties = new Properties();
277 } catch (IOException e) {
278 logger.log(Level.SEVERE, e.getMessage(), e);
287 protected void setShellSize() {
288 shell.setSize(436, shell.getSize().y);
291 protected void close() {
292 logger.info("close the about dialog");
293 aboutImage.dispose();