1
package org.herac.tuxguitar.gui.help.about;
3
import org.eclipse.swt.SWT;
4
import org.eclipse.swt.events.DisposeEvent;
5
import org.eclipse.swt.events.DisposeListener;
6
import org.eclipse.swt.events.PaintEvent;
7
import org.eclipse.swt.events.PaintListener;
8
import org.eclipse.swt.events.SelectionAdapter;
9
import org.eclipse.swt.events.SelectionEvent;
10
import org.eclipse.swt.graphics.Font;
11
import org.eclipse.swt.graphics.Image;
12
import org.eclipse.swt.graphics.Rectangle;
13
import org.eclipse.swt.layout.FormData;
14
import org.eclipse.swt.layout.FormLayout;
15
import org.eclipse.swt.layout.GridData;
16
import org.eclipse.swt.layout.GridLayout;
17
import org.eclipse.swt.widgets.Button;
18
import org.eclipse.swt.widgets.Composite;
19
import org.eclipse.swt.widgets.Label;
20
import org.eclipse.swt.widgets.Shell;
21
import org.eclipse.swt.widgets.TabFolder;
22
import org.eclipse.swt.widgets.TabItem;
23
import org.eclipse.swt.widgets.Text;
24
import org.herac.tuxguitar.gui.TuxGuitar;
25
import org.herac.tuxguitar.gui.editors.TGPainter;
26
import org.herac.tuxguitar.gui.system.config.TGConfigKeys;
27
import org.herac.tuxguitar.gui.util.DialogUtils;
28
import org.herac.tuxguitar.util.TGVersion;
30
public class AboutDialog {
32
private static final String RELEASE_NAME = (TuxGuitar.APPLICATION_NAME + " " + TGVersion.CURRENT.getVersion());
33
private static final String PROPERTY_PREFIX = ("help.about.");
35
private static final int IMAGE_WIDTH = 100;
36
private static final int IMAGE_HEIGHT = 100;
38
private static final int TAB_ITEM_WIDTH = 640;
39
private static final int TAB_ITEM_HEIGHT = 300;
41
protected Composite imageComposite;
42
protected Image image;
44
public AboutDialog() {
48
public void open(Shell shell) {
49
final Shell dialog = DialogUtils.newDialog(shell,SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
50
dialog.setLayout(new GridLayout());
51
dialog.setText(TuxGuitar.getProperty("help.about"));
53
//--------------------HEADER----------------------------------
54
Composite header = new Composite(dialog,SWT.NONE);
55
header.setLayout(new GridLayout(2,false));
56
header.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true ,true));
58
this.image = TuxGuitar.instance().getIconManager().getAboutDescription();
60
this.imageComposite = new Composite(header,SWT.NONE);
61
this.imageComposite.setLayoutData(new GridData(IMAGE_WIDTH,IMAGE_HEIGHT));
62
this.imageComposite.addPaintListener(new PaintListener() {
63
public void paintControl(PaintEvent e) {
64
Rectangle bounds = AboutDialog.this.image.getBounds();
65
TGPainter painter = new TGPainter(e.gc);
66
painter.drawImage(AboutDialog.this.image,((IMAGE_WIDTH - bounds.width) /2),((IMAGE_HEIGHT - bounds.height) /2));
70
final Font titleFont = new Font(dialog.getDisplay(),TuxGuitar.instance().getConfig().getFontDataConfigValue(TGConfigKeys.FONT_ABOUT_DIALOG_TITLE));
71
Label title = new Label(header,SWT.NONE);
72
title.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true ,true));
73
title.setFont(titleFont);
74
title.setForeground(dialog.getDisplay().getSystemColor(SWT.COLOR_GRAY));
75
title.setText(RELEASE_NAME);
76
title.addDisposeListener(new DisposeListener() {
77
public void widgetDisposed(DisposeEvent e) {
82
//-------------------TABS-----------------------
83
Composite tabs = new Composite(dialog, SWT.NONE);
84
tabs.setLayout(new GridLayout());
85
tabs.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
87
final TabFolder tabFolder = new TabFolder(tabs, SWT.NONE);
88
tabFolder.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
89
tabFolder.setLayout(new FormLayout());
91
AboutContentReader docReader = new AboutContentReader();
93
makeTabItem(tabFolder,AboutContentReader.DESCRIPTION,docReader.read(AboutContentReader.DESCRIPTION).toString());
94
makeTabItem(tabFolder,AboutContentReader.AUTHORS,docReader.read(AboutContentReader.AUTHORS).toString());
95
makeTabItem(tabFolder,AboutContentReader.LICENSE,docReader.read(AboutContentReader.LICENSE).toString());
97
tabFolder.addSelectionListener(new SelectionAdapter() {
98
public void widgetSelected(SelectionEvent e) {
99
if(tabFolder.getSelectionIndex() == 0){
100
AboutDialog.this.image = TuxGuitar.instance().getIconManager().getAboutDescription();
101
}else if(tabFolder.getSelectionIndex() == 1){
102
AboutDialog.this.image = TuxGuitar.instance().getIconManager().getAboutAuthors();
103
}else if(tabFolder.getSelectionIndex() == 2){
104
AboutDialog.this.image = TuxGuitar.instance().getIconManager().getAboutLicense();
106
AboutDialog.this.imageComposite.redraw();
110
//------------------BUTTONS--------------------------
111
Composite buttons = new Composite(dialog, SWT.NONE);
112
buttons.setLayout(new GridLayout());
113
buttons.setLayoutData(new GridData(SWT.END,SWT.FILL,true,true));
115
Button buttonClose = new Button(buttons, SWT.PUSH);
116
buttonClose.setLayoutData(getButtonData());
117
buttonClose.setText(TuxGuitar.getProperty("close"));
118
buttonClose.addSelectionListener(new SelectionAdapter() {
119
public void widgetSelected(SelectionEvent arg0) {
124
tabFolder.setSelection(0);
126
dialog.setDefaultButton( buttonClose );
128
DialogUtils.openDialog(dialog,DialogUtils.OPEN_STYLE_CENTER | DialogUtils.OPEN_STYLE_PACK);
131
private GridData getButtonData(){
132
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
133
data.minimumWidth = 80;
134
data.minimumHeight = 25;
138
private void makeTabItem(TabFolder tabFolder,String itemName,String itemText){
139
Composite control = new Composite(tabFolder, SWT.NONE);
140
control.setLayout(new GridLayout());
141
control.setLayoutData(new FormData(TAB_ITEM_WIDTH,TAB_ITEM_HEIGHT));
143
Text text = new Text(control,SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
144
text.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
145
text.setBackground(TuxGuitar.instance().getDisplay().getSystemColor(SWT.COLOR_WHITE));
146
text.setEditable(false);
147
text.append(itemText);
148
text.setSelection(0);
150
TabItem tabItem = new TabItem(tabFolder, SWT.NONE);
151
tabItem.setText(TuxGuitar.getProperty(PROPERTY_PREFIX + itemName));
152
tabItem.setControl(control);