1 /********************************************************************************
2 * Copyright (c) 2001, 2004 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sf.glxdesktop.gui.glxinfo;
12
13
14 import net.sf.glxdesktop.gui.glxinfo.dialog.AboutGlxinfoDialog;
15
16 import org.gnu.gtk.Action;
17 import org.gnu.gtk.ActionEntry;
18 import org.gnu.gtk.ActionGroup;
19 import org.gnu.gtk.Gtk;
20 import org.gnu.gtk.GtkStockItem;
21 import org.gnu.gtk.ToggleAction;
22 import org.gnu.gtk.ToggleActionEntry;
23 import org.gnu.gtk.UIManager;
24 import org.gnu.gtk.VBox;
25 import org.gnu.gtk.event.ActionEntryListener;
26 import org.gnu.gtk.event.ToggleActionEntryListener;
27
28
29 public class GlxInfoWindowMenu implements ActionEntryListener,
30 ToggleActionEntryListener {
31
32 private GlxInfoWindowImpl glxInfoDialog;
33
34 private GlxInfoWindowActions actions;
35
36 private VBox menuBox = (VBox) GlxInfoWindowImpl.glade
37 .getWidget("vbox_menu");
38
39 private static final String ACTION_SHOW_GLXINFO = "showGlxInfo";
40
41 private static final String ACTION_SHOW_GLX_SERVER_INFO = "showGlxServerInfo";
42
43 private static final String ACTION_SHOW_GLX_CLIENT_INFO = "showGlxClientInfo";
44
45 private static final String ACTION_SHOW_OPENGL_INFO = "showOpenGLInfo";
46
47 private static final String ACTION_SHOW_GLU_INFO = "showGLUInfo";
48
49 private static final String ACTION_SHOW_FRAMEBUFFER_INFO = "showFrameBufferInfo";
50
51
52
53 private static final String ACTION_REFRESH_GLXINFO = "refreshGlxInfo";
54
55 private static final String ACTION_EXPAND_ALL = "expandALL";
56
57 private static final String ACTION_SEARCH_EXTENSIONS = "searchExtensions";
58
59 private static final String ACTION_QUIT = "quitAction";
60
61 private static final String ACTION_ABOUT = "aboutAction";
62
63 private ActionEntry[] entries = {
64 new ActionEntry("fileMenu", null, Messages.getString("GlxInfoWindowMenu.file")),
65 new ActionEntry("editMenu", null, Messages.getString("GlxInfoWindowMenu.edit")),
66 new ActionEntry("viewMenu", null, Messages.getString("GlxInfoWindowMenu.view")),
67 new ActionEntry("helpMenu", null, Messages.getString("GlxInfoWindowMenu.help")),
68 new ActionEntry("toolBar", null, Messages.getString("GlxInfoWindowMenu.tool_bar")),
69 new ActionEntry(ACTION_REFRESH_GLXINFO, GtkStockItem.REFRESH
70 .getString(), Messages.getString("GlxInfoWindowMenu.refresh"), null,
71 Messages.getString("GlxInfoWindowMenu.refresh_tooltip"), this),
72 new ActionEntry(ACTION_SEARCH_EXTENSIONS, GtkStockItem.FIND
73 .getString(), Messages.getString("GlxInfoWindowMenu.search"), null,
74 Messages.getString("GlxInfoWindowMenu.search_tooltip"), this),
75 new ActionEntry(ACTION_QUIT, GtkStockItem.QUIT.getString(), Messages.getString("GlxInfoWindowMenu.quit"),
76 null, Messages.getString("GlxInfoWindowMenu.quit_tooltip"), this),
77 new ActionEntry(ACTION_ABOUT, GtkStockItem.ABOUT.getString(),
78 Messages.getString("GlxInfoWindowMenu.about"), null, "About " + "tooltip txt", this), };
79
80 private ToggleActionEntry[] toggleEntries = { new ToggleActionEntry(
81 ACTION_EXPAND_ALL, GtkStockItem.ZOOM_FIT.getString(),
82 Messages.getString("GlxInfoWindowMenu.expand_all"), "<control>E", Messages.getString("GlxInfoWindowMenu.expand_all_tooltip"), false, this), };
83
84 private ToggleActionEntry[] toggleShowEntries = {
85 new ToggleActionEntry(ACTION_SHOW_GLXINFO, null,
86 Messages.getString("GlxInfoWindowMenu.show_glx"), null,
87 Messages.getString("GlxInfoWindowMenu.show_glx_tooltip"), true, this),
88 new ToggleActionEntry(ACTION_SHOW_GLX_SERVER_INFO, null,
89 Messages.getString("GlxInfoWindowMenu.show_glx_server"), null,
90 Messages.getString("GlxInfoWindowMenu.show_glx_server_tooltip"), true, this),
91 new ToggleActionEntry(ACTION_SHOW_GLX_CLIENT_INFO, null,
92 Messages.getString("GlxInfoWindowMenu.show_glx_client"), null,
93 Messages.getString("GlxInfoWindowMenu.show_glx_client_tooltip"), true, this),
94 new ToggleActionEntry(ACTION_SHOW_OPENGL_INFO, null,
95 Messages.getString("GlxInfoWindowMenu.show_opengl"), null,
96 Messages.getString("GlxInfoWindowMenu.show_opengl_tooltip"), true, this),
97 new ToggleActionEntry(ACTION_SHOW_GLU_INFO, null,
98 Messages.getString("GlxInfoWindowMenu.show_glu"), null,
99 Messages.getString("GlxInfoWindowMenu.show_glu_tooltip"), true, this),
100 new ToggleActionEntry(ACTION_SHOW_FRAMEBUFFER_INFO, null,
101 Messages.getString("GlxInfoWindowMenu.show_fb"), null,
102 Messages.getString("GlxInfoWindowMenu.show_fb_tooltip"), true, this), };
103
104
105
106
107 /***
108 * This string defines the structure of the MenuBar and the ToolBar.
109 */
110 private String uiInfo = "<ui>" + " <menubar name='MenuBar'>"
111 + " <menu action='fileMenu'>"
112 + " <menuitem action='" + ACTION_QUIT + "'/>"
113 + " </menu>"
114 + " <menu action='editMenu'>"
115 + " <menuitem action='" + ACTION_SEARCH_EXTENSIONS + "'/>"
116 + " </menu>"
117 + " <menu action='viewMenu'>"
118 + " <menuitem action='" + ACTION_REFRESH_GLXINFO + "'/>"
119 + " <menuitem action='" + ACTION_EXPAND_ALL + "'/>"
120 + " <separator/>"
121 + " <menuitem action='" + ACTION_SHOW_GLXINFO + "'/>"
122 + " <menuitem action='" + ACTION_SHOW_GLX_SERVER_INFO + "'/>"
123 + " <menuitem action='" + ACTION_SHOW_GLX_CLIENT_INFO + "'/>"
124 + " <menuitem action='" + ACTION_SHOW_OPENGL_INFO + "'/>"
125 + " <menuitem action='" + ACTION_SHOW_GLU_INFO + "'/>"
126 + " <separator/>"
127 + " <menuitem action='" + ACTION_SHOW_FRAMEBUFFER_INFO + "'/>"
128 + " <separator/>"
129
130
131 + " </menu>"
132 + " <menu action='helpMenu'>"
133 + " <menuitem action='" + ACTION_ABOUT + "'/>"
134 + " </menu>"
135 + " </menubar>"
136 + " <toolbar name='ToolBar'>"
137 + " <toolitem action='" + ACTION_SEARCH_EXTENSIONS + "'/>"
138 + " <toolitem action='" + ACTION_EXPAND_ALL + "'/>"
139 + " <toolitem action='" + ACTION_REFRESH_GLXINFO + "'/>"
140 + " <toolitem action='" + ACTION_QUIT + "'/>"
141 + " </toolbar>" + "</ui>";
142
143
144 /***
145 * Default Constructor
146 */
147 public GlxInfoWindowMenu(GlxInfoWindowImpl glxInfoDialog) {
148 this.glxInfoDialog = glxInfoDialog;
149 ActionGroup actionsGroup = new ActionGroup("Actions");
150 actionsGroup.addActions(entries);
151 actionsGroup.addToggleActions(toggleEntries);
152 actionsGroup.addToggleActions(toggleShowEntries);
153 UIManager ui = new UIManager();
154 ui.insertActionGroup(actionsGroup, 0);
155 glxInfoDialog.window.addAccelGroup(ui.getAccelGroup());
156 ui.addUIFromString(uiInfo);
157 menuBox.packStart(ui.getWidget("/MenuBar"), false, false, 0);
158 menuBox.packStart(ui.getWidget("/ToolBar"), false, false, 0);
159 }
160
161 public void setActions(GlxInfoWindowActions dialogActions) {
162 actions = dialogActions;
163 }
164
165
166
167
168
169
170 public void actionEvent(Action action) {
171 String actionName = action.getName();
172 if (actionName.equals(ACTION_REFRESH_GLXINFO)) {
173 actions.refreshGlxinfo();
174 } else if (actionName.equals(ACTION_SEARCH_EXTENSIONS)) {
175 actions.openSearchDialog();
176 } else if (actionName.equals(ACTION_ABOUT)) {
177 new AboutGlxinfoDialog();
178 } else if (actionName.equals(ACTION_QUIT)) {
179 Gtk.mainQuit();
180 }
181 }
182
183
184
185
186
187
188 public void actionEvent(ToggleAction action) {
189 String actionName = action.getName();
190 boolean isActived = action.getActive();
191 if (actionName.equals(ACTION_EXPAND_ALL)) {
192 actions.expandedAllExtensions(isActived);
193 } else if (actionName.equals(ACTION_SHOW_GLXINFO)) {
194 actions.setVisibility(glxInfoDialog.expanderGlx, isActived);
195 } else if (actionName.equals(ACTION_SHOW_GLX_CLIENT_INFO)) {
196 actions.setVisibility(glxInfoDialog.expanderGlxClient, isActived);
197 } else if (actionName.equals(ACTION_SHOW_GLX_SERVER_INFO)) {
198 actions.setVisibility(glxInfoDialog.expanderGlxServer, isActived);
199 } else if (actionName.equals(ACTION_SHOW_GLU_INFO)) {
200 actions.setVisibility(glxInfoDialog.expanderGlu, isActived);
201 } else if (actionName.equals(ACTION_SHOW_OPENGL_INFO)) {
202 actions.setVisibility(glxInfoDialog.expanderOpenGL, isActived);
203 } else if (actionName.equals(ACTION_SHOW_FRAMEBUFFER_INFO)) {
204 actions.setVisibility(glxInfoDialog.expanderFrameBuffer, isActived);
205 }
206
207
208
209
210
211
212
213
214
215 }
216
217 }