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.FileInputStream;
33 import java.io.FileNotFoundException;
34 import java.io.IOException;
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.layout.GridData;
42 import org.eclipse.swt.layout.GridLayout;
43 import org.eclipse.swt.widgets.Button;
44 import org.eclipse.swt.widgets.Composite;
45 import org.eclipse.swt.widgets.Shell;
46 import org.eclipse.swt.widgets.Text;
47 import org.tizen.emulator.skin.log.SkinLogger;
48 import org.tizen.emulator.skin.util.IOUtil;
49 import org.tizen.emulator.skin.util.StringUtil;
55 public class LicenseDialog extends SkinDialog {
57 public static final String LICENSE_FILE_PATH = "../license/Open_Source_Announcement.txt";
59 private Logger logger = SkinLogger.getSkinLogger( LicenseDialog.class ).getLogger();
61 public LicenseDialog( Shell parent, String title ) {
62 super( parent, title, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.RESIZE | SWT.MAX );
66 protected Composite createArea( Composite parent ) {
68 Composite composite = new Composite( parent, SWT.NONE );
69 composite.setLayout( new GridLayout() );
71 final Text text = new Text( composite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI );
72 GridData gridData = new GridData( SWT.FILL, SWT.FILL, true, true );
73 text.setLayoutData( gridData );
75 text.setEditable( false );
76 text.setBackground( shell.getDisplay().getSystemColor( SWT.COLOR_WHITE ) );
77 String license = StringUtil.nvl( getLicense() );
78 text.setText( license );
85 protected void setShellSize() {
86 shell.setSize( (int) ( 400 * 1.618 ), 400 );
90 protected void createButtons( Composite parent ) {
91 super.createButtons( parent );
93 Button okButton = createButton( parent, OK );
95 GridData gd = new GridData();
96 gd.grabExcessHorizontalSpace = true;
97 gd.horizontalAlignment = SWT.RIGHT;
98 okButton.setLayoutData( gd );
102 okButton.addSelectionListener( new SelectionAdapter() {
104 public void widgetSelected( SelectionEvent e ) {
105 LicenseDialog.this.shell.close();
111 private String getLicense() {
113 FileInputStream fis = null;
118 fis = new FileInputStream( LICENSE_FILE_PATH );
121 byte[] bytes = IOUtil.getBytes( fis );
122 string = new String( bytes, "UTF-8" );
123 } catch ( IOException e ) {
124 logger.log( Level.SEVERE, e.getMessage(), e );
125 string = "File control error.";
128 } catch ( FileNotFoundException e ) {
129 string = "There is no license info.";
138 protected void close() {
139 logger.info("close the license dialog");