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

« back to all changes in this revision

Viewing changes to TuxGuitar-tray/src/org/herac/tuxguitar/tray/TGTray.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.tray;
 
2
 
 
3
import org.eclipse.swt.SWT;
 
4
import org.eclipse.swt.widgets.Display;
 
5
import org.eclipse.swt.widgets.Event;
 
6
import org.eclipse.swt.widgets.Listener;
 
7
import org.eclipse.swt.widgets.Shell;
 
8
import org.eclipse.swt.widgets.Tray;
 
9
import org.eclipse.swt.widgets.TrayItem;
 
10
import org.herac.tuxguitar.gui.TuxGuitar;
 
11
import org.herac.tuxguitar.gui.system.icons.IconLoader;
 
12
import org.herac.tuxguitar.gui.system.language.LanguageLoader;
 
13
 
 
14
public class TGTray implements IconLoader,LanguageLoader{
 
15
        
 
16
        private boolean visible;
 
17
        private Display display;
 
18
        private Tray tray;
 
19
        private TGTrayIcon icon;
 
20
        private TGTrayMenu menu;
 
21
        
 
22
        public TGTray(){
 
23
                this.display = TuxGuitar.instance().getDisplay();
 
24
                this.tray = this.display.getSystemTray();
 
25
                this.icon = new TGTrayIcon();
 
26
                this.menu = new TGTrayMenu();
 
27
                TuxGuitar.instance().getIconManager().addLoader(this);
 
28
                TuxGuitar.instance().getLanguageManager().addLoader(this);
 
29
        }
 
30
        
 
31
        public void removeTray(){
 
32
                if (this.tray != null) {
 
33
                        setVisible(true);
 
34
                        TrayItem items[] = this.tray.getItems();
 
35
                        for(int i = 0; i < items.length; i ++){
 
36
                                items[i].dispose();
 
37
                        }
 
38
                        this.icon.dispose();
 
39
                        this.menu.dispose();
 
40
                }
 
41
        }
 
42
        
 
43
        public void addTray() {
 
44
                if (this.tray != null) {
 
45
                        this.menu.make();
 
46
                        this.visible = true;
 
47
                        TrayItem item = new TrayItem (this.tray, SWT.NONE);
 
48
                        item.setToolTipText(TuxGuitar.APPLICATION_NAME);
 
49
                        item.addListener (SWT.Selection, new Listener () {
 
50
                                public void handleEvent (Event event) {
 
51
                                        setVisible();
 
52
                                }
 
53
                        });
 
54
                        item.addListener (SWT.MenuDetect, new Listener () {
 
55
                                public void handleEvent (Event event) {
 
56
                                        showMenu();
 
57
                                }
 
58
                        });
 
59
                        this.icon.setItem(item);
 
60
                        this.loadIcons();
 
61
                }
 
62
        }
 
63
        
 
64
        public void loadIcons() {
 
65
                this.icon.loadImage();
 
66
                this.menu.loadIcons();
 
67
        }
 
68
        
 
69
        public void loadProperties(){
 
70
                this.menu.loadProperties();
 
71
        }
 
72
        
 
73
        protected void setVisible(){
 
74
                this.setVisible(!this.visible);
 
75
        }
 
76
        
 
77
        protected void setVisible(boolean visible){
 
78
                if (this.tray != null) {
 
79
                        Shell shells[] = this.display.getShells();
 
80
                        for(int i = 0; i < shells.length; i ++){
 
81
                                shells[i].setVisible( visible );
 
82
                        }
 
83
                        this.visible = visible;
 
84
                }
 
85
        }
 
86
        
 
87
        protected void showMenu(){
 
88
                this.menu.show();
 
89
        }
 
90
}