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