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  import net.sf.glxdesktop.gui.glade.LoadGladeException;
14  
15  import org.gnu.gdk.KeyValue;
16  import org.gnu.gtk.Gtk;
17  import org.gnu.gtk.event.KeyEvent;
18  import org.gnu.gtk.event.KeyListener;
19  import org.gnu.gtk.event.LifeCycleEvent;
20  import org.gnu.gtk.event.LifeCycleListener;
21  
22  public class GlxInfoWindowImpl extends GlxInfoWindow {
23  	
24  	public static final String APP_ICON = "pixmap/3ddesktop.png"; 
25  
26  	public GlxInfoWindowActions actions;
27  
28  	public GlxInfoWindowMenu menu;
29  
30  	protected String display;
31  
32  	protected String glxinfo;
33  
34  	public GlxInfoWindowImpl() throws LoadGladeException {
35  		setListeners();
36  		// TODO add method that retrive a real path from a given file name to 
37  		// Utils Class (like fileToString method.)
38  		window.setIconFromFile(ClassLoader.getSystemClassLoader().getResource(APP_ICON).getFile());
39  		menu = new GlxInfoWindowMenu(this);
40  		actions = new GlxInfoWindowActions(this);
41  		menu.setActions(actions);
42  		actions.refreshGlxinfo();
43  	}
44  	
45  	public void initGui() {
46  
47  		// Set general informations
48  		entryGlxDisplay.setText(actions.getDisplayName()); //$NON-NLS-1$ //$NON-NLS-2$);
49  		labelGlxScreen.setText(actions.getGlxinfoText(
50  				"screen:", "direct rendering:")); //$NON-NLS-1$ //$NON-NLS-2$);
51  		labelGlxDirectRedering.setText(actions.getI18nDirectRendering());
52  		// Set server Glx informations
53  		labelServerGlxVendor.setText(actions.getGlxinfoText(
54  				"server glx vendor string:", "server glx version")); //$NON-NLS-1$ //$NON-NLS-2$);
55  		labelServerGlxVersion.setText(actions.getGlxinfoText(
56  				"server glx version string:", "server glx extensions")); //$NON-NLS-1$ //$NON-NLS-2$);
57  		labelServerGlxExtensions.setText(actions.getGlxServerExtensions());
58  		// Set client Glx informations
59  		labelClientGlxVendor.setText(actions.getGlxinfoText(
60  				"client glx vendor string:", "client glx version")); //$NON-NLS-1$ //$NON-NLS-2$);
61  		labelClientGlxVersion.setText(actions.getGlxinfoText(
62  				"client glx version string:", "client glx extensions")); //$NON-NLS-1$ //$NON-NLS-2$);
63  		labelClientGlxExtensions.setText(actions.getGlxClientExtensions());
64  		// Set GLX infomations
65  		labelGlxVersion.setText(actions.getGlxinfoText(
66  				"GLX version:", "GLX extensions")); //$NON-NLS-1$ //$NON-NLS-2$);
67  		labelGlxExtensions.setText(actions.getGLXExtensions());
68  		// Set OpenGL informations
69  		labelOpenGLVendor.setText(actions.getGlxinfoText(
70  				"OpenGL vendor string:", "OpenGL renderer")); //$NON-NLS-1$ //$NON-NLS-2$);
71  		labelOpenGLRender.setText(actions.getGlxinfoText(
72  				"OpenGL renderer string:", "OpenGL version")); //$NON-NLS-1$ //$NON-NLS-2$);
73  		labelOpenGLVersion.setText(actions.getGlxinfoText(
74  				"OpenGL version string:", "OpenGL extensions")); //$NON-NLS-1$ //$NON-NLS-2$);
75  		labelOpenGLExtensions.setText(actions.getOpenGLExtensions());
76  		// Set GLU informations
77  		String gluExtensions = actions.getGLUExtensions();
78  		labelGluVersion.setText(actions.getGlxinfoText(
79  				"glu version:", "glu extensions")); //$NON-NLS-1$ //$NON-NLS-2$);
80  		if (!gluExtensions.equals("")) {
81  			labelGluExtensions.setText(gluExtensions);	
82  		} else {
83  			labelGluExtensions.setText(Messages.getString("GlxInfoWindowActions.no_dr_info"));
84  		
85  		}
86  		// set Frame Buffer TreeViewer
87  		actions.setGlxTableTreeViewer();
88  	}
89  
90  	private void setListeners() {
91  		window.addListener(new LifeCycleListener() {
92  
93  			/* (non-Javadoc)
94  			 * @see org.gnu.gtk.event.LifeCycleListener#lifeCycleEvent(org.gnu.gtk.event.LifeCycleEvent)
95  			 */
96  			public void lifeCycleEvent(LifeCycleEvent event) {
97  			}
98  
99  			/* (non-Javadoc)
100 			 * @see org.gnu.gtk.event.LifeCycleListener#lifeCycleQuery(org.gnu.gtk.event.LifeCycleEvent)
101 			 */
102 			public boolean lifeCycleQuery(LifeCycleEvent event) {
103 				if (event.isOfType(LifeCycleEvent.Type.DESTROY)
104 						|| event.isOfType(LifeCycleEvent.Type.DELETE)) 
105 					Gtk.mainQuit();
106 				return true;
107 			}
108 		});
109 
110 		entryGlxDisplay.addListener(new KeyListener() {
111 			
112 			/* (non-Javadoc)
113 			 * @see org.gnu.gtk.event.KeyListener#keyEvent(org.gnu.gtk.event.KeyEvent)
114 			 */
115 			public boolean keyEvent(KeyEvent event) {
116 				if (event.isOfType(KeyEvent.Type.KEY_PRESSED)) 
117 					if (event.getKeyval() == KeyValue.Return)
118 						actions.refreshGlxinfo();
119 				return false;
120 			}
121 		});
122 	}
123 
124 	public static void main(String[] args) {
125 		// Initialize Gtk and create the window...
126 		Gtk.init(args);
127 		try {
128 			new GlxInfoWindowImpl();
129 		} catch (LoadGladeException e) {
130 			e.printStackTrace();
131 		}
132 		Gtk.main();
133 	}
134 
135 }