KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > agent > client > gui > swt > SWTAboutDialog


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.agent.client.gui.swt;
21
22 import java.io.IOException JavaDoc;
23
24 import org.eclipse.swt.SWT;
25 import org.eclipse.swt.events.PaintEvent;
26 import org.eclipse.swt.events.PaintListener;
27 import org.eclipse.swt.events.SelectionAdapter;
28 import org.eclipse.swt.events.SelectionEvent;
29 import org.eclipse.swt.events.SelectionListener;
30 import org.eclipse.swt.graphics.Image;
31 import org.eclipse.swt.layout.GridData;
32 import org.eclipse.swt.layout.GridLayout;
33 import org.eclipse.swt.widgets.Button;
34 import org.eclipse.swt.widgets.Canvas;
35 import org.eclipse.swt.widgets.Composite;
36 import org.eclipse.swt.widgets.Dialog;
37 import org.eclipse.swt.widgets.Label;
38 import org.eclipse.swt.widgets.Link;
39 import org.eclipse.swt.widgets.Shell;
40
41 import com.sslexplorer.agent.client.util.BrowserLauncher;
42
43 public class SWTAboutDialog extends Dialog {
44
45     private Shell shell;
46     private Composite accessory;
47
48     public SWTAboutDialog(Shell parent, String JavaDoc closeText, String JavaDoc title, final Image image, String JavaDoc message, String JavaDoc description,
49                             String JavaDoc copyright, final String JavaDoc link) {
50         super(parent, SWT.TITLE | SWT.CLOSE | SWT.BORDER | SWT.RESIZE);
51
52
53         // Create the dialog window
54
shell = new Shell(getParent(), getStyle());
55         shell.setText(getText());
56         shell.setLayout(new GridLayout(1, true));
57         
58         // Common About Details
59

60         Composite commonAboutDetails = new Composite(shell, 0);
61         GridLayout gridLayout = new GridLayout(1, false);
62         gridLayout.verticalSpacing = 10;
63         GridData data = new GridData(GridData.CENTER, GridData.CENTER, true, true);
64 // data.widthHint = 120;
65
// data.heightHint = 48;
66
commonAboutDetails.setLayoutData(data);
67         commonAboutDetails.setLayout(gridLayout);
68         
69
70         // Close
71
Button close = new Button(shell, SWT.PUSH);
72         close.setText(closeText);
73         close.addSelectionListener(new SelectionAdapter() {
74             public void widgetSelected(SelectionEvent event) {
75                 shell.close();
76             }
77         });
78         data = new GridData();
79         data.horizontalAlignment = GridData.CENTER;
80         data.grabExcessHorizontalSpace = true;
81         close.setLayoutData(data);
82         
83         // Common About Details Components
84

85         Canvas canvas = new Canvas(commonAboutDetails, SWT.NONE);
86         canvas.addPaintListener(new PaintListener() {
87             public void paintControl(PaintEvent e) {
88                 e.gc.drawImage(image, 0, 0);
89             }
90         });
91         data = new GridData(GridData.CENTER, GridData.CENTER, true, true);
92         data.widthHint = 48;
93         data.heightHint = 48;
94         canvas.setLayoutData(data);
95
96         Label messageLabel = new Label(commonAboutDetails, SWT.CENTER);
97         messageLabel.setFont(SWTUtil.newFont(parent.getDisplay(), messageLabel.getFont(), 18, SWT.BOLD));
98         messageLabel.setText(message);
99
100         Label descriptionLabel = new Label(commonAboutDetails, SWT.WRAP | SWT.BEGINNING);
101         descriptionLabel.setText(description);
102         data = new GridData();
103         data.widthHint = 400;
104         data.horizontalAlignment = GridData.CENTER;
105         data.grabExcessHorizontalSpace = true;
106         descriptionLabel.setLayoutData(data);
107
108         if (copyright != null) {
109             Label copyrightLabel = new Label(commonAboutDetails, SWT.WRAP | SWT.CENTER);
110             copyrightLabel.setText(copyright);
111             copyrightLabel.setFont(SWTUtil.newFont(parent.getDisplay(), copyrightLabel.getFont(), 8, 0));
112             data = new GridData();
113             data.horizontalAlignment = GridData.CENTER;
114             data.grabExcessHorizontalSpace = true;
115             copyrightLabel.setLayoutData(data);
116         }
117         
118         if(link != null) {
119             Link linkButton = new Link(commonAboutDetails, SWT.CENTER);
120             linkButton.setText("<a HREF=\"" + link + "\">" + link + "</a>");
121             data = new GridData();
122             data.horizontalAlignment = GridData.CENTER;
123             data.grabExcessHorizontalSpace = true;
124             linkButton.setLayoutData(data);
125             linkButton.addSelectionListener(new SelectionListener() {
126                 public void widgetDefaultSelected(SelectionEvent e) {
127                 }
128
129                 public void widgetSelected(SelectionEvent e) {
130                     try {
131                         BrowserLauncher.openURL(link);
132                     } catch (IOException JavaDoc e1) {
133                         e1.printStackTrace();
134                     }
135                 }
136             });
137         }
138
139         // Accessory
140

141         accessory = new Composite(commonAboutDetails, 0);
142         accessory.setLayout(new GridLayout(1, false));
143         data = new GridData();
144         data.horizontalAlignment = GridData.CENTER;
145         data.grabExcessHorizontalSpace = true;
146         accessory.setLayoutData(data);
147     }
148     
149     public void open() {
150         shell.pack();
151         SWTUtil.center(shell);
152         shell.open();
153     }
154
155     public Composite getAccessory() {
156         return accessory;
157     }
158 }
159
Popular Tags