Commit | Line | Data |
---|---|---|
a55887ca | 1 | /********************************************************************** |
df0b8ff4 BH |
2 | * Copyright (c) 2005, 2008 IBM Corporation and others. |
3 | * Copyright (c) 2011, 2012 Ericsson. | |
a55887ca AM |
4 | * |
5 | * All rights reserved. This program and the accompanying materials | |
6 | * are made available under the terms of the Eclipse Public License v1.0 | |
7 | * which accompanies this distribution, and is available at | |
8 | * http://www.eclipse.org/legal/epl-v10.html | |
9 | * | |
10 | * Contributors: | |
73005152 | 11 | * IBM - Initial API and implementation |
a55887ca | 12 | * Bernd Hufmann - Updated for TMF |
73005152 | 13 | **********************************************************************/ |
df0b8ff4 | 14 | package org.eclipse.linuxtools.tmf.ui.views.uml2sd.dialogs; |
73005152 BH |
15 | |
16 | import java.text.MessageFormat; | |
17 | import java.util.Arrays; | |
18 | ||
19 | import org.eclipse.jface.dialogs.MessageDialog; | |
20 | import org.eclipse.jface.wizard.WizardPage; | |
73005152 BH |
21 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.DiagramToolTip; |
22 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.NGC; | |
23 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDWidget; | |
df0b8ff4 | 24 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.util.SDMessages; |
73005152 BH |
25 | import org.eclipse.swt.SWT; |
26 | import org.eclipse.swt.events.FocusEvent; | |
27 | import org.eclipse.swt.events.FocusListener; | |
28 | import org.eclipse.swt.events.KeyEvent; | |
29 | import org.eclipse.swt.events.ModifyEvent; | |
30 | import org.eclipse.swt.events.ModifyListener; | |
31 | import org.eclipse.swt.events.MouseEvent; | |
32 | import org.eclipse.swt.events.MouseTrackListener; | |
33 | import org.eclipse.swt.events.SelectionEvent; | |
34 | import org.eclipse.swt.events.SelectionListener; | |
35 | import org.eclipse.swt.events.TraverseEvent; | |
36 | import org.eclipse.swt.events.TraverseListener; | |
37 | import org.eclipse.swt.graphics.GC; | |
38 | import org.eclipse.swt.graphics.Image; | |
39 | import org.eclipse.swt.graphics.ImageData; | |
40 | import org.eclipse.swt.graphics.RGB; | |
41 | import org.eclipse.swt.graphics.Rectangle; | |
42 | import org.eclipse.swt.layout.GridData; | |
43 | import org.eclipse.swt.layout.GridLayout; | |
44 | import org.eclipse.swt.printing.PrintDialog; | |
45 | import org.eclipse.swt.printing.Printer; | |
46 | import org.eclipse.swt.printing.PrinterData; | |
47 | import org.eclipse.swt.widgets.Button; | |
48 | import org.eclipse.swt.widgets.Composite; | |
49 | import org.eclipse.swt.widgets.Control; | |
50 | import org.eclipse.swt.widgets.Display; | |
51 | import org.eclipse.swt.widgets.Group; | |
52 | import org.eclipse.swt.widgets.Label; | |
53 | import org.eclipse.swt.widgets.Shell; | |
54 | import org.eclipse.swt.widgets.Text; | |
55 | ||
56 | /** | |
df0b8ff4 | 57 | * The class implements the actual print dialog UI for collecting printing data. |
a55887ca | 58 | * |
df0b8ff4 | 59 | * @version 1.0 |
73005152 BH |
60 | * @author sveyrier |
61 | */ | |
62 | public class SDPrintDialogUI { | |
df0b8ff4 BH |
63 | // ------------------------------------------------------------------------ |
64 | // Attributes | |
65 | // ------------------------------------------------------------------------ | |
66 | /** | |
a55887ca | 67 | * The set horizontal pages number. |
df0b8ff4 | 68 | */ |
eb63f5ff | 69 | protected Button fSetHPagesNumber; |
df0b8ff4 | 70 | /** |
a55887ca | 71 | * The set vertical pages number. |
df0b8ff4 | 72 | */ |
eb63f5ff | 73 | protected Button fSetVPagesNumber; |
df0b8ff4 | 74 | /** |
a55887ca | 75 | * Flag whether to use current zoom or not. |
df0b8ff4 | 76 | */ |
eb63f5ff | 77 | protected Button fUseCurrentZoom; |
df0b8ff4 BH |
78 | /** |
79 | * Flag whether to print all pages or not | |
80 | */ | |
eb63f5ff | 81 | protected Button fAllPages; |
df0b8ff4 BH |
82 | /** |
83 | * Flag whether to print current page only | |
84 | */ | |
eb63f5ff | 85 | protected Button fCurrentPage; |
df0b8ff4 BH |
86 | /** |
87 | * Button to select a page list. | |
88 | */ | |
eb63f5ff | 89 | protected Button fPageList; |
df0b8ff4 BH |
90 | /** |
91 | * Button to select a page range. | |
92 | */ | |
eb63f5ff | 93 | protected Button fPageRange; |
df0b8ff4 BH |
94 | /** |
95 | * Text field to enter from page. | |
96 | */ | |
eb63f5ff | 97 | protected Text fFromPage; |
df0b8ff4 BH |
98 | /** |
99 | * Text field to enter to page. | |
100 | */ | |
eb63f5ff | 101 | protected Text fToPage; |
df0b8ff4 | 102 | /** |
a55887ca | 103 | * The sequence diagram widget reference. |
df0b8ff4 | 104 | */ |
eb63f5ff | 105 | protected SDWidget fSdView; |
df0b8ff4 BH |
106 | /** |
107 | * Text field for number of horizontal pages | |
108 | */ | |
eb63f5ff | 109 | protected Text fHorPagesNum; |
df0b8ff4 BH |
110 | /** |
111 | * Text field for number of vertical pages | |
112 | */ | |
eb63f5ff | 113 | protected Text fVertPagesNum; |
df0b8ff4 BH |
114 | /** |
115 | * Text field for toal number of pages | |
116 | */ | |
eb63f5ff | 117 | protected Text fTotalPages; |
df0b8ff4 | 118 | /** |
a55887ca | 119 | * A modify listener implementation to handle modifications. |
df0b8ff4 | 120 | */ |
eb63f5ff | 121 | protected ModifyListener fModifyListener; |
df0b8ff4 BH |
122 | /** |
123 | * A selection listener implementation to handle selections. | |
124 | */ | |
eb63f5ff | 125 | protected SelectionListener fSelectionListener; |
df0b8ff4 BH |
126 | /** |
127 | * Local canvas displaying sequence diagram overview. | |
128 | */ | |
eb63f5ff | 129 | protected LocalSD fOverviewCanvas; |
df0b8ff4 BH |
130 | /** |
131 | * Number of pages | |
132 | */ | |
eb63f5ff | 133 | protected int fNbPages = 0; |
df0b8ff4 BH |
134 | /** |
135 | * Number of selected pages. | |
136 | */ | |
eb63f5ff | 137 | protected int fPageNum = -1; |
df0b8ff4 | 138 | /** |
a55887ca | 139 | * Number of first page. |
df0b8ff4 | 140 | */ |
eb63f5ff | 141 | protected int fFirstPage = -1; |
df0b8ff4 BH |
142 | /** |
143 | * List of pages to print. | |
144 | */ | |
eb63f5ff | 145 | protected int fPagesList[]; |
a0a88f65 AM |
146 | |
147 | /** | |
148 | * Value for dividing the sequence diagram into pages | |
149 | */ | |
150 | protected float fStepX; | |
151 | ||
df0b8ff4 | 152 | /** |
a0a88f65 | 153 | * Value for dividing the sequence diagram into pages |
df0b8ff4 | 154 | */ |
a0a88f65 AM |
155 | protected float fStepY; |
156 | ||
157 | /** | |
158 | * Value for dividing the sequence diagram into pages | |
159 | */ | |
160 | protected float sTX; | |
161 | ||
162 | /** | |
163 | * Value for dividing the sequence diagram into pages | |
164 | */ | |
165 | protected float sTY; | |
166 | ||
df0b8ff4 | 167 | /** |
a55887ca | 168 | * Page which to print from. |
df0b8ff4 | 169 | */ |
eb63f5ff | 170 | protected int fFrom; |
df0b8ff4 | 171 | /** |
a55887ca | 172 | * Page which to print to. |
df0b8ff4 | 173 | */ |
eb63f5ff | 174 | protected int fTo; |
df0b8ff4 BH |
175 | /** |
176 | * Flag for enabling multi-selection. | |
177 | */ | |
eb63f5ff | 178 | protected boolean fMultiSelection = false; |
df0b8ff4 BH |
179 | /** |
180 | * Flag for enabling area selection. | |
181 | */ | |
eb63f5ff | 182 | protected boolean fAreaSelection = false; |
df0b8ff4 BH |
183 | /** |
184 | * Flag for printing all. | |
185 | */ | |
eb63f5ff | 186 | protected boolean fPrintAll; |
df0b8ff4 BH |
187 | /** |
188 | * Flag for printing current page only. | |
189 | */ | |
eb63f5ff | 190 | protected boolean fPrintCurrent; |
df0b8ff4 BH |
191 | /** |
192 | * Flag for printing a selection of pages. | |
193 | */ | |
eb63f5ff | 194 | protected boolean fPrintSelection; |
df0b8ff4 BH |
195 | /** |
196 | * Flag for printing a range of pages. | |
197 | */ | |
eb63f5ff | 198 | protected boolean fPrintRange; |
df0b8ff4 BH |
199 | /** |
200 | * Number of selected rows | |
201 | */ | |
eb63f5ff | 202 | protected int fNbRows; |
df0b8ff4 BH |
203 | /** |
204 | * Number of selected lines | |
205 | */ | |
eb63f5ff | 206 | protected int fNbLines; |
df0b8ff4 BH |
207 | /** |
208 | * The zoom factor. | |
209 | */ | |
eb63f5ff | 210 | protected float fZoomFactor; |
df0b8ff4 | 211 | /** |
a55887ca | 212 | * The printer data reference. |
df0b8ff4 | 213 | */ |
eb63f5ff | 214 | protected PrinterData fPrinterData; |
df0b8ff4 BH |
215 | /** |
216 | * The diagram tooltip to show if necessary. | |
217 | */ | |
eb63f5ff | 218 | protected DiagramToolTip fToolTip = null; |
df0b8ff4 BH |
219 | /** |
220 | * Label for current selection. | |
221 | */ | |
eb63f5ff | 222 | protected Label fCurrentSelection; |
df0b8ff4 BH |
223 | /** |
224 | * The shell reference. | |
225 | */ | |
eb63f5ff | 226 | protected Shell fShell; |
df0b8ff4 BH |
227 | /** |
228 | * Button to open printer dialog from OS. | |
229 | */ | |
eb63f5ff | 230 | protected Button fPrinterDialog; |
df0b8ff4 | 231 | /** |
eb63f5ff | 232 | * Flag for showing print button. |
df0b8ff4 | 233 | */ |
eb63f5ff | 234 | protected boolean fShowPrintButton; |
df0b8ff4 | 235 | /** |
a55887ca | 236 | * Test value |
df0b8ff4 | 237 | */ |
eb63f5ff | 238 | protected int fTest = 3; |
df0b8ff4 BH |
239 | /** |
240 | * Parent wizard page if used as wizard | |
241 | */ | |
eb63f5ff | 242 | protected WizardPage fParentWizardPage = null; |
df0b8ff4 | 243 | /** |
a55887ca | 244 | * Reference to parent print dialog. |
df0b8ff4 | 245 | */ |
eb63f5ff | 246 | protected SDPrintDialog fParentDialog = null; |
73005152 | 247 | |
df0b8ff4 BH |
248 | // ------------------------------------------------------------------------ |
249 | // Helper Class | |
250 | // ------------------------------------------------------------------------ | |
251 | /** | |
252 | * Local sequence diagram widget used to display overview of sequence diagram to print. | |
a55887ca | 253 | * @version 1.0 |
df0b8ff4 | 254 | */ |
73005152 BH |
255 | protected class LocalSD extends SDWidget { |
256 | ||
df0b8ff4 BH |
257 | /** |
258 | * Constructor | |
259 | * @param c Parent composite | |
260 | * @param s Style bits | |
261 | */ | |
262 | public LocalSD(Composite c, int s) { | |
263 | super(c, s); | |
264 | } | |
265 | ||
266 | /* | |
267 | * (non-Javadoc) | |
268 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#getContentsHeight() | |
269 | */ | |
73005152 BH |
270 | @Override |
271 | public int getContentsHeight() { | |
eb63f5ff BH |
272 | if (fSdView.getContentsHeight() > fSdView.getContentsHeight()) { |
273 | return (int) (fSdView.getVisibleHeight() / (float) fTest / fSdView.fZoomValue); | |
df0b8ff4 | 274 | } |
abbdd66a | 275 | return super.getContentsHeight(); |
73005152 BH |
276 | } |
277 | ||
df0b8ff4 BH |
278 | /* |
279 | * (non-Javadoc) | |
280 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#getContentsWidth() | |
281 | */ | |
73005152 BH |
282 | @Override |
283 | public int getContentsWidth() { | |
eb63f5ff BH |
284 | if (fSdView.getVisibleWidth() > fSdView.getContentsWidth()) { |
285 | return (int) (fSdView.getVisibleWidth() / (float) fTest / fSdView.fZoomValue); | |
df0b8ff4 | 286 | } |
abbdd66a | 287 | return super.getContentsWidth(); |
73005152 BH |
288 | } |
289 | ||
df0b8ff4 BH |
290 | /* |
291 | * (non-Javadoc) | |
292 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDWidget#contentsMouseHover(org.eclipse.swt.events.MouseEvent) | |
293 | */ | |
73005152 BH |
294 | @Override |
295 | protected void contentsMouseHover(MouseEvent event) { | |
296 | } | |
297 | ||
df0b8ff4 BH |
298 | /** |
299 | * Creates page selection images. | |
a55887ca | 300 | * |
df0b8ff4 BH |
301 | * @param img - Overview image |
302 | * @param width -The width value | |
303 | * @param stepX - Step X | |
304 | * @param height - Height value | |
305 | * @param stepY - Step Y | |
306 | * @return new image | |
307 | */ | |
73005152 BH |
308 | protected Image createPagesSelectionImages(Image img, int width, float stepX, int height, float stepY) { |
309 | ||
310 | Image over = new Image(super.getShell().getDisplay(), img.getImageData()); | |
311 | ||
eb63f5ff | 312 | for (int pageIndex = 0; pageIndex < fPagesList.length; pageIndex++) { |
73005152 | 313 | |
eb63f5ff | 314 | int pageNum = fPagesList[pageIndex]; |
df0b8ff4 | 315 | |
73005152 BH |
316 | if (getPagesForSelection() > 0 && pageNum > 0) { |
317 | int line = pageNum / getNbRow(); | |
318 | int row = pageNum % getNbRow(); | |
df0b8ff4 | 319 | if (row != 0) { |
73005152 | 320 | line++; |
df0b8ff4 | 321 | } else { |
73005152 | 322 | row = getNbRow(); |
df0b8ff4 | 323 | } |
73005152 BH |
324 | |
325 | line--; | |
326 | row--; | |
327 | ||
328 | Image toDel = over; | |
eb63f5ff BH |
329 | if (fOverviewCanvas.isFocusControl()) { |
330 | over = new Image(super.getShell().getDisplay(), drawRegionSelected(toDel, new Rectangle(contentsToViewX((int) (row * stepX * fOverviewCanvas.fZoomValue)), contentsToViewY((int) (line * stepY * fOverviewCanvas.fZoomValue)), | |
331 | ((int) (stepX * fOverviewCanvas.fZoomValue)), ((int) (stepY * fOverviewCanvas.fZoomValue))), new RGB(0, 0, 128))); | |
df0b8ff4 | 332 | } else { |
eb63f5ff BH |
333 | over = new Image(super.getShell().getDisplay(), drawRegionSelected(toDel, new Rectangle(contentsToViewX((int) (row * stepX * fOverviewCanvas.fZoomValue)), contentsToViewY((int) (line * stepY * fOverviewCanvas.fZoomValue)), |
334 | ((int) (stepX * fOverviewCanvas.fZoomValue)), ((int) (stepY * fOverviewCanvas.fZoomValue))), new RGB(221, 208, 200))); | |
df0b8ff4 | 335 | } |
73005152 BH |
336 | toDel.dispose(); |
337 | } | |
338 | } | |
339 | ||
eb63f5ff BH |
340 | Arrays.sort(fPagesList); |
341 | int pos = Arrays.binarySearch(fPagesList, fPageNum); | |
342 | if ((pos < 0) && (getPagesForSelection() > 0 && fPageNum > 0)) { | |
343 | int line = fPageNum / getNbRow(); | |
344 | int row = fPageNum % getNbRow(); | |
345 | if (row != 0) { | |
346 | line++; | |
347 | } else { | |
348 | row = getNbRow(); | |
349 | } | |
73005152 | 350 | |
eb63f5ff BH |
351 | line--; |
352 | row--; | |
73005152 | 353 | |
eb63f5ff BH |
354 | Image toDel = over; |
355 | over = new Image(super.getShell().getDisplay(), drawRegionSelected(toDel, new Rectangle(contentsToViewX((int) (row * stepX * fOverviewCanvas.fZoomValue)), contentsToViewY((int) (line * stepY * fOverviewCanvas.fZoomValue)), | |
356 | ((int) (stepX * fOverviewCanvas.fZoomValue)), ((int) (stepY * fOverviewCanvas.fZoomValue))), new RGB(221, 208, 200))); | |
357 | toDel.dispose(); | |
358 | } | |
73005152 BH |
359 | |
360 | GC imGC2 = new GC(over); | |
361 | imGC2.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK)); | |
eb63f5ff | 362 | NGC imGC = new NGC(fOverviewCanvas, imGC2); |
df0b8ff4 | 363 | for (int i = 0, x = 0; x <= width && stepX > 0; i++, x = (int) (i * stepX)) { |
73005152 | 364 | imGC.drawLine(x, 0, x, height); |
df0b8ff4 | 365 | } |
73005152 | 366 | |
df0b8ff4 | 367 | for (int j = 0, y = 0; y <= height && stepY > 0; j++, y = (int) (j * stepY)) { |
73005152 | 368 | imGC.drawLine(0, y, width, y); |
df0b8ff4 | 369 | } |
73005152 BH |
370 | |
371 | imGC2.dispose(); | |
372 | imGC.dispose(); | |
373 | return over; | |
374 | } | |
a55887ca | 375 | |
df0b8ff4 BH |
376 | /* |
377 | * (non-Javadoc) | |
378 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDWidget#drawContents(org.eclipse.swt.graphics.GC, int, int, int, int) | |
379 | */ | |
73005152 BH |
380 | @Override |
381 | protected void drawContents(GC gc, int clipx, int clipy, int clipw, int cliph) { | |
382 | ||
df0b8ff4 | 383 | Image dbuffer = getDrawBuffer(); |
73005152 BH |
384 | computeStepXY(); |
385 | Image d; | |
386 | ||
eb63f5ff | 387 | int lw = (int) (getContentsWidth() / fZoomValue); |
df0b8ff4 | 388 | if (getContentsWidth() < getVisibleWidth()) { |
eb63f5ff | 389 | lw = (int) (getVisibleWidth() / fZoomValue); |
df0b8ff4 | 390 | } |
73005152 | 391 | |
eb63f5ff | 392 | int lh = (int) (getContentsHeight() / fZoomValue); |
df0b8ff4 | 393 | if (getContentsHeight() < getVisibleHeight()) { |
eb63f5ff | 394 | lh = (int) (getVisibleHeight() / fZoomValue); |
df0b8ff4 | 395 | } |
eb63f5ff | 396 | d = createPagesSelectionImages(dbuffer, lw, fStepX, lh, fStepY); |
73005152 BH |
397 | |
398 | if (!isEnabled()) { | |
399 | Image toDel = d; | |
400 | d = new Image(super.getShell().getDisplay(), drawRegionSelected(d, new Rectangle(0, 0, lw, lh), new RGB(221, 208, 200))); | |
73005152 BH |
401 | toDel.dispose(); |
402 | } | |
403 | ||
404 | Rectangle area = getClientArea(); | |
405 | int w = d.getBounds().width; | |
406 | int h = d.getBounds().height; | |
407 | gc.drawImage(d, 0, 0, w, h, 0, 0, area.width, area.height); | |
408 | ||
eb63f5ff | 409 | fTotalPages.setText(Integer.valueOf(maxNumOfPages()).toString()); |
73005152 BH |
410 | displayPageNum(); |
411 | dbuffer.dispose(); | |
412 | d.dispose(); | |
413 | gc.dispose(); | |
414 | ||
415 | } | |
416 | ||
df0b8ff4 BH |
417 | /* |
418 | * (non-Javadoc) | |
419 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDWidget#keyPressedEvent(org.eclipse.swt.events.KeyEvent) | |
420 | */ | |
73005152 BH |
421 | @Override |
422 | protected void keyPressedEvent(KeyEvent e) { | |
df0b8ff4 | 423 | if (e.keyCode == SWT.CTRL) { |
eb63f5ff | 424 | fMultiSelection = true; |
df0b8ff4 BH |
425 | } |
426 | if (e.keyCode == SWT.SHIFT) { | |
eb63f5ff | 427 | fAreaSelection = true; |
df0b8ff4 | 428 | } |
73005152 | 429 | if (e.keyCode == SWT.ARROW_DOWN) { |
eb63f5ff BH |
430 | if (fPageNum + getNbRow() <= maxNumOfPages()) { |
431 | fPageNum += getNbRow(); | |
df0b8ff4 | 432 | } |
eb63f5ff BH |
433 | int line = fPageNum / getNbRow(); |
434 | int row = fPageNum % getNbRow(); | |
df0b8ff4 | 435 | if (row == 0) { |
73005152 | 436 | line--; |
df0b8ff4 | 437 | } |
eb63f5ff BH |
438 | if ((line + 1) * fStepY > (fOverviewCanvas.getContentsY() + fOverviewCanvas.getVisibleHeight()) / fOverviewCanvas.fZoomValue) { |
439 | fOverviewCanvas.scrollBy(0, (int) (fStepY * fOverviewCanvas.fZoomValue)); | |
df0b8ff4 | 440 | } |
73005152 BH |
441 | } |
442 | if (e.keyCode == SWT.ARROW_UP) { | |
eb63f5ff BH |
443 | if (fPageNum - getNbRow() > 0) { |
444 | fPageNum -= getNbRow(); | |
df0b8ff4 | 445 | } |
eb63f5ff BH |
446 | int line = fPageNum / getNbRow(); |
447 | int row = fPageNum % getNbRow(); | |
df0b8ff4 | 448 | if (row == 0) { |
73005152 | 449 | line--; |
df0b8ff4 | 450 | } |
eb63f5ff BH |
451 | if ((line) * fStepY <= fOverviewCanvas.getContentsY() / fOverviewCanvas.fZoomValue) { |
452 | fOverviewCanvas.scrollBy(0, -(int) (fStepY * fOverviewCanvas.fZoomValue)); | |
df0b8ff4 | 453 | } |
73005152 BH |
454 | } |
455 | if (e.keyCode == SWT.ARROW_LEFT) { | |
eb63f5ff BH |
456 | if ((fPageNum - 2) / getNbRow() == (fPageNum - 1) / getNbRow() && fPageNum > 1) { |
457 | fPageNum--; | |
df0b8ff4 | 458 | } |
eb63f5ff BH |
459 | int row = fPageNum % getNbRow(); |
460 | if ((row - 1) * fStepX < (fOverviewCanvas.getContentsX()) / fOverviewCanvas.fZoomValue) { | |
461 | fOverviewCanvas.scrollBy(-(int) (fStepX * fOverviewCanvas.fZoomValue), 0); | |
df0b8ff4 | 462 | } |
73005152 BH |
463 | } |
464 | if (e.keyCode == SWT.ARROW_RIGHT) { | |
eb63f5ff BH |
465 | if ((fPageNum - 1) / getNbRow() == fPageNum / getNbRow()) { |
466 | fPageNum++; | |
df0b8ff4 | 467 | } |
eb63f5ff | 468 | int row = fPageNum % getNbRow(); |
df0b8ff4 | 469 | if (row == 0) { |
73005152 | 470 | row = getNbRow(); |
df0b8ff4 | 471 | } |
eb63f5ff BH |
472 | if ((row) * fStepX > (fOverviewCanvas.getContentsX() + fOverviewCanvas.getVisibleWidth()) / fOverviewCanvas.fZoomValue) { |
473 | fOverviewCanvas.scrollBy((int) (fStepX * fOverviewCanvas.fZoomValue), 0); | |
df0b8ff4 | 474 | } |
73005152 BH |
475 | } |
476 | ||
eb63f5ff BH |
477 | if (e.keyCode == 32 && fPageNum > -1) { |
478 | Arrays.sort(fPagesList); | |
479 | int pos = Arrays.binarySearch(fPagesList, fPageNum); | |
df0b8ff4 | 480 | if (pos < 0) { |
eb63f5ff | 481 | addToPagesList(fPageNum); |
df0b8ff4 | 482 | } else { |
eb63f5ff | 483 | removeFromPagesList(fPageNum); |
df0b8ff4 | 484 | } |
73005152 BH |
485 | } |
486 | ||
eb63f5ff BH |
487 | if (!fAreaSelection && !fMultiSelection) { |
488 | fFirstPage = fPageNum; | |
489 | fPagesList = new int[1]; | |
490 | fPagesList[0] = fPageNum; | |
491 | } else if ((fPageNum != -1) && (fAreaSelection) && (fFirstPage != -1)) { | |
492 | fPagesList = new int[0]; | |
493 | int line1 = fFirstPage / getNbRow(); | |
494 | int row1 = fFirstPage % getNbRow(); | |
df0b8ff4 | 495 | if (row1 != 0) { |
73005152 | 496 | line1++; |
df0b8ff4 | 497 | } else { |
73005152 | 498 | row1 = getNbRow(); |
df0b8ff4 | 499 | } |
73005152 | 500 | |
eb63f5ff BH |
501 | int line2 = fPageNum / getNbRow(); |
502 | int row2 = fPageNum % getNbRow(); | |
df0b8ff4 | 503 | if (row2 != 0) { |
73005152 | 504 | line2++; |
df0b8ff4 | 505 | } else { |
73005152 | 506 | row2 = getNbRow(); |
df0b8ff4 | 507 | } |
73005152 BH |
508 | |
509 | int temp; | |
510 | if (line1 > line2) { | |
511 | temp = line2; | |
512 | line2 = line1; | |
513 | line1 = temp; | |
514 | } | |
515 | ||
516 | if (row1 > row2) { | |
517 | temp = row2; | |
518 | row2 = row1; | |
519 | row1 = temp; | |
520 | } | |
521 | ||
df0b8ff4 BH |
522 | for (int i = row1 - 1; i < row2; i++) { |
523 | for (int j = line1 - 1; j < line2; j++) { | |
73005152 | 524 | addToPagesList(i + j * getNbRow() + 1); |
df0b8ff4 BH |
525 | } |
526 | } | |
73005152 BH |
527 | } |
528 | displayPageNum(); | |
eb63f5ff | 529 | fOverviewCanvas.redraw(); |
73005152 BH |
530 | } |
531 | ||
df0b8ff4 BH |
532 | /* |
533 | * (non-Javadoc) | |
534 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDWidget#keyReleasedEvent(org.eclipse.swt.events.KeyEvent) | |
535 | */ | |
73005152 BH |
536 | @Override |
537 | protected void keyReleasedEvent(KeyEvent e) { | |
df0b8ff4 | 538 | if (e.keyCode == SWT.CTRL) { |
eb63f5ff | 539 | fMultiSelection = false; |
df0b8ff4 BH |
540 | } |
541 | if (e.keyCode == SWT.SHIFT) { | |
eb63f5ff | 542 | fAreaSelection = false; |
df0b8ff4 | 543 | } |
73005152 BH |
544 | } |
545 | ||
df0b8ff4 BH |
546 | /* |
547 | * (non-Javadoc) | |
548 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDWidget#contentsMouseDownEvent(org.eclipse.swt.events.MouseEvent) | |
549 | */ | |
73005152 BH |
550 | @Override |
551 | protected void contentsMouseDownEvent(MouseEvent event) { | |
552 | ||
553 | computeStepXY(); | |
eb63f5ff BH |
554 | int x1 = (int) ((event.x / fOverviewCanvas.fZoomValue) / fStepX); |
555 | int x2 = (int) ((event.y / fOverviewCanvas.fZoomValue) / fStepY); | |
73005152 | 556 | |
eb63f5ff | 557 | int oldPage = fPageNum; |
73005152 | 558 | |
eb63f5ff | 559 | fPageNum = x1 + x2 * getNbRow() + 1; |
73005152 | 560 | |
eb63f5ff BH |
561 | if (fPageNum > maxNumOfPages()) { |
562 | fPageNum = oldPage; | |
73005152 BH |
563 | return; |
564 | } | |
565 | ||
eb63f5ff BH |
566 | if (!fAreaSelection) { |
567 | fFirstPage = fPageNum; | |
df0b8ff4 | 568 | } |
73005152 | 569 | |
eb63f5ff BH |
570 | if ((fPageNum != -1) && (fMultiSelection)) { |
571 | Arrays.sort(fPagesList); | |
572 | int pos = Arrays.binarySearch(fPagesList, fPageNum); | |
df0b8ff4 | 573 | if (pos < 0) { |
eb63f5ff | 574 | addToPagesList(fPageNum); |
df0b8ff4 | 575 | } else { |
eb63f5ff | 576 | removeFromPagesList(fPageNum); |
df0b8ff4 | 577 | } |
eb63f5ff | 578 | } else if ((fPageNum != -1) && (fAreaSelection) && (fFirstPage != -1)) { |
73005152 | 579 | |
eb63f5ff | 580 | fPagesList = new int[0]; |
73005152 | 581 | |
eb63f5ff BH |
582 | int line1 = fFirstPage / getNbRow(); |
583 | int row1 = fFirstPage % getNbRow(); | |
df0b8ff4 | 584 | if (row1 != 0) { |
73005152 | 585 | line1++; |
df0b8ff4 | 586 | } else { |
73005152 | 587 | row1 = getNbRow(); |
df0b8ff4 | 588 | } |
73005152 | 589 | |
eb63f5ff BH |
590 | int line2 = fPageNum / getNbRow(); |
591 | int row2 = fPageNum % getNbRow(); | |
df0b8ff4 | 592 | if (row2 != 0) { |
73005152 | 593 | line2++; |
df0b8ff4 | 594 | } else { |
73005152 | 595 | row2 = getNbRow(); |
df0b8ff4 | 596 | } |
73005152 BH |
597 | |
598 | int temp; | |
599 | if (line1 > line2) { | |
600 | temp = line2; | |
601 | line2 = line1; | |
602 | line1 = temp; | |
603 | } | |
604 | ||
605 | if (row1 > row2) { | |
606 | temp = row2; | |
607 | row2 = row1; | |
608 | row1 = temp; | |
609 | } | |
610 | ||
df0b8ff4 BH |
611 | for (int i = row1 - 1; i < row2; i++) { |
612 | for (int j = line1 - 1; j < line2; j++) { | |
73005152 | 613 | addToPagesList(i + j * getNbRow() + 1); |
df0b8ff4 BH |
614 | } |
615 | } | |
73005152 | 616 | } else { |
eb63f5ff BH |
617 | fPagesList = new int[1]; |
618 | fPagesList[0] = fPageNum; | |
73005152 | 619 | } |
df0b8ff4 | 620 | if ((event.stateMask & SWT.CTRL) != 0) { |
eb63f5ff | 621 | fMultiSelection = true; |
df0b8ff4 | 622 | } |
73005152 BH |
623 | displayPageNum(); |
624 | redraw(); | |
625 | } | |
626 | ||
df0b8ff4 BH |
627 | /* |
628 | * (non-Javadoc) | |
629 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDWidget#contentsMouseMoveEvent(org.eclipse.swt.events.MouseEvent) | |
630 | */ | |
73005152 BH |
631 | @Override |
632 | protected void contentsMouseMoveEvent(MouseEvent e) { | |
eb63f5ff | 633 | fToolTip.hideToolTip(); |
73005152 BH |
634 | } |
635 | ||
df0b8ff4 BH |
636 | /* |
637 | * (non-Javadoc) | |
638 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#resizeContents(int, int) | |
639 | */ | |
73005152 | 640 | @Override |
eb63f5ff BH |
641 | public void resizeContents(int w, int h) { |
642 | super.resizeContents(w, h); | |
73005152 BH |
643 | } |
644 | ||
645 | } | |
646 | ||
3145ec83 BH |
647 | /** |
648 | * A traverse listener implementation. | |
649 | */ | |
650 | protected static class LocalTraverseListener implements TraverseListener { | |
651 | /* | |
652 | * (non-Javadoc) | |
653 | * @see org.eclipse.swt.events.TraverseListener#keyTraversed(org.eclipse.swt.events.TraverseEvent) | |
654 | */ | |
655 | @Override | |
656 | public void keyTraversed(TraverseEvent e) { | |
657 | if ((e.detail == SWT.TRAVERSE_TAB_NEXT) || (e.detail == SWT.TRAVERSE_TAB_PREVIOUS)) { | |
658 | e.doit = true; | |
659 | } | |
660 | } | |
661 | } | |
662 | ||
df0b8ff4 BH |
663 | // ------------------------------------------------------------------------ |
664 | // Constructors | |
665 | // ------------------------------------------------------------------------ | |
666 | /** | |
667 | * Constructor | |
a55887ca AM |
668 | * |
669 | * @param shell | |
670 | * The shell reference | |
671 | * @param sdWidget | |
672 | * The sequence diagram widget reference | |
df0b8ff4 | 673 | */ |
eb63f5ff BH |
674 | public SDPrintDialogUI(Shell shell, SDWidget sdWidget) { |
675 | this(shell, sdWidget, false); | |
73005152 | 676 | } |
a55887ca | 677 | |
df0b8ff4 BH |
678 | /** |
679 | * Constructor | |
a55887ca AM |
680 | * |
681 | * @param shell | |
682 | * The shell reference | |
683 | * @param sdWidget | |
684 | * The sequence diagram widget reference | |
685 | * @param showPrintBtn | |
686 | * Flag for showing print buttons | |
df0b8ff4 | 687 | */ |
eb63f5ff BH |
688 | public SDPrintDialogUI(Shell shell, SDWidget sdWidget, boolean showPrintBtn) { |
689 | fShell = shell; | |
690 | fSdView = sdWidget; | |
691 | fShowPrintButton = showPrintBtn; | |
73005152 | 692 | |
eb63f5ff BH |
693 | fPrinterData = Printer.getDefaultPrinterData(); |
694 | if (fPrinterData != null) { | |
695 | fPrinterData.scope = PrinterData.SELECTION; | |
73005152 BH |
696 | } |
697 | ||
eb63f5ff | 698 | fPagesList = new int[0]; |
73005152 | 699 | |
eb63f5ff | 700 | fSelectionListener = new SelectionListener() { |
73005152 BH |
701 | |
702 | @Override | |
703 | public void widgetSelected(SelectionEvent e) { | |
eb63f5ff BH |
704 | if (fUseCurrentZoom.getSelection()) { |
705 | fHorPagesNum.setEnabled(false); | |
706 | fVertPagesNum.setEnabled(false); | |
73005152 | 707 | } |
eb63f5ff BH |
708 | if (fSetHPagesNumber.getSelection()) { |
709 | fHorPagesNum.setEnabled(true); | |
710 | fVertPagesNum.setEnabled(false); | |
711 | if (fCurrentPage.getSelection()) { | |
712 | fCurrentPage.setSelection(false); | |
713 | fAllPages.setSelection(true); | |
73005152 | 714 | } |
a55887ca | 715 | if ("".equals(fHorPagesNum.getText())) { //$NON-NLS-1$ |
eb63f5ff | 716 | fHorPagesNum.setText("1"); //$NON-NLS-1$ |
df0b8ff4 | 717 | } |
73005152 | 718 | } |
eb63f5ff BH |
719 | if (fSetVPagesNumber.getSelection()) { |
720 | fHorPagesNum.setEnabled(false); | |
721 | fVertPagesNum.setEnabled(true); | |
722 | if (fCurrentPage.getSelection()) { | |
723 | fCurrentPage.setSelection(false); | |
724 | fAllPages.setSelection(true); | |
73005152 | 725 | } |
3145ec83 | 726 | if ("".equals(fVertPagesNum.getText())) { //$NON-NLS-1$ |
eb63f5ff | 727 | fVertPagesNum.setText("1"); //$NON-NLS-1$ |
df0b8ff4 | 728 | } |
73005152 | 729 | } |
eb63f5ff BH |
730 | if (fCurrentPage.getSelection() || fAllPages.getSelection() || fPageList.getSelection()) { |
731 | fFromPage.setEnabled(false); | |
732 | fToPage.setEnabled(false); | |
73005152 | 733 | } else { |
eb63f5ff BH |
734 | fFromPage.setEnabled(true); |
735 | fToPage.setEnabled(true); | |
73005152 BH |
736 | } |
737 | ||
eb63f5ff BH |
738 | fCurrentPage.setEnabled(fUseCurrentZoom.getSelection()); |
739 | fOverviewCanvas.setEnabled(fPageList.getSelection()); | |
740 | if (fOverviewCanvas.isEnabled() && (e.widget == fUseCurrentZoom || e.widget == fSetHPagesNumber || e.widget == fSetVPagesNumber)) { | |
741 | fPagesList = new int[1]; | |
742 | fPagesList[0] = 1; | |
743 | fPageNum = 1; | |
744 | fFirstPage = 1; | |
a55887ca | 745 | } else if ((fOverviewCanvas.isEnabled() && (e.widget == fPageList)) && |
eb63f5ff BH |
746 | (fPagesList == null || fPagesList.length <= 0)) { |
747 | ||
748 | fPagesList = new int[1]; | |
749 | fPagesList[0] = 1; | |
750 | fPageNum = 1; | |
751 | fFirstPage = 1; | |
73005152 BH |
752 | } |
753 | computeStepXY(); | |
eb63f5ff BH |
754 | fTotalPages.setText(Integer.valueOf(maxNumOfPages()).toString()); |
755 | fOverviewCanvas.redraw(); | |
756 | fOverviewCanvas.update(); | |
73005152 BH |
757 | } |
758 | ||
df0b8ff4 BH |
759 | /* |
760 | * (non-Javadoc) | |
761 | * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent) | |
762 | */ | |
73005152 BH |
763 | @Override |
764 | public void widgetDefaultSelected(SelectionEvent e) { | |
eb63f5ff | 765 | fPagesList = new int[0]; |
73005152 | 766 | computeStepXY(); |
eb63f5ff | 767 | fOverviewCanvas.redraw(); |
73005152 BH |
768 | } |
769 | ||
770 | }; | |
771 | ||
eb63f5ff | 772 | fModifyListener = new ModifyListener() { |
df0b8ff4 BH |
773 | /* |
774 | * (non-Javadoc) | |
775 | * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent) | |
776 | */ | |
73005152 BH |
777 | @Override |
778 | public void modifyText(ModifyEvent e) { | |
eb63f5ff | 779 | fPagesList = new int[0]; |
73005152 | 780 | computeStepXY(); |
eb63f5ff BH |
781 | fTotalPages.setText(Integer.valueOf(maxNumOfPages()).toString()); |
782 | fOverviewCanvas.redraw(); | |
73005152 BH |
783 | } |
784 | ||
785 | }; | |
786 | } | |
787 | ||
df0b8ff4 BH |
788 | // ------------------------------------------------------------------------ |
789 | // Methods | |
790 | // ------------------------------------------------------------------------ | |
791 | ||
792 | /** | |
793 | * Creates new grid data object. | |
a55887ca | 794 | * |
df0b8ff4 BH |
795 | * @param span horizontal span. |
796 | * @return grid data | |
797 | */ | |
73005152 BH |
798 | protected GridData newGridData(int span) { |
799 | GridData data = new GridData(GridData.GRAB_VERTICAL | GridData.VERTICAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL); | |
800 | data.horizontalSpan = span; | |
801 | return data; | |
802 | } | |
803 | ||
df0b8ff4 BH |
804 | /** |
805 | * Creates the dialog area. | |
a55887ca | 806 | * |
df0b8ff4 BH |
807 | * @param parent The parent composite |
808 | * @return dialog control | |
809 | */ | |
73005152 BH |
810 | public Control createDialogArea(Composite parent) { |
811 | ||
812 | GridLayout parentLayout = new GridLayout(); | |
813 | parentLayout.numColumns = 6; | |
814 | parent.setLayout(parentLayout); | |
815 | ||
816 | Group g1 = new Group(parent, SWT.SHADOW_NONE); | |
817 | g1.setText(SDMessages._113); | |
818 | g1.setLayoutData(newGridData(3)); | |
819 | GridLayout g1layout = new GridLayout(); | |
820 | g1layout.numColumns = 2; | |
821 | g1.setLayout(g1layout); | |
822 | ||
eb63f5ff BH |
823 | fUseCurrentZoom = new Button(g1, SWT.RADIO); |
824 | fUseCurrentZoom.setText(SDMessages._112); | |
825 | fUseCurrentZoom.setLayoutData(newGridData(2)); | |
826 | fUseCurrentZoom.addSelectionListener(fSelectionListener); | |
73005152 | 827 | |
eb63f5ff BH |
828 | fSetHPagesNumber = new Button(g1, SWT.RADIO); |
829 | fSetHPagesNumber.setText(SDMessages._110); | |
830 | fSetHPagesNumber.setLayoutData(newGridData(1)); | |
831 | fSetHPagesNumber.addSelectionListener(fSelectionListener); | |
73005152 | 832 | |
eb63f5ff BH |
833 | fHorPagesNum = new Text(g1, SWT.SINGLE | SWT.BORDER); |
834 | fHorPagesNum.addModifyListener(fModifyListener); | |
73005152 | 835 | |
eb63f5ff BH |
836 | fSetVPagesNumber = new Button(g1, SWT.RADIO); |
837 | fSetVPagesNumber.setText(SDMessages._111); | |
838 | fSetVPagesNumber.setLayoutData(newGridData(1)); | |
839 | fSetVPagesNumber.addSelectionListener(fSelectionListener); | |
73005152 | 840 | |
eb63f5ff BH |
841 | fVertPagesNum = new Text(g1, SWT.SINGLE | SWT.BORDER); |
842 | fVertPagesNum.addModifyListener(fModifyListener); | |
73005152 BH |
843 | |
844 | Label nbTotal = new Label(g1, SWT.SHADOW_NONE | SWT.RIGHT); | |
845 | nbTotal.setText(SDMessages._109); | |
846 | // nbTotal.setLayoutData(newGridData(1)); | |
847 | ||
eb63f5ff | 848 | fTotalPages = new Text(g1, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY); |
73005152 BH |
849 | // nbHV.addModifyListener(modifListener); |
850 | ||
851 | Group g2 = new Group(parent, SWT.SHADOW_NONE); | |
852 | g2.setText(SDMessages._119); | |
853 | GridData data = new GridData(GridData.GRAB_VERTICAL | GridData.VERTICAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL); | |
854 | data.horizontalSpan = 3; | |
855 | data.verticalSpan = 2; | |
856 | g2.setLayoutData(data); | |
857 | GridLayout g2layout = new GridLayout(); | |
858 | // g2layout. | |
859 | g2layout.numColumns = 1; | |
860 | // SVLayout g2layout = new SVLayout(); | |
861 | g2.setLayout(g2layout); | |
862 | ||
863 | GridData data2 = new GridData(GridData.GRAB_VERTICAL | GridData.VERTICAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL); | |
864 | data2.horizontalSpan = 1; | |
865 | data2.verticalSpan = 1; | |
866 | ||
eb63f5ff | 867 | fOverviewCanvas = new LocalSD(g2, SWT.NO_BACKGROUND); |
3145ec83 | 868 | GridData seqDiagLayoutData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL); |
eb63f5ff | 869 | fOverviewCanvas.setLayoutData(seqDiagLayoutData); |
73005152 | 870 | // overviewCanvas.resizeContents(100,100); |
eb63f5ff BH |
871 | if (fSdView.getContentsWidth() < fSdView.getVisibleWidth() && fSdView.getContentsHeight() < fSdView.getVisibleHeight()) { |
872 | fTest = 3; | |
df0b8ff4 | 873 | } else { |
eb63f5ff | 874 | fTest = 10; |
df0b8ff4 | 875 | } |
eb63f5ff BH |
876 | fOverviewCanvas.setFrame(fSdView.getFrame(), true); |
877 | fOverviewCanvas.fZoomValue = (float) 1 / fTest; | |
878 | fOverviewCanvas.setCornerControl(null); | |
879 | seqDiagLayoutData.widthHint = fOverviewCanvas.getContentsWidth() / fTest; | |
880 | seqDiagLayoutData.widthHint = fOverviewCanvas.getFrame().getWidth() / fTest + 15; | |
881 | ||
882 | if (fSdView.getVisibleWidth() < fSdView.getContentsWidth()) { | |
883 | seqDiagLayoutData.widthHint = fOverviewCanvas.getContentsWidth() / fTest; | |
df0b8ff4 | 884 | if (seqDiagLayoutData.widthHint > Display.getDefault().getClientArea().width / 4) { |
73005152 | 885 | seqDiagLayoutData.widthHint = Display.getDefault().getClientArea().width / 4; |
df0b8ff4 BH |
886 | } |
887 | } else { | |
eb63f5ff | 888 | seqDiagLayoutData.widthHint = fOverviewCanvas.getFrame().getWidth() / fTest + 15; |
df0b8ff4 | 889 | } |
73005152 | 890 | |
eb63f5ff BH |
891 | if (fSdView.getVisibleHeight() < fSdView.getContentsHeight()) { |
892 | seqDiagLayoutData.heightHint = fOverviewCanvas.getContentsHeight() / fTest; | |
df0b8ff4 | 893 | if (seqDiagLayoutData.heightHint > Display.getDefault().getClientArea().width / 4) { |
73005152 | 894 | seqDiagLayoutData.heightHint = Display.getDefault().getClientArea().width / 4; |
df0b8ff4 BH |
895 | } |
896 | } else { | |
eb63f5ff | 897 | seqDiagLayoutData.heightHint = fOverviewCanvas.getFrame().getHeight() / fTest; |
df0b8ff4 | 898 | } |
73005152 | 899 | |
eb63f5ff | 900 | fOverviewCanvas.setEnabled(false); |
73005152 | 901 | |
eb63f5ff BH |
902 | fCurrentSelection = new Label(g2, SWT.SHADOW_NONE | SWT.LEFT); |
903 | fCurrentSelection.setLayoutData(newGridData(1)); | |
73005152 BH |
904 | |
905 | Group g3 = new Group(parent, SWT.SHADOW_NONE); | |
906 | g3.setText(SDMessages._118); | |
907 | g3.setLayoutData(newGridData(3)); | |
908 | GridLayout g3layout = new GridLayout(); | |
909 | g3layout.numColumns = 4; | |
910 | g3.setLayout(g3layout); | |
911 | ||
eb63f5ff BH |
912 | fAllPages = new Button(g3, SWT.RADIO); |
913 | fAllPages.setText(SDMessages._108); | |
914 | fAllPages.setLayoutData(newGridData(4)); | |
915 | fAllPages.addSelectionListener(fSelectionListener); | |
73005152 | 916 | |
eb63f5ff BH |
917 | fCurrentPage = new Button(g3, SWT.RADIO); |
918 | fCurrentPage.setText(SDMessages._107); | |
919 | fCurrentPage.setLayoutData(newGridData(4)); | |
920 | fCurrentPage.setEnabled(true); | |
921 | fCurrentPage.setSelection(true); | |
922 | fCurrentPage.addSelectionListener(fSelectionListener); | |
73005152 | 923 | |
eb63f5ff BH |
924 | fPageList = new Button(g3, SWT.RADIO); |
925 | fPageList.setText(SDMessages._106); | |
926 | fPageList.setLayoutData(newGridData(4)); | |
927 | fPageList.addSelectionListener(fSelectionListener); | |
73005152 | 928 | |
eb63f5ff BH |
929 | fPageRange = new Button(g3, SWT.RADIO); |
930 | fPageRange.setText(SDMessages._103); | |
931 | fPageRange.setLayoutData(newGridData(1)); | |
932 | fPageRange.addSelectionListener(fSelectionListener); | |
73005152 | 933 | |
eb63f5ff | 934 | fFromPage = new Text(g3, SWT.SINGLE | SWT.BORDER); |
73005152 BH |
935 | |
936 | Label labelTo = new Label(g3, SWT.CENTER); | |
937 | labelTo.setText(SDMessages._105); | |
938 | ||
eb63f5ff | 939 | fToPage = new Text(g3, SWT.SINGLE | SWT.BORDER); |
73005152 | 940 | |
eb63f5ff | 941 | fToolTip = new DiagramToolTip(fOverviewCanvas); |
73005152 | 942 | |
eb63f5ff | 943 | fOverviewCanvas.getViewControl().addMouseTrackListener(new MouseTrackListener() { |
df0b8ff4 BH |
944 | /* |
945 | * (non-Javadoc) | |
946 | * @see org.eclipse.swt.events.MouseTrackListener#mouseEnter(org.eclipse.swt.events.MouseEvent) | |
947 | */ | |
73005152 BH |
948 | @Override |
949 | public void mouseEnter(MouseEvent e) { | |
eb63f5ff | 950 | fToolTip.hideToolTip(); |
73005152 BH |
951 | } |
952 | ||
df0b8ff4 BH |
953 | /* |
954 | * (non-Javadoc) | |
955 | * @see org.eclipse.swt.events.MouseTrackListener#mouseExit(org.eclipse.swt.events.MouseEvent) | |
956 | */ | |
73005152 BH |
957 | @Override |
958 | public void mouseExit(MouseEvent e) { | |
eb63f5ff | 959 | fToolTip.hideToolTip(); |
73005152 BH |
960 | } |
961 | ||
df0b8ff4 BH |
962 | /* |
963 | * (non-Javadoc) | |
964 | * @see org.eclipse.swt.events.MouseTrackListener#mouseHover(org.eclipse.swt.events.MouseEvent) | |
965 | */ | |
73005152 BH |
966 | @Override |
967 | public void mouseHover(MouseEvent e) { | |
eb63f5ff BH |
968 | int x1 = (int) (fOverviewCanvas.viewToContentsX(e.x) / fOverviewCanvas.fZoomValue / fStepX); |
969 | int x2 = (int) (fOverviewCanvas.viewToContentsY(e.y) / fOverviewCanvas.fZoomValue / fStepY); | |
73005152 | 970 | int num = x1 + x2 * getNbRow() + 1; |
df0b8ff4 | 971 | if (num > maxNumOfPages()) { |
73005152 | 972 | return; |
df0b8ff4 | 973 | } |
73005152 | 974 | if (num > 0) { |
eb63f5ff | 975 | fToolTip.showToolTip(String.valueOf(num)); |
73005152 BH |
976 | displayPageNum(); |
977 | } else { | |
eb63f5ff BH |
978 | fCurrentSelection.setText("");//$NON-NLS-1$ |
979 | fToolTip.hideToolTip(); | |
73005152 BH |
980 | } |
981 | } | |
982 | ||
983 | }); | |
984 | ||
3145ec83 | 985 | fOverviewCanvas.addTraverseListener(new LocalTraverseListener()); |
73005152 | 986 | |
eb63f5ff | 987 | fOverviewCanvas.addFocusListener(new FocusListener() { |
df0b8ff4 BH |
988 | /* |
989 | * (non-Javadoc) | |
990 | * @see org.eclipse.swt.events.FocusListener#focusGained(org.eclipse.swt.events.FocusEvent) | |
991 | */ | |
73005152 BH |
992 | @Override |
993 | public void focusGained(FocusEvent e) { | |
eb63f5ff | 994 | fOverviewCanvas.redraw(); |
73005152 BH |
995 | } |
996 | ||
df0b8ff4 BH |
997 | /* |
998 | * (non-Javadoc) | |
999 | * @see org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent) | |
1000 | */ | |
73005152 BH |
1001 | @Override |
1002 | public void focusLost(FocusEvent e) { | |
eb63f5ff | 1003 | fOverviewCanvas.redraw(); |
73005152 BH |
1004 | } |
1005 | }); | |
1006 | ||
eb63f5ff | 1007 | if (fShowPrintButton) { |
73005152 | 1008 | Composite printerDlg = new Composite(parent, SWT.NONE); |
2fa130b8 | 1009 | data = new GridData(SWT.FILL, SWT.DEFAULT, true, false); |
73005152 BH |
1010 | data.horizontalSpan = 6; |
1011 | parentLayout = new GridLayout(); | |
1012 | parentLayout.numColumns = 2; | |
1013 | printerDlg.setLayout(parentLayout); | |
1014 | printerDlg.setLayoutData(data); | |
1015 | ||
1016 | Label label = new Label(printerDlg, SWT.NONE); | |
2fa130b8 | 1017 | label.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false)); |
eb63f5ff BH |
1018 | fPrinterDialog = new Button(printerDlg, SWT.PUSH); |
1019 | fPrinterDialog.setText(SDMessages._115); | |
73005152 | 1020 | |
eb63f5ff | 1021 | fPrinterDialog.addSelectionListener(new SelectionListener() { |
73005152 | 1022 | |
df0b8ff4 BH |
1023 | /* |
1024 | * (non-Javadoc) | |
1025 | * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) | |
1026 | */ | |
73005152 BH |
1027 | @Override |
1028 | public void widgetSelected(SelectionEvent e) { | |
73005152 BH |
1029 | printButtonSelected(); |
1030 | } | |
1031 | ||
df0b8ff4 BH |
1032 | /* |
1033 | * (non-Javadoc) | |
1034 | * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent) | |
1035 | */ | |
73005152 BH |
1036 | @Override |
1037 | public void widgetDefaultSelected(SelectionEvent e) { | |
1038 | } | |
1039 | ||
1040 | }); | |
1041 | } | |
1042 | ||
1043 | updatePrinterStatus(); | |
1044 | ||
1045 | return parent; | |
1046 | } | |
1047 | ||
df0b8ff4 BH |
1048 | /** |
1049 | * Get number of pages for selection. | |
1050 | * @return number of pages for selection. | |
1051 | */ | |
73005152 | 1052 | public int getPagesForSelection() { |
eb63f5ff | 1053 | return fNbPages; |
73005152 BH |
1054 | } |
1055 | ||
a55887ca AM |
1056 | /** |
1057 | * Handler for when the OK button is pressed | |
1058 | * | |
1059 | * @return True if the operation was successful, false if there was an error | |
1060 | */ | |
73005152 | 1061 | public boolean okPressed() { |
eb63f5ff BH |
1062 | fPrintAll = fAllPages.getSelection(); |
1063 | fPrintCurrent = fCurrentPage.getSelection(); | |
1064 | fPrintSelection = fPageList.getSelection(); | |
1065 | fPrintRange = fPageRange.getSelection(); | |
73005152 | 1066 | try { |
eb63f5ff BH |
1067 | if (fPrintRange) { |
1068 | fFrom = Integer.valueOf(fFromPage.getText()).intValue(); | |
1069 | fTo = Integer.valueOf(fToPage.getText()).intValue(); | |
1070 | if (fFrom > maxNumOfPages() || fTo > maxNumOfPages() || fFrom <= 0 || fTo <= 0) { | |
73005152 BH |
1071 | MessageDialog.openError(getShell(), SDMessages._98, SDMessages._99); |
1072 | return false; | |
1073 | } | |
eb63f5ff | 1074 | } else if (fSetHPagesNumber.getSelection() && fNbPages <= 0) { |
73005152 BH |
1075 | MessageDialog.openError(getShell(), SDMessages._98, SDMessages._101); |
1076 | return false; | |
eb63f5ff | 1077 | } else if (fSetVPagesNumber.getSelection() && fNbPages <= 0) { |
73005152 BH |
1078 | MessageDialog.openError(getShell(), SDMessages._98, SDMessages._100); |
1079 | return false; | |
eb63f5ff | 1080 | } else if (fPrintSelection && getPageList().length <= 0) { |
73005152 BH |
1081 | MessageDialog.openError(getShell(), SDMessages._98, SDMessages._102); |
1082 | return false; | |
1083 | } | |
1084 | ||
1085 | } catch (Exception e) { | |
1086 | MessageDialog.openError(getShell(), SDMessages._98, SDMessages._99); | |
eb63f5ff BH |
1087 | fFrom = 0; |
1088 | fTo = 0; | |
73005152 BH |
1089 | return false; |
1090 | } | |
1091 | ||
1092 | return true; | |
1093 | } | |
1094 | ||
df0b8ff4 BH |
1095 | /** |
1096 | * Draws region that was selected | |
1097 | * @param img The corresponding image | |
1098 | * @param r The selected rectangle. | |
1099 | * @param color The color to use for selection | |
eb63f5ff | 1100 | * @return image data reference |
df0b8ff4 | 1101 | */ |
73005152 BH |
1102 | public ImageData drawRegionSelected(Image img, Rectangle r, RGB color) { |
1103 | ImageData id = img.getImageData(); | |
1104 | for (int a = 0; a < r.width && r.x + a < id.width; a++) { | |
1105 | for (int b = 0; b < r.height && r.y + b < id.height; b++) { | |
1106 | int index = id.getPixel(r.x + a, r.y + b); | |
1107 | RGB rgb = id.palette.getRGB(index); | |
1108 | rgb = combine(color, rgb); | |
1109 | id.setPixel(r.x + a, r.y + b, id.palette.getPixel(rgb)); | |
1110 | } | |
1111 | } | |
1112 | return id; | |
1113 | } | |
1114 | ||
df0b8ff4 BH |
1115 | /** |
1116 | * Combines two RGB colors. | |
1117 | * @param front The front color | |
1118 | * @param back The back color | |
1119 | * @return new RGB color | |
1120 | */ | |
73005152 BH |
1121 | public static RGB combine(RGB front, RGB back) { |
1122 | int _af = 128; | |
73005152 | 1123 | int _ab = 200; |
73005152 BH |
1124 | |
1125 | double af = (_af) / 255.0; | |
1126 | double rf = front.red; | |
1127 | double gf = front.green; | |
1128 | double bf = front.blue; | |
1129 | ||
1130 | double ab = (_ab) / 255.0; | |
1131 | double rb = back.red; | |
1132 | double gb = back.green; | |
1133 | double bb = back.blue; | |
1134 | ||
1135 | double k = (1.0 - af) * ab; | |
1136 | int r = (int) ((af * rf + k * rb)); | |
1137 | int g = (int) ((af * gf + k * gb)); | |
1138 | int b = (int) ((af * bf + k * bb)); | |
1139 | ||
1140 | return new RGB(r, g, b); | |
1141 | } | |
1142 | ||
df0b8ff4 BH |
1143 | /** |
1144 | * Computes value for X coordinates step and Y coordinates step. | |
1145 | */ | |
73005152 | 1146 | protected void computeStepXY() { |
eb63f5ff BH |
1147 | float cw = fOverviewCanvas.getContentsWidth() / fOverviewCanvas.fZoomValue; |
1148 | float ch = fOverviewCanvas.getContentsHeight() / fOverviewCanvas.fZoomValue; | |
73005152 | 1149 | try { |
eb63f5ff BH |
1150 | if (fPrinterData == null) { |
1151 | fStepX = 0; | |
1152 | fStepY = 0; | |
1153 | fNbPages = 0; | |
1154 | fZoomFactor = 0; | |
73005152 | 1155 | } else { |
eb63f5ff BH |
1156 | Printer printer = new Printer(fPrinterData); |
1157 | if (fSetHPagesNumber.getSelection()) { | |
1158 | fNbPages = Integer.valueOf(fHorPagesNum.getText()).intValue(); | |
abbdd66a | 1159 | float z1 = fSdView.getContentsWidth() / cw; |
eb63f5ff BH |
1160 | float z2 = printer.getClientArea().width / ((float) fSdView.getContentsWidth() / fNbPages); |
1161 | ||
1162 | fStepY = printer.getClientArea().height / z1 / z2; | |
1163 | fStepX = cw / fNbPages; | |
1164 | } else if (fSetVPagesNumber.getSelection()) { | |
1165 | fNbPages = Integer.valueOf(fVertPagesNum.getText()).intValue(); | |
abbdd66a | 1166 | float z1 = fSdView.getContentsHeight() / ch; |
eb63f5ff BH |
1167 | float z2 = printer.getClientArea().height / ((float) fSdView.getContentsHeight() / fNbPages); |
1168 | fStepX = printer.getClientArea().width / z1 / z2; | |
1169 | fStepY = ch / fNbPages; | |
73005152 | 1170 | } else { |
eb63f5ff | 1171 | float z1 = fSdView.getContentsWidth() / (cw); |
abbdd66a | 1172 | fStepX = fSdView.getVisibleWidth() / z1; |
eb63f5ff BH |
1173 | fNbPages = Math.round(cw / fStepX); |
1174 | if (fNbPages == 0) { | |
1175 | fNbPages = 1; | |
df0b8ff4 | 1176 | } |
73005152 BH |
1177 | int pw = printer.getClientArea().width; |
1178 | int ph = printer.getClientArea().height; | |
eb63f5ff | 1179 | float z2 = pw / ((float) fSdView.getContentsWidth() / fNbPages); |
abbdd66a | 1180 | fStepY = ph / z1 / z2; |
73005152 BH |
1181 | } |
1182 | } | |
e6ace8bb | 1183 | } catch (NumberFormatException e) { |
eb63f5ff BH |
1184 | fStepX = fStepY = fNbPages = 0; |
1185 | fZoomFactor = 0; | |
73005152 | 1186 | } |
eb63f5ff BH |
1187 | sTX = fStepX * (fSdView.getContentsWidth() / cw); |
1188 | sTY = fStepY * (fSdView.getContentsHeight() / ch); | |
73005152 | 1189 | float rat = 1; |
eb63f5ff BH |
1190 | if ((fSdView.getVisibleWidth() > fSdView.getContentsWidth()) && (fSetVPagesNumber.getSelection() || fSetHPagesNumber.getSelection())) { |
1191 | rat = (float) fSdView.getVisibleWidth() / (float) fSdView.getContentsWidth(); | |
df0b8ff4 | 1192 | } |
3145ec83 | 1193 | fZoomFactor = (fOverviewCanvas.getContentsWidth() / cw) / fOverviewCanvas.getZoomFactor() * rat; |
73005152 BH |
1194 | } |
1195 | ||
df0b8ff4 | 1196 | /** |
eb63f5ff | 1197 | * Returns the pages list. |
a55887ca | 1198 | * |
df0b8ff4 BH |
1199 | * @return the pages list. |
1200 | */ | |
73005152 | 1201 | public int[] getPageList() { |
eb63f5ff | 1202 | return Arrays.copyOf(fPagesList, fPagesList.length); |
73005152 BH |
1203 | } |
1204 | ||
df0b8ff4 BH |
1205 | /** |
1206 | * Adds a page to pages list. | |
a55887ca | 1207 | * |
df0b8ff4 | 1208 | * @param num |
a55887ca | 1209 | * The number of the the new page |
df0b8ff4 | 1210 | */ |
73005152 | 1211 | public void addToPagesList(int num) { |
eb63f5ff BH |
1212 | int temp[] = new int[fPagesList.length + 1]; |
1213 | System.arraycopy(fPagesList, 0, temp, 0, fPagesList.length); | |
73005152 | 1214 | temp[temp.length - 1] = num; |
eb63f5ff BH |
1215 | fPagesList = new int[temp.length]; |
1216 | System.arraycopy(temp, 0, fPagesList, 0, temp.length); | |
73005152 BH |
1217 | } |
1218 | ||
df0b8ff4 BH |
1219 | /** |
1220 | * Removes a page from the pages list. | |
a55887ca | 1221 | * |
df0b8ff4 | 1222 | * @param num |
a55887ca | 1223 | * The number of the page to remove |
df0b8ff4 | 1224 | */ |
73005152 | 1225 | public void removeFromPagesList(int num) { |
eb63f5ff BH |
1226 | int pos = Arrays.binarySearch(fPagesList, num); |
1227 | int temp[] = new int[fPagesList.length - 1]; | |
1228 | System.arraycopy(fPagesList, 0, temp, 0, pos); | |
1229 | System.arraycopy(fPagesList, pos + 1, temp, pos, fPagesList.length - pos - 1); | |
1230 | fPagesList = new int[temp.length]; | |
1231 | System.arraycopy(temp, 0, fPagesList, 0, temp.length); | |
73005152 BH |
1232 | } |
1233 | ||
df0b8ff4 | 1234 | /** |
eb63f5ff | 1235 | * Returns the maximum number of pages. |
a55887ca | 1236 | * |
df0b8ff4 BH |
1237 | * @return maximum number of pages. |
1238 | */ | |
73005152 | 1239 | public int maxNumOfPages() { |
eb63f5ff | 1240 | return (getNbRow() * getNbLines()); |
73005152 BH |
1241 | } |
1242 | ||
df0b8ff4 | 1243 | /** |
eb63f5ff | 1244 | * Returns the number of rows. |
a55887ca | 1245 | * |
df0b8ff4 BH |
1246 | * @return number of rows. |
1247 | */ | |
73005152 | 1248 | public int getNbRow() { |
eb63f5ff BH |
1249 | if (!fSetHPagesNumber.isDisposed()) { |
1250 | int cw = (int) (fOverviewCanvas.getContentsWidth() / fOverviewCanvas.fZoomValue); | |
e6ace8bb | 1251 | int row = 1; |
eb63f5ff BH |
1252 | if (fStepX != 0) { |
1253 | row = (int) (cw / fStepX); | |
1254 | if (fSetHPagesNumber.getSelection()) { | |
abbdd66a | 1255 | row = Math.round(cw / fStepX); |
eb63f5ff | 1256 | } else if ((cw % fStepX != 0)) { |
e6ace8bb | 1257 | row++; |
df0b8ff4 | 1258 | } |
e6ace8bb | 1259 | } |
eb63f5ff | 1260 | fNbRows = row; |
73005152 | 1261 | } |
eb63f5ff | 1262 | return fNbRows; |
73005152 BH |
1263 | } |
1264 | ||
df0b8ff4 | 1265 | /** |
eb63f5ff | 1266 | * Returns the number of lines. |
a55887ca | 1267 | * |
df0b8ff4 BH |
1268 | * @return number of lines |
1269 | */ | |
73005152 | 1270 | public int getNbLines() { |
eb63f5ff BH |
1271 | if (!fSetVPagesNumber.isDisposed()) { |
1272 | int ch = (int) (fOverviewCanvas.getContentsHeight() / fOverviewCanvas.fZoomValue); | |
e6ace8bb | 1273 | int line = 1; |
eb63f5ff BH |
1274 | if (fStepY != 0) { |
1275 | line = (int) (ch / fStepY); | |
1276 | if (fSetVPagesNumber.getSelection()) { | |
abbdd66a | 1277 | line = Math.round(ch / fStepY); |
eb63f5ff | 1278 | } else if (ch % fStepY != 0) { |
e6ace8bb | 1279 | line++; |
df0b8ff4 | 1280 | } |
e6ace8bb | 1281 | } |
eb63f5ff | 1282 | fNbLines = line; |
73005152 | 1283 | } |
eb63f5ff | 1284 | return fNbLines; |
73005152 BH |
1285 | } |
1286 | ||
df0b8ff4 | 1287 | /** |
eb63f5ff | 1288 | * Returns whether to print all pages or not. |
a55887ca | 1289 | * |
eb63f5ff | 1290 | * @return <code>true</code> for all pages else <code>false</code>. |
df0b8ff4 | 1291 | */ |
73005152 | 1292 | public boolean printAll() { |
eb63f5ff | 1293 | return fPrintAll; |
73005152 BH |
1294 | } |
1295 | ||
df0b8ff4 | 1296 | /** |
a55887ca AM |
1297 | * Returns whether to print only current page |
1298 | * | |
eb63f5ff | 1299 | * @return <code>true</code> for current page only else <code>false</code>.. |
df0b8ff4 | 1300 | */ |
73005152 | 1301 | public boolean printCurrent() { |
eb63f5ff | 1302 | return fPrintCurrent; |
73005152 BH |
1303 | } |
1304 | ||
df0b8ff4 | 1305 | /** |
eb63f5ff | 1306 | * Returns whether to print selected pages. |
a55887ca AM |
1307 | * |
1308 | * @return <code>true</code> for selected pages only else <code>false</code>. | |
df0b8ff4 | 1309 | */ |
73005152 | 1310 | public boolean printSelection() { |
eb63f5ff | 1311 | return fPrintSelection; |
73005152 | 1312 | } |
a55887ca | 1313 | |
df0b8ff4 | 1314 | /** |
eb63f5ff | 1315 | * Returns whether to print range of pages. |
a55887ca | 1316 | * |
eb63f5ff | 1317 | * @return <code>true</code> for range of pages only else <code>false</code>. |
df0b8ff4 | 1318 | */ |
73005152 | 1319 | public boolean printRange() { |
eb63f5ff | 1320 | return fPrintRange; |
73005152 BH |
1321 | } |
1322 | ||
df0b8ff4 | 1323 | /** |
eb63f5ff | 1324 | * Returns the step in X direction. |
a55887ca | 1325 | * |
df0b8ff4 BH |
1326 | * @return step in X direction |
1327 | */ | |
73005152 BH |
1328 | public float getStepX() { |
1329 | return sTX; | |
1330 | } | |
1331 | ||
df0b8ff4 | 1332 | /** |
eb63f5ff | 1333 | * Returns the step in Y direction. |
a55887ca | 1334 | * |
df0b8ff4 BH |
1335 | * @return step in Y direction |
1336 | */ | |
73005152 BH |
1337 | public float getStepY() { |
1338 | return sTY; | |
1339 | } | |
1340 | ||
df0b8ff4 | 1341 | /** |
eb63f5ff | 1342 | * Returns the zoom factor |
a55887ca | 1343 | * |
df0b8ff4 BH |
1344 | * @return zoom factor |
1345 | */ | |
73005152 | 1346 | public float getZoomFactor() { |
eb63f5ff | 1347 | return fZoomFactor; |
73005152 BH |
1348 | } |
1349 | ||
df0b8ff4 | 1350 | /** |
eb63f5ff | 1351 | * Returns the printer data reference. |
a55887ca | 1352 | * |
df0b8ff4 BH |
1353 | * @return printer data reference |
1354 | */ | |
73005152 | 1355 | public PrinterData getPrinterData() { |
eb63f5ff | 1356 | return fPrinterData; |
73005152 BH |
1357 | } |
1358 | ||
df0b8ff4 | 1359 | /** |
eb63f5ff | 1360 | * Returns the page number to start printing from. |
a55887ca | 1361 | * |
df0b8ff4 BH |
1362 | * @return page number to start printing from |
1363 | */ | |
73005152 | 1364 | public int getFrom() { |
eb63f5ff | 1365 | return fFrom; |
73005152 BH |
1366 | } |
1367 | ||
df0b8ff4 | 1368 | /** |
eb63f5ff | 1369 | * Returns the page number to print to. |
a55887ca | 1370 | * |
df0b8ff4 BH |
1371 | * @return page number to print to |
1372 | */ | |
73005152 | 1373 | public int getTo() { |
eb63f5ff | 1374 | return fTo; |
73005152 BH |
1375 | } |
1376 | ||
df0b8ff4 BH |
1377 | /** |
1378 | * Displays current number of pages | |
1379 | */ | |
73005152 | 1380 | protected void displayPageNum() { |
eb63f5ff BH |
1381 | if (fPageNum > 0) { |
1382 | String message = MessageFormat.format(SDMessages._117, new Object[] { Integer.valueOf(fPageNum) }); | |
1383 | fCurrentSelection.setText(message); | |
1384 | fCurrentSelection.getParent().layout(); | |
73005152 BH |
1385 | } |
1386 | } | |
1387 | ||
df0b8ff4 | 1388 | /** |
eb63f5ff | 1389 | * Returns the shell reference. |
a55887ca | 1390 | * |
df0b8ff4 BH |
1391 | * @return the shell reference. |
1392 | */ | |
73005152 | 1393 | public Shell getShell() { |
eb63f5ff | 1394 | return fShell; |
73005152 BH |
1395 | } |
1396 | ||
df0b8ff4 | 1397 | /** |
eb63f5ff | 1398 | * Sets the shell. |
a55887ca | 1399 | * |
df0b8ff4 BH |
1400 | * @param shell The shell reference. |
1401 | */ | |
73005152 | 1402 | public void setShell(Shell shell) { |
eb63f5ff | 1403 | fShell = shell; |
73005152 BH |
1404 | } |
1405 | ||
df0b8ff4 BH |
1406 | /** |
1407 | * Handle selection of print button. | |
1408 | */ | |
73005152 BH |
1409 | public void printButtonSelected() { |
1410 | PrintDialog printer = new PrintDialog(getShell()); | |
eb63f5ff | 1411 | if (fAllPages.getSelection()) { |
73005152 | 1412 | printer.setScope(PrinterData.ALL_PAGES); |
df0b8ff4 | 1413 | } |
eb63f5ff | 1414 | if (fCurrentPage.getSelection()) { |
73005152 | 1415 | printer.setScope(PrinterData.SELECTION); |
df0b8ff4 | 1416 | } |
eb63f5ff | 1417 | if (fPageList.getSelection()) { |
73005152 | 1418 | printer.setScope(PrinterData.SELECTION); |
df0b8ff4 | 1419 | } |
eb63f5ff | 1420 | if (fPageRange.getSelection()) { |
73005152 | 1421 | printer.setScope(PrinterData.PAGE_RANGE); |
eb63f5ff BH |
1422 | fFrom = Integer.valueOf(fFromPage.getText()).intValue(); |
1423 | fTo = Integer.valueOf(fToPage.getText()).intValue(); | |
1424 | printer.setStartPage(fFrom); | |
1425 | printer.setEndPage(fTo); | |
73005152 BH |
1426 | } |
1427 | ||
1428 | PrinterData newPrinterData = printer.open(); | |
1429 | if (newPrinterData != null) { | |
eb63f5ff | 1430 | fPrinterData = newPrinterData; |
73005152 BH |
1431 | } |
1432 | updatePrinterStatus(); | |
1433 | ||
1434 | if (printer.getScope() == PrinterData.ALL_PAGES) { | |
eb63f5ff BH |
1435 | fAllPages.setSelection(true); |
1436 | fCurrentPage.setSelection(false); | |
1437 | fPageList.setSelection(false); | |
1438 | fPageRange.setSelection(false); | |
1439 | fHorPagesNum.setEnabled(false); | |
1440 | fVertPagesNum.setEnabled(false); | |
73005152 BH |
1441 | } |
1442 | if (printer.getScope() == PrinterData.PAGE_RANGE) { | |
eb63f5ff BH |
1443 | fAllPages.setSelection(false); |
1444 | fCurrentPage.setSelection(false); | |
1445 | fPageList.setSelection(false); | |
1446 | fPageRange.setSelection(true); | |
1447 | fFromPage.setEnabled(true); | |
1448 | fToPage.setEnabled(true); | |
1449 | fFromPage.setText((Integer.valueOf(printer.getStartPage())).toString()); | |
1450 | fToPage.setText((Integer.valueOf(printer.getEndPage())).toString()); | |
73005152 BH |
1451 | } |
1452 | computeStepXY(); | |
eb63f5ff | 1453 | fOverviewCanvas.redraw(); |
73005152 BH |
1454 | } |
1455 | ||
df0b8ff4 BH |
1456 | /** |
1457 | * Sets parent wizard page | |
a55887ca | 1458 | * |
df0b8ff4 BH |
1459 | * @param parent The parent wizard page |
1460 | */ | |
73005152 | 1461 | public void setParentWizardPage(WizardPage parent) { |
eb63f5ff | 1462 | fParentWizardPage = parent; |
73005152 BH |
1463 | } |
1464 | ||
df0b8ff4 BH |
1465 | /** |
1466 | * Sets the parent dialog box. | |
a55887ca AM |
1467 | * |
1468 | * @param parent The parent dialog box. | |
df0b8ff4 | 1469 | */ |
73005152 | 1470 | public void setParentDialog(SDPrintDialog parent) { |
eb63f5ff | 1471 | fParentDialog = parent; |
73005152 BH |
1472 | } |
1473 | ||
df0b8ff4 BH |
1474 | /** |
1475 | * Updates the printer status | |
1476 | */ | |
73005152 | 1477 | protected void updatePrinterStatus() { |
eb63f5ff | 1478 | if (fParentWizardPage != null) { |
73005152 | 1479 | // used in the wizard dialog |
eb63f5ff | 1480 | if (fPrinterData == null) { |
73005152 | 1481 | // show error message and disable Finish button |
eb63f5ff BH |
1482 | fParentWizardPage.setErrorMessage(SDMessages._135); |
1483 | fParentWizardPage.setPageComplete(false); | |
73005152 BH |
1484 | } else { |
1485 | // clear error message and enable Finish button | |
eb63f5ff BH |
1486 | fParentWizardPage.setErrorMessage(null); |
1487 | fParentWizardPage.setPageComplete(true); | |
73005152 | 1488 | } |
eb63f5ff | 1489 | } else if (fParentDialog != null) { |
73005152 | 1490 | // used in the print dialog |
eb63f5ff | 1491 | if (fPrinterData == null) { |
73005152 | 1492 | // show error message and disable OK button |
eb63f5ff BH |
1493 | fParentDialog.setErrorMessage(SDMessages._135); |
1494 | fParentDialog.setPageComplete(false); | |
73005152 BH |
1495 | } else { |
1496 | // clear error message and enable OK button | |
eb63f5ff BH |
1497 | fParentDialog.setErrorMessage(null); |
1498 | fParentDialog.setPageComplete(true); | |
73005152 BH |
1499 | } |
1500 | } | |
1501 | } | |
1502 | ||
1503 | } |