KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > tools > menu > Menu


1 /*
2  * Copyright (c) 2001-2005 by Genimen BV (www.genimen.com) All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, is permitted provided that the following conditions are met: -
6  * Redistributions of source code must retain the above copyright notice, this
7  * list of conditions and the following disclaimer. - Redistributions in binary
8  * form must reproduce the above copyright notice, this list of conditions and
9  * the following disclaimer in the documentation and/or other materials
10  * provided with the distribution. - All advertising materials mentioning
11  * features or use of this software must display the following acknowledgment:
12  * "This product includes Djeneric." - Products derived from this software may
13  * not be called "Djeneric" nor may "Djeneric" appear in their names without
14  * prior written permission of Genimen BV. - Redistributions of any form
15  * whatsoever must retain the following acknowledgment: "This product includes
16  * Djeneric."
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL GENIMEN BV, DJENERIC.ORG, OR CONTRIBUTORS
22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */

30
31 package com.genimen.djeneric.tools.menu;
32
33 import java.awt.AWTEvent JavaDoc;
34 import java.awt.BorderLayout JavaDoc;
35 import java.awt.Dimension JavaDoc;
36 import java.awt.Image JavaDoc;
37 import java.awt.Toolkit JavaDoc;
38 import java.awt.event.WindowEvent JavaDoc;
39 import java.net.URL JavaDoc;
40
41 import javax.swing.JPanel JavaDoc;
42
43 import com.genimen.djeneric.language.Messages;
44 import com.genimen.djeneric.tools.common.DjenericTool;
45 import com.genimen.djeneric.util.DjEnvironment;
46 import com.genimen.djeneric.util.DjLogger;
47 import com.genimen.djeneric.util.DjVersion;
48
49 /**
50  * @author Wido Riezebos @created 27 mei 2002
51  */

52 public class Menu extends DjenericTool
53 {
54   private static final long serialVersionUID = 1L;
55   private final String JavaDoc PROPERTIES_FILE_NAME = DjEnvironment.getAbsoluteFileName("menu.properties");
56
57   final static String JavaDoc TOOL_VM_OPTIONS = "tool.vmoptions";
58   final static String JavaDoc TOOL_LANGUAGE = "tool.language";
59   final static String JavaDoc TOOL_PROTOTYPING = "tool.prototyping";
60   final static String JavaDoc TOOL_STRIPSPACES = "tool.stripspaces";
61   final static String JavaDoc MENU_RECENTDBS = "menu.recentdbs";
62
63   String JavaDoc _repositoriesFile;
64
65   public Menu(String JavaDoc repositoriesFile)
66   {
67     enableEvents(AWTEvent.WINDOW_EVENT_MASK);
68     loadProps(PROPERTIES_FILE_NAME);
69
70     String JavaDoc language = getProperty(Menu.TOOL_LANGUAGE, "");
71     if (language.trim().length() > 0) System.setProperty(Messages.DJENERIC_LANGUAGE, language);
72     Messages.reloadResources();
73
74     setIconImage(getImage("djenericsmall.gif"));
75
76     JPanel JavaDoc contentPane = (JPanel JavaDoc) this.getContentPane();
77     contentPane.setLayout(new BorderLayout JavaDoc());
78     this.setSize(new Dimension JavaDoc(380, 173));
79     MenuPanel menuPanel = new MenuPanel();
80     menuPanel.setRepositoriesFile(repositoriesFile);
81     contentPane.add(menuPanel, BorderLayout.CENTER);
82
83     _repositoriesFile = repositoriesFile;
84
85     String JavaDoc title = Messages.getString("global.Version", "Djeneric", DjVersion.getVersion());
86
87     setTitle(title);
88
89     menuPanel.setProps(getProperties());
90   }
91
92   protected void processWindowEvent(WindowEvent JavaDoc e)
93   {
94     if (e.getID() == WindowEvent.WINDOW_CLOSING)
95     {
96       saveProps();
97
98       System.exit(0);
99     }
100     else
101     {
102       super.processWindowEvent(e);
103     }
104   }
105
106   protected void updateProperties()
107   {
108   }
109
110   public static Image JavaDoc getImage(String JavaDoc fileName)
111   {
112     URL JavaDoc url = Menu.class.getResource("images/" + fileName);
113     if (url != null)
114     {
115       return Toolkit.getDefaultToolkit().getImage(url);
116     }
117     else
118     {
119       return Toolkit.getDefaultToolkit().getImage("");
120     }
121   }
122
123   public static void main(String JavaDoc args[])
124   {
125     try
126     {
127       DjenericTool.setLookAndFeel();
128
129       if (args.length < 1)
130       {
131         System.out.println(Messages.getString("global.Usage", Menu.class.getName()));
132         return;
133       }
134
135       new Menu(args[0]).startApp();
136
137     }
138     catch (Exception JavaDoc e)
139     {
140       DjLogger.log(e);
141     }
142   }
143
144 }
Popular Tags