~ubuntu-branches/ubuntu/oneiric/tuxguitar/oneiric

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/gui/help/about/AboutDialog.java

  • Committer: Bazaar Package Importer
  • Author(s): Philippe Coval
  • Date: 2008-06-19 00:30:30 UTC
  • mto: (5.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20080619003030-h719szrhsngou7c6
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.herac.tuxguitar.gui.help.about;
 
2
 
 
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;
 
29
 
 
30
public class AboutDialog {
 
31
        
 
32
        private static final String RELEASE_NAME = (TuxGuitar.APPLICATION_NAME + " " + TGVersion.CURRENT.getVersion());
 
33
        private static final String PROPERTY_PREFIX = ("help.about.");
 
34
        
 
35
        private static final int IMAGE_WIDTH = 100;
 
36
        private static final int IMAGE_HEIGHT = 100;
 
37
        
 
38
        private static final int TAB_ITEM_WIDTH = 640;
 
39
        private static final int TAB_ITEM_HEIGHT = 300;
 
40
        
 
41
        protected Composite imageComposite;
 
42
        protected Image image;
 
43
        
 
44
        public AboutDialog() {
 
45
                super();
 
46
        }
 
47
        
 
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"));
 
52
                
 
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));
 
57
                
 
58
                this.image = TuxGuitar.instance().getIconManager().getAboutDescription();
 
59
                
 
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));
 
67
                        }
 
68
                });
 
69
                
 
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) {
 
78
                                titleFont.dispose();
 
79
                        }
 
80
                });
 
81
                
 
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));
 
86
                
 
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());
 
90
                
 
91
                AboutContentReader docReader = new AboutContentReader();
 
92
                
 
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());
 
96
                
 
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();
 
105
                                }
 
106
                                AboutDialog.this.imageComposite.redraw();
 
107
                        }
 
108
                });
 
109
                
 
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));
 
114
                
 
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) {
 
120
                                dialog.dispose();
 
121
                        }
 
122
                });
 
123
                
 
124
                tabFolder.setSelection(0);
 
125
                
 
126
                dialog.setDefaultButton( buttonClose );
 
127
                
 
128
                DialogUtils.openDialog(dialog,DialogUtils.OPEN_STYLE_CENTER | DialogUtils.OPEN_STYLE_PACK);
 
129
        }
 
130
        
 
131
        private GridData getButtonData(){
 
132
                GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
 
133
                data.minimumWidth = 80;
 
134
                data.minimumHeight = 25;
 
135
                return data;
 
136
        }
 
137
        
 
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));
 
142
                
 
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);
 
149
                
 
150
                TabItem tabItem = new TabItem(tabFolder, SWT.NONE);
 
151
                tabItem.setText(TuxGuitar.getProperty(PROPERTY_PREFIX + itemName));
 
152
                tabItem.setControl(control);
 
153
        }
 
154
}