2
* Created on 17-dic-2005
4
* TODO To change the template for this generated file go to
5
* Window - Preferences - Java - Code Style - Code Templates
7
package org.herac.tuxguitar.gui.actions.help;
9
import org.eclipse.swt.SWT;
10
import org.eclipse.swt.events.PaintEvent;
11
import org.eclipse.swt.events.PaintListener;
12
import org.eclipse.swt.events.SelectionAdapter;
13
import org.eclipse.swt.events.SelectionEvent;
14
import org.eclipse.swt.events.TypedEvent;
15
import org.eclipse.swt.graphics.Font;
16
import org.eclipse.swt.graphics.Image;
17
import org.eclipse.swt.graphics.Rectangle;
18
import org.eclipse.swt.layout.FormData;
19
import org.eclipse.swt.layout.FormLayout;
20
import org.eclipse.swt.layout.GridData;
21
import org.eclipse.swt.layout.GridLayout;
22
import org.eclipse.swt.widgets.Button;
23
import org.eclipse.swt.widgets.Canvas;
24
import org.eclipse.swt.widgets.Composite;
25
import org.eclipse.swt.widgets.Label;
26
import org.eclipse.swt.widgets.Shell;
27
import org.eclipse.swt.widgets.TabFolder;
28
import org.eclipse.swt.widgets.TabItem;
29
import org.eclipse.swt.widgets.Text;
30
import org.herac.tuxguitar.gui.SystemImages;
31
import org.herac.tuxguitar.gui.TuxGuitar;
32
import org.herac.tuxguitar.gui.actions.Action;
33
import org.herac.tuxguitar.gui.doc.DocReader;
34
import org.herac.tuxguitar.gui.editors.TablatureEditor;
35
import org.herac.tuxguitar.gui.system.config.ConfigKeys;
40
* TODO To change the template for this generated type comment go to Window -
41
* Preferences - Java - Code Style - Code Templates
43
public class ShowAboutDialogAction extends Action {
44
public static final String NAME = "action.help.about";
46
private static final String RELEASE_NAME = ("TuxGuitar " + TuxGuitar.TUXGUITAR_VERSION);
48
private static final int IMAGE_WIDTH = 100;
49
private static final int IMAGE_HEIGHT = 100;
51
private static final int TAB_ITEM_WIDTH = 500;
52
private static final int TAB_ITEM_HEIGHT = 200;
54
private Canvas imageCanvas;
55
private Image tabImage;
57
public ShowAboutDialogAction(TablatureEditor tablatureEditor) {
58
super(NAME, false, tablatureEditor);
61
public boolean doAction(TypedEvent e) {
62
showDialog(getEditor().getTablature().getShell());
66
public void showDialog(Shell shell) {
68
final Shell dialog = new Shell(shell,SWT.DIALOG_TRIM|SWT.APPLICATION_MODAL);
70
dialog.setLayout(new GridLayout());
71
dialog.setText(TuxGuitar.getProperty("help.about"));
74
//--------------------HEADER----------------------------------
75
Composite header = new Composite(dialog,SWT.NONE);
76
imageCanvas = new Canvas(header,SWT.NONE);
77
tabImage = SystemImages.ABOUT_DESCRIPTION;
78
Label title = new Label(header,SWT.NONE);
79
Font font = new Font(dialog.getDisplay(),TuxGuitar.instance().getConfig().getFontDataConfigValue(ConfigKeys.FONT_ABOUT_DIALOG_TITLE));
81
header.setLayout(new GridLayout(2,false));
83
imageCanvas.setLayoutData(new GridData(IMAGE_WIDTH,IMAGE_HEIGHT));
84
imageCanvas.addPaintListener(new PaintListener() {
85
public void paintControl(PaintEvent e) {
86
Rectangle bounds = tabImage.getBounds();
87
e.gc.drawImage(tabImage,((IMAGE_WIDTH - bounds.width) /2),((IMAGE_HEIGHT - bounds.height) /2));
92
title.setForeground(dialog.getDisplay().getSystemColor(SWT.COLOR_GRAY));
93
title.setText(RELEASE_NAME);
95
//-------------------TABS-----------------------
96
Composite tabs = new Composite(dialog, SWT.NONE);
97
tabs.setLayout(new GridLayout());
98
tabs.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
100
final TabFolder tabFolder = new TabFolder(tabs, SWT.NONE);
101
tabFolder.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
102
tabFolder.setLayout(new FormLayout());
104
DocReader docReader = new DocReader();
106
makeTabItem(tabFolder,DocReader.DESCRIPTION,docReader.read(DocReader.DESCRIPTION).toString());
107
makeTabItem(tabFolder,DocReader.AUTHORS,docReader.read(DocReader.AUTHORS).toString());
108
makeTabItem(tabFolder,DocReader.LICENSE,docReader.read(DocReader.LICENSE).toString());
110
tabFolder.addSelectionListener(new SelectionAdapter() {
111
public void widgetSelected(SelectionEvent e) {
112
if(tabFolder.getSelectionIndex() == 0){
113
tabImage = SystemImages.ABOUT_DESCRIPTION;
114
}else if(tabFolder.getSelectionIndex() == 1){
115
tabImage = SystemImages.ABOUT_AUTHORS;
116
}else if(tabFolder.getSelectionIndex() == 2){
117
tabImage = SystemImages.ABOUT_LICENSE;
119
imageCanvas.redraw();
124
tabFolder.setSelection(0);
125
//------------------BUTTONS--------------------------
126
Composite buttons = new Composite(dialog, SWT.NONE);
127
buttons.setLayout(new GridLayout());
128
buttons.setLayoutData(new GridData(SWT.END,SWT.FILL,true,true));
130
GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);
131
data.minimumWidth = 80;
132
data.minimumHeight = 25;
134
Button buttonExit = new Button(buttons, SWT.PUSH);
135
buttonExit.setLayoutData(data);
136
buttonExit.setText(TuxGuitar.getProperty("exit"));
137
buttonExit.addSelectionListener(new SelectionAdapter() {
138
public void widgetSelected(SelectionEvent arg0) {
146
int x = shell.getBounds().x
147
+ (shell.getBounds().width - dialog.getSize().x) / 2;
148
int y = shell.getBounds().y
149
+ (shell.getBounds().height - dialog.getSize().y) / 2;
150
dialog.setLocation(x, y);
154
private void makeTabItem(TabFolder tabFolder,String itemName,String itemText){
155
Composite control = new Composite(tabFolder, SWT.NONE);
156
control.setLayout(new GridLayout());
157
control.setLayoutData(new FormData(TAB_ITEM_WIDTH,TAB_ITEM_HEIGHT));
159
Text text = new Text(control,SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
160
text.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
161
text.setEditable(false);
162
text.append(itemText);
163
text.setSelection(0);
165
TabItem tabItem = new TabItem(tabFolder, SWT.NONE);
166
tabItem.setText(itemName);
167
tabItem.setControl(control);