Commit | Line | Data |
---|---|---|
73005152 | 1 | /********************************************************************** |
df0b8ff4 BH |
2 | * Copyright (c) 2005, 2008 IBM Corporation and others. |
3 | * Copyright (c) 2011, 2012 Ericsson. | |
4 | * | |
73005152 BH |
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 | |
73005152 BH |
9 | * |
10 | * Contributors: | |
11 | * IBM - Initial API and implementation | |
12 | * Bernd Hufmann - Updated for TMF | |
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 BH |
57 | * The class implements the actual print dialog UI for collecting printing data. |
58 | * | |
59 | * @version 1.0 | |
73005152 BH |
60 | * @author sveyrier |
61 | */ | |
62 | public class SDPrintDialogUI { | |
df0b8ff4 BH |
63 | // ------------------------------------------------------------------------ |
64 | // Attributes | |
65 | // ------------------------------------------------------------------------ | |
66 | /** | |
67 | * The set horizontal pages number. | |
68 | */ | |
eb63f5ff | 69 | protected Button fSetHPagesNumber; |
df0b8ff4 BH |
70 | /** |
71 | * The set vertical pages number. | |
72 | */ | |
eb63f5ff | 73 | protected Button fSetVPagesNumber; |
df0b8ff4 BH |
74 | /** |
75 | * Flag whether to use current zoom or not. | |
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 BH |
102 | /** |
103 | * The sequence diagram widget reference. | |
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 BH |
118 | /** |
119 | * A modify listener implementation to handle modifications. | |
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 BH |
138 | /** |
139 | * Number of first page. | |
140 | */ | |
eb63f5ff | 141 | protected int fFirstPage = -1; |
df0b8ff4 BH |
142 | /** |
143 | * List of pages to print. | |
144 | */ | |
eb63f5ff | 145 | protected int fPagesList[]; |
df0b8ff4 BH |
146 | /** |
147 | * Values for dividing sequence diagram into pages. | |
148 | */ | |
eb63f5ff | 149 | protected float fStepX, fStepY, sTX, sTY; |
df0b8ff4 BH |
150 | /** |
151 | * Page which to print from. | |
152 | */ | |
eb63f5ff | 153 | protected int fFrom; |
df0b8ff4 BH |
154 | /** |
155 | * Page which to print to. | |
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 BH |
194 | /** |
195 | * The printer data reference. | |
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 BH |
218 | /** |
219 | * Test value | |
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 BH |
226 | /** |
227 | * Reference to parent print dialog. | |
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. | |
236 | * @version 1.0 | |
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. | |
283 | * | |
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 | } | |
df0b8ff4 BH |
358 | |
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 | |
651 | * | |
eb63f5ff BH |
652 | * @param shell The shell reference |
653 | * @param sdWidget The sequence diagram widget reference | |
df0b8ff4 | 654 | */ |
eb63f5ff BH |
655 | public SDPrintDialogUI(Shell shell, SDWidget sdWidget) { |
656 | this(shell, sdWidget, false); | |
73005152 | 657 | } |
df0b8ff4 BH |
658 | |
659 | /** | |
660 | * Constructor | |
661 | * | |
eb63f5ff BH |
662 | * @param shello The shell reference |
663 | * @param sdWidget The sequence diagram widget reference | |
df0b8ff4 BH |
664 | * @param showPrintBtn Flag for showing print buttons |
665 | */ | |
eb63f5ff BH |
666 | public SDPrintDialogUI(Shell shell, SDWidget sdWidget, boolean showPrintBtn) { |
667 | fShell = shell; | |
668 | fSdView = sdWidget; | |
669 | fShowPrintButton = showPrintBtn; | |
73005152 | 670 | |
eb63f5ff BH |
671 | fPrinterData = Printer.getDefaultPrinterData(); |
672 | if (fPrinterData != null) { | |
673 | fPrinterData.scope = PrinterData.SELECTION; | |
73005152 BH |
674 | } |
675 | ||
eb63f5ff | 676 | fPagesList = new int[0]; |
73005152 | 677 | |
eb63f5ff | 678 | fSelectionListener = new SelectionListener() { |
73005152 BH |
679 | |
680 | @Override | |
681 | public void widgetSelected(SelectionEvent e) { | |
eb63f5ff BH |
682 | if (fUseCurrentZoom.getSelection()) { |
683 | fHorPagesNum.setEnabled(false); | |
684 | fVertPagesNum.setEnabled(false); | |
73005152 | 685 | } |
eb63f5ff BH |
686 | if (fSetHPagesNumber.getSelection()) { |
687 | fHorPagesNum.setEnabled(true); | |
688 | fVertPagesNum.setEnabled(false); | |
689 | if (fCurrentPage.getSelection()) { | |
690 | fCurrentPage.setSelection(false); | |
691 | fAllPages.setSelection(true); | |
73005152 | 692 | } |
eb63f5ff BH |
693 | if ("".equals(fHorPagesNum.getText())) { //$NON-NLS-1$ |
694 | fHorPagesNum.setText("1"); //$NON-NLS-1$ | |
df0b8ff4 | 695 | } |
73005152 | 696 | } |
eb63f5ff BH |
697 | if (fSetVPagesNumber.getSelection()) { |
698 | fHorPagesNum.setEnabled(false); | |
699 | fVertPagesNum.setEnabled(true); | |
700 | if (fCurrentPage.getSelection()) { | |
701 | fCurrentPage.setSelection(false); | |
702 | fAllPages.setSelection(true); | |
73005152 | 703 | } |
3145ec83 | 704 | if ("".equals(fVertPagesNum.getText())) { //$NON-NLS-1$ |
eb63f5ff | 705 | fVertPagesNum.setText("1"); //$NON-NLS-1$ |
df0b8ff4 | 706 | } |
73005152 | 707 | } |
eb63f5ff BH |
708 | if (fCurrentPage.getSelection() || fAllPages.getSelection() || fPageList.getSelection()) { |
709 | fFromPage.setEnabled(false); | |
710 | fToPage.setEnabled(false); | |
73005152 | 711 | } else { |
eb63f5ff BH |
712 | fFromPage.setEnabled(true); |
713 | fToPage.setEnabled(true); | |
73005152 BH |
714 | } |
715 | ||
eb63f5ff BH |
716 | fCurrentPage.setEnabled(fUseCurrentZoom.getSelection()); |
717 | fOverviewCanvas.setEnabled(fPageList.getSelection()); | |
718 | if (fOverviewCanvas.isEnabled() && (e.widget == fUseCurrentZoom || e.widget == fSetHPagesNumber || e.widget == fSetVPagesNumber)) { | |
719 | fPagesList = new int[1]; | |
720 | fPagesList[0] = 1; | |
721 | fPageNum = 1; | |
722 | fFirstPage = 1; | |
723 | } else if ((fOverviewCanvas.isEnabled() && (e.widget == fPageList)) && | |
724 | (fPagesList == null || fPagesList.length <= 0)) { | |
725 | ||
726 | fPagesList = new int[1]; | |
727 | fPagesList[0] = 1; | |
728 | fPageNum = 1; | |
729 | fFirstPage = 1; | |
73005152 BH |
730 | } |
731 | computeStepXY(); | |
eb63f5ff BH |
732 | fTotalPages.setText(Integer.valueOf(maxNumOfPages()).toString()); |
733 | fOverviewCanvas.redraw(); | |
734 | fOverviewCanvas.update(); | |
73005152 BH |
735 | } |
736 | ||
df0b8ff4 BH |
737 | /* |
738 | * (non-Javadoc) | |
739 | * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent) | |
740 | */ | |
73005152 BH |
741 | @Override |
742 | public void widgetDefaultSelected(SelectionEvent e) { | |
eb63f5ff | 743 | fPagesList = new int[0]; |
73005152 | 744 | computeStepXY(); |
eb63f5ff | 745 | fOverviewCanvas.redraw(); |
73005152 BH |
746 | } |
747 | ||
748 | }; | |
749 | ||
eb63f5ff | 750 | fModifyListener = new ModifyListener() { |
df0b8ff4 BH |
751 | /* |
752 | * (non-Javadoc) | |
753 | * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent) | |
754 | */ | |
73005152 BH |
755 | @Override |
756 | public void modifyText(ModifyEvent e) { | |
eb63f5ff | 757 | fPagesList = new int[0]; |
73005152 | 758 | computeStepXY(); |
eb63f5ff BH |
759 | fTotalPages.setText(Integer.valueOf(maxNumOfPages()).toString()); |
760 | fOverviewCanvas.redraw(); | |
73005152 BH |
761 | } |
762 | ||
763 | }; | |
764 | } | |
765 | ||
df0b8ff4 BH |
766 | // ------------------------------------------------------------------------ |
767 | // Methods | |
768 | // ------------------------------------------------------------------------ | |
769 | ||
770 | /** | |
771 | * Creates new grid data object. | |
772 | * | |
773 | * @param span horizontal span. | |
774 | * @return grid data | |
775 | */ | |
73005152 BH |
776 | protected GridData newGridData(int span) { |
777 | GridData data = new GridData(GridData.GRAB_VERTICAL | GridData.VERTICAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL); | |
778 | data.horizontalSpan = span; | |
779 | return data; | |
780 | } | |
781 | ||
df0b8ff4 BH |
782 | /** |
783 | * Creates the dialog area. | |
784 | * | |
785 | * @param parent The parent composite | |
786 | * @return dialog control | |
787 | */ | |
73005152 BH |
788 | public Control createDialogArea(Composite parent) { |
789 | ||
790 | GridLayout parentLayout = new GridLayout(); | |
791 | parentLayout.numColumns = 6; | |
792 | parent.setLayout(parentLayout); | |
793 | ||
794 | Group g1 = new Group(parent, SWT.SHADOW_NONE); | |
795 | g1.setText(SDMessages._113); | |
796 | g1.setLayoutData(newGridData(3)); | |
797 | GridLayout g1layout = new GridLayout(); | |
798 | g1layout.numColumns = 2; | |
799 | g1.setLayout(g1layout); | |
800 | ||
eb63f5ff BH |
801 | fUseCurrentZoom = new Button(g1, SWT.RADIO); |
802 | fUseCurrentZoom.setText(SDMessages._112); | |
803 | fUseCurrentZoom.setLayoutData(newGridData(2)); | |
804 | fUseCurrentZoom.addSelectionListener(fSelectionListener); | |
73005152 | 805 | |
eb63f5ff BH |
806 | fSetHPagesNumber = new Button(g1, SWT.RADIO); |
807 | fSetHPagesNumber.setText(SDMessages._110); | |
808 | fSetHPagesNumber.setLayoutData(newGridData(1)); | |
809 | fSetHPagesNumber.addSelectionListener(fSelectionListener); | |
73005152 | 810 | |
eb63f5ff BH |
811 | fHorPagesNum = new Text(g1, SWT.SINGLE | SWT.BORDER); |
812 | fHorPagesNum.addModifyListener(fModifyListener); | |
73005152 | 813 | |
eb63f5ff BH |
814 | fSetVPagesNumber = new Button(g1, SWT.RADIO); |
815 | fSetVPagesNumber.setText(SDMessages._111); | |
816 | fSetVPagesNumber.setLayoutData(newGridData(1)); | |
817 | fSetVPagesNumber.addSelectionListener(fSelectionListener); | |
73005152 | 818 | |
eb63f5ff BH |
819 | fVertPagesNum = new Text(g1, SWT.SINGLE | SWT.BORDER); |
820 | fVertPagesNum.addModifyListener(fModifyListener); | |
73005152 BH |
821 | |
822 | Label nbTotal = new Label(g1, SWT.SHADOW_NONE | SWT.RIGHT); | |
823 | nbTotal.setText(SDMessages._109); | |
824 | // nbTotal.setLayoutData(newGridData(1)); | |
825 | ||
eb63f5ff | 826 | fTotalPages = new Text(g1, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY); |
73005152 BH |
827 | // nbHV.addModifyListener(modifListener); |
828 | ||
829 | Group g2 = new Group(parent, SWT.SHADOW_NONE); | |
830 | g2.setText(SDMessages._119); | |
831 | GridData data = new GridData(GridData.GRAB_VERTICAL | GridData.VERTICAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL); | |
832 | data.horizontalSpan = 3; | |
833 | data.verticalSpan = 2; | |
834 | g2.setLayoutData(data); | |
835 | GridLayout g2layout = new GridLayout(); | |
836 | // g2layout. | |
837 | g2layout.numColumns = 1; | |
838 | // SVLayout g2layout = new SVLayout(); | |
839 | g2.setLayout(g2layout); | |
840 | ||
841 | GridData data2 = new GridData(GridData.GRAB_VERTICAL | GridData.VERTICAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL); | |
842 | data2.horizontalSpan = 1; | |
843 | data2.verticalSpan = 1; | |
844 | ||
eb63f5ff | 845 | fOverviewCanvas = new LocalSD(g2, SWT.NO_BACKGROUND); |
3145ec83 | 846 | GridData seqDiagLayoutData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL); |
eb63f5ff | 847 | fOverviewCanvas.setLayoutData(seqDiagLayoutData); |
73005152 | 848 | // overviewCanvas.resizeContents(100,100); |
eb63f5ff BH |
849 | if (fSdView.getContentsWidth() < fSdView.getVisibleWidth() && fSdView.getContentsHeight() < fSdView.getVisibleHeight()) { |
850 | fTest = 3; | |
df0b8ff4 | 851 | } else { |
eb63f5ff | 852 | fTest = 10; |
df0b8ff4 | 853 | } |
eb63f5ff BH |
854 | fOverviewCanvas.setFrame(fSdView.getFrame(), true); |
855 | fOverviewCanvas.fZoomValue = (float) 1 / fTest; | |
856 | fOverviewCanvas.setCornerControl(null); | |
857 | seqDiagLayoutData.widthHint = fOverviewCanvas.getContentsWidth() / fTest; | |
858 | seqDiagLayoutData.widthHint = fOverviewCanvas.getFrame().getWidth() / fTest + 15; | |
859 | ||
860 | if (fSdView.getVisibleWidth() < fSdView.getContentsWidth()) { | |
861 | seqDiagLayoutData.widthHint = fOverviewCanvas.getContentsWidth() / fTest; | |
df0b8ff4 | 862 | if (seqDiagLayoutData.widthHint > Display.getDefault().getClientArea().width / 4) { |
73005152 | 863 | seqDiagLayoutData.widthHint = Display.getDefault().getClientArea().width / 4; |
df0b8ff4 BH |
864 | } |
865 | } else { | |
eb63f5ff | 866 | seqDiagLayoutData.widthHint = fOverviewCanvas.getFrame().getWidth() / fTest + 15; |
df0b8ff4 | 867 | } |
73005152 | 868 | |
eb63f5ff BH |
869 | if (fSdView.getVisibleHeight() < fSdView.getContentsHeight()) { |
870 | seqDiagLayoutData.heightHint = fOverviewCanvas.getContentsHeight() / fTest; | |
df0b8ff4 | 871 | if (seqDiagLayoutData.heightHint > Display.getDefault().getClientArea().width / 4) { |
73005152 | 872 | seqDiagLayoutData.heightHint = Display.getDefault().getClientArea().width / 4; |
df0b8ff4 BH |
873 | } |
874 | } else { | |
eb63f5ff | 875 | seqDiagLayoutData.heightHint = fOverviewCanvas.getFrame().getHeight() / fTest; |
df0b8ff4 | 876 | } |
73005152 | 877 | |
eb63f5ff | 878 | fOverviewCanvas.setEnabled(false); |
73005152 | 879 | |
eb63f5ff BH |
880 | fCurrentSelection = new Label(g2, SWT.SHADOW_NONE | SWT.LEFT); |
881 | fCurrentSelection.setLayoutData(newGridData(1)); | |
73005152 BH |
882 | |
883 | Group g3 = new Group(parent, SWT.SHADOW_NONE); | |
884 | g3.setText(SDMessages._118); | |
885 | g3.setLayoutData(newGridData(3)); | |
886 | GridLayout g3layout = new GridLayout(); | |
887 | g3layout.numColumns = 4; | |
888 | g3.setLayout(g3layout); | |
889 | ||
eb63f5ff BH |
890 | fAllPages = new Button(g3, SWT.RADIO); |
891 | fAllPages.setText(SDMessages._108); | |
892 | fAllPages.setLayoutData(newGridData(4)); | |
893 | fAllPages.addSelectionListener(fSelectionListener); | |
73005152 | 894 | |
eb63f5ff BH |
895 | fCurrentPage = new Button(g3, SWT.RADIO); |
896 | fCurrentPage.setText(SDMessages._107); | |
897 | fCurrentPage.setLayoutData(newGridData(4)); | |
898 | fCurrentPage.setEnabled(true); | |
899 | fCurrentPage.setSelection(true); | |
900 | fCurrentPage.addSelectionListener(fSelectionListener); | |
73005152 | 901 | |
eb63f5ff BH |
902 | fPageList = new Button(g3, SWT.RADIO); |
903 | fPageList.setText(SDMessages._106); | |
904 | fPageList.setLayoutData(newGridData(4)); | |
905 | fPageList.addSelectionListener(fSelectionListener); | |
73005152 | 906 | |
eb63f5ff BH |
907 | fPageRange = new Button(g3, SWT.RADIO); |
908 | fPageRange.setText(SDMessages._103); | |
909 | fPageRange.setLayoutData(newGridData(1)); | |
910 | fPageRange.addSelectionListener(fSelectionListener); | |
73005152 | 911 | |
eb63f5ff | 912 | fFromPage = new Text(g3, SWT.SINGLE | SWT.BORDER); |
73005152 BH |
913 | |
914 | Label labelTo = new Label(g3, SWT.CENTER); | |
915 | labelTo.setText(SDMessages._105); | |
916 | ||
eb63f5ff | 917 | fToPage = new Text(g3, SWT.SINGLE | SWT.BORDER); |
73005152 | 918 | |
eb63f5ff | 919 | fToolTip = new DiagramToolTip(fOverviewCanvas); |
73005152 | 920 | |
eb63f5ff | 921 | fOverviewCanvas.getViewControl().addMouseTrackListener(new MouseTrackListener() { |
df0b8ff4 BH |
922 | /* |
923 | * (non-Javadoc) | |
924 | * @see org.eclipse.swt.events.MouseTrackListener#mouseEnter(org.eclipse.swt.events.MouseEvent) | |
925 | */ | |
73005152 BH |
926 | @Override |
927 | public void mouseEnter(MouseEvent e) { | |
eb63f5ff | 928 | fToolTip.hideToolTip(); |
73005152 BH |
929 | } |
930 | ||
df0b8ff4 BH |
931 | /* |
932 | * (non-Javadoc) | |
933 | * @see org.eclipse.swt.events.MouseTrackListener#mouseExit(org.eclipse.swt.events.MouseEvent) | |
934 | */ | |
73005152 BH |
935 | @Override |
936 | public void mouseExit(MouseEvent e) { | |
eb63f5ff | 937 | fToolTip.hideToolTip(); |
73005152 BH |
938 | } |
939 | ||
df0b8ff4 BH |
940 | /* |
941 | * (non-Javadoc) | |
942 | * @see org.eclipse.swt.events.MouseTrackListener#mouseHover(org.eclipse.swt.events.MouseEvent) | |
943 | */ | |
73005152 BH |
944 | @Override |
945 | public void mouseHover(MouseEvent e) { | |
eb63f5ff BH |
946 | int x1 = (int) (fOverviewCanvas.viewToContentsX(e.x) / fOverviewCanvas.fZoomValue / fStepX); |
947 | int x2 = (int) (fOverviewCanvas.viewToContentsY(e.y) / fOverviewCanvas.fZoomValue / fStepY); | |
73005152 | 948 | int num = x1 + x2 * getNbRow() + 1; |
df0b8ff4 | 949 | if (num > maxNumOfPages()) { |
73005152 | 950 | return; |
df0b8ff4 | 951 | } |
73005152 | 952 | if (num > 0) { |
eb63f5ff | 953 | fToolTip.showToolTip(String.valueOf(num)); |
73005152 BH |
954 | displayPageNum(); |
955 | } else { | |
eb63f5ff BH |
956 | fCurrentSelection.setText("");//$NON-NLS-1$ |
957 | fToolTip.hideToolTip(); | |
73005152 BH |
958 | } |
959 | } | |
960 | ||
961 | }); | |
962 | ||
3145ec83 | 963 | fOverviewCanvas.addTraverseListener(new LocalTraverseListener()); |
73005152 | 964 | |
eb63f5ff | 965 | fOverviewCanvas.addFocusListener(new FocusListener() { |
df0b8ff4 BH |
966 | /* |
967 | * (non-Javadoc) | |
968 | * @see org.eclipse.swt.events.FocusListener#focusGained(org.eclipse.swt.events.FocusEvent) | |
969 | */ | |
73005152 BH |
970 | @Override |
971 | public void focusGained(FocusEvent e) { | |
eb63f5ff | 972 | fOverviewCanvas.redraw(); |
73005152 BH |
973 | } |
974 | ||
df0b8ff4 BH |
975 | /* |
976 | * (non-Javadoc) | |
977 | * @see org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent) | |
978 | */ | |
73005152 BH |
979 | @Override |
980 | public void focusLost(FocusEvent e) { | |
eb63f5ff | 981 | fOverviewCanvas.redraw(); |
73005152 BH |
982 | } |
983 | }); | |
984 | ||
eb63f5ff | 985 | if (fShowPrintButton) { |
73005152 | 986 | Composite printerDlg = new Composite(parent, SWT.NONE); |
2fa130b8 | 987 | data = new GridData(SWT.FILL, SWT.DEFAULT, true, false); |
73005152 BH |
988 | data.horizontalSpan = 6; |
989 | parentLayout = new GridLayout(); | |
990 | parentLayout.numColumns = 2; | |
991 | printerDlg.setLayout(parentLayout); | |
992 | printerDlg.setLayoutData(data); | |
993 | ||
994 | Label label = new Label(printerDlg, SWT.NONE); | |
2fa130b8 | 995 | label.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false)); |
eb63f5ff BH |
996 | fPrinterDialog = new Button(printerDlg, SWT.PUSH); |
997 | fPrinterDialog.setText(SDMessages._115); | |
73005152 | 998 | |
eb63f5ff | 999 | fPrinterDialog.addSelectionListener(new SelectionListener() { |
73005152 | 1000 | |
df0b8ff4 BH |
1001 | /* |
1002 | * (non-Javadoc) | |
1003 | * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) | |
1004 | */ | |
73005152 BH |
1005 | @Override |
1006 | public void widgetSelected(SelectionEvent e) { | |
73005152 BH |
1007 | printButtonSelected(); |
1008 | } | |
1009 | ||
df0b8ff4 BH |
1010 | /* |
1011 | * (non-Javadoc) | |
1012 | * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent) | |
1013 | */ | |
73005152 BH |
1014 | @Override |
1015 | public void widgetDefaultSelected(SelectionEvent e) { | |
1016 | } | |
1017 | ||
1018 | }); | |
1019 | } | |
1020 | ||
1021 | updatePrinterStatus(); | |
1022 | ||
1023 | return parent; | |
1024 | } | |
1025 | ||
df0b8ff4 BH |
1026 | /** |
1027 | * Get number of pages for selection. | |
1028 | * @return number of pages for selection. | |
1029 | */ | |
73005152 | 1030 | public int getPagesForSelection() { |
eb63f5ff | 1031 | return fNbPages; |
73005152 BH |
1032 | } |
1033 | ||
1034 | public boolean okPressed() { | |
eb63f5ff BH |
1035 | fPrintAll = fAllPages.getSelection(); |
1036 | fPrintCurrent = fCurrentPage.getSelection(); | |
1037 | fPrintSelection = fPageList.getSelection(); | |
1038 | fPrintRange = fPageRange.getSelection(); | |
73005152 | 1039 | try { |
eb63f5ff BH |
1040 | if (fPrintRange) { |
1041 | fFrom = Integer.valueOf(fFromPage.getText()).intValue(); | |
1042 | fTo = Integer.valueOf(fToPage.getText()).intValue(); | |
1043 | if (fFrom > maxNumOfPages() || fTo > maxNumOfPages() || fFrom <= 0 || fTo <= 0) { | |
73005152 BH |
1044 | MessageDialog.openError(getShell(), SDMessages._98, SDMessages._99); |
1045 | return false; | |
1046 | } | |
eb63f5ff | 1047 | } else if (fSetHPagesNumber.getSelection() && fNbPages <= 0) { |
73005152 BH |
1048 | MessageDialog.openError(getShell(), SDMessages._98, SDMessages._101); |
1049 | return false; | |
eb63f5ff | 1050 | } else if (fSetVPagesNumber.getSelection() && fNbPages <= 0) { |
73005152 BH |
1051 | MessageDialog.openError(getShell(), SDMessages._98, SDMessages._100); |
1052 | return false; | |
eb63f5ff | 1053 | } else if (fPrintSelection && getPageList().length <= 0) { |
73005152 BH |
1054 | MessageDialog.openError(getShell(), SDMessages._98, SDMessages._102); |
1055 | return false; | |
1056 | } | |
1057 | ||
1058 | } catch (Exception e) { | |
1059 | MessageDialog.openError(getShell(), SDMessages._98, SDMessages._99); | |
eb63f5ff BH |
1060 | fFrom = 0; |
1061 | fTo = 0; | |
73005152 BH |
1062 | return false; |
1063 | } | |
1064 | ||
1065 | return true; | |
1066 | } | |
1067 | ||
df0b8ff4 BH |
1068 | /** |
1069 | * Draws region that was selected | |
1070 | * @param img The corresponding image | |
1071 | * @param r The selected rectangle. | |
1072 | * @param color The color to use for selection | |
eb63f5ff | 1073 | * @return image data reference |
df0b8ff4 | 1074 | */ |
73005152 BH |
1075 | public ImageData drawRegionSelected(Image img, Rectangle r, RGB color) { |
1076 | ImageData id = img.getImageData(); | |
1077 | for (int a = 0; a < r.width && r.x + a < id.width; a++) { | |
1078 | for (int b = 0; b < r.height && r.y + b < id.height; b++) { | |
1079 | int index = id.getPixel(r.x + a, r.y + b); | |
1080 | RGB rgb = id.palette.getRGB(index); | |
1081 | rgb = combine(color, rgb); | |
1082 | id.setPixel(r.x + a, r.y + b, id.palette.getPixel(rgb)); | |
1083 | } | |
1084 | } | |
1085 | return id; | |
1086 | } | |
1087 | ||
df0b8ff4 BH |
1088 | /** |
1089 | * Combines two RGB colors. | |
1090 | * @param front The front color | |
1091 | * @param back The back color | |
1092 | * @return new RGB color | |
1093 | */ | |
73005152 BH |
1094 | public static RGB combine(RGB front, RGB back) { |
1095 | int _af = 128; | |
73005152 | 1096 | int _ab = 200; |
73005152 BH |
1097 | |
1098 | double af = (_af) / 255.0; | |
1099 | double rf = front.red; | |
1100 | double gf = front.green; | |
1101 | double bf = front.blue; | |
1102 | ||
1103 | double ab = (_ab) / 255.0; | |
1104 | double rb = back.red; | |
1105 | double gb = back.green; | |
1106 | double bb = back.blue; | |
1107 | ||
1108 | double k = (1.0 - af) * ab; | |
1109 | int r = (int) ((af * rf + k * rb)); | |
1110 | int g = (int) ((af * gf + k * gb)); | |
1111 | int b = (int) ((af * bf + k * bb)); | |
1112 | ||
1113 | return new RGB(r, g, b); | |
1114 | } | |
1115 | ||
df0b8ff4 BH |
1116 | /** |
1117 | * Computes value for X coordinates step and Y coordinates step. | |
1118 | */ | |
73005152 | 1119 | protected void computeStepXY() { |
eb63f5ff BH |
1120 | float cw = fOverviewCanvas.getContentsWidth() / fOverviewCanvas.fZoomValue; |
1121 | float ch = fOverviewCanvas.getContentsHeight() / fOverviewCanvas.fZoomValue; | |
73005152 | 1122 | try { |
eb63f5ff BH |
1123 | if (fPrinterData == null) { |
1124 | fStepX = 0; | |
1125 | fStepY = 0; | |
1126 | fNbPages = 0; | |
1127 | fZoomFactor = 0; | |
73005152 | 1128 | } else { |
eb63f5ff BH |
1129 | Printer printer = new Printer(fPrinterData); |
1130 | if (fSetHPagesNumber.getSelection()) { | |
1131 | fNbPages = Integer.valueOf(fHorPagesNum.getText()).intValue(); | |
1132 | float z1 = (float) fSdView.getContentsWidth() / (cw); | |
1133 | float z2 = printer.getClientArea().width / ((float) fSdView.getContentsWidth() / fNbPages); | |
1134 | ||
1135 | fStepY = printer.getClientArea().height / z1 / z2; | |
1136 | fStepX = cw / fNbPages; | |
1137 | } else if (fSetVPagesNumber.getSelection()) { | |
1138 | fNbPages = Integer.valueOf(fVertPagesNum.getText()).intValue(); | |
1139 | float z1 = (float) fSdView.getContentsHeight() / (ch); | |
1140 | float z2 = printer.getClientArea().height / ((float) fSdView.getContentsHeight() / fNbPages); | |
1141 | fStepX = printer.getClientArea().width / z1 / z2; | |
1142 | fStepY = ch / fNbPages; | |
73005152 | 1143 | } else { |
eb63f5ff BH |
1144 | float z1 = fSdView.getContentsWidth() / (cw); |
1145 | fStepX = ((float) fSdView.getVisibleWidth() / z1); | |
1146 | fNbPages = Math.round(cw / fStepX); | |
1147 | if (fNbPages == 0) { | |
1148 | fNbPages = 1; | |
df0b8ff4 | 1149 | } |
73005152 BH |
1150 | int pw = printer.getClientArea().width; |
1151 | int ph = printer.getClientArea().height; | |
eb63f5ff BH |
1152 | float z2 = pw / ((float) fSdView.getContentsWidth() / fNbPages); |
1153 | fStepY = ((float) ph / z1 / z2); | |
73005152 BH |
1154 | } |
1155 | } | |
e6ace8bb | 1156 | } catch (NumberFormatException e) { |
eb63f5ff BH |
1157 | fStepX = fStepY = fNbPages = 0; |
1158 | fZoomFactor = 0; | |
73005152 | 1159 | } |
eb63f5ff BH |
1160 | sTX = fStepX * (fSdView.getContentsWidth() / cw); |
1161 | sTY = fStepY * (fSdView.getContentsHeight() / ch); | |
73005152 | 1162 | float rat = 1; |
eb63f5ff BH |
1163 | if ((fSdView.getVisibleWidth() > fSdView.getContentsWidth()) && (fSetVPagesNumber.getSelection() || fSetHPagesNumber.getSelection())) { |
1164 | rat = (float) fSdView.getVisibleWidth() / (float) fSdView.getContentsWidth(); | |
df0b8ff4 | 1165 | } |
3145ec83 | 1166 | fZoomFactor = (fOverviewCanvas.getContentsWidth() / cw) / fOverviewCanvas.getZoomFactor() * rat; |
73005152 BH |
1167 | } |
1168 | ||
df0b8ff4 | 1169 | /** |
eb63f5ff BH |
1170 | * Returns the pages list. |
1171 | * | |
df0b8ff4 BH |
1172 | * @return the pages list. |
1173 | */ | |
73005152 | 1174 | public int[] getPageList() { |
eb63f5ff | 1175 | return Arrays.copyOf(fPagesList, fPagesList.length); |
73005152 BH |
1176 | } |
1177 | ||
df0b8ff4 BH |
1178 | /** |
1179 | * Adds a page to pages list. | |
1180 | * @param num | |
1181 | */ | |
73005152 | 1182 | public void addToPagesList(int num) { |
eb63f5ff BH |
1183 | int temp[] = new int[fPagesList.length + 1]; |
1184 | System.arraycopy(fPagesList, 0, temp, 0, fPagesList.length); | |
73005152 | 1185 | temp[temp.length - 1] = num; |
eb63f5ff BH |
1186 | fPagesList = new int[temp.length]; |
1187 | System.arraycopy(temp, 0, fPagesList, 0, temp.length); | |
73005152 BH |
1188 | } |
1189 | ||
df0b8ff4 BH |
1190 | /** |
1191 | * Removes a page from the pages list. | |
1192 | * @param num | |
1193 | */ | |
73005152 | 1194 | public void removeFromPagesList(int num) { |
eb63f5ff BH |
1195 | int pos = Arrays.binarySearch(fPagesList, num); |
1196 | int temp[] = new int[fPagesList.length - 1]; | |
1197 | System.arraycopy(fPagesList, 0, temp, 0, pos); | |
1198 | System.arraycopy(fPagesList, pos + 1, temp, pos, fPagesList.length - pos - 1); | |
1199 | fPagesList = new int[temp.length]; | |
1200 | System.arraycopy(temp, 0, fPagesList, 0, temp.length); | |
73005152 BH |
1201 | } |
1202 | ||
df0b8ff4 | 1203 | /** |
eb63f5ff BH |
1204 | * Returns the maximum number of pages. |
1205 | * | |
df0b8ff4 BH |
1206 | * @return maximum number of pages. |
1207 | */ | |
73005152 | 1208 | public int maxNumOfPages() { |
eb63f5ff | 1209 | return (getNbRow() * getNbLines()); |
73005152 BH |
1210 | } |
1211 | ||
df0b8ff4 | 1212 | /** |
eb63f5ff BH |
1213 | * Returns the number of rows. |
1214 | * | |
df0b8ff4 BH |
1215 | * @return number of rows. |
1216 | */ | |
73005152 | 1217 | public int getNbRow() { |
eb63f5ff BH |
1218 | if (!fSetHPagesNumber.isDisposed()) { |
1219 | int cw = (int) (fOverviewCanvas.getContentsWidth() / fOverviewCanvas.fZoomValue); | |
e6ace8bb | 1220 | int row = 1; |
eb63f5ff BH |
1221 | if (fStepX != 0) { |
1222 | row = (int) (cw / fStepX); | |
1223 | if (fSetHPagesNumber.getSelection()) { | |
1224 | row = Math.round((float) cw / fStepX); | |
1225 | } else if ((cw % fStepX != 0)) { | |
e6ace8bb | 1226 | row++; |
df0b8ff4 | 1227 | } |
e6ace8bb | 1228 | } |
eb63f5ff | 1229 | fNbRows = row; |
73005152 | 1230 | } |
eb63f5ff | 1231 | return fNbRows; |
73005152 BH |
1232 | } |
1233 | ||
df0b8ff4 | 1234 | /** |
eb63f5ff BH |
1235 | * Returns the number of lines. |
1236 | * | |
df0b8ff4 BH |
1237 | * @return number of lines |
1238 | */ | |
73005152 | 1239 | public int getNbLines() { |
eb63f5ff BH |
1240 | if (!fSetVPagesNumber.isDisposed()) { |
1241 | int ch = (int) (fOverviewCanvas.getContentsHeight() / fOverviewCanvas.fZoomValue); | |
e6ace8bb | 1242 | int line = 1; |
eb63f5ff BH |
1243 | if (fStepY != 0) { |
1244 | line = (int) (ch / fStepY); | |
1245 | if (fSetVPagesNumber.getSelection()) { | |
1246 | line = Math.round((float) ch / fStepY); | |
1247 | } else if (ch % fStepY != 0) { | |
e6ace8bb | 1248 | line++; |
df0b8ff4 | 1249 | } |
e6ace8bb | 1250 | } |
eb63f5ff | 1251 | fNbLines = line; |
73005152 | 1252 | } |
eb63f5ff | 1253 | return fNbLines; |
73005152 BH |
1254 | } |
1255 | ||
df0b8ff4 | 1256 | /** |
eb63f5ff BH |
1257 | * Returns whether to print all pages or not. |
1258 | * | |
1259 | * @return <code>true</code> for all pages else <code>false</code>. | |
df0b8ff4 | 1260 | */ |
73005152 | 1261 | public boolean printAll() { |
eb63f5ff | 1262 | return fPrintAll; |
73005152 BH |
1263 | } |
1264 | ||
df0b8ff4 | 1265 | /** |
eb63f5ff BH |
1266 | * Returns whether to print only current page |
1267 | * | |
1268 | * @return <code>true</code> for current page only else <code>false</code>.. | |
df0b8ff4 | 1269 | */ |
73005152 | 1270 | public boolean printCurrent() { |
eb63f5ff | 1271 | return fPrintCurrent; |
73005152 BH |
1272 | } |
1273 | ||
df0b8ff4 | 1274 | /** |
eb63f5ff BH |
1275 | * Returns whether to print selected pages. |
1276 | * | |
1277 | * @return <code>true</code> for selected pages only else <code>false</code>. | |
df0b8ff4 | 1278 | */ |
73005152 | 1279 | public boolean printSelection() { |
eb63f5ff | 1280 | return fPrintSelection; |
73005152 | 1281 | } |
df0b8ff4 BH |
1282 | |
1283 | /** | |
eb63f5ff BH |
1284 | * Returns whether to print range of pages. |
1285 | * | |
1286 | * @return <code>true</code> for range of pages only else <code>false</code>. | |
df0b8ff4 | 1287 | */ |
73005152 | 1288 | public boolean printRange() { |
eb63f5ff | 1289 | return fPrintRange; |
73005152 BH |
1290 | } |
1291 | ||
df0b8ff4 | 1292 | /** |
eb63f5ff BH |
1293 | * Returns the step in X direction. |
1294 | * | |
df0b8ff4 BH |
1295 | * @return step in X direction |
1296 | */ | |
73005152 BH |
1297 | public float getStepX() { |
1298 | return sTX; | |
1299 | } | |
1300 | ||
df0b8ff4 | 1301 | /** |
eb63f5ff BH |
1302 | * Returns the step in Y direction. |
1303 | * | |
df0b8ff4 BH |
1304 | * @return step in Y direction |
1305 | */ | |
73005152 BH |
1306 | public float getStepY() { |
1307 | return sTY; | |
1308 | } | |
1309 | ||
df0b8ff4 | 1310 | /** |
eb63f5ff BH |
1311 | * Returns the zoom factor |
1312 | * | |
df0b8ff4 BH |
1313 | * @return zoom factor |
1314 | */ | |
73005152 | 1315 | public float getZoomFactor() { |
eb63f5ff | 1316 | return fZoomFactor; |
73005152 BH |
1317 | } |
1318 | ||
df0b8ff4 | 1319 | /** |
eb63f5ff BH |
1320 | * Returns the printer data reference. |
1321 | * | |
df0b8ff4 BH |
1322 | * @return printer data reference |
1323 | */ | |
73005152 | 1324 | public PrinterData getPrinterData() { |
eb63f5ff | 1325 | return fPrinterData; |
73005152 BH |
1326 | } |
1327 | ||
df0b8ff4 | 1328 | /** |
eb63f5ff BH |
1329 | * Returns the page number to start printing from. |
1330 | * | |
df0b8ff4 BH |
1331 | * @return page number to start printing from |
1332 | */ | |
73005152 | 1333 | public int getFrom() { |
eb63f5ff | 1334 | return fFrom; |
73005152 BH |
1335 | } |
1336 | ||
df0b8ff4 | 1337 | /** |
eb63f5ff BH |
1338 | * Returns the page number to print to. |
1339 | * | |
df0b8ff4 BH |
1340 | * @return page number to print to |
1341 | */ | |
73005152 | 1342 | public int getTo() { |
eb63f5ff | 1343 | return fTo; |
73005152 BH |
1344 | } |
1345 | ||
df0b8ff4 BH |
1346 | /** |
1347 | * Displays current number of pages | |
1348 | */ | |
73005152 | 1349 | protected void displayPageNum() { |
eb63f5ff BH |
1350 | if (fPageNum > 0) { |
1351 | String message = MessageFormat.format(SDMessages._117, new Object[] { Integer.valueOf(fPageNum) }); | |
1352 | fCurrentSelection.setText(message); | |
1353 | fCurrentSelection.getParent().layout(); | |
73005152 BH |
1354 | } |
1355 | } | |
1356 | ||
df0b8ff4 | 1357 | /** |
eb63f5ff BH |
1358 | * Returns the shell reference. |
1359 | * | |
df0b8ff4 BH |
1360 | * @return the shell reference. |
1361 | */ | |
73005152 | 1362 | public Shell getShell() { |
eb63f5ff | 1363 | return fShell; |
73005152 BH |
1364 | } |
1365 | ||
df0b8ff4 | 1366 | /** |
eb63f5ff BH |
1367 | * Sets the shell. |
1368 | * | |
df0b8ff4 BH |
1369 | * @param shell The shell reference. |
1370 | */ | |
73005152 | 1371 | public void setShell(Shell shell) { |
eb63f5ff | 1372 | fShell = shell; |
73005152 BH |
1373 | } |
1374 | ||
df0b8ff4 BH |
1375 | /** |
1376 | * Handle selection of print button. | |
1377 | */ | |
73005152 BH |
1378 | public void printButtonSelected() { |
1379 | PrintDialog printer = new PrintDialog(getShell()); | |
eb63f5ff | 1380 | if (fAllPages.getSelection()) { |
73005152 | 1381 | printer.setScope(PrinterData.ALL_PAGES); |
df0b8ff4 | 1382 | } |
eb63f5ff | 1383 | if (fCurrentPage.getSelection()) { |
73005152 | 1384 | printer.setScope(PrinterData.SELECTION); |
df0b8ff4 | 1385 | } |
eb63f5ff | 1386 | if (fPageList.getSelection()) { |
73005152 | 1387 | printer.setScope(PrinterData.SELECTION); |
df0b8ff4 | 1388 | } |
eb63f5ff | 1389 | if (fPageRange.getSelection()) { |
73005152 | 1390 | printer.setScope(PrinterData.PAGE_RANGE); |
eb63f5ff BH |
1391 | fFrom = Integer.valueOf(fFromPage.getText()).intValue(); |
1392 | fTo = Integer.valueOf(fToPage.getText()).intValue(); | |
1393 | printer.setStartPage(fFrom); | |
1394 | printer.setEndPage(fTo); | |
73005152 BH |
1395 | } |
1396 | ||
1397 | PrinterData newPrinterData = printer.open(); | |
1398 | if (newPrinterData != null) { | |
eb63f5ff | 1399 | fPrinterData = newPrinterData; |
73005152 BH |
1400 | } |
1401 | updatePrinterStatus(); | |
1402 | ||
1403 | if (printer.getScope() == PrinterData.ALL_PAGES) { | |
eb63f5ff BH |
1404 | fAllPages.setSelection(true); |
1405 | fCurrentPage.setSelection(false); | |
1406 | fPageList.setSelection(false); | |
1407 | fPageRange.setSelection(false); | |
1408 | fHorPagesNum.setEnabled(false); | |
1409 | fVertPagesNum.setEnabled(false); | |
73005152 BH |
1410 | } |
1411 | if (printer.getScope() == PrinterData.PAGE_RANGE) { | |
eb63f5ff BH |
1412 | fAllPages.setSelection(false); |
1413 | fCurrentPage.setSelection(false); | |
1414 | fPageList.setSelection(false); | |
1415 | fPageRange.setSelection(true); | |
1416 | fFromPage.setEnabled(true); | |
1417 | fToPage.setEnabled(true); | |
1418 | fFromPage.setText((Integer.valueOf(printer.getStartPage())).toString()); | |
1419 | fToPage.setText((Integer.valueOf(printer.getEndPage())).toString()); | |
73005152 BH |
1420 | } |
1421 | computeStepXY(); | |
eb63f5ff | 1422 | fOverviewCanvas.redraw(); |
73005152 BH |
1423 | } |
1424 | ||
df0b8ff4 BH |
1425 | /** |
1426 | * Sets parent wizard page | |
1427 | * | |
1428 | * @param parent The parent wizard page | |
1429 | */ | |
73005152 | 1430 | public void setParentWizardPage(WizardPage parent) { |
eb63f5ff | 1431 | fParentWizardPage = parent; |
73005152 BH |
1432 | } |
1433 | ||
df0b8ff4 BH |
1434 | /** |
1435 | * Sets the parent dialog box. | |
1436 | * | |
1437 | * @param parent The parent dialog box. | |
1438 | */ | |
73005152 | 1439 | public void setParentDialog(SDPrintDialog parent) { |
eb63f5ff | 1440 | fParentDialog = parent; |
73005152 BH |
1441 | } |
1442 | ||
df0b8ff4 BH |
1443 | /** |
1444 | * Updates the printer status | |
1445 | */ | |
73005152 | 1446 | protected void updatePrinterStatus() { |
eb63f5ff | 1447 | if (fParentWizardPage != null) { |
73005152 | 1448 | // used in the wizard dialog |
eb63f5ff | 1449 | if (fPrinterData == null) { |
73005152 | 1450 | // show error message and disable Finish button |
eb63f5ff BH |
1451 | fParentWizardPage.setErrorMessage(SDMessages._135); |
1452 | fParentWizardPage.setPageComplete(false); | |
73005152 BH |
1453 | } else { |
1454 | // clear error message and enable Finish button | |
eb63f5ff BH |
1455 | fParentWizardPage.setErrorMessage(null); |
1456 | fParentWizardPage.setPageComplete(true); | |
73005152 | 1457 | } |
eb63f5ff | 1458 | } else if (fParentDialog != null) { |
73005152 | 1459 | // used in the print dialog |
eb63f5ff | 1460 | if (fPrinterData == null) { |
73005152 | 1461 | // show error message and disable OK button |
eb63f5ff BH |
1462 | fParentDialog.setErrorMessage(SDMessages._135); |
1463 | fParentDialog.setPageComplete(false); | |
73005152 BH |
1464 | } else { |
1465 | // clear error message and enable OK button | |
eb63f5ff BH |
1466 | fParentDialog.setErrorMessage(null); |
1467 | fParentDialog.setPageComplete(true); | |
73005152 BH |
1468 | } |
1469 | } | |
1470 | } | |
1471 | ||
1472 | } |