Mercurial > projects > dwt-samples
annotate examples/addressbook/SearchDialog.d @ 161:eb84f9418bbf
Change module names to this not have examples in the FQN.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 01 Sep 2008 22:24:27 +0200 |
parents | 9c2803aea121 |
children |
rev | line source |
---|---|
78 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2003 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 *******************************************************************************/ | |
161
eb84f9418bbf
Change module names to this not have examples in the FQN.
Frank Benoit <benoit@tionex.de>
parents:
82
diff
changeset
|
11 module addressbook.SearchDialog; |
78 | 12 |
13 | |
14 import dwt.DWT; | |
15 import dwt.events.ModifyEvent; | |
16 import dwt.events.ModifyListener; | |
17 import dwt.events.SelectionAdapter; | |
18 import dwt.events.SelectionEvent; | |
19 import dwt.events.ShellAdapter; | |
20 import dwt.events.ShellEvent; | |
21 import dwt.layout.FillLayout; | |
22 import dwt.layout.GridData; | |
23 import dwt.layout.GridLayout; | |
24 import dwt.widgets.Button; | |
25 import dwt.widgets.Combo; | |
26 import dwt.widgets.Composite; | |
27 import dwt.widgets.Group; | |
28 import dwt.widgets.Label; | |
29 import dwt.widgets.MessageBox; | |
30 import dwt.widgets.Shell; | |
31 import dwt.widgets.Text; | |
32 | |
161
eb84f9418bbf
Change module names to this not have examples in the FQN.
Frank Benoit <benoit@tionex.de>
parents:
82
diff
changeset
|
33 import addressbook.FindListener; |
78 | 34 |
35 import dwt.dwthelper.ResourceBundle; | |
36 | |
37 /** | |
38 * SearchDialog is a simple class that uses <code>org.eclipse.swt</code> | |
39 * libraries to implement a basic search dialog. | |
40 */ | |
41 public class SearchDialog { | |
42 | |
43 private static ResourceBundle resAddressBook; | |
44 | |
45 Shell shell; | |
46 Text searchText; | |
47 Combo searchArea; | |
48 Label searchAreaLabel; | |
49 Button matchCase; | |
50 Button matchWord; | |
51 Button findButton; | |
52 Button down; | |
53 FindListener findHandler; | |
54 | |
55 /** | |
56 * Class constructor that sets the parent shell and the table widget that | |
57 * the dialog will search. | |
58 * | |
59 * @param parent Shell | |
60 * The shell that is the parent of the dialog. | |
61 */ | |
82
9c2803aea121
Fix Addressbook example and HG ignores
Frank Benoit <benoit@tionex.de>
parents:
78
diff
changeset
|
62 public this(Shell parent, ResourceBundle bdl ) { |
78 | 63 if( resAddressBook is null ){ |
82
9c2803aea121
Fix Addressbook example and HG ignores
Frank Benoit <benoit@tionex.de>
parents:
78
diff
changeset
|
64 resAddressBook = bdl;//ResourceBundle.getBundle("examples_addressbook"); |
78 | 65 } |
66 shell = new Shell(parent, DWT.CLOSE | DWT.BORDER | DWT.TITLE); | |
67 GridLayout layout = new GridLayout(); | |
68 layout.numColumns = 2; | |
69 shell.setLayout(layout); | |
70 shell.setText(resAddressBook.getString("Search_dialog_title")); | |
71 shell.addShellListener(new class() ShellAdapter{ | |
72 public void shellClosed(ShellEvent e) { | |
73 // don't dispose of the shell, just hide it for later use | |
74 e.doit = false; | |
75 shell.setVisible(false); | |
76 } | |
77 }); | |
78 | |
79 Label label = new Label(shell, DWT.LEFT); | |
80 label.setText(resAddressBook.getString("Dialog_find_what")); | |
81 searchText = new Text(shell, DWT.BORDER); | |
82 GridData gridData = new GridData(GridData.FILL_HORIZONTAL); | |
83 gridData.widthHint = 200; | |
84 searchText.setLayoutData(gridData); | |
85 searchText.addModifyListener(new class() ModifyListener { | |
86 public void modifyText(ModifyEvent e) { | |
87 bool enableFind = (searchText.getCharCount() !is 0); | |
88 findButton.setEnabled(enableFind); | |
89 } | |
90 }); | |
91 | |
92 searchAreaLabel = new Label(shell, DWT.LEFT); | |
93 searchArea = new Combo(shell, DWT.DROP_DOWN | DWT.READ_ONLY); | |
94 gridData = new GridData(GridData.FILL_HORIZONTAL); | |
95 gridData.widthHint = 200; | |
96 searchArea.setLayoutData(gridData); | |
97 | |
98 matchCase = new Button(shell, DWT.CHECK); | |
99 matchCase.setText(resAddressBook.getString("Dialog_match_case")); | |
100 gridData = new GridData(); | |
101 gridData.horizontalSpan = 2; | |
102 matchCase.setLayoutData(gridData); | |
103 | |
104 matchWord = new Button(shell, DWT.CHECK); | |
105 matchWord.setText(resAddressBook.getString("Dialog_match_word")); | |
106 gridData = new GridData(); | |
107 gridData.horizontalSpan = 2; | |
108 matchWord.setLayoutData(gridData); | |
109 | |
110 Group direction = new Group(shell, DWT.NONE); | |
111 gridData = new GridData(); | |
112 gridData.horizontalSpan = 2; | |
113 direction.setLayoutData(gridData); | |
114 direction.setLayout (new FillLayout ()); | |
115 direction.setText(resAddressBook.getString("Dialog_direction")); | |
116 | |
117 Button up = new Button(direction, DWT.RADIO); | |
118 up.setText(resAddressBook.getString("Dialog_dir_up")); | |
119 up.setSelection(false); | |
120 | |
121 down = new Button(direction, DWT.RADIO); | |
122 down.setText(resAddressBook.getString("Dialog_dir_down")); | |
123 down.setSelection(true); | |
124 | |
125 Composite composite = new Composite(shell, DWT.NONE); | |
126 gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); | |
127 gridData.horizontalSpan = 2; | |
128 composite.setLayoutData(gridData); | |
129 layout = new GridLayout(); | |
130 layout.numColumns = 2; | |
131 layout.makeColumnsEqualWidth = true; | |
132 composite.setLayout(layout); | |
133 | |
134 findButton = new Button(composite, DWT.PUSH); | |
135 findButton.setText(resAddressBook.getString("Dialog_find")); | |
136 findButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); | |
137 findButton.setEnabled(false); | |
138 findButton.addSelectionListener(new class() SelectionAdapter { | |
139 public void widgetSelected(SelectionEvent e) { | |
140 if (!findHandler.find()){ | |
141 MessageBox box = new MessageBox(shell, DWT.ICON_INFORMATION | DWT.OK | DWT.PRIMARY_MODAL); | |
142 box.setText(shell.getText()); | |
143 box.setMessage(resAddressBook.getString("Cannot_find") ~ "\"" ~ searchText.getText() ~ "\""); | |
144 box.open(); | |
145 } | |
146 } | |
147 }); | |
148 | |
149 Button cancelButton = new Button(composite, DWT.PUSH); | |
150 cancelButton.setText(resAddressBook.getString("Cancel")); | |
151 cancelButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING)); | |
152 cancelButton.addSelectionListener(new class() SelectionAdapter { | |
153 public void widgetSelected(SelectionEvent e) { | |
154 shell.setVisible(false); | |
155 } | |
156 }); | |
157 | |
158 shell.pack(); | |
159 } | |
160 public char[] getSearchAreaLabel(char[] label) { | |
161 return searchAreaLabel.getText(); | |
162 } | |
163 | |
164 public char[][] getsearchAreaNames() { | |
165 return searchArea.getItems(); | |
166 } | |
167 public bool getMatchCase() { | |
168 return matchCase.getSelection(); | |
169 } | |
170 public bool getMatchWord() { | |
171 return matchWord.getSelection(); | |
172 } | |
173 public char[] getSearchString() { | |
174 return searchText.getText(); | |
175 } | |
176 public bool getSearchDown(){ | |
177 return down.getSelection(); | |
178 } | |
179 public int getSelectedSearchArea() { | |
180 return searchArea.getSelectionIndex(); | |
181 } | |
182 public void open() { | |
183 if (shell.isVisible()) { | |
184 shell.setFocus(); | |
185 } else { | |
186 shell.open(); | |
187 } | |
188 searchText.setFocus(); | |
189 } | |
190 public void setSearchAreaNames(char[][] names) { | |
191 for (int i = 0; i < names.length; i++) { | |
192 searchArea.add(names[i]); | |
193 } | |
194 searchArea.select(0); | |
195 } | |
196 public void setSearchAreaLabel(char[] label) { | |
197 searchAreaLabel.setText(label); | |
198 } | |
199 public void setMatchCase(bool match) { | |
200 matchCase.setSelection(match); | |
201 } | |
202 public void setMatchWord(bool match) { | |
203 matchWord.setSelection(match); | |
204 } | |
205 public void setSearchDown(bool searchDown){ | |
206 down.setSelection(searchDown); | |
207 } | |
208 public void setSearchString(char[] searchString) { | |
209 searchText.setText(searchString); | |
210 } | |
211 | |
212 public void setSelectedSearchArea(int index) { | |
213 searchArea.select(index); | |
214 } | |
215 public void addFindListener(FindListener listener) { | |
216 this.findHandler = listener; | |
217 } | |
218 public void removeFindListener(FindListener listener) { | |
219 this.findHandler = null; | |
220 } | |
221 } |