|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 package com.symbian.smt.gui.smtwidgets; |
|
17 |
|
18 import java.util.ArrayList; |
|
19 import java.util.Collection; |
|
20 import java.util.Collections; |
|
21 import java.util.HashSet; |
|
22 import java.util.List; |
|
23 |
|
24 import org.eclipse.swt.SWT; |
|
25 import org.eclipse.swt.events.ModifyEvent; |
|
26 import org.eclipse.swt.events.ModifyListener; |
|
27 import org.eclipse.swt.layout.FillLayout; |
|
28 import org.eclipse.swt.layout.GridData; |
|
29 import org.eclipse.swt.layout.GridLayout; |
|
30 import org.eclipse.swt.widgets.Button; |
|
31 import org.eclipse.swt.widgets.Combo; |
|
32 import org.eclipse.swt.widgets.Composite; |
|
33 import org.eclipse.swt.widgets.Label; |
|
34 |
|
35 import com.symbian.smt.gui.Helper; |
|
36 import com.symbian.smt.gui.PersistentDataStore; |
|
37 import com.symbian.smt.gui.smtwidgets.ValidModelEvent.Type; |
|
38 |
|
39 public class ModelControlWidget extends Composite implements |
|
40 ValidModelObservable { |
|
41 private Combo levelOfDetailCombo; |
|
42 private Combo printedDpiCombo; |
|
43 private Button highlightCoreOsButton; |
|
44 private Button suppressMouseOverEffectButton; |
|
45 private Button fixItemSizeButton; |
|
46 private Label fixedItemSizeLabel; |
|
47 private Label suppressMouseOverEffectsLabel; |
|
48 private Label printedDpiLabel; |
|
49 |
|
50 private ArrayList<ValidModelDefinedListener> listeners = new ArrayList<ValidModelDefinedListener>(); |
|
51 |
|
52 /** |
|
53 * Creates a ModelControlWidget composite object |
|
54 * |
|
55 * @return void |
|
56 */ |
|
57 public ModelControlWidget(final Composite parent, int style) { |
|
58 super(parent, style); |
|
59 |
|
60 this.setLayout(new FillLayout()); |
|
61 |
|
62 final Composite gridLayoutComposite = new Composite(this, SWT.NONE); |
|
63 final GridLayout gridLayout = new GridLayout(); |
|
64 gridLayout.verticalSpacing = 10; |
|
65 gridLayout.horizontalSpacing = 20; |
|
66 gridLayout.numColumns = 2; |
|
67 gridLayoutComposite.setLayout(gridLayout); |
|
68 |
|
69 final Label levelOfDetailLabel = new Label(gridLayoutComposite, |
|
70 SWT.NONE); |
|
71 levelOfDetailLabel.setText("Level of Detail"); |
|
72 |
|
73 levelOfDetailCombo = new Combo(gridLayoutComposite, SWT.READ_ONLY); |
|
74 GridData data = new GridData(200, SWT.DEFAULT); |
|
75 data.horizontalAlignment = SWT.LEFT; |
|
76 levelOfDetailCombo.setLayoutData(data); |
|
77 levelOfDetailCombo.setItems(new String[] { "layer", "block", |
|
78 "subblock", "collection", "component" }); |
|
79 |
|
80 printedDpiLabel = new Label(gridLayoutComposite, SWT.NONE); |
|
81 printedDpiLabel.setText("Printed Resolution (DPI)"); |
|
82 |
|
83 printedDpiCombo = new Combo(gridLayoutComposite, SWT.NONE); |
|
84 data = new GridData(50, SWT.DEFAULT); |
|
85 data.horizontalAlignment = SWT.LEFT; |
|
86 |
|
87 printedDpiCombo.setLayoutData(data); |
|
88 |
|
89 final Label highlightCoreOs = new Label(gridLayoutComposite, SWT.NONE); |
|
90 highlightCoreOs.setText("Highlight Core OS"); |
|
91 |
|
92 highlightCoreOsButton = new Button(gridLayoutComposite, SWT.CHECK); |
|
93 |
|
94 suppressMouseOverEffectsLabel = new Label(gridLayoutComposite, |
|
95 SWT.NONE); |
|
96 suppressMouseOverEffectsLabel.setText("Suppress Mouseover Effects"); |
|
97 |
|
98 suppressMouseOverEffectButton = new Button(gridLayoutComposite, |
|
99 SWT.CHECK); |
|
100 |
|
101 fixedItemSizeLabel = new Label(gridLayoutComposite, SWT.NONE); |
|
102 fixedItemSizeLabel.setText("Fix Items Size"); |
|
103 |
|
104 fixItemSizeButton = new Button(gridLayoutComposite, SWT.CHECK); |
|
105 } |
|
106 |
|
107 /** |
|
108 * @see com.symbian.smt.gui.smtwidgets.ValidModelObservable#addModelListener(ValidModelDefinedListener) |
|
109 */ |
|
110 public void addModelListener(ValidModelDefinedListener listener) { |
|
111 synchronized (listeners) { |
|
112 listeners.add(listener); |
|
113 } |
|
114 } |
|
115 |
|
116 private void checkDpi() { |
|
117 if (listeners.size() > 0) { |
|
118 Boolean modelDefined = true; |
|
119 String message = ""; |
|
120 Type type = Type.SUCCESS; |
|
121 |
|
122 String text = printedDpiCombo.getText().trim(); |
|
123 |
|
124 if (text.length() > 0) { |
|
125 try { |
|
126 Integer i = new Integer(text); |
|
127 |
|
128 if (i < 0) { |
|
129 throw new NumberFormatException(); |
|
130 } |
|
131 } catch (NumberFormatException nfe) { |
|
132 modelDefined = false; |
|
133 message = "The DPI value must be a positive integer less than 2147483648 or empty."; |
|
134 type = Type.ERROR; |
|
135 } |
|
136 } |
|
137 |
|
138 ValidModelEvent event = new ValidModelEvent(modelDefined, message, |
|
139 type); |
|
140 |
|
141 for (ValidModelDefinedListener listener : listeners) { |
|
142 listener.validModelDefined(event); |
|
143 } |
|
144 } |
|
145 } |
|
146 |
|
147 /** |
|
148 * This method is for PDE JUnit testing purposes. |
|
149 * |
|
150 * @return the fixedItemSizeLabel |
|
151 */ |
|
152 public Label getFixedItemSizeLabel() { |
|
153 return fixedItemSizeLabel; |
|
154 } |
|
155 |
|
156 /** |
|
157 * Returns a Boolean indicating if the Fix Items Size button has been |
|
158 * selected |
|
159 * |
|
160 * @return Boolean |
|
161 */ |
|
162 public Boolean getFixItemSize() { |
|
163 return fixItemSizeButton.getSelection(); |
|
164 } |
|
165 |
|
166 /** |
|
167 * This method is for PDE JUnit testing purposes. |
|
168 * |
|
169 * @return the fixItemSizeButton |
|
170 */ |
|
171 public Button getFixItemSizeButton() { |
|
172 return fixItemSizeButton; |
|
173 } |
|
174 |
|
175 /** |
|
176 * Returns a boolean value indicating if the Highlight Core OS button has |
|
177 * been selected |
|
178 * |
|
179 * @return Boolean |
|
180 */ |
|
181 public Boolean getHighlightCoreOS() { |
|
182 return highlightCoreOsButton.getSelection(); |
|
183 } |
|
184 |
|
185 /** |
|
186 * This method is for PDE JUnit testing purposes. |
|
187 * |
|
188 * @return the highlightCoreOsButton |
|
189 */ |
|
190 public Button getHighlightCoreOsButton() { |
|
191 return highlightCoreOsButton; |
|
192 } |
|
193 |
|
194 /** |
|
195 * Returns the level of detail |
|
196 * |
|
197 * @return String |
|
198 */ |
|
199 public String getLevelOfDetail() { |
|
200 return levelOfDetailCombo.getText(); |
|
201 } |
|
202 |
|
203 /** |
|
204 * This method is for PDE JUnit testing purposes. |
|
205 * |
|
206 * @return the levelOfDetailCombo |
|
207 */ |
|
208 public Combo getLevelOfDetailCombo() { |
|
209 return levelOfDetailCombo; |
|
210 } |
|
211 |
|
212 /** |
|
213 * This method is for PDE JUnit testing purposes. |
|
214 * |
|
215 * @return the listeners |
|
216 */ |
|
217 public ArrayList<ValidModelDefinedListener> getListeners() { |
|
218 return listeners; |
|
219 } |
|
220 |
|
221 /** |
|
222 * This method is for testing purposes only. |
|
223 * |
|
224 * @return |
|
225 */ |
|
226 public List<ValidModelDefinedListener> getModelListeners() { |
|
227 List<ValidModelDefinedListener> l; |
|
228 |
|
229 synchronized (listeners) { |
|
230 l = new ArrayList<ValidModelDefinedListener>(listeners); |
|
231 } |
|
232 |
|
233 return l; |
|
234 } |
|
235 |
|
236 /** |
|
237 * This method is for PDE JUnit testing purposes. |
|
238 * |
|
239 * @return the printedDpiCombo |
|
240 */ |
|
241 public Combo getPrintedDpiCombo() { |
|
242 return printedDpiCombo; |
|
243 } |
|
244 |
|
245 /** |
|
246 * This method is for PDE JUnit testing purposes. |
|
247 * |
|
248 * @return the printedDpiLabel |
|
249 */ |
|
250 public Label getPrintedDpiLabel() { |
|
251 return printedDpiLabel; |
|
252 } |
|
253 |
|
254 /** |
|
255 * Returns the printed DPI values. We need to take into account both the |
|
256 * list items and the item that the user may have typed in. We also need to |
|
257 * make sure that all items in the pulldown are sorted. |
|
258 * |
|
259 * @return String the list of all current DPI values, including the one that |
|
260 * the user may have typed in. |
|
261 */ |
|
262 public String[] getPrintedDpis() { |
|
263 Collection<Integer> c = new HashSet<Integer>(); |
|
264 List<String> items = Helper.toListOfStrings(printedDpiCombo.getItems()); |
|
265 |
|
266 for (String item : items) { |
|
267 c.add(new Integer(item)); |
|
268 } |
|
269 |
|
270 String text = printedDpiCombo.getText().trim(); |
|
271 |
|
272 if (text.length() > 0) { |
|
273 if (!items.contains(text)) { |
|
274 c.add(new Integer(text)); |
|
275 } |
|
276 } |
|
277 |
|
278 Integer[] allNumbers = new Integer[c.size()]; |
|
279 List<Integer> sortedNumbers = sort(c.toArray(allNumbers)); |
|
280 List<String> dpis = new ArrayList<String>(); |
|
281 |
|
282 for (Integer number : sortedNumbers) { |
|
283 dpis.add(number.toString()); |
|
284 } |
|
285 |
|
286 return dpis.toArray(new String[dpis.size()]); |
|
287 } |
|
288 |
|
289 /** |
|
290 * Returns the selected printed DPI value |
|
291 * |
|
292 * @return String |
|
293 */ |
|
294 public String getSelectedPrintedDpi() { |
|
295 return printedDpiCombo.getText(); |
|
296 } |
|
297 |
|
298 /** |
|
299 * Returns a boolean value indicating if the Suppress Mouseover Effects |
|
300 * button has been selected |
|
301 * |
|
302 * @return Boolean |
|
303 */ |
|
304 public Boolean getSuppressMouseOverEffect() { |
|
305 return suppressMouseOverEffectButton.getSelection(); |
|
306 } |
|
307 |
|
308 /** |
|
309 * This method is for PDE JUnit testing purposes. |
|
310 * |
|
311 * @return the suppressMouseOverEffectButton |
|
312 */ |
|
313 public Button getSuppressMouseOverEffectButton() { |
|
314 return suppressMouseOverEffectButton; |
|
315 } |
|
316 |
|
317 /** |
|
318 * This method is for PDE JUnit testing purposes. |
|
319 * |
|
320 * @return the suppressMouseOverEffectsLabel |
|
321 */ |
|
322 public Label getSuppressMouseOverEffectsLabel() { |
|
323 return suppressMouseOverEffectsLabel; |
|
324 } |
|
325 |
|
326 public void initialisePrintedDpi(PersistentDataStore store) { |
|
327 printedDpiCombo.setItems(store.getPrintedDpis()); |
|
328 printedDpiCombo.setText(store.getSelectedPrintedDpi()); |
|
329 |
|
330 printedDpiCombo.addModifyListener(new ModifyListener() { |
|
331 public void modifyText(ModifyEvent e) { |
|
332 checkDpi(); |
|
333 } |
|
334 }); |
|
335 } |
|
336 |
|
337 /** |
|
338 * @see com.symbian.smt.gui.smtwidgets.ValidModelObservable#removeModelListener(ValidModelDefinedListener) |
|
339 */ |
|
340 public void removeModelListener(ValidModelDefinedListener listener) { |
|
341 synchronized (listeners) { |
|
342 listeners.remove(listener); |
|
343 } |
|
344 } |
|
345 |
|
346 /** |
|
347 * Sets the value for the Fix Items Size button |
|
348 * |
|
349 * @param fixItemSize |
|
350 * Boolean indicating if the Fix Items Size is to be used when |
|
351 * generating the diagram |
|
352 * @return void |
|
353 */ |
|
354 public void setFixItemSize(Boolean fixItemSize) { |
|
355 fixItemSizeButton.setSelection(fixItemSize); |
|
356 } |
|
357 |
|
358 /** |
|
359 * Sets the value for the Highlight Core OS button |
|
360 * |
|
361 * @param HighlightCoreOS |
|
362 * Boolean value indicating if the Core OS section is to be |
|
363 * highlighted |
|
364 * @return void |
|
365 */ |
|
366 public void setHighlightCoreOS(Boolean HighlightCoreOS) { |
|
367 highlightCoreOsButton.setSelection(HighlightCoreOS); |
|
368 } |
|
369 |
|
370 /** |
|
371 * Sets the level of detail |
|
372 * |
|
373 * @param level |
|
374 * The level of detail to set. |
|
375 * @return void |
|
376 */ |
|
377 public void setLevelOfDetail(String level) { |
|
378 String[] items = levelOfDetailCombo.getItems(); |
|
379 int index = 0; |
|
380 |
|
381 for (String item : items) { |
|
382 if (item.equals(level)) { |
|
383 break; |
|
384 } |
|
385 index++; |
|
386 } |
|
387 |
|
388 levelOfDetailCombo.select(index); |
|
389 } |
|
390 |
|
391 /** |
|
392 * Sets the printed DPI values |
|
393 * |
|
394 * @param dpi |
|
395 * The DPI values to populate the combo box with. |
|
396 * @return void |
|
397 */ |
|
398 public void setPrintedDpis(String[] dpis) { |
|
399 printedDpiCombo.setItems(dpis); |
|
400 } |
|
401 |
|
402 /** |
|
403 * Sets the selected printed DPI value |
|
404 * |
|
405 * @param dpi |
|
406 * The DPI value to set as selected. |
|
407 * @return void |
|
408 */ |
|
409 public void setSelectedPrintedDpi(String dpi) { |
|
410 String[] items = printedDpiCombo.getItems(); |
|
411 int index = 0; |
|
412 |
|
413 for (String item : items) { |
|
414 if (item.equals(dpi)) { |
|
415 break; |
|
416 } |
|
417 |
|
418 index++; |
|
419 } |
|
420 |
|
421 printedDpiCombo.select(index); |
|
422 } |
|
423 |
|
424 /** |
|
425 * Sets the value for the Suppress Mouseover Effects button |
|
426 * |
|
427 * @param suppressMouseOverEffect |
|
428 * Boolean value indicating if the Suppress Mouseover Effects is |
|
429 * it be used when generating the diagram |
|
430 * @return void |
|
431 */ |
|
432 public void setSuppressMouseOverEffect(Boolean suppressMouseOverEffect) { |
|
433 suppressMouseOverEffectButton.setSelection(suppressMouseOverEffect); |
|
434 } |
|
435 |
|
436 private List<Integer> sort(Integer[] numbers) { |
|
437 ArrayList<Integer> al = new ArrayList<Integer>(); |
|
438 |
|
439 for (int i = 0; i < numbers.length; i++) { |
|
440 al.add(i, (numbers[i])); |
|
441 } |
|
442 |
|
443 List<Integer> list = Collections.synchronizedList(al); |
|
444 Collections.sort(list); |
|
445 |
|
446 return list; |
|
447 } |
|
448 |
|
449 } |