~ubuntu-branches/ubuntu/lucid/tuxguitar/lucid

« back to all changes in this revision

Viewing changes to src/org/herac/tuxguitar/gui/actions/help/ShowAboutDialogAction.java

  • Committer: Bazaar Package Importer
  • Author(s): Philippe Coval
  • Date: 2008-06-19 00:30:30 UTC
  • mfrom: (1.1.1 upstream) (2.1.3 hardy)
  • Revision ID: james.westby@ubuntu.com-20080619003030-agens2gvd5m4dacu
New upstream release (Closes: #481728) also (LP: #176979, #212207)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Created on 17-dic-2005
3
 
 *
4
 
 * TODO To change the template for this generated file go to
5
 
 * Window - Preferences - Java - Code Style - Code Templates
6
 
 */
7
 
package org.herac.tuxguitar.gui.actions.help;
8
 
 
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;
36
 
 
37
 
/**
38
 
 * @author julian
39
 
 * 
40
 
 * TODO To change the template for this generated type comment go to Window -
41
 
 * Preferences - Java - Code Style - Code Templates
42
 
 */
43
 
public class ShowAboutDialogAction extends Action {
44
 
        public static final String NAME = "action.help.about";
45
 
 
46
 
        private static final String RELEASE_NAME = ("TuxGuitar " + TuxGuitar.TUXGUITAR_VERSION);
47
 
        
48
 
        private static final int IMAGE_WIDTH = 100;
49
 
        private static final int IMAGE_HEIGHT = 100;
50
 
 
51
 
        private static final int TAB_ITEM_WIDTH = 500;
52
 
        private static final int TAB_ITEM_HEIGHT = 200; 
53
 
        
54
 
        private Canvas imageCanvas;
55
 
        private Image tabImage; 
56
 
        
57
 
        public ShowAboutDialogAction(TablatureEditor tablatureEditor) {
58
 
                super(NAME, false, tablatureEditor);
59
 
        }
60
 
 
61
 
        public boolean doAction(TypedEvent e) {
62
 
                showDialog(getEditor().getTablature().getShell());
63
 
                return true;
64
 
        }
65
 
 
66
 
        public void showDialog(Shell shell) {
67
 
 
68
 
                final Shell dialog = new Shell(shell,SWT.DIALOG_TRIM|SWT.APPLICATION_MODAL);
69
 
 
70
 
                dialog.setLayout(new GridLayout());
71
 
                dialog.setText(TuxGuitar.getProperty("help.about"));
72
 
 
73
 
                
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));          
80
 
                
81
 
                header.setLayout(new GridLayout(2,false));              
82
 
                
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));
88
 
                        }
89
 
                });
90
 
                
91
 
                title.setFont(font);
92
 
                title.setForeground(dialog.getDisplay().getSystemColor(SWT.COLOR_GRAY));
93
 
                title.setText(RELEASE_NAME);            
94
 
                font.dispose();
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));  
99
 
        
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());
103
 
        
104
 
        DocReader docReader = new DocReader();
105
 
        
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());
109
 
        
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;
118
 
                                }
119
 
                                imageCanvas.redraw();
120
 
                        }
121
 
                
122
 
                });
123
 
                        
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));        
129
 
        
130
 
        GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);    
131
 
        data.minimumWidth = 80;
132
 
        data.minimumHeight = 25;    
133
 
        
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) {
139
 
                                dialog.dispose();
140
 
                        }
141
 
                });
142
 
 
143
 
                dialog.pack();
144
 
                dialog.open();
145
 
 
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);
151
 
 
152
 
        }
153
 
        
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));
158
 
        
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);
164
 
        
165
 
        TabItem tabItem = new TabItem(tabFolder, SWT.NONE);
166
 
        tabItem.setText(itemName);
167
 
        tabItem.setControl(control);            
168
 
        }
169
 
        
170
 
}