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.dialog;
12  
13  import org.gnu.gdk.KeyValue;
14  import org.gnu.glade.LibGlade;
15  import org.gnu.gtk.Button;
16  import org.gnu.gtk.CheckButton;
17  import org.gnu.gtk.Dialog;
18  import org.gnu.gtk.Entry;
19  import org.gnu.gtk.GtkStockItem;
20  import org.gnu.gtk.event.ButtonEvent;
21  import org.gnu.gtk.event.ButtonListener;
22  import org.gnu.gtk.event.KeyEvent;
23  import org.gnu.gtk.event.KeyListener;
24  import org.gnu.gtk.event.LifeCycleEvent;
25  import org.gnu.gtk.event.LifeCycleListener;
26  
27  import net.sf.glxdesktop.gui.glxinfo.GlxInfoWindowActions;
28  import net.sf.glxdesktop.gui.glxinfo.GlxInfoWindowImpl;
29  import net.sf.glxdesktop.gui.glxinfo.Messages;
30  
31  /***
32   * @author fons
33   * 
34   */
35  public class GlxSearchDialog {
36  	
37  	private GlxInfoWindowActions actions;
38  	
39  	protected static LibGlade glade = GlxInfoWindowImpl.glade;
40  	
41  	protected static Dialog dialogSearch = (Dialog) glade
42  	.getWidget("dialog_glxinfo_search"); //$NON-NLS-1$
43  	
44  	protected static Button buttonFindExtensions = (Button) glade
45  	.getWidget("button_extensions_search"); //$NON-NLS-1$
46  	
47  	protected static Button buttonCancel = (Button) glade
48  	.getWidget("cancel_button_search"); //$NON-NLS-1$
49  	
50  	protected static Entry entrySearch = (Entry) glade
51  	.getWidget("entry_glx_search"); //$NON-NLS-1$
52  	
53  	protected static CheckButton checkButtonCaseSensitive = (CheckButton) glade
54  	.getWidget("checkbutton_case_sensitive"); //$NON-NLS-1$
55  	
56  	public GlxSearchDialog(GlxInfoWindowActions actions) {
57  		this.actions = actions;
58  		dialogSearch.setTitle(Messages.getString("GlxSearchDialog.search_dialog_title")); //$NON-NLS-1$
59  		dialogSearch.setIconName(GtkStockItem.FIND.getString());
60  		setListeners();
61  	}
62  	
63  	/***
64  	 * Show dialog
65  	 */
66  	public void show() {
67  		entrySearch.activate();
68  		dialogSearch.show();
69  	}
70  	
71  	/***
72  	 * Hide dialog
73  	 */
74  	public void hide() {
75  		dialogSearch.hide();
76  	}
77  	
78  	private void setListeners() {
79  		dialogSearch.addListener(new LifeCycleListener() {
80  			public void lifeCycleEvent(LifeCycleEvent event) {
81  			}
82  			
83  			public boolean lifeCycleQuery(LifeCycleEvent event) {
84  				if (event.isOfType(LifeCycleEvent.Type.DESTROY)
85  						|| event.isOfType(LifeCycleEvent.Type.DELETE)) {
86  					hide();
87  				}
88  				return true;
89  			}
90  		});
91  		
92  		buttonFindExtensions.addListener(new ButtonListener() {
93  			public void buttonEvent(ButtonEvent event) {
94  				if (event.isOfType(ButtonEvent.Type.CLICK)) {
95  					searchExtensions();
96  				}
97  			}
98  		});
99  		
100 		buttonCancel.addListener(new ButtonListener() {
101 			public void buttonEvent(ButtonEvent event) {
102 				if (event.isOfType(ButtonEvent.Type.CLICK)) {
103 					hide();
104 				}
105 			}
106 		});
107 		
108 		entrySearch.addListener(new KeyListener() {
109 			
110 			public boolean keyEvent(KeyEvent event) {
111 				if (event.isOfType(KeyEvent.Type.KEY_PRESSED)) {
112 					if (event.getKeyval() == KeyValue.Return) {
113 						searchExtensions();
114 						return true;
115 					}
116 				}
117 				return false;
118 			}
119 		});
120 	}
121 	
122 	private void searchExtensions() {
123 		boolean isCaseSensitive = checkButtonCaseSensitive.getState();
124 		if (entrySearch.getText().trim().equals("")) { //$NON-NLS-1$
125 			actions.searchExtensions("IMPOSIBLE A TROUVER", isCaseSensitive); //$NON-NLS-1$
126 		} else {
127 			actions.searchExtensions(entrySearch.getText(), isCaseSensitive);
128 		}
129 		hide();
130 	}
131 	
132 
133 }