Lines 11-16
Link Here
|
11 |
|
11 |
|
12 |
package org.eclipse.gmf.runtime.diagram.ui.printing.internal.printpreview; |
12 |
package org.eclipse.gmf.runtime.diagram.ui.printing.internal.printpreview; |
13 |
|
13 |
|
|
|
14 |
|
14 |
import java.util.ArrayList; |
15 |
import java.util.ArrayList; |
15 |
import java.util.List; |
16 |
import java.util.List; |
16 |
|
17 |
|
Lines 31-36
Link Here
|
31 |
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart; |
32 |
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart; |
32 |
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramRootEditPart; |
33 |
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramRootEditPart; |
33 |
import org.eclipse.gmf.runtime.diagram.ui.editparts.IDiagramPreferenceSupport; |
34 |
import org.eclipse.gmf.runtime.diagram.ui.editparts.IDiagramPreferenceSupport; |
|
|
35 |
import org.eclipse.gmf.runtime.diagram.ui.internal.editparts.PageBreakEditPart; |
36 |
import org.eclipse.gmf.runtime.diagram.ui.internal.figures.PageBreaksFigure; |
34 |
import org.eclipse.gmf.runtime.diagram.ui.internal.pagesetup.PageInfoHelper; |
37 |
import org.eclipse.gmf.runtime.diagram.ui.internal.pagesetup.PageInfoHelper; |
35 |
import org.eclipse.gmf.runtime.diagram.ui.internal.pagesetup.PageInfoHelper.PageMargins; |
38 |
import org.eclipse.gmf.runtime.diagram.ui.internal.pagesetup.PageInfoHelper.PageMargins; |
36 |
import org.eclipse.gmf.runtime.diagram.ui.internal.properties.WorkspaceViewerProperties; |
39 |
import org.eclipse.gmf.runtime.diagram.ui.internal.properties.WorkspaceViewerProperties; |
Lines 70-75
Link Here
|
70 |
import org.eclipse.swt.widgets.Menu; |
73 |
import org.eclipse.swt.widgets.Menu; |
71 |
import org.eclipse.swt.widgets.MenuItem; |
74 |
import org.eclipse.swt.widgets.MenuItem; |
72 |
import org.eclipse.swt.widgets.Shell; |
75 |
import org.eclipse.swt.widgets.Shell; |
|
|
76 |
import org.eclipse.swt.widgets.Text; |
73 |
import org.eclipse.swt.widgets.ToolBar; |
77 |
import org.eclipse.swt.widgets.ToolBar; |
74 |
import org.eclipse.swt.widgets.ToolItem; |
78 |
import org.eclipse.swt.widgets.ToolItem; |
75 |
import org.eclipse.ui.IEditorPart; |
79 |
import org.eclipse.ui.IEditorPart; |
Lines 80-89
Link Here
|
80 |
* methods, so you must create an instance of this class. |
84 |
* methods, so you must create an instance of this class. |
81 |
* |
85 |
* |
82 |
* Call doPrintPreview() after you've made an instance. |
86 |
* Call doPrintPreview() after you've made an instance. |
|
|
87 |
* |
88 |
* This class should be combined with the DiagramPrinter to reuse functionality. |
83 |
* |
89 |
* |
84 |
* @author Wayne Diu, wdiu |
90 |
* @author Wayne Diu, wdiu |
85 |
*/ |
91 |
*/ |
86 |
public class PrintPreviewHelper { |
92 |
public class PrintPreviewHelper{ |
87 |
|
93 |
|
88 |
/** |
94 |
/** |
89 |
* Action helper for print. This must be passed in to have something happen |
95 |
* Action helper for print. This must be passed in to have something happen |
Lines 279-286
Link Here
|
279 |
|
285 |
|
280 |
/** |
286 |
/** |
281 |
* The print preview helper is capable of showing zoom input. |
287 |
* The print preview helper is capable of showing zoom input. |
|
|
288 |
* userScale is a value between 0 and 1. |
282 |
*/ |
289 |
*/ |
283 |
protected double userScale = 1; |
290 |
protected double userScale = 1; |
|
|
291 |
|
292 |
/** |
293 |
* The amount to offset images. This is currently used with fit-to-page option. |
294 |
*/ |
295 |
protected Point translated = new Point(0,0); |
296 |
|
297 |
/** |
298 |
* Determine if we should consider fit to page options or not. |
299 |
*/ |
300 |
private boolean fitToPage = false; |
284 |
|
301 |
|
285 |
/** |
302 |
/** |
286 |
* Initialize all toolbar images |
303 |
* Initialize all toolbar images |
Lines 337-342
Link Here
|
337 |
public void doPrintPreview(IPrintActionHelper prActionHelper) { |
354 |
public void doPrintPreview(IPrintActionHelper prActionHelper) { |
338 |
this.printActionHelper = prActionHelper; |
355 |
this.printActionHelper = prActionHelper; |
339 |
|
356 |
|
|
|
357 |
setUserScale(PrintHelperUtil.getScale()); |
358 |
|
340 |
if (getDiagramEditorPart() == null) { |
359 |
if (getDiagramEditorPart() == null) { |
341 |
MessageDialog |
360 |
MessageDialog |
342 |
.openInformation(PlatformUI.getWorkbench() |
361 |
.openInformation(PlatformUI.getWorkbench() |
Lines 413-418
Link Here
|
413 |
public void widgetSelected(SelectionEvent e) { |
432 |
public void widgetSelected(SelectionEvent e) { |
414 |
//should not be enabled |
433 |
//should not be enabled |
415 |
Assert.isNotNull(printActionHelper); |
434 |
Assert.isNotNull(printActionHelper); |
|
|
435 |
|
416 |
printActionHelper |
436 |
printActionHelper |
417 |
.doPrint(PlatformUI.getWorkbench() |
437 |
.doPrint(PlatformUI.getWorkbench() |
418 |
.getActiveWorkbenchWindow().getActivePage() |
438 |
.getActiveWorkbenchWindow().getActivePage() |
Lines 470-480
Link Here
|
470 |
if (userY < 0) |
490 |
if (userY < 0) |
471 |
userY = 0; |
491 |
userY = 0; |
472 |
} |
492 |
} |
473 |
|
493 |
|
474 |
updateLeftRightUpDownButtonsForToolbar(); |
494 |
refreshComposite(); |
475 |
|
|
|
476 |
updateCompositeForNumberOfColumns(numberOfRowsToDisplay, |
477 |
numberOfColumnsToDisplay); |
478 |
|
495 |
|
479 |
} |
496 |
} |
480 |
|
497 |
|
Lines 553-561
Link Here
|
553 |
public void widgetSelected(SelectionEvent e) { |
570 |
public void widgetSelected(SelectionEvent e) { |
554 |
if (userX > 0) { |
571 |
if (userX > 0) { |
555 |
userX--; |
572 |
userX--; |
556 |
updateCompositeForNumberOfColumns(numberOfRowsToDisplay, |
573 |
refreshComposite(); |
557 |
numberOfColumnsToDisplay); |
|
|
558 |
updateLeftRightUpDownButtonsForToolbar(); |
559 |
} |
574 |
} |
560 |
} |
575 |
} |
561 |
|
576 |
|
Lines 589-597
Link Here
|
589 |
//check for max pages to be safe |
604 |
//check for max pages to be safe |
590 |
if (!(userX + numberOfColumnsToDisplay + 1 > getTotalNumberOfColumns())) { |
605 |
if (!(userX + numberOfColumnsToDisplay + 1 > getTotalNumberOfColumns())) { |
591 |
userX++; |
606 |
userX++; |
592 |
updateCompositeForNumberOfColumns(numberOfRowsToDisplay, |
607 |
refreshComposite(); |
593 |
numberOfColumnsToDisplay); |
|
|
594 |
updateLeftRightUpDownButtonsForToolbar(); |
595 |
} |
608 |
} |
596 |
} |
609 |
} |
597 |
|
610 |
|
Lines 615-623
Link Here
|
615 |
public void widgetSelected(SelectionEvent e) { |
628 |
public void widgetSelected(SelectionEvent e) { |
616 |
if (userY > 0) { |
629 |
if (userY > 0) { |
617 |
userY--; |
630 |
userY--; |
618 |
updateCompositeForNumberOfColumns(numberOfRowsToDisplay, |
631 |
refreshComposite(); |
619 |
numberOfColumnsToDisplay); |
|
|
620 |
updateLeftRightUpDownButtonsForToolbar(); |
621 |
} |
632 |
} |
622 |
} |
633 |
} |
623 |
|
634 |
|
Lines 641-649
Link Here
|
641 |
public void widgetSelected(SelectionEvent e) { |
652 |
public void widgetSelected(SelectionEvent e) { |
642 |
if (!(userY + numberOfRowsToDisplay + 1 > getTotalNumberOfRows())) { |
653 |
if (!(userY + numberOfRowsToDisplay + 1 > getTotalNumberOfRows())) { |
643 |
userY++; |
654 |
userY++; |
644 |
updateCompositeForNumberOfColumns(numberOfRowsToDisplay, |
655 |
refreshComposite(); |
645 |
numberOfColumnsToDisplay); |
|
|
646 |
updateLeftRightUpDownButtonsForToolbar(); |
647 |
} |
656 |
} |
648 |
} |
657 |
} |
649 |
|
658 |
|
Lines 654-660
Link Here
|
654 |
widgetSelected(e); |
663 |
widgetSelected(e); |
655 |
} |
664 |
} |
656 |
}); |
665 |
}); |
|
|
666 |
|
667 |
new ToolItem(bar, SWT.SEPARATOR); |
668 |
|
669 |
ToolItem separator = new ToolItem(bar, SWT.SEPARATOR); |
670 |
Text textField = new Text(bar, SWT.SINGLE | SWT.BORDER); |
671 |
textField.setText("XXXXX");//$NON-NLS-1$ |
672 |
textField.setEnabled(true); |
673 |
textField.pack(); |
674 |
textField.setText(getDisplayScale(PrintHelperUtil.getScale())); |
675 |
|
676 |
separator.setWidth(textField.getBounds().width); |
677 |
separator.setControl(textField); |
678 |
|
679 |
textField.addSelectionListener(new SelectionListener() { |
680 |
|
681 |
public void widgetSelected(SelectionEvent e) { |
682 |
// do nothing. |
683 |
} |
684 |
|
685 |
public void widgetDefaultSelected(SelectionEvent e) { |
686 |
String scaleFactor = ((Text) e.getSource()).getText(); |
657 |
|
687 |
|
|
|
688 |
int percentageIndex = scaleFactor.indexOf("%"); //$NON-NLS-1$ |
689 |
if (percentageIndex > 0) { |
690 |
scaleFactor = scaleFactor.substring(0, percentageIndex); |
691 |
} |
692 |
int scalePercentage = Integer.parseInt(scaleFactor); |
693 |
setPercentScaling(scalePercentage); |
694 |
refreshComposite(); |
695 |
((Text) e.getSource()).setText(getDisplayScale(scalePercentage)); |
696 |
} |
697 |
}); |
698 |
|
658 |
new ToolItem(bar, SWT.SEPARATOR); |
699 |
new ToolItem(bar, SWT.SEPARATOR); |
659 |
closeTool = new ToolItem(bar, SWT.NULL); |
700 |
closeTool = new ToolItem(bar, SWT.NULL); |
660 |
closeTool.setToolTipText(DiagramUIPrintingMessages.PrintPreview_CloseToolItem); |
701 |
closeTool.setToolTipText(DiagramUIPrintingMessages.PrintPreview_CloseToolItem); |
Lines 690-706
Link Here
|
690 |
|
731 |
|
691 |
composite = new Composite(body, SWT.NULL); |
732 |
composite = new Composite(body, SWT.NULL); |
692 |
composite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true)); |
733 |
composite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true)); |
693 |
|
734 |
|
694 |
updateCompositeForNumberOfColumns(numberOfRowsToDisplay, numberOfColumnsToDisplay); |
735 |
refreshComposite(); |
695 |
|
|
|
696 |
updateLeftRightUpDownButtonsForToolbar(); |
697 |
|
736 |
|
698 |
shell.open(); |
737 |
shell.open(); |
699 |
while (!shell.isDisposed()) { |
738 |
while (!shell.isDisposed()) { |
700 |
if (!display.readAndDispatch()) |
739 |
if (!display.readAndDispatch()) |
701 |
display.sleep(); |
740 |
display.sleep(); |
702 |
} |
741 |
} |
703 |
|
742 |
|
|
|
743 |
dispose(); |
704 |
shell.dispose(); |
744 |
shell.dispose(); |
705 |
|
745 |
|
706 |
} |
746 |
} |
Lines 926-931
Link Here
|
926 |
} |
966 |
} |
927 |
|
967 |
|
928 |
/** |
968 |
/** |
|
|
969 |
* A convenience method for refreshing the displayed image in the preview. |
970 |
*/ |
971 |
private void refreshComposite(){ |
972 |
|
973 |
updateCompositeForNumberOfColumns(numberOfRowsToDisplay, |
974 |
numberOfColumnsToDisplay); |
975 |
|
976 |
updateLeftRightUpDownButtonsForToolbar(); |
977 |
} |
978 |
|
979 |
/** |
929 |
* Draw the composite centered on the body based on the number of columns. |
980 |
* Draw the composite centered on the body based on the number of columns. |
930 |
* Also calls the method to make the images and insert them into the |
981 |
* Also calls the method to make the images and insert them into the |
931 |
* composite. |
982 |
* composite. |
Lines 984-993
Link Here
|
984 |
|
1035 |
|
985 |
PageMargins margins = PageInfoHelper.getPageMargins(getPreferenceStore(), getMapMode()); |
1036 |
PageMargins margins = PageInfoHelper.getPageMargins(getPreferenceStore(), getMapMode()); |
986 |
|
1037 |
|
987 |
margins.left /= userScale; |
|
|
988 |
margins.right /= userScale; |
989 |
margins.bottom /= userScale; |
990 |
margins.top /= userScale; |
991 |
|
1038 |
|
992 |
//make sure height and width are not 0, if too small <4, don't bother |
1039 |
//make sure height and width are not 0, if too small <4, don't bother |
993 |
if (!(imageHeight <= 4 || imageWidth <= 4)) { |
1040 |
if (!(imageHeight <= 4 || imageWidth <= 4)) { |
Lines 998-1003
Link Here
|
998 |
|
1045 |
|
999 |
scale *= userScale; |
1046 |
scale *= userScale; |
1000 |
|
1047 |
|
|
|
1048 |
margins.left /= userScale; |
1049 |
margins.right /= userScale; |
1050 |
margins.bottom /= userScale; |
1051 |
margins.top /= userScale; |
1052 |
|
1053 |
Rectangle figureBounds = getDiagramEditPart().getChildrenBounds(); |
1054 |
|
1055 |
translated = new Point((int) (-figureBounds.x * scale ), |
1056 |
(int) (-figureBounds.y * scale)); |
1057 |
|
1001 |
for (int i = 0; i < numberOfRows; i++) { |
1058 |
for (int i = 0; i < numberOfRows; i++) { |
1002 |
for (int j = 0; j < numberOfColumns; j++) { |
1059 |
for (int j = 0; j < numberOfColumns; j++) { |
1003 |
Label label = new Label(composite, SWT.NULL); |
1060 |
Label label = new Label(composite, SWT.NULL); |
Lines 1007-1013
Link Here
|
1007 |
imageList.add(pageImg); |
1064 |
imageList.add(pageImg); |
1008 |
} |
1065 |
} |
1009 |
} |
1066 |
} |
1010 |
|
|
|
1011 |
} |
1067 |
} |
1012 |
|
1068 |
|
1013 |
composite.pack(); |
1069 |
composite.pack(); |
Lines 1091-1118
Link Here
|
1091 |
|
1147 |
|
1092 |
//if mmg's font is null, gc.setFont will use a default font |
1148 |
//if mmg's font is null, gc.setFont will use a default font |
1093 |
gc.setFont(mmg.getFont()); |
1149 |
gc.setFont(mmg.getFont()); |
1094 |
drawPage(mmg, gc, scale, row, col, margins); |
1150 |
|
1095 |
|
1151 |
if (fitToPage) { |
|
|
1152 |
Rectangle figureBounds = getDiagramEditPart().getChildrenBounds(); |
1153 |
drawFitToPage(scale, getDiagramEditPart(), figureBounds, |
1154 |
getPreferenceStore(), margins, mmg, row, col); |
1155 |
} else { |
1156 |
drawPage(mmg, gc, scale, row, col, margins); |
1157 |
} |
1158 |
|
1096 |
gc.dispose(); |
1159 |
gc.dispose(); |
1097 |
|
1160 |
|
1098 |
return image; |
1161 |
return image; |
1099 |
|
|
|
1100 |
} |
1101 |
|
1102 |
/** |
1103 |
* Convenience method to determine if a page at row y and |
1104 |
* column x exists. |
1105 |
* Pages start at 1. |
1106 |
* |
1107 |
* For example, the first page is 1-1. |
1108 |
* |
1109 |
* @param x, column number of the page to check |
1110 |
* @param y, row number of the page to check |
1111 |
* |
1112 |
* @return boolean true if the page exists, false if it doesn't |
1113 |
*/ |
1114 |
private boolean doesPageExist(int x, int y) { |
1115 |
return x > 0 && y > 0 && x <= getTotalNumberOfColumns() && y <= getTotalNumberOfRows(); |
1116 |
} |
1162 |
} |
1117 |
|
1163 |
|
1118 |
/** |
1164 |
/** |
Lines 1137-1149
Link Here
|
1137 |
* displaying in the print preview. |
1183 |
* displaying in the print preview. |
1138 |
*/ |
1184 |
*/ |
1139 |
protected void drawPage(Graphics g, GC gc, float scale, int row, int col, PageMargins margins) { |
1185 |
protected void drawPage(Graphics g, GC gc, float scale, int row, int col, PageMargins margins) { |
|
|
1186 |
|
1140 |
org.eclipse.draw2d.geometry.Point pageSize = PageInfoHelper |
1187 |
org.eclipse.draw2d.geometry.Point pageSize = PageInfoHelper |
1141 |
.getPageSize(getPreferenceStore(), false, getMapMode()); |
1188 |
.getPageSize(getPreferenceStore(), false, getMapMode()); |
1142 |
|
1189 |
|
1143 |
g.pushState(); |
1190 |
g.pushState(); |
1144 |
|
1191 |
|
1145 |
Rectangle bounds = getBounds(); |
1192 |
Rectangle bounds = getBounds(); |
1146 |
|
1193 |
|
1147 |
int scaledPageSizeWidth = (int)(pageSize.x/userScale) ; |
1194 |
int scaledPageSizeWidth = (int)(pageSize.x/userScale) ; |
1148 |
int scaledPageSizeHeight = (int)(pageSize.y/userScale) ; |
1195 |
int scaledPageSizeHeight = (int)(pageSize.y/userScale) ; |
1149 |
|
1196 |
|
Lines 1205-1210
Link Here
|
1205 |
|
1252 |
|
1206 |
g.popState(); |
1253 |
g.popState(); |
1207 |
} |
1254 |
} |
|
|
1255 |
|
1256 |
/** |
1257 |
* The real rendering of the page to the given graphical object occurs here. |
1258 |
*/ |
1259 |
protected void drawFitToPage(float scale, DiagramEditPart dgrmEP, |
1260 |
Rectangle figureBounds, IPreferenceStore fPreferences, |
1261 |
PageMargins margins, Graphics g, int rowIndex, int colIndex) { |
1262 |
|
1263 |
org.eclipse.draw2d.geometry.Point pageSize = PageInfoHelper |
1264 |
.getPageSize(fPreferences, false, getMapMode()); |
1265 |
|
1266 |
int width = pageSize.x, height = pageSize.y; |
1267 |
|
1268 |
g.pushState(); |
1269 |
|
1270 |
g.translate(translated.x, translated.y); |
1271 |
g.scale(scale); |
1272 |
|
1273 |
int translateX = -(width * (colIndex + userX)); |
1274 |
int translateY = -(height * (rowIndex + userY)); |
1275 |
|
1276 |
int scaledTranslateX = (int) ((translateX / scale)); |
1277 |
int scaledTranslateY = (int) ((translateY / scale)); |
1278 |
|
1279 |
|
1280 |
scaledTranslateX += ((margins.left * (colIndex+1)) + (margins.right * (colIndex + userX))); |
1281 |
scaledTranslateY += ((margins.top * (rowIndex+1)) + (margins.bottom * (rowIndex + userY))); |
1282 |
|
1283 |
g.translate(scaledTranslateX, scaledTranslateY); |
1284 |
|
1285 |
int scaledWidth = (int) ((width / scale) * userScale); |
1286 |
int scaledHeight = (int) ((height / scale) * userScale); |
1287 |
|
1288 |
Rectangle clip = new Rectangle( |
1289 |
(scaledWidth - margins.left - margins.right) |
1290 |
* (colIndex + userX) + figureBounds.x, |
1291 |
(scaledHeight - margins.bottom - margins.top) |
1292 |
* (rowIndex + userY) + figureBounds.y, scaledWidth |
1293 |
- margins.right - margins.left, scaledHeight |
1294 |
- margins.top - margins.bottom); |
1295 |
g.clipRect(clip); |
1296 |
|
1297 |
dgrmEP.getLayer(LayerConstants.PRINTABLE_LAYERS).paint(g); |
1298 |
|
1299 |
g.popState(); |
1300 |
} |
1301 |
|
1302 |
|
1303 |
/** |
1304 |
* Convenience method to determine if a page at row y and |
1305 |
* column x exists. |
1306 |
* Pages start at 1. |
1307 |
* |
1308 |
* For example, the first page is 1-1. |
1309 |
* |
1310 |
* @param x, column number of the page to check |
1311 |
* @param y, row number of the page to check |
1312 |
* |
1313 |
* @return boolean true if the page exists, false if it doesn't |
1314 |
*/ |
1315 |
private boolean doesPageExist(int x, int y) { |
1316 |
return x > 0 && y > 0 && x <= getTotalNumberOfColumns() && y <= getTotalNumberOfRows(); |
1317 |
} |
1318 |
|
1208 |
|
1319 |
|
1209 |
/** |
1320 |
/** |
1210 |
* Safely dispose an image |
1321 |
* Safely dispose an image |
Lines 1271-1279
Link Here
|
1271 |
ScaledGraphics scaledGraphics) { |
1382 |
ScaledGraphics scaledGraphics) { |
1272 |
return new MapModeGraphics(scaledGraphics, getMapMode()); |
1383 |
return new MapModeGraphics(scaledGraphics, getMapMode()); |
1273 |
} |
1384 |
} |
1274 |
|
1385 |
|
1275 |
public void setUserScale(double userScale){ |
1386 |
/** |
1276 |
this.userScale = userScale; |
1387 |
* Sets the scale factor. |
|
|
1388 |
* |
1389 |
* @param scale : valid input is an integer larger than 0 representing a scale percentage |
1390 |
*/ |
1391 |
private void setUserScale(int scale){ |
1392 |
userScale = scale/100f; |
1393 |
PrintHelperUtil.setScale(scale); |
1277 |
} |
1394 |
} |
|
|
1395 |
|
1396 |
/** |
1397 |
* Prepare a string appropriate to show the scale factor to the user. |
1398 |
* |
1399 |
* @param scale the scale factor, an integer greater than 0. |
1400 |
* @return A string of the scale factor to be displayed to the user. |
1401 |
*/ |
1402 |
private String getDisplayScale(int scale) { |
1403 |
return String.valueOf(scale) + "%"; //$NON-NLS-1$ |
1404 |
} |
1405 |
|
1278 |
|
1406 |
|
|
|
1407 |
/** |
1408 |
* Determine the page count when fit to page is used. |
1409 |
* |
1410 |
* @param dgrmEP - The diagram edit part |
1411 |
* @param figureBounds - The bounds of the figure |
1412 |
* @param pageSize - Page size |
1413 |
* @param applyUserScale - The user scale |
1414 |
* @return Point.x contains the total number of pages that span in a column |
1415 |
* Point.y contains the total number of pages that span in a row |
1416 |
*/ |
1417 |
protected org.eclipse.draw2d.geometry.Point getPageCount( |
1418 |
DiagramEditPart dgrmEP, Rectangle figureBounds, |
1419 |
org.eclipse.draw2d.geometry.Point pageSize, boolean applyUserScale) { |
1420 |
RootEditPart rootEditPart = dgrmEP.getRoot(); |
1421 |
|
1422 |
if (rootEditPart instanceof DiagramRootEditPart) { |
1423 |
|
1424 |
DiagramRootEditPart diagramRootEditPart = (DiagramRootEditPart) rootEditPart; |
1425 |
PageBreakEditPart pageBreakEditPart = diagramRootEditPart |
1426 |
.getPageBreakEditPart(); |
1427 |
|
1428 |
double fNumCols = ((PageBreaksFigure) pageBreakEditPart.getFigure()) |
1429 |
.getPageCount().y |
1430 |
* (applyUserScale ? userScale : 1); |
1431 |
|
1432 |
double fNumRows = ((PageBreaksFigure) pageBreakEditPart.getFigure()) |
1433 |
.getPageCount().x |
1434 |
* (applyUserScale ? userScale : 1); |
1435 |
|
1436 |
int numCols = (int) Math.ceil(fNumCols); |
1437 |
int numRows = (int) Math.ceil(fNumRows); |
1438 |
|
1439 |
return new org.eclipse.draw2d.geometry.Point(numCols, numRows); |
1440 |
|
1441 |
} else { |
1442 |
double fNumRows = (figureBounds.height * (applyUserScale ? userScale : 1)) |
1443 |
/ pageSize.y; |
1444 |
int numRows = (int) Math.ceil(fNumRows); |
1445 |
|
1446 |
double fNumCols = (figureBounds.width * (applyUserScale ? userScale : 1)) |
1447 |
/ pageSize.x; |
1448 |
int numCols = (int) Math.ceil(fNumCols); |
1449 |
|
1450 |
return new org.eclipse.draw2d.geometry.Point(numCols, numRows); |
1451 |
} |
1452 |
} |
1453 |
|
1454 |
/** |
1455 |
* Reset the fit to page flag and set the user scale when the |
1456 |
* preview is triggered from the print dialog. |
1457 |
* |
1458 |
* @param userScale a whole number greater than zero |
1459 |
*/ |
1460 |
public void setPercentScaling(int userScale){ |
1461 |
fitToPage = false; |
1462 |
setUserScale(userScale); |
1463 |
} |
1464 |
|
1465 |
/** |
1466 |
* Recalculates a zoom ratio that can be used when displaying fit to page. |
1467 |
* |
1468 |
* @param rows The number of rows to fit the display to. |
1469 |
* @param columns The number of columns to fit the display to. |
1470 |
*/ |
1471 |
public void setFitToPage(int rows, int columns) { |
1472 |
|
1473 |
fitToPage = true; |
1474 |
|
1475 |
initializeMapMode(); |
1476 |
Rectangle figureBounds = PrintHelperUtil.getPageBreakBounds( |
1477 |
getDiagramEditPart(), true); |
1478 |
|
1479 |
org.eclipse.draw2d.geometry.Point pageBounds = PageInfoHelper |
1480 |
.getPageSize(getPreferenceStore(), getMapMode()); |
1481 |
org.eclipse.draw2d.geometry.Point pageCount = getPageCount( |
1482 |
getDiagramEditPart(), figureBounds, pageBounds, true); |
1483 |
int numCols = pageCount.x; |
1484 |
int numRows = pageCount.y; |
1485 |
|
1486 |
float actualWidth = 0; |
1487 |
float actualHeight = 0; |
1488 |
|
1489 |
if (rows == 1 && columns == 1) { |
1490 |
figureBounds = getDiagramEditPart().getChildrenBounds(); |
1491 |
actualWidth = figureBounds.width; |
1492 |
actualHeight = figureBounds.height; |
1493 |
} else { |
1494 |
actualWidth = numCols * pageBounds.x; |
1495 |
actualHeight = numRows * pageBounds.y; |
1496 |
} |
1497 |
|
1498 |
int totalHeight = (rows * pageBounds.y); |
1499 |
int totalWidth = (columns * pageBounds.x); |
1500 |
|
1501 |
int vScale = (int) ((totalHeight * 100) / actualHeight); |
1502 |
int hScale = (int) ((totalWidth * 100) / actualWidth); |
1503 |
|
1504 |
setUserScale(Math.min(hScale, vScale)); |
1505 |
} |
1506 |
|
1279 |
} |
1507 |
} |