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