View Javadoc

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"); //$NON-NLS-1$
38  
39  	private static final String ACTION_SHOW_GLXINFO = "showGlxInfo"; //$NON-NLS-1$
40  
41  	private static final String ACTION_SHOW_GLX_SERVER_INFO = "showGlxServerInfo"; //$NON-NLS-1$
42  
43  	private static final String ACTION_SHOW_GLX_CLIENT_INFO = "showGlxClientInfo"; //$NON-NLS-1$
44  
45  	private static final String ACTION_SHOW_OPENGL_INFO = "showOpenGLInfo"; //$NON-NLS-1$
46  
47  	private static final String ACTION_SHOW_GLU_INFO = "showGLUInfo"; //$NON-NLS-1$
48  
49  	private static final String ACTION_SHOW_FRAMEBUFFER_INFO = "showFrameBufferInfo"; //$NON-NLS-1$
50  
51  	// private static final String ACTION_SHOW_ALL = "showAll"; //$NON-NLS-1$
52  
53  	private static final String ACTION_REFRESH_GLXINFO = "refreshGlxInfo"; //$NON-NLS-1$
54  
55  	private static final String ACTION_EXPAND_ALL = "expandALL"; //$NON-NLS-1$
56  
57  	private static final String ACTION_SEARCH_EXTENSIONS = "searchExtensions"; //$NON-NLS-1$
58  
59  	private static final String ACTION_QUIT = "quitAction"; //$NON-NLS-1$
60  
61  	private static final String ACTION_ABOUT = "aboutAction"; //$NON-NLS-1$
62  
63  	private ActionEntry[] entries = {
64  			new ActionEntry("fileMenu", null, Messages.getString("GlxInfoWindowMenu.file")), //$NON-NLS-1$ //$NON-NLS-2$
65  			new ActionEntry("editMenu", null, Messages.getString("GlxInfoWindowMenu.edit")), //$NON-NLS-1$ //$NON-NLS-2$
66  			new ActionEntry("viewMenu", null, Messages.getString("GlxInfoWindowMenu.view")), //$NON-NLS-1$ //$NON-NLS-2$
67  			new ActionEntry("helpMenu", null, Messages.getString("GlxInfoWindowMenu.help")), //$NON-NLS-1$ //$NON-NLS-2$
68  			new ActionEntry("toolBar", null, Messages.getString("GlxInfoWindowMenu.tool_bar")), //$NON-NLS-1$ //$NON-NLS-2$
69  			new ActionEntry(ACTION_REFRESH_GLXINFO, GtkStockItem.REFRESH
70  					.getString(), Messages.getString("GlxInfoWindowMenu.refresh"), null, //$NON-NLS-1$
71  					Messages.getString("GlxInfoWindowMenu.refresh_tooltip"), this), //$NON-NLS-1$
72  			new ActionEntry(ACTION_SEARCH_EXTENSIONS, GtkStockItem.FIND
73  					.getString(), Messages.getString("GlxInfoWindowMenu.search"), null, //$NON-NLS-1$
74  					Messages.getString("GlxInfoWindowMenu.search_tooltip"), this), //$NON-NLS-1$
75  			new ActionEntry(ACTION_QUIT, GtkStockItem.QUIT.getString(), Messages.getString("GlxInfoWindowMenu.quit"), //$NON-NLS-1$
76  					null, Messages.getString("GlxInfoWindowMenu.quit_tooltip"), this), //$NON-NLS-1$
77  			new ActionEntry(ACTION_ABOUT, GtkStockItem.ABOUT.getString(),
78  					Messages.getString("GlxInfoWindowMenu.about"), null, "About " + "tooltip txt", this), }; //$NON-NLS-1$ //$NON-NLS-3$
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), }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
83  
84  	private ToggleActionEntry[] toggleShowEntries = {
85  			new ToggleActionEntry(ACTION_SHOW_GLXINFO, null,
86  					Messages.getString("GlxInfoWindowMenu.show_glx"), null, //$NON-NLS-1$
87  					Messages.getString("GlxInfoWindowMenu.show_glx_tooltip"), true, this), //$NON-NLS-1$
88  			new ToggleActionEntry(ACTION_SHOW_GLX_SERVER_INFO, null,
89  					Messages.getString("GlxInfoWindowMenu.show_glx_server"), null, //$NON-NLS-1$
90  					Messages.getString("GlxInfoWindowMenu.show_glx_server_tooltip"), true, this), //$NON-NLS-1$
91  			new ToggleActionEntry(ACTION_SHOW_GLX_CLIENT_INFO, null,
92  					Messages.getString("GlxInfoWindowMenu.show_glx_client"), null, //$NON-NLS-1$
93  					Messages.getString("GlxInfoWindowMenu.show_glx_client_tooltip"), true, this), //$NON-NLS-1$
94  			new ToggleActionEntry(ACTION_SHOW_OPENGL_INFO, null,
95  					Messages.getString("GlxInfoWindowMenu.show_opengl"), null, //$NON-NLS-1$
96  					Messages.getString("GlxInfoWindowMenu.show_opengl_tooltip"), true, this), //$NON-NLS-1$
97  			new ToggleActionEntry(ACTION_SHOW_GLU_INFO, null,
98  					Messages.getString("GlxInfoWindowMenu.show_glu"), null, //$NON-NLS-1$
99  					Messages.getString("GlxInfoWindowMenu.show_glu_tooltip"), true, this), //$NON-NLS-1$
100 			new ToggleActionEntry(ACTION_SHOW_FRAMEBUFFER_INFO, null,
101 					Messages.getString("GlxInfoWindowMenu.show_fb"), null, //$NON-NLS-1$
102 					Messages.getString("GlxInfoWindowMenu.show_fb_tooltip"), true, this), }; //$NON-NLS-1$
103 
104 	// new ToggleActionEntry(ACTION_SHOW_ALL, null, "Show All informations",
105 	// null, "Show All informations tooltip txt", true, this),};
106 
107 	/***
108 	 * This string defines the structure of the MenuBar and the ToolBar.
109 	 */
110 	private String uiInfo = "<ui>" + "  <menubar name='MenuBar'>" //$NON-NLS-1$ //$NON-NLS-2$
111 			+ "    <menu action='fileMenu'>" //$NON-NLS-1$
112 			+ "      <menuitem action='" + ACTION_QUIT + "'/>" //$NON-NLS-1$ //$NON-NLS-2$
113 			+ "    </menu>" //$NON-NLS-1$
114 			+ "    <menu action='editMenu'>" //$NON-NLS-1$
115 			+ "      <menuitem action='" + ACTION_SEARCH_EXTENSIONS + "'/>" //$NON-NLS-1$ //$NON-NLS-2$
116 			+ "    </menu>" //$NON-NLS-1$
117 			+ "    <menu action='viewMenu'>" //$NON-NLS-1$
118 			+ "      <menuitem action='" + ACTION_REFRESH_GLXINFO + "'/>" //$NON-NLS-1$ //$NON-NLS-2$
119 			+ "      <menuitem action='" + ACTION_EXPAND_ALL + "'/>" //$NON-NLS-1$ //$NON-NLS-2$
120 			+ "      <separator/>" //$NON-NLS-1$
121 			+ "      <menuitem action='" + ACTION_SHOW_GLXINFO + "'/>" //$NON-NLS-1$ //$NON-NLS-2$
122 			+ "      <menuitem action='" + ACTION_SHOW_GLX_SERVER_INFO + "'/>" //$NON-NLS-1$ //$NON-NLS-2$
123 			+ "      <menuitem action='" + ACTION_SHOW_GLX_CLIENT_INFO + "'/>" //$NON-NLS-1$ //$NON-NLS-2$
124 			+ "      <menuitem action='" + ACTION_SHOW_OPENGL_INFO + "'/>" //$NON-NLS-1$ //$NON-NLS-2$
125 			+ "      <menuitem action='" + ACTION_SHOW_GLU_INFO + "'/>" //$NON-NLS-1$ //$NON-NLS-2$
126 			+ "      <separator/>" //$NON-NLS-1$
127 			+ "      <menuitem action='" + ACTION_SHOW_FRAMEBUFFER_INFO + "'/>" //$NON-NLS-1$ //$NON-NLS-2$
128 			+ "      <separator/>" //$NON-NLS-1$
129 			// + " <menuitem action='" + ACTION_SHOW_ALL + "'/>" //$NON-NLS-1$
130 			// //$NON-NLS-2$
131 			+ "    </menu>" //$NON-NLS-1$
132 			+ "    <menu action='helpMenu'>" //$NON-NLS-1$
133 			+ "      <menuitem action='" + ACTION_ABOUT + "'/>" //$NON-NLS-1$ //$NON-NLS-2$
134 			+ "    </menu>" //$NON-NLS-1$
135 			+ "  </menubar>" //$NON-NLS-1$
136 			+ "  <toolbar name='ToolBar'>" //$NON-NLS-1$
137 			+ "    <toolitem action='" + ACTION_SEARCH_EXTENSIONS + "'/>" //$NON-NLS-1$ //$NON-NLS-2$
138 			+ "    <toolitem action='" + ACTION_EXPAND_ALL + "'/>" //$NON-NLS-1$ //$NON-NLS-2$
139 			+ "    <toolitem action='" + ACTION_REFRESH_GLXINFO + "'/>" //$NON-NLS-1$ //$NON-NLS-2$
140 			+ "    <toolitem action='" + ACTION_QUIT + "'/>" //$NON-NLS-1$ //$NON-NLS-2$
141 			+ "  </toolbar>" + "</ui>"; //$NON-NLS-1$ //$NON-NLS-2$
142 
143 	
144 	/***
145 	 * Default Constructor
146 	 */
147 	public GlxInfoWindowMenu(GlxInfoWindowImpl glxInfoDialog) {
148 		this.glxInfoDialog = glxInfoDialog;
149 		ActionGroup actionsGroup = new ActionGroup("Actions"); //$NON-NLS-1$
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); //$NON-NLS-1$
158 		menuBox.packStart(ui.getWidget("/ToolBar"), false, false, 0); //$NON-NLS-1$
159 	}
160 
161 	public void setActions(GlxInfoWindowActions dialogActions) {
162 		actions = dialogActions;
163 	}
164 
165 	/*
166 	 * (non-Javadoc)
167 	 * 
168 	 * @see org.gnu.gtk.event.ActionEntryListener#actionEvent(org.gnu.gtk.Action)
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 	 * (non-Javadoc)
185 	 * 
186 	 * @see org.gnu.gtk.event.ToggleActionEntryListener#actionEvent(org.gnu.gtk.ToggleAction)
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 		// } else if (actionName.equals(ACTION_SHOW_ALL)){
207 		// setVisibility(glxInfoDialog.expanderGlx, isActived);
208 		// setVisibility(glxInfoDialog.expanderGlxClient, isActived);
209 		// setVisibility(glxInfoDialog.expanderGlxServer, isActived);
210 		// setVisibility(glxInfoDialog.expanderGlu, isActived);
211 		// setVisibility(glxInfoDialog.expanderOpenGL, isActived);
212 		// setVisibility(glxInfoDialog.expanderFrameBuffer, isActived);
213 		// }
214 
215 	}
216 
217 }