sync with tizen_2.2
[sdk/emulator/qemu.git] / tizen / src / skin / client / src / org / tizen / emulator / skin / dialog / LicenseDialog.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.FileInputStream;
33 import java.io.FileNotFoundException;
34 import java.io.IOException;
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.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;
50
51 /**
52  * 
53  *
54  */
55 public class LicenseDialog extends SkinDialog {
56
57         public static final String LICENSE_FILE_PATH = "../license/Open_Source_Announcement.txt";
58
59         private Logger logger = SkinLogger.getSkinLogger( LicenseDialog.class ).getLogger();
60
61         public LicenseDialog( Shell parent, String title ) {
62                 super( parent, title, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.RESIZE | SWT.MAX );
63         }
64
65         @Override
66         protected Composite createArea( Composite parent ) {
67
68                 Composite composite = new Composite( parent, SWT.NONE );
69                 composite.setLayout( new GridLayout() );
70
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 );
74
75                 text.setEditable( false );
76                 text.setBackground( shell.getDisplay().getSystemColor( SWT.COLOR_WHITE ) );
77                 String license = StringUtil.nvl( getLicense() );
78                 text.setText( license );
79
80                 return composite;
81
82         }
83
84         @Override
85         protected void setShellSize() {
86                 shell.setSize( (int) ( 400 * 1.618 ), 400 );
87         }
88
89         @Override
90         protected void createButtons( Composite parent ) {
91                 super.createButtons( parent );
92
93                 Button okButton = createButton( parent, OK );
94
95                 GridData gd = new GridData();
96                 gd.grabExcessHorizontalSpace = true;
97                 gd.horizontalAlignment = SWT.RIGHT;
98                 okButton.setLayoutData( gd );
99
100                 okButton.setFocus();
101
102                 okButton.addSelectionListener( new SelectionAdapter() {
103                         @Override
104                         public void widgetSelected( SelectionEvent e ) {
105                                 LicenseDialog.this.shell.close();
106                         }
107                 } );
108
109         }
110
111         private String getLicense() {
112
113                 FileInputStream fis = null;
114                 String string = "";
115
116                 try {
117
118                         fis = new FileInputStream( LICENSE_FILE_PATH );
119
120                         try {
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.";
126                         }
127
128                 } catch ( FileNotFoundException e ) {
129                         string = "There is no license info.";
130                 } finally {
131                         IOUtil.close( fis );
132                 }
133
134                 return string;
135
136         }
137
138         protected void close() {
139                 logger.info("close the license dialog");
140         }
141 }