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 import net.sf.glxdesktop.gui.glxinfo.dialog.GlxSearchDialog;
14 import net.sf.glxdesktop.gui.glxinfo.dialog.RunGlxinfoCmdDialog;
15 import net.sf.glxdesktop.parser.ConfigFileTools;
16
17 import org.gnu.gtk.CellRenderer;
18 import org.gnu.gtk.CellRendererText;
19 import org.gnu.gtk.DataColumn;
20 import org.gnu.gtk.DataColumnString;
21 import org.gnu.gtk.Expander;
22 import org.gnu.gtk.Label;
23 import org.gnu.gtk.TreeIter;
24 import org.gnu.gtk.TreeStore;
25 import org.gnu.gtk.TreeViewColumn;
26
27
28 public class GlxInfoWindowActions {
29
30 private static final String[] frameBufferTitles = { "Vis\nid", "Vis\ndepth", "Vis\ntype",
31 "trans\nparent", "buff\nsize", "lev\nel", "render\ntype", "DB", "ste\nreo", "r\nsz", "g\nsz",
32 "b\nsz", "a\nsz", "aux\nbuf", "dep\nth", "ste\nncl", "abr", "abg", "abb", "aba",
33 "MS\nnum", "MS\nbufs" };
34
35 private TreeViewColumn[] frameBufferColumn;
36
37 private String glxinfo;
38
39 private GlxInfoWindowImpl glxInfoDialog;
40
41 private GlxSearchDialog searchDialog;
42
43 public GlxInfoWindowActions(GlxInfoWindowImpl glxInfoDialog) {
44 this.glxInfoDialog = glxInfoDialog;
45 }
46
47 public void setGlxinfo(String glxinfo) {
48 this.glxinfo = glxinfo;
49 }
50
51 /***
52 * Get a i18n direct redering status string
53 *
54 * @return i18n string
55 */
56 public String getI18nDirectRendering() {
57 String render = getGlxinfoText("direct rendering:", "server glx vendor string:");
58 if (render.equalsIgnoreCase("No")) {
59 return Messages.getString("GlxInfoWindowImpl.drendering_false");
60 } else if (render.equalsIgnoreCase("Yes")) {
61 return Messages.getString("GlxInfoWindowImpl.drendering_true");
62 } else {
63 return Messages.getString("GlxInfoWindowActions.no_dr_info");
64 }
65 }
66
67 /***
68 *
69 * Get Glx information between two regexp
70 *
71 * @param beginRegexp
72 * @param endRegexp
73 * @return the String between the two regexp
74 */
75 public String getGlxinfoText(String beginRegexp, String endRegexp) {
76 String glxinfoStr = ConfigFileTools.findTextInInterval(glxinfo,
77 beginRegexp, endRegexp).trim();
78 if (!glxinfoStr.trim().equals(""))
79 return glxinfoStr;
80 else
81 return Messages.getString("GlxInfoWindowActions.no_info_for_diplay");
82 }
83
84 /***
85 * Get Display Name.
86 *
87 * @return the DISPLAY name.
88 */
89 public String getDisplayName() {
90 String glxinfoStr = ConfigFileTools.findTextInInterval(glxinfo,
91 "name of display:", "display.*screen").trim();
92 if (!glxinfoStr.trim().equals(""))
93 return glxinfoStr;
94 else
95 return glxInfoDialog.entryGlxDisplay.getText();
96 }
97
98 /***
99 * Get glx client extensions.
100 *
101 * @return glx client extensions string.
102 */
103 public String getGlxClientExtensions() {
104 return cleanExtensionsString(ConfigFileTools.findTextInInterval(
105 glxinfo, "client glx extensions:", "GLX version"));
106 }
107
108 /***
109 * Get glx server extensions.
110 *
111 * @return glx server extensions string.
112 */
113 public String getGlxServerExtensions() {
114 return cleanExtensionsString(ConfigFileTools.findTextInInterval(
115 glxinfo, "server glx extensions:", "client glx"));
116 }
117
118 /***
119 * Get GLX extensions.
120 *
121 * @return GLX extensions string.
122 */
123 public String getGLXExtensions() {
124 return cleanExtensionsString(ConfigFileTools.findTextInInterval(
125 glxinfo, "GLX extensions:", "OpenGL vendor"));
126 }
127
128 /***
129 * Get OpenGL extensions.
130 *
131 * @return OpenGL extensions string.
132 */
133 public String getOpenGLExtensions() {
134 return cleanExtensionsString(ConfigFileTools.findTextInInterval(
135 glxinfo, "OpenGL extensions:", "glu version| visual|Vis"));
136 }
137
138 /***
139 * Get glu extensions.
140 *
141 * @return glu extensions string.
142 */
143 public String getGLUExtensions() {
144 return cleanExtensionsString(ConfigFileTools.findTextInInterval(
145 glxinfo, "glu extensions:", " visual|Vis"));
146 }
147
148 public void openSearchDialog() {
149 if (searchDialog == null) {
150 searchDialog = new GlxSearchDialog(this);
151 } else {
152 refreshGlxinfo();
153 }
154 expandedAllExtensions(false);
155 searchDialog.show();
156 }
157
158 public void expandedAllExtensions(boolean bool) {
159 glxInfoDialog.expanderGlxClientExtensions.setExpanded(bool);
160 glxInfoDialog.expanderGlxServerExtensions.setExpanded(bool);
161 glxInfoDialog.expanderGlxExtensions.setExpanded(bool);
162 glxInfoDialog.expanderGluExtensions.setExpanded(bool);
163 glxInfoDialog.expanderOpenGLExtensions.setExpanded(bool);
164 glxInfoDialog.expanderGlxClientExtensions.unHighlight();
165 glxInfoDialog.expanderGlxServerExtensions.unHighlight();
166 glxInfoDialog.expanderGlxExtensions.unHighlight();
167 glxInfoDialog.expanderGluExtensions.unHighlight();
168 glxInfoDialog.expanderOpenGLExtensions.unHighlight();
169 }
170
171 public void refreshGlxinfo() {
172 String display;
173 if (!glxInfoDialog.entryGlxDisplay.getText().equals("")) {
174 display = glxInfoDialog.entryGlxDisplay.getText();
175 } else {
176 display = System.getenv("DISPLAY");
177 }
178 RunGlxinfoCmdDialog glxinfoCmd = new RunGlxinfoCmdDialog("glxinfo -t -display "
179 + display, glxInfoDialog, this);
180 glxinfoCmd.execute();
181 }
182
183 /***
184 * Set Frame Buffer configuration Tree viewer
185 */
186 public void setGlxTableTreeViewer() {
187
188
189 String[] rowsData = getGlxinfoText("--\n", "EOF").split("\n");
190
191 DataColumn[] columns = new DataColumn[frameBufferTitles.length];
192 for (int i = 0; i < frameBufferTitles.length; i++) {
193 DataColumnString dataString = new DataColumnString();
194 columns[i] = dataString;
195 }
196 TreeStore store = new TreeStore(columns);
197
198 for (int row = 0; row < rowsData.length; row++) {
199 String[] tableFields = rowsData[row]
200 .split("// |// |// |// |// ");
201 TreeIter iter = store.appendRow(null);
202 for (int field = 0; field < tableFields.length; field++) {
203 store.setValue(iter, (DataColumnString) columns[field],
204 tableFields[field].trim());
205 }
206 }
207
208 if (frameBufferColumn != null) {
209 for (int i = 0; i < frameBufferColumn.length; i++) {
210 glxInfoDialog.treeViewGlxTable
211 .removeColumn(frameBufferColumn[i]);
212 }
213 frameBufferColumn = null;
214 }
215 glxInfoDialog.treeViewGlxTable.setModel(store);
216 frameBufferColumn = new TreeViewColumn[frameBufferTitles.length];
217
218 for (int i = 0; i < frameBufferTitles.length; i++) {
219 frameBufferColumn[i] = new TreeViewColumn();
220 frameBufferColumn[i].setTitle(frameBufferTitles[i]);
221 frameBufferColumn[i].setSortColumn(columns[i]);
222 glxInfoDialog.treeViewGlxTable.appendColumn(frameBufferColumn[i]);
223 CellRenderer renderer = new CellRendererText();
224 frameBufferColumn[i].packStart(renderer, true);
225 frameBufferColumn[i].addAttributeMapping(renderer,
226 CellRendererText.Attribute.TEXT,
227 (DataColumnString) columns[i]);
228 }
229 }
230
231 /***
232 * Play with the exander visible propreties.
233 *
234 * @param expander
235 * to set.
236 * @param isVisible
237 * visibility stat to set.
238 */
239 public void setVisibility(Expander expander, boolean isVisible) {
240 if (isVisible) {
241 expander.show();
242 } else {
243 expander.hide();
244 }
245 }
246
247 /***
248 * This method expand and highlight ALL extentions Expander, if the given
249 * regexp search string is found. see {@link GlxInfoWindowActions}
250 * <code>makeFindResult</code> method for more informations.
251 *
252 * @param regexp
253 * to search.
254 * @param caseSensitive
255 * set this to true to make the search case sensitive.
256 */
257 public void searchExtensions(String regexp, boolean caseSensitive) {
258 makeSearchResult(regexp, caseSensitive,
259 glxInfoDialog.expanderGlxExtensions,
260 glxInfoDialog.labelGlxExtensions);
261 makeSearchResult(regexp, caseSensitive,
262 glxInfoDialog.expanderGluExtensions,
263 glxInfoDialog.labelGluExtensions);
264 makeSearchResult(regexp, caseSensitive,
265 glxInfoDialog.expanderGlxServerExtensions,
266 glxInfoDialog.labelServerGlxExtensions);
267 makeSearchResult(regexp, caseSensitive,
268 glxInfoDialog.expanderGlxClientExtensions,
269 glxInfoDialog.labelClientGlxExtensions);
270 makeSearchResult(regexp, caseSensitive,
271 glxInfoDialog.expanderOpenGLExtensions,
272 glxInfoDialog.labelOpenGLExtensions);
273 }
274
275 /***
276 * This method expand and highlight a extentions Expander, if the given
277 * regexp search string is found.
278 *
279 * @param regexp
280 * to search.
281 * @param caseSensitive
282 * set this to true to make the search case sensitive.
283 * @param expander
284 * the Exander that contain the glx extensions.
285 * @param label
286 * the Label that contain the glx extensions string.
287 */
288 private void makeSearchResult(String regexp, boolean caseSensitive,
289 Expander expander, Label label) {
290 String glxExtensions;
291 if (!caseSensitive) {
292 glxExtensions = label.getText().toUpperCase();
293 regexp = regexp.toUpperCase();
294 } else
295 glxExtensions = label.getText();
296
297 if (glxExtensions.contains(regexp)) {
298 String txt = label.getText().replaceAll(regexp,
299 "<b>" + regexp + "</b>");
300 txt = txt.replaceAll(regexp.toLowerCase(), "<b>"
301 + regexp.toLowerCase() + "</b>");
302 label.setMarkup(txt);
303 expander.setExpanded(true);
304 expander.highlight();
305 } else
306 expander.unHighlight();
307 }
308
309 private String cleanExtensionsString(String extentionsStr) {
310 extentionsStr = extentionsStr.replaceAll(" ", "").trim();
311 return extentionsStr.replaceAll(",", ", ").trim();
312 }
313 }