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