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