KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > syncclient > demo > DemoMenuBar


1 /**
2  * Copyright (C) 2003-2005 Funambol
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package sync4j.syncclient.demo;
20
21 import java.awt.Menu JavaDoc;
22 import java.awt.MenuBar JavaDoc;
23 import java.awt.MenuItem JavaDoc;
24 import java.awt.event.ActionEvent JavaDoc;
25 import java.awt.event.ActionListener JavaDoc;
26
27 /**
28  * The menu for this GUI.
29  *
30  * @author Fabio Maggi @ Funambol
31  * @author Alessandro Morandi, Giorgio Orsi
32  * @version $Id: DemoMenuBar.java,v 1.8 2005/03/14 16:46:03 fabius Exp $
33  */

34 public class DemoMenuBar
35 extends MenuBar JavaDoc
36 implements ActionListener JavaDoc, ConfigurationParameters {
37
38     //---------------------------------------------------------- Constants
39

40     //---------------------------------------------------------- Private data
41

42     //
43
// The window containing this menubar
44
//
45
private MainWindow mw = null ;
46     private About ppcAbout = null ;
47
48     private Language ln = new Language() ;
49
50     //---------------------------------------------------------- Public methods
51

52     /**
53      * Creates the panel.
54      *
55      * @param mw the window containing this panel
56      */

57     public DemoMenuBar(MainWindow mw) {
58
59         MenuItem JavaDoc mi = null;
60         Menu JavaDoc menuFile = null;
61         Menu JavaDoc menuEdit = null;
62         Menu JavaDoc menuView = null;
63         Menu JavaDoc menuHelp = null;
64
65         this.mw = mw;
66
67         //
68
// File Menu
69
//
70
menuFile = new Menu JavaDoc(ln.getString("file"));
71
72         menuFile.add(mi = new MenuItem JavaDoc (ln.getString ("synchronize" )) ) ;
73         mi.addActionListener(this);
74         menuFile.add(mi = new MenuItem JavaDoc (ln.getString ("configure" )) ) ;
75         mi.addActionListener(this);
76         menuFile.addSeparator();
77         menuFile.add(mi = new MenuItem JavaDoc (ln.getString ("exit" )) ) ;
78         mi.addActionListener(this);
79
80         //
81
// Edit Menu
82
//
83
menuEdit = new Menu JavaDoc(ln.getString("edit"));
84         menuEdit.add(mi = new MenuItem JavaDoc (ln.getString ("new_contact" )) );
85         mi.addActionListener(this);
86         menuEdit.add(mi = new MenuItem JavaDoc (ln.getString ("new_calendar" )) );
87         mi.addActionListener(this);
88
89         //
90
// View Menu
91
//
92
menuView = new Menu JavaDoc(ln.getString("view"));
93         menuView.add(mi = new MenuItem JavaDoc (ln.getString ("contact_list" )) );
94         mi.addActionListener(this);
95         menuView.add(mi = new MenuItem JavaDoc (ln.getString ("calendar_list" )) );
96         mi.addActionListener(this);
97
98         //
99
// Help Menu
100
//
101
menuHelp = new Menu JavaDoc (ln.getString ("help" )) ;
102         menuHelp.add(mi = new MenuItem JavaDoc (ln.getString ("about" ))) ;
103         mi.addActionListener(this);
104
105         //
106
// About Window
107
//
108
ppcAbout = new About(mw);
109
110         add (menuFile ) ;
111         add (menuEdit ) ;
112         add (menuView ) ;
113         add (menuHelp ) ;
114     }
115
116     /**
117      * Invoked when an action occurs (i.e. a menu item is selected).
118      *
119      * @param evt the occurred action
120      */

121     public void actionPerformed(ActionEvent JavaDoc evt) {
122
123         String JavaDoc item = evt.getActionCommand();
124
125         if (item.equals(ln.getString("exit"))) {
126             mw.exit();
127         } else if (item.equals (ln.getString ("configure" ))) {
128             mw.show(KEY_CONFIG);
129         } else if (item.equals (ln.getString ("contact_list" ))) {
130             mw.show(KEY_CONTACTLIST);
131         } else if (item.equals (ln.getString ("new_contact" ))) {
132             mw.show(KEY_CONTACTNEW);
133         } else if (item.equals (ln.getString ("calendar_list" ))) {
134              mw.show(KEY_CALENDARLIST);
135         } else if (item.equals (ln.getString ("new_calendar" ))) {
136             mw.show(KEY_CALENDARNEW);
137         } else if (item.equals (ln.getString ("synchronize" ))) {
138             mw.show(KEY_SYNC);
139         } else if (item.equals (ln.getString ("about" ))) {
140             mw.setEnabled(false);
141             ppcAbout.show();
142         }
143     }
144
145     //---------------------------------------------------------- Private methods
146

147 }
Popular Tags