### Eclipse Workspace Patch 1.0
#P org.eclipse.gmf.runtime.diagram.ui.render
Index: plugin.xml
===================================================================
RCS file: /cvsroot/modeling/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.diagram.ui.render/plugin.xml,v
retrieving revision 1.4
diff -u -r1.4 plugin.xml
--- plugin.xml 20 Jan 2006 22:07:26 -0000 1.4
+++ plugin.xml 29 Feb 2008 18:52:52 -0000
@@ -23,6 +23,17 @@
+
+
+
+
+
+
+
+
+
+
+
Index: META-INF/MANIFEST.MF
===================================================================
RCS file: /cvsroot/modeling/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.diagram.ui.render/META-INF/MANIFEST.MF,v
retrieving revision 1.16
diff -u -r1.16 MANIFEST.MF
--- META-INF/MANIFEST.MF 31 Oct 2007 16:34:19 -0000 1.16
+++ META-INF/MANIFEST.MF 29 Feb 2008 18:52:52 -0000
@@ -25,5 +25,7 @@
org.eclipse.gmf.runtime.draw2d.ui.render;bundle-version="[1.0.0,2.0.0)",
org.eclipse.gmf.runtime.emf.commands.core;bundle-version="[1.0.0,2.0.0)",
org.eclipse.gmf.runtime.diagram.ui.providers;bundle-version="[1.0.0,2.0.0)",
- org.eclipse.gmf.runtime.draw2d.ui.render.awt;bundle-version="[1.0.0,2.0.0)"
+ org.eclipse.gmf.runtime.draw2d.ui.render.awt;bundle-version="[1.0.0,2.0.0)",
+ org.eclipse.gmf.runtime.diagram.ui.printing.render,
+ org.eclipse.gmf.runtime.diagram.ui.printing
Eclipse-LazyStart: true
Index: src/org/eclipse/gmf/runtime/diagram/ui/render/internal/providers/PrintingExperimentalContributionItemProvider.java
===================================================================
RCS file: src/org/eclipse/gmf/runtime/diagram/ui/render/internal/providers/PrintingExperimentalContributionItemProvider.java
diff -N src/org/eclipse/gmf/runtime/diagram/ui/render/internal/providers/PrintingExperimentalContributionItemProvider.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/gmf/runtime/diagram/ui/render/internal/providers/PrintingExperimentalContributionItemProvider.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,40 @@
+/******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ****************************************************************************/
+
+package org.eclipse.gmf.runtime.diagram.ui.render.internal.providers;
+
+import org.eclipse.gmf.runtime.common.ui.services.action.contributionitem.AbstractContributionItemProvider;
+import org.eclipse.gmf.runtime.common.ui.util.IWorkbenchPartDescriptor;
+import org.eclipse.jface.action.IAction;
+
+
+/**
+ * This class is strictly temporary while we introduce the printing via the
+ * Print Service API.
+ *
+ * @author James Bruck (jbruck)
+ */
+public class PrintingExperimentalContributionItemProvider extends
+ AbstractContributionItemProvider {
+
+ /**
+ * @see org.eclipse.gmf.runtime.common.ui.services.action.contributionitem.AbstractContributionItemProvider#createAction(java.lang.String, org.eclipse.gmf.runtime.common.ui.services.contributionitem.IWorkbenchPartDescriptor)
+ */
+ protected IAction createAction(
+ String actionId,
+ IWorkbenchPartDescriptor partDescriptor) {
+
+ if (actionId.equals(PrintExperimentalAction.ID))
+ return new PrintExperimentalAction();
+
+ return super.createAction(actionId, partDescriptor);
+ }
+}
Index: src/org/eclipse/gmf/runtime/diagram/ui/render/internal/providers/PrintExperimentalAction.java
===================================================================
RCS file: src/org/eclipse/gmf/runtime/diagram/ui/render/internal/providers/PrintExperimentalAction.java
diff -N src/org/eclipse/gmf/runtime/diagram/ui/render/internal/providers/PrintExperimentalAction.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/gmf/runtime/diagram/ui/render/internal/providers/PrintExperimentalAction.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,138 @@
+/******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ****************************************************************************/
+
+package org.eclipse.gmf.runtime.diagram.ui.render.internal.providers;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.gef.RootEditPart;
+import org.eclipse.gmf.runtime.common.core.util.Log;
+import org.eclipse.gmf.runtime.common.core.util.Trace;
+import org.eclipse.gmf.runtime.common.ui.action.actions.IPrintActionHelper;
+import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramRootEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IDiagramPreferenceSupport;
+import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor;
+import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramGraphicalViewer;
+import org.eclipse.gmf.runtime.diagram.ui.printing.render.actions.EnhancedPrintActionHelper;
+import org.eclipse.gmf.runtime.diagram.ui.printing.render.internal.DiagramUIPrintingRenderDebugOptions;
+import org.eclipse.gmf.runtime.diagram.ui.printing.render.internal.DiagramUIPrintingRenderPlugin;
+import org.eclipse.gmf.runtime.diagram.ui.printing.render.internal.JPSDiagramPrinter;
+import org.eclipse.gmf.runtime.diagram.ui.printing.render.internal.JPSDiagramPrinterHelper;
+import org.eclipse.gmf.runtime.draw2d.ui.mapmode.IMapMode;
+import org.eclipse.gmf.runtime.draw2d.ui.mapmode.MapModeUtil;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.IWorkbenchWindowActionDelegate;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * This class is strictly temporary while we introduce the printing via the
+ * Print Service API.
+ *
+ * @author James Bruck (jbruck)
+ */
+public class PrintExperimentalAction extends Action implements
+ IWorkbenchWindowActionDelegate {
+
+ /**
+ * ID for this page setup action
+ */
+ public static final String ID = "printExperimentalAction";//$NON-NLS-1$
+
+ /**
+ * Constructor sets the id and label that is displayed in the menu bar.
+ */
+ public PrintExperimentalAction() {
+ setId(ID);
+ setText("Print (Experimental)..."); //$NON-NLS-1$
+ }
+
+ /**
+ * We override the print to always use the newer JPS printing options.
+ */
+ public void run() {
+
+ IPrintActionHelper helper = new EnhancedPrintActionHelper() {
+ @Override
+ public void doPrint(IWorkbenchPart workbenchPart) {
+
+ DiagramEditor diagramEditor = null;
+
+ if (workbenchPart instanceof DiagramEditor) {
+ diagramEditor = (DiagramEditor) workbenchPart;
+ } else {
+ Log.error(DiagramUIPrintingRenderPlugin.getInstance(),
+ IStatus.ERROR, "Invalid IWorkbenchPart"); //$NON-NLS-1$
+ IllegalArgumentException e = new IllegalArgumentException(
+ "Invalid IWorkbenchPart."); //$NON-NLS-1$
+ Trace
+ .throwing(
+ DiagramUIPrintingRenderPlugin.getInstance(),
+ DiagramUIPrintingRenderDebugOptions.EXCEPTIONS_THROWING,
+ EnhancedPrintActionHelper.class,
+ "doPrint()", e); //$NON-NLS-1$
+ throw e;
+ }
+
+ IDiagramGraphicalViewer viewer = diagramEditor
+ .getDiagramGraphicalViewer();
+ RootEditPart rootEP = (viewer == null) ? null : viewer
+ .getRootEditPart();
+ PreferencesHint preferencesHint = (rootEP instanceof IDiagramPreferenceSupport) ? ((IDiagramPreferenceSupport) rootEP)
+ .getPreferencesHint()
+ : PreferencesHint.USE_DEFAULTS;
+
+ IMapMode mapMode = (rootEP instanceof DiagramRootEditPart) ? ((DiagramRootEditPart) rootEP)
+ .getMapMode()
+ : MapModeUtil.getMapMode();
+
+ JPSDiagramPrinterHelper
+ .getDiagramPrinterHelper()
+ .printWithSettings(diagramEditor, createDiagramMap(),
+ new JPSDiagramPrinter(preferencesHint, mapMode));
+ }
+ };
+
+ helper.doPrint(PlatformUI.getWorkbench().getActiveWorkbenchWindow()
+ .getActivePage().getActivePart());
+ }
+
+ /**
+ * The run method does the real run action. From IActionDelegate
+ */
+ public void run(IAction action) {
+ run();
+ }
+
+ /**
+ * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
+ */
+ public void dispose() {
+ // do nothing
+ }
+
+ /**
+ * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(IWorkbenchWindow)
+ */
+ public void init(IWorkbenchWindow window) {
+ // do nothing
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
+ */
+ public void selectionChanged(IAction action, ISelection selection) {
+ //do nothing
+ }
+}
#P org.eclipse.gmf.runtime.draw2d.ui.render.awt
Index: META-INF/MANIFEST.MF
===================================================================
RCS file: /cvsroot/modeling/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.draw2d.ui.render.awt/META-INF/MANIFEST.MF,v
retrieving revision 1.8
diff -u -r1.8 MANIFEST.MF
--- META-INF/MANIFEST.MF 1 May 2007 17:03:07 -0000 1.8
+++ META-INF/MANIFEST.MF 29 Feb 2008 18:52:53 -0000
@@ -7,7 +7,7 @@
Bundle-Vendor: %Plugin.providerName
Bundle-Localization: plugin
Export-Package: org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal;x-friends:="org.eclipse.gmf.tests.runtime.draw2d.ui.render,org.eclipse.gmf.runtime.diagram.ui,org.eclipse.gmf.runtime.diagram.ui.render",
- org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.graphics;x-friends:="org.eclipse.gmf.tests.runtime.draw2d.ui.render,org.eclipse.gmf.runtime.diagram.ui,org.eclipse.gmf.runtime.diagram.ui.render",
+ org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.graphics;x-friends:="org.eclipse.gmf.tests.runtime.draw2d.ui.render,org.eclipse.gmf.runtime.diagram.ui,org.eclipse.gmf.runtime.diagram.ui.render,org.eclipse.gmf.runtime.diagram.ui.printing.render",
org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.image;x-friends:="org.eclipse.gmf.tests.runtime.draw2d.ui.render,org.eclipse.gmf.runtime.diagram.ui,org.eclipse.gmf.runtime.diagram.ui.render",
org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.svg;x-friends:="org.eclipse.gmf.tests.runtime.draw2d.ui.render,org.eclipse.gmf.runtime.diagram.ui,org.eclipse.gmf.runtime.diagram.ui.render",
org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.svg.export;x-friends:="org.eclipse.gmf.tests.runtime.draw2d.ui.render,org.eclipse.gmf.runtime.diagram.ui,org.eclipse.gmf.runtime.diagram.ui.render",
#P org.eclipse.gmf.runtime.diagram.ui.printing.render
Index: META-INF/MANIFEST.MF
===================================================================
RCS file: /cvsroot/modeling/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.diagram.ui.printing.render/META-INF/MANIFEST.MF,v
retrieving revision 1.13
diff -u -r1.13 MANIFEST.MF
--- META-INF/MANIFEST.MF 3 Oct 2006 15:03:02 -0000 1.13
+++ META-INF/MANIFEST.MF 29 Feb 2008 18:52:53 -0000
@@ -15,5 +15,10 @@
org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
org.eclipse.gmf.runtime.diagram.ui;bundle-version="[1.0.0,2.0.0)",
org.eclipse.gmf.runtime.diagram.ui.printing;bundle-version="[1.0.0,2.0.0)",
- org.eclipse.gmf.runtime.draw2d.ui.render;bundle-version="[1.0.0,2.0.0)"
+ org.eclipse.gmf.runtime.draw2d.ui.render;bundle-version="[1.0.0,2.0.0)",
+ org.eclipse.core.databinding;bundle-version="[1.1.0,2.0.0)",
+ org.eclipse.core.databinding.beans;bundle-version="[1.0.0,2.0.0)",
+ org.eclipse.jface.databinding;bundle-version="[1.2.0,2.0.0)",
+ org.eclipse.gmf.runtime.common.ui.printing;bundle-version="[1.0.0,2.0.0)",
+ org.eclipse.gmf.runtime.draw2d.ui.render.awt;bundle-version="[1.0.0,2.0.0)"
Eclipse-LazyStart: true
Index: src/org/eclipse/gmf/runtime/diagram/ui/printing/render/actions/EnhancedPrintActionHelper.java
===================================================================
RCS file: /cvsroot/modeling/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.diagram.ui.printing.render/src/org/eclipse/gmf/runtime/diagram/ui/printing/render/actions/EnhancedPrintActionHelper.java,v
retrieving revision 1.3
diff -u -r1.3 EnhancedPrintActionHelper.java
--- src/org/eclipse/gmf/runtime/diagram/ui/printing/render/actions/EnhancedPrintActionHelper.java 3 Oct 2006 15:03:02 -0000 1.3
+++ src/org/eclipse/gmf/runtime/diagram/ui/printing/render/actions/EnhancedPrintActionHelper.java 29 Feb 2008 18:52:53 -0000
@@ -1,5 +1,5 @@
/******************************************************************************
- * Copyright (c) 2005, 2006 IBM Corporation and others.
+ * Copyright (c) 2005, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -18,6 +18,7 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.gef.RootEditPart;
import org.eclipse.gmf.runtime.common.core.util.Log;
import org.eclipse.gmf.runtime.common.core.util.Trace;
@@ -28,13 +29,15 @@
import org.eclipse.gmf.runtime.diagram.ui.editparts.IDiagramPreferenceSupport;
import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor;
import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramGraphicalViewer;
-import org.eclipse.gmf.runtime.diagram.ui.printing.actions.DefaultPrintActionHelper;
import org.eclipse.gmf.runtime.diagram.ui.printing.render.internal.DiagramUIPrintingRenderDebugOptions;
import org.eclipse.gmf.runtime.diagram.ui.printing.render.internal.DiagramUIPrintingRenderPlugin;
+import org.eclipse.gmf.runtime.diagram.ui.printing.render.internal.JPSDiagramPrinter;
+import org.eclipse.gmf.runtime.diagram.ui.printing.render.internal.JPSDiagramPrinterHelper;
import org.eclipse.gmf.runtime.diagram.ui.printing.render.util.RenderedDiagramPrinter;
import org.eclipse.gmf.runtime.diagram.ui.printing.util.DiagramPrinterUtil;
import org.eclipse.gmf.runtime.draw2d.ui.mapmode.IMapMode;
import org.eclipse.gmf.runtime.draw2d.ui.mapmode.MapModeUtil;
+import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IWorkbenchPart;
@@ -58,6 +61,7 @@
*
* @param IWorkbenchPart the workbenchPart containing the diagram to print
*/
+
public void doPrint(IWorkbenchPart workbenchPart) {
DiagramEditor diagramEditor = null;
@@ -83,18 +87,23 @@
//get actual map mode, default is MapModeUtil.getMapMode()
IMapMode mapMode = (rootEP instanceof DiagramRootEditPart) ? ((DiagramRootEditPart) rootEP)
- .getMapMode()
- : MapModeUtil.getMapMode();
-
- if (!System.getProperty("os.name").toUpperCase().startsWith("WIN")) { //$NON-NLS-1$ //$NON-NLS-2$
- //do default action when not Windows and this action is enabled
- DefaultPrintActionHelper.doRun(diagramEditor,
- new RenderedDiagramPrinter(preferencesHint, mapMode));
- return;
- }
+ .getMapMode()
+ : MapModeUtil.getMapMode();
- DiagramPrinterUtil.printWithSettings(diagramEditor, createDiagramMap(),
- new RenderedDiagramPrinter(preferencesHint, mapMode));
+ if (Platform.getOS().startsWith(Platform.OS_WIN32)) {
+ DiagramPrinterUtil.printWithSettings(diagramEditor,
+ createDiagramMap(), new RenderedDiagramPrinter(
+ preferencesHint, mapMode));
+ }
+ //
+ // Eventually the windows based printing will be replaced with the
+ // JPSDiagramPrinter.
+ //
+ // else {
+ // JPSDiagramPrinterHelper.getDiagramPrinterHelper().printWithSettings(
+ // diagramEditor, createDiagramMap(),
+ // new JPSDiagramPrinter(preferencesHint, mapMode));
+ // }
}
/**
@@ -105,9 +114,9 @@
* All entries in the map correspond to open editors with the
* diagramEditor's id.
*/
- private Map createDiagramMap() {
+ protected Map createDiagramMap() {
- Map diagramMap = new HashMap();
+ Map diagramMap = new HashMap();
//get all diagram editors with the matching id
List diagramEditors = EditorService.getInstance().getRegisteredEditorParts();
@@ -122,8 +131,7 @@
String diagramName = null;
IEditorInput editorInput = dEditor.getEditorInput();
-
-
+
//try to be more descriptive and get the IFile path which includes the project
IFile file = (IFile)(editorInput.getAdapter(IFile.class));
Index: src/org/eclipse/gmf/runtime/diagram/ui/printing/render/util/RenderedDiagramPrinter.java
===================================================================
RCS file: /cvsroot/modeling/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.diagram.ui.printing.render/src/org/eclipse/gmf/runtime/diagram/ui/printing/render/util/RenderedDiagramPrinter.java,v
retrieving revision 1.5
diff -u -r1.5 RenderedDiagramPrinter.java
--- src/org/eclipse/gmf/runtime/diagram/ui/printing/render/util/RenderedDiagramPrinter.java 3 Oct 2006 15:03:02 -0000 1.5
+++ src/org/eclipse/gmf/runtime/diagram/ui/printing/render/util/RenderedDiagramPrinter.java 29 Feb 2008 18:52:53 -0000
@@ -12,9 +12,8 @@
package org.eclipse.gmf.runtime.diagram.ui.printing.render.util;
import org.eclipse.draw2d.Graphics;
-
import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
-import org.eclipse.gmf.runtime.diagram.ui.printing.internal.util.DiagramPrinter;
+import org.eclipse.gmf.runtime.diagram.ui.printing.internal.util.SWTDiagramPrinter;
import org.eclipse.gmf.runtime.draw2d.ui.internal.graphics.MapModeGraphics;
import org.eclipse.gmf.runtime.draw2d.ui.internal.graphics.PrinterGraphics;
import org.eclipse.gmf.runtime.draw2d.ui.mapmode.IMapMode;
@@ -28,7 +27,7 @@
* @author cmahoney
*/
public class RenderedDiagramPrinter
- extends DiagramPrinter {
+ extends SWTDiagramPrinter {
/**
* Creates a new instance.
Index: src/org/eclipse/gmf/runtime/diagram/ui/printing/render/dialogs/ActionsBlock.java
===================================================================
RCS file: src/org/eclipse/gmf/runtime/diagram/ui/printing/render/dialogs/ActionsBlock.java
diff -N src/org/eclipse/gmf/runtime/diagram/ui/printing/render/dialogs/ActionsBlock.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/gmf/runtime/diagram/ui/printing/render/dialogs/ActionsBlock.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,103 @@
+/******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ****************************************************************************/
+
+package org.eclipse.gmf.runtime.diagram.ui.printing.render.dialogs;
+
+import org.eclipse.gmf.runtime.common.ui.action.actions.IPrintActionHelper;
+import org.eclipse.gmf.runtime.diagram.ui.printing.internal.l10n.DiagramUIPrintingMessages;
+import org.eclipse.gmf.runtime.diagram.ui.printing.internal.printpreview.PrintPreviewHelper;
+import org.eclipse.gmf.runtime.diagram.ui.printing.render.actions.EnhancedPrintActionHelper;
+import org.eclipse.gmf.runtime.diagram.ui.printing.render.internal.printpreview.RenderedPrintPreviewHelper;
+import org.eclipse.gmf.runtime.diagram.ui.printing.render.model.PrintOptions;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+
+/**
+ * A section of the JPS print dialog that handles extra actions. In this case,
+ * we contribute print preview capabilities.
+ *
+ * @author Christian Damus (cdamus)
+ * @author James Bruck (jbruck)
+ */
+class ActionsBlock extends DialogBlock {
+ private final PrintOptions options;
+
+ private Button printPreview;
+ private PrintPreviewHelper printPreviewHelper;
+ private IPrintActionHelper printActionHelper;
+
+
+ ActionsBlock(IDialogUnitConverter dluConverter, PrintOptions options) {
+ super(dluConverter);
+ this.options = options;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.gmf.runtime.common.ui.printing.internal.dialogs.DialogBlock#createContents(org.eclipse.swt.widgets.Composite)
+ */
+ public Control createContents(Composite parent) {
+ printPreview = new Button(parent, SWT.PUSH);
+ printPreview.setData(new Integer(2));
+ printPreview
+ .setText(DiagramUIPrintingMessages.JPSPrintDialog_Button_PrintPreview);
+
+ printPreview.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ buttonPressed(((Integer) event.widget.getData()).intValue());
+ }
+ });
+ layoutVerticalIndent(layoutAlignLeft(printPreview));
+
+ return printPreview;
+ }
+
+ /**
+ * Bring up the print preview with printing disabled.
+ *
+ * @param buttonId
+ */
+ protected void buttonPressed(int buttonId) {
+ switch (buttonId) {
+ case -1:
+ break;
+ default:
+ getPrintPreviewHelper().enablePrinting(false);
+ getPrintPreviewHelper().doPrintPreview(getPrintActionHelper());
+ }
+ }
+
+ /**
+ * Return the print preview helper responsible for performing the print
+ * preview.
+ *
+ * @return PrintPreviewHelper the print preview helper.
+ */
+ private PrintPreviewHelper getPrintPreviewHelper() {
+ if (printPreviewHelper == null) {
+ printPreviewHelper = new RenderedPrintPreviewHelper();
+ }
+ return printPreviewHelper;
+ }
+
+ private IPrintActionHelper getPrintActionHelper() {
+ if (printActionHelper == null) {
+ printActionHelper = new EnhancedPrintActionHelper();
+ }
+ return printActionHelper;
+ }
+
+}
Index: src/org/eclipse/gmf/runtime/diagram/ui/printing/render/dialogs/PrinterBlock.java
===================================================================
RCS file: src/org/eclipse/gmf/runtime/diagram/ui/printing/render/dialogs/PrinterBlock.java
diff -N src/org/eclipse/gmf/runtime/diagram/ui/printing/render/dialogs/PrinterBlock.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/gmf/runtime/diagram/ui/printing/render/dialogs/PrinterBlock.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,293 @@
+/******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ****************************************************************************/
+
+package org.eclipse.gmf.runtime.diagram.ui.printing.render.dialogs;
+
+import java.util.List;
+import java.util.Locale;
+
+import javax.print.DocFlavor;
+import javax.print.PrintService;
+import javax.print.PrintServiceLookup;
+import javax.print.attribute.AttributeSet;
+import javax.print.attribute.HashPrintServiceAttributeSet;
+import javax.print.attribute.PrintServiceAttributeSet;
+import javax.print.attribute.standard.PrinterLocation;
+import javax.print.attribute.standard.PrinterMakeAndModel;
+import javax.print.attribute.standard.PrinterMessageFromOperator;
+import javax.print.attribute.standard.PrinterName;
+import javax.print.attribute.standard.PrinterState;
+
+import org.eclipse.core.databinding.DataBindingContext;
+import org.eclipse.core.databinding.beans.BeansObservables;
+import org.eclipse.core.databinding.observable.Realm;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.gmf.runtime.diagram.ui.printing.internal.l10n.DiagramUIPrintingMessages;
+import org.eclipse.gmf.runtime.diagram.ui.printing.render.model.PrintDestination;
+import org.eclipse.gmf.runtime.diagram.ui.printing.render.model.PrintOptions;
+import org.eclipse.jface.databinding.viewers.ViewersObservables;
+import org.eclipse.jface.viewers.ComboViewer;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+
+/**
+ * A section of the JPS print dialog that adds printer options.
+ *
+ * @author Christian Damus (cdamus)
+ * @author James Bruck (jbruck)
+ */
+class PrinterBlock extends DialogBlock {
+ private final DataBindingContext bindings;
+ private final PrintOptions options;
+
+ private List destinations = new java.util.ArrayList();
+
+ private ComboViewer combo;
+
+ private Label resultStatusLabel;
+ private Label resultTypeLabel;
+ private Label resultWhereLabel;
+ private Label resultCommentLabel;
+
+ PrinterBlock(IDialogUnitConverter dluConverter,
+ DataBindingContext bindings, PrintOptions options) {
+
+ super(dluConverter);
+
+ this.bindings = bindings;
+ this.options = options;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.gmf.runtime.common.ui.printing.internal.dialogs.DialogBlock#createContents(org.eclipse.swt.widgets.Composite)
+ */
+ public Control createContents(Composite parent) {
+ final Realm realm = bindings.getValidationRealm();
+
+ Composite result = group(parent,
+ DiagramUIPrintingMessages.JPSPrintDialog_Printer);
+ layout(result, 3);
+
+ label(result, DiagramUIPrintingMessages.JPSPrintDialog_Name);
+ combo = combo(result);
+ //
+ // The JPS API does not correctly return the printer status
+ // information under windows. These options will be temporarily disabled
+ // until a workaround can be discovered.
+ //
+
+ // combo.addSelectionChangedListener(new ISelectionChangedListener() {
+ //
+ // public void selectionChanged(SelectionChangedEvent event) {
+ // if (event != null) {
+ // handlePrinterSelectionChanged(event);
+ // }
+ // }
+ // });
+
+ layoutFillHorizontal(combo.getControl());
+
+ Button propertiesButton = button(result,
+ DiagramUIPrintingMessages.JPSPrintDialog_Properties);
+ propertiesButton.setEnabled(false);
+
+ propertiesButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ // TODO: Introduce new dialog in phase 2
+ }
+ });
+
+ IObservableValue destination = BeansObservables.observeValue(realm,
+ options, PrintOptions.PROPERTY_DESTINATION);
+ bindings.bindValue(ViewersObservables.observeSingleSelection(combo),
+ destination, null, null);
+
+ // Label statusLabel = label(result, "Status:");
+ // layoutAlignLeft(statusLabel);
+ // resultStatusLabel = label(result, "");
+ // layoutFillHorizontal(layoutSpanHorizontal(resultStatusLabel, 2));
+ //
+ // Label typeLabel = label(result, "Type:");
+ // layoutAlignLeft(typeLabel);
+ // resultTypeLabel = label(result, "");
+ // layoutFillHorizontal(layoutSpanHorizontal(resultTypeLabel, 2));
+ //
+ // Label whereLabel = label(result, "Where:");
+ // layoutAlignLeft(whereLabel);
+ // resultWhereLabel = label(result, "");
+ // layoutFillHorizontal(layoutSpanHorizontal(resultWhereLabel, 2));
+ //
+ // Label commentLabel = label(result, "Comment:");
+ // layoutAlignLeft(commentLabel);
+ // resultCommentLabel = label(result, "");
+ // layoutFillHorizontal(resultCommentLabel);
+
+ Button printToFile = check(result,
+ DiagramUIPrintingMessages.JPSPrintDialog_PrintToFile);
+ layoutSpanHorizontal(printToFile, 3);
+
+ // TODO: implement in phase 2
+ printToFile.setEnabled(false);
+
+ init();
+
+ return result;
+ }
+
+ /**
+ * When the printer selection has changed, we update the status information.
+ * The print service API does not currently update the status correctly in Windows
+ *
+ * This will be re-enabled when a workaround for obtaining printer attributes will
+ * be discovered.
+ *
+ * @param selectionChangedEvent
+ */
+ private void handlePrinterSelectionChanged(
+ SelectionChangedEvent selectionChangedEvent) {
+
+ StructuredSelection selection = (StructuredSelection) selectionChangedEvent
+ .getSelection();
+
+ if (selection != null) {
+ PrintDestination destination = (PrintDestination) selection
+ .getFirstElement();
+ if (destination != null) {
+
+ String printerName = destination.getName();
+
+ AttributeSet attributes = new HashPrintServiceAttributeSet(
+ new PrinterName(printerName, Locale.getDefault()));
+
+ PrintService[] services = PrintServiceLookup
+ .lookupPrintServices(
+ DocFlavor.SERVICE_FORMATTED.PRINTABLE,
+ attributes);
+
+ PrintService printService = services[0];
+
+ PrintServiceAttributeSet printServiceAttributes = printService
+ .getAttributes();
+
+ PrinterState printerState = (PrinterState) printServiceAttributes
+ .get(PrinterState.class);
+
+ PrinterLocation printerLocation = (PrinterLocation) printServiceAttributes
+ .get(PrinterLocation.class);
+
+ PrinterMakeAndModel printerMakeAndModel = (PrinterMakeAndModel) printServiceAttributes
+ .get(PrinterMakeAndModel.class);
+
+ PrinterMessageFromOperator printerComment = (PrinterMessageFromOperator) printServiceAttributes
+ .get(PrinterMessageFromOperator.class);
+
+ if (printerState != null) {
+ resultStatusLabel.setText(printerState.getName());
+ }
+ if (printerLocation != null) {
+ resultWhereLabel.setText(printerLocation.getName());
+ }
+ if (printerComment != null) {
+ resultCommentLabel.setText(printerComment.getName());
+ }
+ if (printerMakeAndModel != null) {
+ resultTypeLabel.setText(printerMakeAndModel.getName());
+ }
+ }
+ }
+ }
+
+ /**
+ * At initialization time, we lookup all the print services and select the default one.
+ */
+ private void init() {
+ PrintService[] printServices = PrintServiceLookup.lookupPrintServices(
+ null, null);
+ PrintService defaultPrintService = PrintServiceLookup
+ .lookupDefaultPrintService();
+
+ for (PrintService printService : printServices) {
+ destinations.add(new PrintDestination(printService.getName()));
+ }
+
+ PrintDestination defaultPrintDestination = getPrinterByName(defaultPrintService.getName());
+
+ combo.setContentProvider(new PrinterContentProvider());
+ combo.setLabelProvider(new PrinterLabelProvider());
+
+ initializePrinterCombo(defaultPrintDestination);
+ }
+
+ /**
+ * Initialize the list of printers.
+ *
+ * @param selection
+ */
+ private void initializePrinterCombo(PrintDestination selection) {
+ combo.setInput(destinations);
+ combo.setSelection(new StructuredSelection(selection));
+ }
+
+ /**
+ *
+ * @param name
+ * @return
+ */
+ private PrintDestination getPrinterByName(String name) {
+
+ PrintDestination result = null;
+ for (PrintDestination printDestination : destinations) {
+ if (printDestination.getName().equals(name)) {
+ result = printDestination;
+ break;
+ }
+ }
+ return result;
+ }
+
+ /**
+ * A helper class used to retrieve label text
+ *
+ * @author Christian Damus (cdamus)
+ * @author James Bruck (jbruck)
+ */
+ private class PrinterContentProvider implements IStructuredContentProvider {
+ public Object[] getElements(Object inputElement) {
+ return destinations.toArray();
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ // input never changes
+ }
+
+ public void dispose() {
+ // nothing to dispose
+ }
+ }
+
+ private class PrinterLabelProvider extends LabelProvider {
+ public String getText(Object element) {
+ return ((PrintDestination) element).getName();
+ }
+ }
+}
Index: src/org/eclipse/gmf/runtime/diagram/ui/printing/render/util/PrintHelper.java
===================================================================
RCS file: src/org/eclipse/gmf/runtime/diagram/ui/printing/render/util/PrintHelper.java
diff -N src/org/eclipse/gmf/runtime/diagram/ui/printing/render/util/PrintHelper.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/gmf/runtime/diagram/ui/printing/render/util/PrintHelper.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,138 @@
+/******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ****************************************************************************/
+
+
+
+package org.eclipse.gmf.runtime.diagram.ui.printing.render.util;
+
+import java.util.List;
+
+import org.eclipse.gmf.runtime.common.ui.printing.IPrintHelper;
+import org.eclipse.gmf.runtime.diagram.ui.printing.render.dialogs.JPSPrintDialog;
+import org.eclipse.gmf.runtime.diagram.ui.printing.render.model.PrintOptions;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.printing.PrinterData;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * Default implementation of a print-helper.
+ *
+ * @author Christian W. Damus (cdamus)
+ */
+public class PrintHelper implements IPrintHelper {
+ private final PrintOptions options = new PrintOptions();
+
+ public PrintHelper() {
+ initPrintOptions();
+ }
+
+ /**
+ * Initialize the default options.
+ */
+ private void initPrintOptions() {
+ options.setPercentScaling(true);
+ options.setScaleFactor(100);
+ options.setFitToPagesWidth(1);
+ options.setFitToPagesHeight(1);
+
+ options.setAllPages(true);
+ options.setRangeFrom(1);
+ options.setRangeTo(1);
+
+ options.setCopies(1);
+ options.setCollate(false);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.gmf.runtime.common.ui.printing.IPrintHelper#openPrintDlg(java.util.List)
+ */
+ public PrinterData openPrintDlg(List diagramList) {
+ PrinterData result = null;
+ JPSPrintDialog dlg = new JPSPrintDialog(PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow(), options);
+
+ if (dlg.open() == IDialogConstants.OK_ID) {
+ if (options.getDestination() != null) {
+ result = options.getDestination().getPrinterData();
+ }
+ } else {
+ // revert
+ initPrintOptions();
+ }
+ return result;
+ }
+
+ public boolean getDlgCollate() {
+ return options.isCollate();
+ }
+
+ public int getDlgNumberOfCopies() {
+ return options.getCopies();
+ }
+
+ public int getDlgPagesFrom() {
+ return options.getRangeFrom();
+ }
+
+ public int getDlgPagesTo() {
+ return options.getRangeTo();
+ }
+
+ public boolean getDlgPrintRangeAll() {
+ return options.isAllPages();
+ }
+
+ public boolean getDlgPrintRangePages() {
+ return !getDlgPrintRangeAll();
+ }
+
+ public int getDlgScaleFitToM() {
+ return options.getFitToPagesWidth();
+ }
+
+ public int getDlgScaleFitToN() {
+ return options.getFitToPagesHeight();
+ }
+
+ public int getDlgScalePercent() {
+ return options.isPercentScaling() ? options.getScaleFactor() : -1;
+ }
+
+ public void setDlgOrientation(boolean landscape) {
+ // TODO Auto-generated method stub
+ }
+
+ public void setDlgPaperSize(int index, double width, double length) {
+ // TODO Auto-generated method stub
+ }
+
+ public boolean getDlgDiagramPrintRangeCurrent() {
+ // TODO Not supported by the JPS dialog
+ return true;
+ }
+
+ public boolean getDlgDiagramPrintRangeSelection() {
+ // TODO Not supported by the JPS dialog
+ return false;
+ }
+
+ public boolean isDlgDiagramSelected(int index) {
+ // TODO Not supported by the JPS dialog
+ return false;
+ }
+
+ public boolean getDlgDiagramPrintRangeAll() {
+ // TODO Not supported by the JPS dialog
+ return false;
+ }
+
+}
Index: src/org/eclipse/gmf/runtime/diagram/ui/printing/render/dialogs/ScalingBlock.java
===================================================================
RCS file: src/org/eclipse/gmf/runtime/diagram/ui/printing/render/dialogs/ScalingBlock.java
diff -N src/org/eclipse/gmf/runtime/diagram/ui/printing/render/dialogs/ScalingBlock.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/gmf/runtime/diagram/ui/printing/render/dialogs/ScalingBlock.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,114 @@
+/******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ****************************************************************************/
+
+package org.eclipse.gmf.runtime.diagram.ui.printing.render.dialogs;
+
+import org.eclipse.core.databinding.DataBindingContext;
+import org.eclipse.core.databinding.beans.BeansObservables;
+import org.eclipse.core.databinding.observable.Realm;
+import org.eclipse.core.databinding.observable.value.ComputedValue;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.gmf.runtime.diagram.ui.printing.internal.l10n.DiagramUIPrintingMessages;
+import org.eclipse.gmf.runtime.diagram.ui.printing.render.model.PrintOptions;
+import org.eclipse.jface.databinding.swt.SWTObservables;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Text;
+
+
+/**
+ * A section of the JPS print dialog that adds scaling support.
+ *
+ * @author Christian Damus (cdamus)
+ * @author James Bruck (jbruck)
+ */
+class ScalingBlock extends DialogBlock {
+ private final DataBindingContext bindings;
+ private final PrintOptions options;
+
+ ScalingBlock(IDialogUnitConverter dluConverter,
+ DataBindingContext bindings, PrintOptions options) {
+ super(dluConverter);
+
+ this.bindings = bindings;
+ this.options = options;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.gmf.runtime.common.ui.printing.internal.dialogs.DialogBlock#createContents(org.eclipse.swt.widgets.Composite)
+ */
+ public Control createContents(Composite parent) {
+ final Realm realm = bindings.getValidationRealm();
+
+ Composite result = group(parent,
+ DiagramUIPrintingMessages.JPSPrintDialog_Scaling);
+ layout(result, 5);
+
+ Button adjustRadio = radio(result,
+ DiagramUIPrintingMessages.JPSPrintDialog_Adjust);
+ layoutSpanHorizontal(adjustRadio, 2);
+ Text textScale = text(result, 20);
+ layoutSpanHorizontal(blank(result), 2);
+
+ final IObservableValue scalingValue = BeansObservables.observeValue(
+ realm, options, PrintOptions.PROPERTY_PERCENT_SCALING);
+
+ bindings.bindValue(SWTObservables.observeSelection(adjustRadio),
+ scalingValue, null, null);
+
+ bindings.bindValue(SWTObservables.observeText(textScale, SWT.Modify),
+ BeansObservables.observeValue(realm, options,
+ PrintOptions.PROPERTY_SCALE_FACTOR), null, null);
+ bindings.bindValue(SWTObservables.observeEnabled(textScale),
+ scalingValue, null, null);
+
+ Button fitToRadio = radio(result,
+ DiagramUIPrintingMessages.JPSPrintDialog_FitTo);
+
+ IObservableValue fitToValue = new ComputedValue(realm) {
+ protected Object calculate() {
+ return Boolean.valueOf(!((Boolean) scalingValue.getValue())
+ .booleanValue());
+ }
+ };
+
+ bindings.bindValue(SWTObservables.observeSelection(fitToRadio),
+ fitToValue, null, null);
+
+ layoutHorizontalIndent(layoutAlignRight(label(result,
+ DiagramUIPrintingMessages.JPSPrintDialog_PagesWide)));
+
+ Text textWide = text(result, 20);
+
+ layoutHorizontalIndent(layoutAlignRight(label(result,
+ DiagramUIPrintingMessages.JPSPrintDialog_PagesTall)));
+ Text textTall = text(result, 20);
+
+ bindings.bindValue(SWTObservables.observeText(textWide, SWT.Modify),
+ BeansObservables.observeValue(realm, options,
+ PrintOptions.PROPERTY_FIT_TO_WIDTH), null, null);
+
+ bindings.bindValue(SWTObservables.observeEnabled(textWide), fitToValue,
+ null, null);
+
+ bindings.bindValue(SWTObservables.observeText(textTall, SWT.Modify),
+ BeansObservables.observeValue(realm, options,
+ PrintOptions.PROPERTY_FIT_TO_HEIGHT), null, null);
+
+ bindings.bindValue(SWTObservables.observeEnabled(textTall), fitToValue,
+ null, null);
+
+ return result;
+ }
+}
Index: src/org/eclipse/gmf/runtime/diagram/ui/printing/render/model/PrintModelElement.java
===================================================================
RCS file: src/org/eclipse/gmf/runtime/diagram/ui/printing/render/model/PrintModelElement.java
diff -N src/org/eclipse/gmf/runtime/diagram/ui/printing/render/model/PrintModelElement.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/gmf/runtime/diagram/ui/printing/render/model/PrintModelElement.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,73 @@
+/******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ****************************************************************************/
+
+package org.eclipse.gmf.runtime.diagram.ui.printing.render.model;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+
+/**
+ * This class is used as the model in the MVC infrastructure required for databindings
+ * used with the JPS dialog.
+ *
+ * @author Christian Damus (cdamus)
+ * @author James Bruck (jbruck)
+ */
+abstract class PrintModelElement {
+ protected final PropertyChangeSupport bean = new PropertyChangeSupport(this);
+
+ public PrintModelElement() {
+ super();
+ }
+
+ public void addPropertyChangeListener(PropertyChangeListener listener) {
+ bean.addPropertyChangeListener(listener);
+ }
+
+ public void addPropertyChangeListener(String propertyName,
+ PropertyChangeListener listener) {
+ bean.addPropertyChangeListener(propertyName, listener);
+ }
+
+ public PropertyChangeListener[] getPropertyChangeListeners() {
+ return bean.getPropertyChangeListeners();
+ }
+
+ public PropertyChangeListener[] getPropertyChangeListeners(
+ String propertyName) {
+ return bean.getPropertyChangeListeners(propertyName);
+ }
+
+ public boolean hasListeners(String propertyName) {
+ return bean.hasListeners(propertyName);
+ }
+
+ public void removePropertyChangeListener(PropertyChangeListener listener) {
+ bean.removePropertyChangeListener(listener);
+ }
+
+ public void removePropertyChangeListener(String propertyName,
+ PropertyChangeListener listener) {
+ bean.removePropertyChangeListener(propertyName, listener);
+ }
+
+ protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
+ bean.firePropertyChange(propertyName, oldValue, newValue);
+ }
+
+ protected void firePropertyChange(String propertyName, int oldValue, int newValue) {
+ bean.firePropertyChange(propertyName, oldValue, newValue);
+ }
+
+ protected void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) {
+ bean.firePropertyChange(propertyName, oldValue, newValue);
+ }
+}
Index: src/org/eclipse/gmf/runtime/diagram/ui/printing/render/internal/JPSDiagramPrinter.java
===================================================================
RCS file: src/org/eclipse/gmf/runtime/diagram/ui/printing/render/internal/JPSDiagramPrinter.java
diff -N src/org/eclipse/gmf/runtime/diagram/ui/printing/render/internal/JPSDiagramPrinter.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/gmf/runtime/diagram/ui/printing/render/internal/JPSDiagramPrinter.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,547 @@
+/******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ****************************************************************************/
+
+package org.eclipse.gmf.runtime.diagram.ui.printing.render.internal;
+
+import java.awt.print.PageFormat;
+import java.awt.print.PrinterException;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+
+import javax.print.Doc;
+import javax.print.DocFlavor;
+import javax.print.DocPrintJob;
+import javax.print.PrintException;
+import javax.print.PrintService;
+import javax.print.PrintServiceLookup;
+import javax.print.SimpleDoc;
+import javax.print.attribute.AttributeSet;
+import javax.print.attribute.HashDocAttributeSet;
+import javax.print.attribute.HashPrintRequestAttributeSet;
+import javax.print.attribute.HashPrintServiceAttributeSet;
+import javax.print.attribute.PrintRequestAttributeSet;
+import javax.print.attribute.standard.Copies;
+import javax.print.attribute.standard.JobName;
+import javax.print.attribute.standard.MediaSizeName;
+import javax.print.attribute.standard.OrientationRequested;
+import javax.print.attribute.standard.PrinterName;
+import javax.print.attribute.standard.SheetCollate;
+
+import org.eclipse.draw2d.Graphics;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gef.LayerConstants;
+import org.eclipse.gef.RootEditPart;
+import org.eclipse.gmf.runtime.common.core.util.Log;
+import org.eclipse.gmf.runtime.common.core.util.Trace;
+import org.eclipse.gmf.runtime.common.ui.printing.IPrintHelper;
+import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
+import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramRootEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.internal.pagesetup.PageInfoHelper;
+import org.eclipse.gmf.runtime.diagram.ui.internal.pagesetup.PageSetupPageType;
+import org.eclipse.gmf.runtime.diagram.ui.internal.pagesetup.PageInfoHelper.PageMargins;
+import org.eclipse.gmf.runtime.diagram.ui.internal.properties.WorkspaceViewerProperties;
+import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor;
+import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramGraphicalViewer;
+import org.eclipse.gmf.runtime.diagram.ui.printing.internal.DiagramPrintingDebugOptions;
+import org.eclipse.gmf.runtime.diagram.ui.printing.internal.DiagramPrintingPlugin;
+import org.eclipse.gmf.runtime.diagram.ui.printing.internal.DiagramPrintingStatusCodes;
+import org.eclipse.gmf.runtime.diagram.ui.printing.internal.l10n.DiagramUIPrintingMessages;
+import org.eclipse.gmf.runtime.diagram.ui.printing.internal.util.DiagramPrinter;
+import org.eclipse.gmf.runtime.diagram.ui.printing.internal.util.PrintHelperUtil;
+import org.eclipse.gmf.runtime.diagram.ui.printing.util.DiagramPrinterUtil;
+import org.eclipse.gmf.runtime.diagram.ui.util.DiagramEditorUtil;
+import org.eclipse.gmf.runtime.draw2d.ui.internal.graphics.ScaledGraphics;
+import org.eclipse.gmf.runtime.draw2d.ui.mapmode.IMapMode;
+import org.eclipse.gmf.runtime.draw2d.ui.mapmode.MapModeUtil;
+import org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.graphics.GraphicsToGraphics2DAdaptor;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * This class supports printing using the Java Print Service API.
+ * The logic of calculating page break etc. follows that of SWT printing
+ * but the actual printing is done asynchronously in a platform independent way.
+ *
+ * Much of the paging code was derived from the previous DiagramPrinter.
+ *
+ * @author James Bruck (jbruck)
+ */
+public class JPSDiagramPrinter extends DiagramPrinter implements
+ java.awt.print.Printable {
+
+ private PrintService printService;
+ private PageData[] pages;
+ private IPrintHelper printHelper;
+
+ public JPSDiagramPrinter(PreferencesHint preferencesHint, IMapMode mm) {
+ super(preferencesHint, mm);
+ this.preferencesHint = preferencesHint;
+ this.mapMode = mm;
+ }
+
+ public JPSDiagramPrinter(PreferencesHint preferencesHint) {
+ this(preferencesHint, MapModeUtil.getMapMode());
+ }
+
+ public void setPrintHelper(IPrintHelper helper) {
+ this.printHelper = helper;
+ }
+
+ /**
+ * Create a new print service given a printer name.
+ *
+ * @param printerName
+ */
+ public void setPrinter(String printerName) {
+ AttributeSet attributes = new HashPrintServiceAttributeSet(
+ new PrinterName(printerName, Locale.getDefault()));
+ PrintService[] services = PrintServiceLookup.lookupPrintServices(
+ DocFlavor.SERVICE_FORMATTED.PRINTABLE, attributes);
+ printService = services[0];
+ }
+
+ /**
+ * Prints the contents of the diagram editor part.
+ */
+ public void run() {
+
+ Iterator it = diagrams.iterator();
+ Shell shell = new Shell();
+ try {
+ while (it.hasNext()) {
+ Diagram diagram = it.next();
+ DiagramEditor openedDiagramEditor = DiagramEditorUtil
+ .findOpenedDiagramEditorForID(ViewUtil
+ .getIdStr(diagram));
+ DiagramEditPart dgrmEP = openedDiagramEditor == null ? PrintHelperUtil
+ .createDiagramEditPart(diagram, preferencesHint, shell)
+ : openedDiagramEditor.getDiagramEditPart();
+
+ boolean loadedPreferences = openedDiagramEditor != null
+ || PrintHelperUtil.initializePreferences(dgrmEP,
+ preferencesHint);
+
+ RootEditPart rep = dgrmEP.getRoot();
+ if (rep instanceof DiagramRootEditPart) {
+ this.mapMode = ((DiagramRootEditPart) rep).getMapMode();
+ }
+
+ IPreferenceStore preferenceStore = ((DiagramGraphicalViewer) dgrmEP
+ .getViewer()).getWorkspaceViewerPreferenceStore();
+ if (preferenceStore
+ .getBoolean(WorkspaceViewerProperties.PREF_USE_WORKSPACE_SETTINGS)) {
+ if (dgrmEP.getDiagramPreferencesHint().getPreferenceStore() != null) {
+ preferenceStore = (IPreferenceStore) dgrmEP
+ .getDiagramPreferencesHint()
+ .getPreferenceStore();
+ }
+ }
+ doPrintDiagram(printService.createPrintJob(), dgrmEP,
+ loadedPreferences, preferenceStore);
+ }
+ } finally {
+ dispose();
+ shell.dispose();
+ }
+ }
+
+ /**
+ * Print the diagram figure using specified scale factor.
+ *
+ * @param dgrmEP The diagram edit part to print
+ * @param loadedPreferences true if existing prefs could be loaded
+ * successfully, false if not and defaults are being used. This parameter
+ * is important to obtain the correct page break bounds.
+ * @param fPreferences the preferenceStore that could either contain
+ * existing preferences or defaults
+ */
+ protected void printToScale(DiagramEditPart dgrmEP,
+ boolean loadedPreferences, IPreferenceStore fPreferences) {
+
+ Rectangle figureBounds = PrintHelperUtil.getPageBreakBounds(dgrmEP,
+ loadedPreferences);
+
+ org.eclipse.draw2d.geometry.Point pageBounds = PageInfoHelper
+ .getPageSize(fPreferences, getMapMode());
+ //
+ // Translate to offset initial figure position
+ //
+ translated = new Point((int) (-figureBounds.x * userScale),
+ (int) (-figureBounds.y * userScale));
+ //
+ // Calculate the number of page rows and columns
+ //
+ int numRows = 0, numCols = 0;
+
+ PageMargins margins = adjustMarginsToScale(PageInfoHelper
+ .getPageMargins(fPreferences, getMapMode()));
+
+ FontData fontData = JFaceResources.getDefaultFont().getFontData()[0];
+
+ org.eclipse.draw2d.geometry.Point pageCount = getPageCount(dgrmEP,
+ figureBounds, pageBounds, true);
+
+ numCols = pageCount.x;
+ numRows = pageCount.y;
+
+ int row = 1, col = 1, finalRow = 0, finalColumn = 0;
+
+ List pageList = new java.util.ArrayList();
+
+ if (this.printRangePageSelection) {
+ //
+ // Print only the pages specified in the page range...
+ //
+ row = calculateRowFromPage(this.pageFrom, numCols);
+ col = calculateColumnFromPage(this.pageFrom, numCols, row);
+
+ finalRow = calculateRowFromPage(this.pageTo, numCols);
+ finalColumn = calculateColumnFromPage(this.pageTo, numCols,
+ finalRow);
+ }
+ //
+ // Print the pages in row, column order
+ //
+ for (; row <= numRows; row++) {
+ for (; col <= numCols; col++) {
+
+ pageList.add(new PageData(pageList.size(), row, col, dgrmEP,
+ figureBounds, margins, fontData, fPreferences));
+
+ if (row == finalRow && col == finalColumn
+ && this.printRangePageSelection == true) {
+ break;
+ }
+ }
+ if (row == finalRow && col == finalColumn
+ && this.printRangePageSelection == true) {
+ break;
+ }
+ col = 1;
+ }
+ pages = pageList.toArray(new PageData[pageList.size()]);
+ }
+
+ /**
+ * Print the diagram figure to fit the number and rows and columns
+ * specified by the user.
+ *
+ * @param dgrmEP The diagram edit part to print
+ * @param loadedPreferences true if existing prefs could be loaded
+ * successfully, false if not and defaults are being used. This parameter
+ * is important to obtain the correct page break bounds.
+ * @param fPreferences the preferenceStore that could either contain
+ * existing preferences or defaults
+ */
+ protected void printToPages(DiagramEditPart dgrmEP,
+ boolean loadedPreferences, IPreferenceStore fPreferences) {
+
+ Rectangle figureBounds = PrintHelperUtil.getPageBreakBounds(dgrmEP,
+ loadedPreferences);
+
+ org.eclipse.draw2d.geometry.Point pageBounds = PageInfoHelper
+ .getPageSize(fPreferences, getMapMode());
+ org.eclipse.draw2d.geometry.Point pageCount = getPageCount(dgrmEP,
+ figureBounds, pageBounds, false);
+ int numCols = pageCount.x;
+ int numRows = pageCount.y;
+
+ float actualWidth = 0;
+ float actualHeight = 0;
+ if (this.rows == 1 && this.columns == 1 && fitToPage) {
+ figureBounds = dgrmEP.getChildrenBounds();
+ actualWidth = figureBounds.width;
+ actualHeight = figureBounds.height;
+ } else {
+ actualWidth = numCols * pageBounds.x;
+ actualHeight = numRows * pageBounds.y;
+ }
+
+ int totalHeight = (this.rows * pageBounds.y);
+ int totalWidth = (this.columns * pageBounds.x);
+
+ float vScale = totalHeight / actualHeight;
+ float hScale = totalWidth / actualWidth;
+
+ this.userScale = Math.min(hScale, vScale);
+
+ PageMargins margins = adjustMarginsToScale(PageInfoHelper
+ .getPageMargins(fPreferences, getMapMode()));
+
+ translated = new Point((int) (-figureBounds.x * userScale),
+ (int) (-figureBounds.y * userScale));
+
+ FontData fontData = JFaceResources.getDefaultFont().getFontData()[0];
+
+ int row = 1, col = 1, finalRow = 0, finalColumn = 0;
+ List pageList = new java.util.ArrayList();
+
+ if (this.printRangePageSelection) {
+ //
+ // Print only the pages specified in the page range
+ // this corresponds to the physical pages, not the print range of
+ // pages on one physical page.
+ //
+ row = calculateRowFromPage(this.pageFrom, this.columns);
+ col = calculateColumnFromPage(this.pageFrom, this.columns, row);
+
+ finalRow = calculateRowFromPage(this.pageTo, this.columns);
+ finalColumn = calculateColumnFromPage(this.pageTo, this.columns,
+ finalRow);
+ }
+
+ for (; row <= rows; row++) {
+ for (; col <= columns; col++) {
+
+ pageList.add(new PageData(pageList.size(), row, col, dgrmEP,
+ figureBounds, margins, fontData, fPreferences));
+
+ if (row == finalRow && col == finalColumn
+ && this.printRangePageSelection == true) {
+ break;
+ }
+ }
+ if (row == finalRow && col == finalColumn
+ && this.printRangePageSelection == true) {
+ break;
+ }
+ col = 1;
+ }
+ pages = pageList.toArray(new PageData[pageList.size()]);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.awt.print.Printable#print(java.awt.Graphics,
+ * java.awt.print.PageFormat, int)
+ */
+ public int print(java.awt.Graphics printGraphics, PageFormat pageFormat,
+ int pageIndex) throws PrinterException {
+
+ if (pageIndex >= pages.length) {
+ return java.awt.print.Printable.NO_SUCH_PAGE;
+ }
+
+ try {
+ swtGraphics = new GraphicsToGraphics2DAdaptor(
+ (java.awt.Graphics2D) printGraphics, new Rectangle(0, 0,
+ (int) pageFormat.getWidth(), (int) pageFormat
+ .getHeight()));
+
+ graphics = createMapModeGraphics(new ScaledGraphics(swtGraphics));
+ //
+ // Take into account screen display DPI and the graphic DPI
+ // 72.0 DPI is an AWT constant @see java.awt.Graphics2D
+ //
+ graphics.scale(72.0 / display_dpi.x);
+
+ drawPage(pages[pageIndex]);
+ } finally {
+ dispose();
+ }
+
+ return java.awt.print.Printable.PAGE_EXISTS;
+ }
+
+ /**
+ * Set printing options in a format that is suitable for the Java print service
+ *
+ * @param jobName The printer job name to use
+ * @param fPreferences obtain page information from preferences
+ * @return PrintRequestAttribute set suitable for Java print service
+ */
+ protected PrintRequestAttributeSet initializePrintOptions(
+ String jobName,
+ IPreferenceStore fPreferences) {
+
+ PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
+
+ if (fPreferences
+ .getBoolean(WorkspaceViewerProperties.PREF_USE_PORTRAIT)) {
+ printRequestAttributeSet.add(OrientationRequested.PORTRAIT);
+ } else {
+ printRequestAttributeSet.add(OrientationRequested.LANDSCAPE);
+ }
+
+ String pageSize = fPreferences
+ .getString(WorkspaceViewerProperties.PREF_PAGE_SIZE);
+
+ if (pageSize.compareToIgnoreCase(PageSetupPageType.LETTER.getName()) == 0) {
+ printRequestAttributeSet.add(MediaSizeName.NA_LETTER);
+ } else if (pageSize.compareToIgnoreCase(PageSetupPageType.LEGAL
+ .getName()) == 0) {
+ printRequestAttributeSet.add(MediaSizeName.NA_LEGAL);
+ } else if (pageSize.compareToIgnoreCase(PageSetupPageType.EXECUTIVE
+ .getName()) == 0) {
+ printRequestAttributeSet.add(MediaSizeName.EXECUTIVE);
+ } else if (pageSize.compareToIgnoreCase(PageSetupPageType.A3.getName()) == 0) {
+ printRequestAttributeSet.add(MediaSizeName.ISO_A3);
+ } else if (pageSize.compareToIgnoreCase(PageSetupPageType.A4.getName()) == 0) {
+ printRequestAttributeSet.add(MediaSizeName.ISO_A4);
+ } else if (pageSize.compareToIgnoreCase(PageSetupPageType.B4.getName()) == 0) {
+ printRequestAttributeSet.add(MediaSizeName.ISO_B4);
+ } else if (pageSize.compareToIgnoreCase(PageSetupPageType.B5.getName()) == 0) {
+ printRequestAttributeSet.add(MediaSizeName.ISO_B5);
+ }
+
+ printRequestAttributeSet.add(new Copies(printHelper
+ .getDlgNumberOfCopies()));
+
+ if (printHelper.getDlgCollate()) {
+ printRequestAttributeSet.add(SheetCollate.COLLATED);
+ } else {
+ printRequestAttributeSet.add(SheetCollate.UNCOLLATED);
+ }
+
+ printRequestAttributeSet.add(new JobName(jobName, Locale.getDefault()));
+
+ return printRequestAttributeSet;
+ }
+
+ /**
+ * Prints to scale or prints to rows x columns pages
+ *
+ * @param printJob
+ * @param diagramEditPart
+ * @param loadedPreferences
+ * @param fPreferences
+ */
+ protected void doPrintDiagram(DocPrintJob printJob,
+ DiagramEditPart diagramEditPart, boolean loadedPreferences,
+ IPreferenceStore fPreferences) {
+
+ if (isScaledPercent) {
+ printToScale(diagramEditPart, loadedPreferences, fPreferences);
+ } else {
+ printToPages(diagramEditPart, loadedPreferences, fPreferences);
+ }
+
+ PrintRequestAttributeSet printRequestAttributeSet = initializePrintOptions(
+ diagramEditPart
+ .getDiagramView().getName(), fPreferences);
+
+ Doc doc = new SimpleDoc(this, DocFlavor.SERVICE_FORMATTED.PRINTABLE,
+ new HashDocAttributeSet());
+
+ try {
+ printJob.print(doc, printRequestAttributeSet);
+ } catch (PrintException e) {
+
+ Trace.catching(DiagramPrintingPlugin.getInstance(),
+ DiagramPrintingDebugOptions.EXCEPTIONS_CATCHING,
+ DiagramPrinterUtil.class, e.getMessage(), e);
+ Log.warning(DiagramPrintingPlugin.getInstance(),
+ DiagramPrintingStatusCodes.RESOURCE_FAILURE,
+ e.getMessage(), e);
+
+ MessageDialog
+ .openError(
+ Display.getDefault().getActiveShell(),
+ DiagramUIPrintingMessages.JPSDiagramPrinterUtil_ErrorTitle,
+ DiagramUIPrintingMessages.JPSDiagramPrinterUtil_ErrorMessage);
+ }
+ }
+
+ /**
+ *
+ * This method paints a portion of the diagram. (The area painted
+ * representing one page.)
+ *
+ * @param page indicates which page to print.
+ */
+ protected void drawPage(PageData page) {
+ this.graphics.pushState();
+
+ internalDrawPage(page.diagram, page.bounds, page.preferences,
+ page.margins, graphics, page.row, page.column, false);
+
+ // TODO: Re-enable printing of header and footer in phase 2
+ this.graphics.popState();
+ }
+
+ /**
+ * The real rendering of the page to the given graphical object occurs here.
+ */
+ protected void internalDrawPage(DiagramEditPart dgrmEP,
+ Rectangle figureBounds, IPreferenceStore fPreferences,
+ PageMargins margins, Graphics g, int rowIndex, int colIndex,
+ boolean RTL_ENABLED) {
+
+ org.eclipse.draw2d.geometry.Point pageSize = PageInfoHelper
+ .getPageSize(fPreferences, false, getMapMode());
+
+ int width = pageSize.x, height = pageSize.y;
+
+ g.pushState();
+
+ g.translate(translated.x, translated.y);
+ g.scale(userScale);
+
+ int translateX = -(width * (colIndex - 1));
+ int translateY = -(height * (rowIndex - 1));
+
+ int scaledTranslateX = (int) (translateX / userScale);
+ int scaledTranslateY = (int) (translateY / userScale);
+
+ int scaledWidth = (int) (width / userScale);
+ int scaledHeight = (int) (height / userScale);
+
+ if (RTL_ENABLED) {
+ scaledTranslateX += (margins.left * (colIndex - 1))
+ + (margins.right * (colIndex));
+ scaledTranslateY += ((margins.top * rowIndex) + (margins.bottom * (rowIndex - 1)));
+ } else {
+ scaledTranslateX += ((margins.left * colIndex) + (margins.right * (colIndex - 1)));
+ scaledTranslateY += ((margins.top * rowIndex) + (margins.bottom * (rowIndex - 1)));
+ }
+
+ g.translate(scaledTranslateX, scaledTranslateY);
+
+ Rectangle clip = new Rectangle(
+ (scaledWidth - margins.left - margins.right) * (colIndex - 1)
+ + figureBounds.x, (scaledHeight
+ - margins.bottom - margins.top)
+ * (rowIndex - 1) + figureBounds.y, scaledWidth
+ - margins.right - margins.left, scaledHeight
+ - margins.top - margins.bottom);
+ g.clipRect(clip);
+
+ dgrmEP.getLayer(LayerConstants.PRINTABLE_LAYERS).paint(g);
+
+ g.popState();
+ }
+
+ /**
+ * Adjust the page margins to be compatible with the user scale.
+ *
+ * @param margins the page margins to adjust
+ * @return adjusted page margins
+ */
+ private PageMargins adjustMarginsToScale(PageMargins margins) {
+ margins.left /= userScale;
+ margins.top /= userScale;
+ margins.bottom /= userScale;
+ margins.right /= userScale;
+
+ return margins;
+ }
+
+}
Index: src/org/eclipse/gmf/runtime/diagram/ui/printing/render/internal/JPSDiagramPrinterHelper.java
===================================================================
RCS file: src/org/eclipse/gmf/runtime/diagram/ui/printing/render/internal/JPSDiagramPrinterHelper.java
diff -N src/org/eclipse/gmf/runtime/diagram/ui/printing/render/internal/JPSDiagramPrinterHelper.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/gmf/runtime/diagram/ui/printing/render/internal/JPSDiagramPrinterHelper.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,137 @@
+/******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ****************************************************************************/
+package org.eclipse.gmf.runtime.diagram.ui.printing.render.internal;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.gmf.runtime.common.core.util.Log;
+import org.eclipse.gmf.runtime.common.core.util.Trace;
+import org.eclipse.gmf.runtime.common.ui.printing.IPrintHelper;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart;
+import org.eclipse.gmf.runtime.diagram.ui.printing.internal.DiagramPrintingDebugOptions;
+import org.eclipse.gmf.runtime.diagram.ui.printing.internal.DiagramPrintingPlugin;
+import org.eclipse.gmf.runtime.diagram.ui.printing.internal.DiagramPrintingStatusCodes;
+import org.eclipse.gmf.runtime.diagram.ui.printing.internal.l10n.DiagramUIPrintingMessages;
+import org.eclipse.gmf.runtime.diagram.ui.printing.internal.util.DiagramPrinterHelper;
+import org.eclipse.gmf.runtime.diagram.ui.printing.render.util.PrintHelper;
+import org.eclipse.gmf.runtime.diagram.ui.printing.util.DiagramPrinterUtil;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.printing.PrinterData;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorPart;
+
+/**
+ * Utility for using the DiagramPrinter to print diagrams after displaying
+ * a print dialog box to the user. Diagrams are printed using the
+ * DiagramPrinter and respect the settings chosen by the user in the print
+ * dialog.
+ *
+ * This class uses the java print service API to accomplish its task.
+ * This class was derived from @see org.eclipse.gmf.runtime.diagram.ui.printing.util.DiagramPrinterUtil
+ *
+ * This class is subject to change/removal during phase 2 of printing enhancements
+ *
+ */
+public class JPSDiagramPrinterHelper extends DiagramPrinterHelper {
+
+ private static JPSDiagramPrinterHelper jpsDiagramPrinterHelper;
+
+ public static JPSDiagramPrinterHelper getDiagramPrinterHelper() {
+ if(jpsDiagramPrinterHelper == null){
+ jpsDiagramPrinterHelper = new JPSDiagramPrinterHelper();
+ }
+ return jpsDiagramPrinterHelper;
+ }
+
+ /**
+ * Prevent instantiation.
+ */
+ private JPSDiagramPrinterHelper() {
+ }
+
+ /**
+ * Opens up the print diagrams dialog, allows the user to choose the
+ * settings, and prints.
+ *
+ * @param editorPart
+ * current editor part
+ * @param diagramMap
+ * map of String names to Diagram objects. Should be initialized
+ * by caller of this method. String names will show up in the
+ * print dialog that allows the user to choose which diagrams to
+ * print from a list.
+ * @param jpsDiagramPrinter
+ * the diagram printer that does the work of actually printing the diagrams
+ */
+ public void printWithSettings(IEditorPart editorPart,
+ Map diagramMap, JPSDiagramPrinter jpsDiagramPrinter) {
+
+ try {
+ IPrintHelper helper = new PrintHelper();
+ List diagramNames = new ArrayList(diagramMap
+ .keySet());
+
+ PrinterData printerData = collectPrintInformation(
+ jpsDiagramPrinter, helper, diagramNames, editorPart,
+ diagramMap);
+
+ if (printerData != null) {
+
+ jpsDiagramPrinter.setPrinter(printerData.name);
+ jpsDiagramPrinter.setDisplayDPI(Display.getDefault().getDPI());
+ jpsDiagramPrinter.setPrintHelper(helper);
+
+ if (helper.getDlgDiagramPrintRangeCurrent()) {
+ DiagramEditPart dgrmEP = ((IDiagramWorkbenchPart) editorPart)
+ .getDiagramEditPart();
+ assert dgrmEP != null;
+ jpsDiagramPrinter
+ .setDiagrams(Collections.singletonList(dgrmEP
+ .getDiagramView().getDiagram()));
+ } else if (helper.getDlgDiagramPrintRangeAll()) {
+ jpsDiagramPrinter.setDiagrams(diagramMap.values());
+ } else if (helper.getDlgDiagramPrintRangeSelection()) {
+ Object obj;
+ List list = new ArrayList();
+ for (int i = 0; i < diagramNames.size(); i++) {
+ if (helper.isDlgDiagramSelected(i)) {
+ obj = diagramMap.get(diagramNames.get(i));
+ if (obj instanceof Diagram) {
+ list.add((Diagram) obj);
+ }
+ }
+ }
+ jpsDiagramPrinter.setDiagrams(list);
+ }
+ printDiagrams(jpsDiagramPrinter, helper);
+ }
+ } catch (Throwable e) {
+
+ Trace.catching(DiagramPrintingPlugin.getInstance(),
+ DiagramPrintingDebugOptions.EXCEPTIONS_CATCHING,
+ DiagramPrinterUtil.class, e.getMessage(), e);
+ Log.warning(DiagramPrintingPlugin.getInstance(),
+ DiagramPrintingStatusCodes.RESOURCE_FAILURE,
+ e.getMessage(), e);
+
+ MessageDialog
+ .openError(
+ Display.getDefault().getActiveShell(),
+ DiagramUIPrintingMessages.JPSDiagramPrinterUtil_ErrorTitle,
+ DiagramUIPrintingMessages.JPSDiagramPrinterUtil_ErrorMessage);
+ }
+ }
+}
Index: src/org/eclipse/gmf/runtime/diagram/ui/printing/render/model/PrintDestination.java
===================================================================
RCS file: src/org/eclipse/gmf/runtime/diagram/ui/printing/render/model/PrintDestination.java
diff -N src/org/eclipse/gmf/runtime/diagram/ui/printing/render/model/PrintDestination.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/gmf/runtime/diagram/ui/printing/render/model/PrintDestination.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,73 @@
+/******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ****************************************************************************/
+
+package org.eclipse.gmf.runtime.diagram.ui.printing.render.model;
+
+import org.eclipse.swt.printing.PrinterData;
+
+
+/**
+ * This class is used as part of the infrastructure required for data-bindings
+ * used with the JPS dialog.
+ *
+ * @author Christian Damus (cdamus)
+ * @author James Bruck (jbruck)
+ */
+public class PrintDestination extends PrintModelElement {
+ public static String PROPERTY_NAME = "name"; //$NON-NLS-1$
+ public static String PROPERTY_PRINT_TO_FILE = "printToFile"; //$NON-NLS-1$
+ public static String PROPERTY_FILE_PATH = "filePath"; //$NON-NLS-1$
+
+
+ protected PrinterData printerData;
+
+ public PrinterData getPrinterData(){
+ if(printerData == null){
+ printerData = new PrinterData();
+ }
+ return printerData;
+ }
+
+ public PrintDestination(String printerName) {
+ getPrinterData().name = printerName;
+ }
+
+ public String getName() {
+ return getPrinterData().name;
+ }
+
+ public void setName(String name) {
+ String oldName = this.getPrinterData().name;
+ this.getPrinterData().name = name;
+ firePropertyChange(PROPERTY_NAME, oldName, name);
+ }
+
+ public boolean isPrintToFile() {
+ return getPrinterData().printToFile;
+ }
+
+ public void setPrintToFile(boolean printToFile) {
+ boolean oldToFile = getPrinterData().printToFile;
+ getPrinterData().printToFile = printToFile;
+ firePropertyChange(PROPERTY_PRINT_TO_FILE, oldToFile, printToFile);
+ }
+
+ public String getFilePath() {
+ return getPrinterData().fileName;
+ }
+
+ public void setFilePath(String filePath) {
+ String oldPath = getPrinterData().fileName;
+ getPrinterData().fileName = filePath;
+ firePropertyChange(PROPERTY_FILE_PATH, oldPath, filePath);
+ }
+
+}
Index: src/org/eclipse/gmf/runtime/diagram/ui/printing/render/dialogs/RangeBlock.java
===================================================================
RCS file: src/org/eclipse/gmf/runtime/diagram/ui/printing/render/dialogs/RangeBlock.java
diff -N src/org/eclipse/gmf/runtime/diagram/ui/printing/render/dialogs/RangeBlock.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/gmf/runtime/diagram/ui/printing/render/dialogs/RangeBlock.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,101 @@
+/******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ****************************************************************************/
+
+package org.eclipse.gmf.runtime.diagram.ui.printing.render.dialogs;
+
+import org.eclipse.core.databinding.DataBindingContext;
+import org.eclipse.core.databinding.beans.BeansObservables;
+import org.eclipse.core.databinding.observable.Realm;
+import org.eclipse.core.databinding.observable.value.ComputedValue;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.gmf.runtime.diagram.ui.printing.internal.l10n.DiagramUIPrintingMessages;
+import org.eclipse.gmf.runtime.diagram.ui.printing.render.model.PrintOptions;
+import org.eclipse.jface.databinding.swt.SWTObservables;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Text;
+
+
+/**
+ * A section of the JPS print dialog that adds range checking.
+ *
+ * @author Christian Damus (cdamus)
+ * @author James Bruck (jbruck)
+ */
+class RangeBlock extends DialogBlock {
+ private final DataBindingContext bindings;
+ private final PrintOptions options;
+
+ RangeBlock(IDialogUnitConverter dluConverter, DataBindingContext bindings,
+ PrintOptions options) {
+ super(dluConverter);
+
+ this.bindings = bindings;
+ this.options = options;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.gmf.runtime.common.ui.printing.internal.dialogs.DialogBlock#createContents(org.eclipse.swt.widgets.Composite)
+ */
+ public Control createContents(Composite parent) {
+ final Realm realm = bindings.getValidationRealm();
+
+ Composite result = group(parent,
+ DiagramUIPrintingMessages.JPSPrintDialog_PrintRange);
+ layout(result, 4);
+
+ Button allRadio = radio(result,
+ DiagramUIPrintingMessages.JPSPrintDialog_All);
+ layoutSpanHorizontal(allRadio, 4);
+
+ final IObservableValue allValue = BeansObservables.observeValue(realm,
+ options, PrintOptions.PROPERTY_ALL_PAGES);
+ bindings.bindValue(SWTObservables.observeSelection(allRadio), allValue,
+ null, null);
+
+ Button rangeRadio = radio(result,
+ DiagramUIPrintingMessages.JPSPrintDialog_Pages);
+ layoutSpanHorizontal(rangeRadio, 4);
+
+ IObservableValue rangeValue = new ComputedValue(realm) {
+ protected Object calculate() {
+ return Boolean.valueOf(!((Boolean) allValue.getValue())
+ .booleanValue());
+ }
+ };
+ bindings.bindValue(SWTObservables.observeSelection(rangeRadio),
+ rangeValue, null, null);
+
+ layoutHorizontalIndent(label(result,
+ DiagramUIPrintingMessages.JPSPrintDialog_From));
+ Text textFrom = text(result, 20);
+
+ layoutHorizontalIndent(label(result,
+ DiagramUIPrintingMessages.JPSPrintDialog_To));
+ Text textTo = text(result, 20);
+
+ bindings.bindValue(SWTObservables.observeText(textFrom, SWT.Modify),
+ BeansObservables.observeValue(realm, options,
+ PrintOptions.PROPERTY_RANGE_FROM), null, null);
+ bindings.bindValue(SWTObservables.observeEnabled(textFrom), rangeValue,
+ null, null);
+ bindings.bindValue(SWTObservables.observeText(textTo, SWT.Modify),
+ BeansObservables.observeValue(realm, options,
+ PrintOptions.PROPERTY_RANGE_TO), null, null);
+ bindings.bindValue(SWTObservables.observeEnabled(textTo), rangeValue,
+ null, null);
+
+ return result;
+ }
+}
Index: src/org/eclipse/gmf/runtime/diagram/ui/printing/render/internal/PageData.java
===================================================================
RCS file: src/org/eclipse/gmf/runtime/diagram/ui/printing/render/internal/PageData.java
diff -N src/org/eclipse/gmf/runtime/diagram/ui/printing/render/internal/PageData.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/gmf/runtime/diagram/ui/printing/render/internal/PageData.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,57 @@
+/******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ****************************************************************************/
+
+
+package org.eclipse.gmf.runtime.diagram.ui.printing.render.internal;
+
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.internal.pagesetup.PageInfoHelper.PageMargins;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.swt.graphics.FontData;
+
+
+ /**
+ * PageData is used during the JPS printing process to cache
+ * information that will be used later when printing is invoked
+ * through a call-back mechanism.
+ *
+ * @author Christian Damus (cdamus)
+ * @author James Bruck (jbruck)
+ *
+ */
+
+public class PageData {
+
+ final int index;
+ final int row;
+ final int column;
+
+ final DiagramEditPart diagram;
+ final Rectangle bounds;
+ final PageMargins margins;
+ final FontData font;
+ final IPreferenceStore preferences;
+
+ PageData(int index, int row, int column, DiagramEditPart diagram,
+ Rectangle bounds, PageMargins margins, FontData font,
+ IPreferenceStore preferences) {
+
+ this.index = index;
+ this.row = row;
+ this.column = column;
+ this.diagram = diagram;
+ this.bounds = bounds;
+ this.margins = margins;
+ this.font = font;
+ this.preferences = preferences;
+ }
+}
Index: src/org/eclipse/gmf/runtime/diagram/ui/printing/render/model/PrintOptions.java
===================================================================
RCS file: src/org/eclipse/gmf/runtime/diagram/ui/printing/render/model/PrintOptions.java
diff -N src/org/eclipse/gmf/runtime/diagram/ui/printing/render/model/PrintOptions.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/gmf/runtime/diagram/ui/printing/render/model/PrintOptions.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,154 @@
+/******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ****************************************************************************/
+
+package org.eclipse.gmf.runtime.diagram.ui.printing.render.model;
+
+
+/**
+ * This class is used as part of the infrastructure required for data-bindings
+ * used with the JPS dialog.
+ *
+ * @author Christian Damus (cdamus)
+ * @author James Bruck (jbruck)
+ */
+public class PrintOptions extends PrintModelElement {
+ public static String PROPERTY_DESTINATION = "destination"; //$NON-NLS-1$
+
+ public static String PROPERTY_PERCENT_SCALING = "percentScaling"; //$NON-NLS-1$
+ public static String PROPERTY_SCALE_FACTOR = "scaleFactor"; //$NON-NLS-1$
+ public static String PROPERTY_FIT_TO_WIDTH = "fitToPagesWidth"; //$NON-NLS-1$
+ public static String PROPERTY_FIT_TO_HEIGHT = "fitToPagesHeight"; //$NON-NLS-1$
+
+ public static String PROPERTY_ALL_PAGES = "allPages"; //$NON-NLS-1$
+ public static String PROPERTY_RANGE_FROM = "rangeFrom"; //$NON-NLS-1$
+ public static String PROPERTY_RANGE_TO = "rangeTo"; //$NON-NLS-1$
+
+ public static String PROPERTY_COPIES = "copies"; //$NON-NLS-1$
+ public static String PROPERTY_COLLATE = "collate"; //$NON-NLS-1$
+
+ private PrintDestination destination;
+
+ private boolean percentScaling;
+ private int scaleFactor;
+ private int fitToPagesWidth;
+ private int fitToPagesHeight;
+
+ private boolean allPages;
+ private int rangeFrom;
+ private int rangeTo;
+
+ private int copies;
+ private boolean collate;
+
+ public PrintOptions() {
+ super();
+ }
+
+ public PrintDestination getDestination() {
+ return destination;
+ }
+
+ public void setDestination(PrintDestination destination) {
+ PrintDestination oldDestination = this.destination;
+ this.destination = destination;
+ firePropertyChange(PROPERTY_DESTINATION, oldDestination, destination);
+ }
+
+ public boolean isPercentScaling() {
+ return percentScaling;
+ }
+
+ public void setPercentScaling(boolean percentScaling) {
+ boolean oldScaling = this.percentScaling;
+ this.percentScaling = percentScaling;
+ firePropertyChange(PROPERTY_PERCENT_SCALING, oldScaling, percentScaling);
+ }
+
+ public int getScaleFactor() {
+ return scaleFactor;
+ }
+
+ public void setScaleFactor(int scaleFactor) {
+ int oldFactor = this.scaleFactor;
+ this.scaleFactor = scaleFactor;
+ firePropertyChange(PROPERTY_SCALE_FACTOR, oldFactor, scaleFactor);
+ }
+
+ public int getFitToPagesWidth() {
+ return fitToPagesWidth;
+ }
+
+ public void setFitToPagesWidth(int fitToPagesWidth) {
+ int oldWidth = this.fitToPagesWidth;
+ this.fitToPagesWidth = fitToPagesWidth;
+ firePropertyChange(PROPERTY_FIT_TO_WIDTH, oldWidth, fitToPagesWidth);
+ }
+
+ public int getFitToPagesHeight() {
+ return fitToPagesHeight;
+ }
+
+ public void setFitToPagesHeight(int fitToPagesHeight) {
+ int oldHeight = this.fitToPagesHeight;
+ this.fitToPagesHeight = fitToPagesHeight;
+ firePropertyChange(PROPERTY_FIT_TO_HEIGHT, oldHeight, fitToPagesHeight);
+ }
+
+ public boolean isAllPages() {
+ return allPages;
+ }
+
+ public void setAllPages(boolean allPages) {
+ boolean oldAll = this.allPages;
+ this.allPages = allPages;
+ firePropertyChange(PROPERTY_ALL_PAGES, oldAll, allPages);
+ }
+
+ public int getRangeFrom() {
+ return rangeFrom;
+ }
+
+ public void setRangeFrom(int rangeFrom) {
+ int oldFrom = this.rangeFrom;
+ this.rangeFrom = rangeFrom;
+ firePropertyChange(PROPERTY_RANGE_FROM, oldFrom, rangeFrom);
+ }
+
+ public int getRangeTo() {
+ return rangeTo;
+ }
+
+ public void setRangeTo(int rangeTo) {
+ int oldTo = this.rangeTo;
+ this.rangeTo = rangeTo;
+ firePropertyChange(PROPERTY_RANGE_TO, oldTo, rangeTo);
+ }
+
+ public int getCopies() {
+ return copies;
+ }
+
+ public void setCopies(int copies) {
+ int oldCopies = this.copies;
+ this.copies = copies;
+ firePropertyChange(PROPERTY_COPIES, oldCopies, copies);
+ }
+
+ public boolean isCollate() {
+ return collate;
+ }
+
+ public void setCollate(boolean collate) {
+ boolean oldCollate = this.collate;
+ this.collate = collate;
+ firePropertyChange(PROPERTY_COLLATE, oldCollate, collate);
+ }
+}
Index: src/org/eclipse/gmf/runtime/diagram/ui/printing/render/dialogs/DialogBlock.java
===================================================================
RCS file: src/org/eclipse/gmf/runtime/diagram/ui/printing/render/dialogs/DialogBlock.java
diff -N src/org/eclipse/gmf/runtime/diagram/ui/printing/render/dialogs/DialogBlock.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/gmf/runtime/diagram/ui/printing/render/dialogs/DialogBlock.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,236 @@
+/******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ****************************************************************************/
+
+package org.eclipse.gmf.runtime.diagram.ui.printing.render.dialogs;
+
+import org.eclipse.jface.viewers.ComboViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Spinner;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * Intended to be used as a base for other specializing dialog blocks.
+ * Provides common layout functionality
+ *
+ * @author Christian Damus (cdamus)
+ * @author James Bruck (jbruck)
+ */
+abstract class DialogBlock {
+ private final IDialogUnitConverter dluConverter;
+
+ DialogBlock(IDialogUnitConverter dluConverter) {
+ this.dluConverter = dluConverter;
+ }
+
+ protected Shell getShell() {
+ return dluConverter.getShell();
+ }
+
+
+ static Composite layout(Composite composite, int columns) {
+ GridLayout g = new GridLayout(columns, false);
+ g.marginLeft = 6;
+ g.marginRight = 6;
+ g.marginTop = 6;
+ g.marginBottom = 3;
+ composite.setLayout(g);
+
+ return composite;
+ }
+
+ GridData getLayoutData(Control control) {
+ GridData result = (GridData) control.getLayoutData();
+
+ if (result == null) {
+ result = new GridData();
+ control.setLayoutData(result);
+ }
+
+ return result;
+ }
+
+ Control layoutFillHorizontal(Control control) {
+ layoutFillHorizontal(control, true);
+
+ return control;
+ }
+
+ Control layoutFillHorizontal(Control control, boolean grab) {
+ GridData data = getLayoutData(control);
+
+ data.horizontalAlignment = SWT.FILL;
+ data.grabExcessHorizontalSpace = grab;
+
+ return control;
+ }
+
+ Control layoutFillVertical(Control control) {
+ GridData data = getLayoutData(control);
+
+ data.verticalAlignment = SWT.FILL;
+ data.grabExcessVerticalSpace = true;
+
+ return control;
+ }
+
+ Control layoutAlignLeft(Control control) {
+ GridData data = getLayoutData(control);
+
+ data.horizontalAlignment = SWT.BEGINNING;
+ data.grabExcessHorizontalSpace = false;
+
+ return control;
+ }
+
+ Control layoutAlignRight(Control control) {
+ GridData data = getLayoutData(control);
+
+ data.horizontalAlignment = SWT.END;
+ data.grabExcessHorizontalSpace = false;
+
+ return control;
+ }
+
+ Control layoutFillBoth(Control control) {
+ GridData data = getLayoutData(control);
+
+ data.horizontalAlignment = SWT.FILL;
+ data.grabExcessHorizontalSpace = true;
+ data.verticalAlignment = SWT.FILL;
+ data.grabExcessVerticalSpace = true;
+
+ return control;
+ }
+
+ Control layoutSpanHorizontal(Control control, int span) {
+ GridData data = getLayoutData(control);
+
+ data.horizontalSpan = span;
+
+ return control;
+ }
+
+ Control layoutSpanVertical(Control control, int span) {
+ GridData data = getLayoutData(control);
+
+ data.verticalSpan = span;
+
+ return control;
+ }
+
+ Control layoutHorizontalIndent(Control control) {
+ layoutHorizontalIndent(control, 15);
+
+ return control;
+ }
+
+ Control layoutHorizontalIndent(Control control, int inset) {
+ GridData data = getLayoutData(control);
+ data.horizontalIndent = inset;
+
+ return control;
+ }
+
+ Control layoutVerticalIndent(Control control) {
+ layoutVerticalIndent(control, 15);
+
+ return control;
+ }
+
+ Control layoutVerticalIndent(Control control, int inset) {
+ GridData data = getLayoutData(control);
+ data.verticalIndent = inset;
+
+ return control;
+ }
+
+ Control layoutWidth(Control control, int dlus) {
+ if (dlus > 0) {
+ GridData data = getLayoutData(control);
+ data.widthHint = dluConverter.convertHorizontalDLUsToPixels(dlus);
+ }
+
+ return control;
+ }
+
+ Group group(Composite parent, String text) {
+ Group result = new Group(parent, SWT.NONE);
+ result.setText(text);
+ layoutFillBoth(result);
+ return result;
+ }
+
+ Label label(Composite parent, String text) {
+ Label result = new Label(parent, SWT.NONE);
+ result.setText(text);
+ return result;
+ }
+
+ Text text(Composite parent, int width) {
+ Text result = new Text(parent, SWT.SINGLE | SWT.BORDER);
+ layoutFillHorizontal(result, false);
+ layoutWidth(result, width);
+
+ return result;
+ }
+
+ ComboViewer combo(Composite parent) {
+ ComboViewer result = new ComboViewer(parent);
+ return result;
+ }
+
+ Button button(Composite parent, String text) {
+ Button result = new Button(parent, SWT.PUSH);
+ result.setText(text);
+ return result;
+ }
+
+ Button radio(Composite parent, String text) {
+ Button result = new Button(parent, SWT.RADIO);
+ result.setText(text);
+ return result;
+ }
+
+ Button check(Composite parent, String text) {
+ Button result = new Button(parent, SWT.CHECK);
+ result.setText(text);
+ return result;
+ }
+
+ Spinner spinner(Composite parent, int min, int max) {
+ Spinner result = new Spinner(parent, SWT.BORDER);
+ result.setMinimum(min);
+ result.setMaximum(max);
+
+ return result;
+ }
+
+ Control blank(Composite parent) {
+ Label result = new Label(parent, SWT.NONE);
+ return result;
+ }
+
+ public abstract Control createContents(Composite parent);
+
+ public static interface IDialogUnitConverter {
+ int convertHorizontalDLUsToPixels(int dlus);
+
+ Shell getShell();
+ }
+}
Index: src/org/eclipse/gmf/runtime/diagram/ui/printing/render/dialogs/CopiesBlock.java
===================================================================
RCS file: src/org/eclipse/gmf/runtime/diagram/ui/printing/render/dialogs/CopiesBlock.java
diff -N src/org/eclipse/gmf/runtime/diagram/ui/printing/render/dialogs/CopiesBlock.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/gmf/runtime/diagram/ui/printing/render/dialogs/CopiesBlock.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,72 @@
+/******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ****************************************************************************/
+
+package org.eclipse.gmf.runtime.diagram.ui.printing.render.dialogs;
+
+import org.eclipse.core.databinding.DataBindingContext;
+import org.eclipse.core.databinding.beans.BeansObservables;
+import org.eclipse.core.databinding.observable.Realm;
+import org.eclipse.gmf.runtime.diagram.ui.printing.internal.l10n.DiagramUIPrintingMessages;
+import org.eclipse.gmf.runtime.diagram.ui.printing.render.model.PrintOptions;
+import org.eclipse.jface.databinding.swt.SWTObservables;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Spinner;
+
+
+/**
+ * A section of the JPS print dialog that handles the number of copies of
+ * a diagram to print.
+ *
+ * @author Christian Damus (cdamus)
+ * @author James Bruck (jbruck)
+ */
+class CopiesBlock extends DialogBlock {
+
+ private final DataBindingContext bindings;
+ private final PrintOptions options;
+
+ CopiesBlock(IDialogUnitConverter dluConverter, DataBindingContext bindings,
+ PrintOptions options) {
+ super(dluConverter);
+
+ this.bindings = bindings;
+ this.options = options;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.gmf.runtime.common.ui.printing.internal.dialogs.DialogBlock#createContents(org.eclipse.swt.widgets.Composite)
+ */
+ public Control createContents(Composite parent) {
+ final Realm realm = bindings.getValidationRealm();
+
+ Composite result = group(parent, DiagramUIPrintingMessages.JPSPrintDialog_Copies);
+ layout(result, 2);
+
+ label(result, DiagramUIPrintingMessages.JPSPrintDialog_NumberOfCopies);
+ Spinner copiesSpinner = spinner(result, 1, 999);
+
+ bindings.bindValue(SWTObservables.observeSelection(copiesSpinner),
+ BeansObservables.observeValue(realm, options, PrintOptions.PROPERTY_COPIES),
+ null, null);
+
+ blank(result);
+ Button collateCheck = check(result, DiagramUIPrintingMessages.JPSPrintDialog_Collate);
+
+ bindings.bindValue(SWTObservables.observeSelection(collateCheck),
+ BeansObservables.observeValue(realm, options, PrintOptions.PROPERTY_COLLATE),
+ null, null);
+
+ return result;
+ }
+}
Index: src/org/eclipse/gmf/runtime/diagram/ui/printing/render/dialogs/JPSPrintDialog.java
===================================================================
RCS file: src/org/eclipse/gmf/runtime/diagram/ui/printing/render/dialogs/JPSPrintDialog.java
diff -N src/org/eclipse/gmf/runtime/diagram/ui/printing/render/dialogs/JPSPrintDialog.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/gmf/runtime/diagram/ui/printing/render/dialogs/JPSPrintDialog.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,158 @@
+/******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ****************************************************************************/
+
+
+
+package org.eclipse.gmf.runtime.diagram.ui.printing.render.dialogs;
+
+import org.eclipse.core.databinding.DataBindingContext;
+import org.eclipse.gmf.runtime.diagram.ui.printing.internal.l10n.DiagramUIPrintingMessages;
+import org.eclipse.gmf.runtime.diagram.ui.printing.render.model.PrintOptions;
+import org.eclipse.jface.databinding.swt.SWTObservables;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.TrayDialog;
+import org.eclipse.jface.window.IShellProvider;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+
+/**
+ * A dialog that supports platform independent printing based on the
+ * Java Printing Service API.
+ *
+ * @author Christian Damus (cdamus)
+ * @author James Bruck (jbruck)
+ */
+public class JPSPrintDialog
+ extends TrayDialog {
+
+ private DataBindingContext bindings;
+ private final PrintOptions options;
+
+ protected PrinterBlock printerBlock;
+ protected ScalingBlock scalingBlock;
+ private RangeBlock rangeBlock;
+ private CopiesBlock copiesBlock;
+ private ActionsBlock actionsBlock;
+
+ private final DialogBlock.IDialogUnitConverter dluConverter =
+ new DialogBlock.IDialogUnitConverter() {
+
+ public int convertHorizontalDLUsToPixels(int dlus) {
+ return JPSPrintDialog.this.convertHorizontalDLUsToPixels(dlus);
+ }
+
+ public Shell getShell() {
+ return JPSPrintDialog.this.getShell();
+ }};
+
+ public JPSPrintDialog(IShellProvider parentShell, PrintOptions options) {
+ super(parentShell);
+ this.options = options;
+ }
+
+ public JPSPrintDialog(Shell shell, PrintOptions options) {
+ super(shell);
+ this.options = options;
+ }
+
+ protected void configureShell(Shell newShell) {
+ super.configureShell(newShell);
+
+ newShell.setText(DiagramUIPrintingMessages.JPSPrintDialog_Title);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
+ */
+ protected Control createDialogArea(Composite parent) {
+ bindings = new DataBindingContext(SWTObservables.getRealm(parent.getDisplay()));
+
+ Composite result = new Composite(parent,SWT.NONE);
+ DialogBlock.layout(result, 2);
+
+ createPrinterBlockArea(result);
+ createScalingBlockArea(result);
+ createExtensibleBlockArea(result);
+ createRangeBlockArea(result);
+ createCopiesBlockArea(result);
+ createActionsBlockArea(result);
+
+ return result;
+ }
+
+ protected void createPrinterBlockArea(Composite result) {
+ printerBlock = new PrinterBlock(dluConverter, bindings, options);
+ printerBlock.layoutSpanHorizontal(printerBlock.createContents(result),
+ 2);
+ }
+
+ protected void createScalingBlockArea(Composite result) {
+ scalingBlock = new ScalingBlock(dluConverter, bindings, options);
+ scalingBlock.layoutSpanHorizontal(scalingBlock.createContents(result), 2);
+ }
+
+ protected void createRangeBlockArea(Composite result) {
+ rangeBlock = new RangeBlock(dluConverter, bindings, options);
+ rangeBlock.createContents(result);
+ }
+
+ protected void createCopiesBlockArea(Composite result) {
+ copiesBlock = new CopiesBlock(dluConverter, bindings, options);
+ copiesBlock.createContents(result);
+ }
+
+ protected void createActionsBlockArea(Composite result) {
+ actionsBlock = new ActionsBlock(dluConverter, options);
+ actionsBlock.layoutSpanHorizontal(actionsBlock.createContents(result), 2);
+ }
+
+ protected void createExtensibleBlockArea(Composite result) {
+ // meant to be overiden by subclasses to add additional blocks.
+ }
+
+
+ protected void createButtonsForButtonBar(Composite parent) {
+ createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
+ createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
+ }
+
+ protected void buttonPressed(int buttonId) {
+ switch (buttonId) {
+ case -1:
+ break;
+ default:
+ super.buttonPressed(buttonId);
+ }
+ }
+
+ public boolean close() {
+ bindings.dispose();
+ return super.close();
+ }
+
+ protected void cancelPressed() {
+ super.cancelPressed();
+ }
+
+ /**
+ * Obtains the user's selected printing options, or null
if
+ * the user canceled the print operation.
+ *
+ * @return the printing options, or null
if canceled
+ */
+ public PrintOptions getPrintOptions() {
+ return options;
+ }
+}
#P org.eclipse.gmf.runtime.diagram.ui
Index: src/org/eclipse/gmf/runtime/diagram/ui/internal/pagesetup/DefaultValues.java
===================================================================
RCS file: /cvsroot/modeling/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.diagram.ui/src/org/eclipse/gmf/runtime/diagram/ui/internal/pagesetup/DefaultValues.java,v
retrieving revision 1.2
diff -u -r1.2 DefaultValues.java
--- src/org/eclipse/gmf/runtime/diagram/ui/internal/pagesetup/DefaultValues.java 12 Sep 2005 21:29:10 -0000 1.2
+++ src/org/eclipse/gmf/runtime/diagram/ui/internal/pagesetup/DefaultValues.java 29 Feb 2008 18:52:54 -0000
@@ -1,5 +1,5 @@
/******************************************************************************
- * Copyright (c) 2002, 2005 IBM Corporation and others.
+ * Copyright (c) 2002, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -61,6 +61,18 @@
/** Represents default value for WorkspaceViewerProperties.PREF_MARGIN_RIGHT. */
public static double DEFAULT_MARGIN_RIGHT = 0.5;
+
+ /** Enforce a minimum margin to take printer limitations into account */
+ public static double MINIMUM_MARGIN_TOP = 0.2;
+
+ /** Enforce a minimum margin to take printer limitations into account */
+ public static double MINIMUM_MARGIN_BOTTOM = 0.2;
+
+ /** Enforce a minimum margin to take printer limitations into account */
+ public static double MINIMUM_MARGIN_LEFT = 0.2;
+
+ /** Enforce a minimum margin to take printer limitations into account */
+ public static double MINIMUM_MARGIN_RIGHT = 0.2;
/**
* Returns locale specific page size.
Index: src/org/eclipse/gmf/runtime/diagram/ui/internal/dialogs/PageSetupConfigBlock.java
===================================================================
RCS file: /cvsroot/modeling/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.diagram.ui/src/org/eclipse/gmf/runtime/diagram/ui/internal/dialogs/PageSetupConfigBlock.java,v
retrieving revision 1.10
diff -u -r1.10 PageSetupConfigBlock.java
--- src/org/eclipse/gmf/runtime/diagram/ui/internal/dialogs/PageSetupConfigBlock.java 16 Jan 2008 21:07:43 -0000 1.10
+++ src/org/eclipse/gmf/runtime/diagram/ui/internal/dialogs/PageSetupConfigBlock.java 29 Feb 2008 18:52:54 -0000
@@ -12,11 +12,23 @@
package org.eclipse.gmf.runtime.diagram.ui.internal.dialogs;
+import java.awt.print.PageFormat;
+import java.awt.print.Paper;
+import java.awt.print.PrinterJob;
import java.text.ParseException;
import java.util.ArrayList;
+import org.eclipse.draw2d.geometry.PrecisionPoint;
+import org.eclipse.gmf.runtime.diagram.ui.internal.pagesetup.DefaultValues;
+import org.eclipse.gmf.runtime.diagram.ui.internal.pagesetup.ILabels;
+import org.eclipse.gmf.runtime.diagram.ui.internal.pagesetup.PageSetupPageType;
+import org.eclipse.gmf.runtime.diagram.ui.internal.pagesetup.PageSetupWidgetFactory;
+import org.eclipse.gmf.runtime.diagram.ui.internal.properties.WorkspaceViewerProperties;
+import org.eclipse.gmf.runtime.diagram.ui.preferences.PrintingPreferencePage;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionEvent;
@@ -33,13 +45,6 @@
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Text;
-import org.eclipse.gmf.runtime.diagram.ui.internal.pagesetup.DefaultValues;
-import org.eclipse.gmf.runtime.diagram.ui.internal.pagesetup.ILabels;
-import org.eclipse.gmf.runtime.diagram.ui.internal.pagesetup.PageSetupPageType;
-import org.eclipse.gmf.runtime.diagram.ui.internal.pagesetup.PageSetupWidgetFactory;
-import org.eclipse.gmf.runtime.diagram.ui.internal.properties.WorkspaceViewerProperties;
-import org.eclipse.gmf.runtime.diagram.ui.preferences.PrintingPreferencePage;
-
import com.ibm.icu.text.NumberFormat;
/**
@@ -388,7 +393,16 @@
}
}
-
+
+ /**
+ * Determine if the current set of units are in inches.
+ *
+ * @return true if the current units are in inches.
+ */
+ private boolean isUnitsInInch() {
+ return (fCurrentUnit.startsWith("inc")); //$NON-NLS-1$
+ }
+
/**
* Create part of PSDialog allowing the user to specify page margin values.
*/
@@ -409,14 +423,53 @@
fLabelMarginRight = PageSetupWidgetFactory.createLabel(group, LABEL_MARGIN_RIGHT_INCHES);
fTextMarginRight = PageSetupWidgetFactory.createTextMargin(group);
+
+ fTextMarginTop.addFocusListener(new FocusListener() {
+
+ public void focusGained(FocusEvent e) {
+ // do nothing.
+ }
+
+ public void focusLost(FocusEvent e) {
+ double marginTop = getDblFromString(fTextMarginTop.getText());
+ double minimumTop = DefaultValues.MINIMUM_MARGIN_TOP;
+ if (!isUnitsInInch()) {
+ marginTop = fConvertor.convertMilimToInches(marginTop);
+ minimumTop = fConvertor.convertInchesToMilim(minimumTop);
+ }
+ if (marginTop < DefaultValues.MINIMUM_MARGIN_TOP) {
+ fTextMarginTop.setText(fNumberFormat.format(minimumTop));
+ }
+ }
+ });
fTextMarginTop.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
if (fTextMarginTop.isFocusControl()) {
setOkButtonEnableStatus();
}
}
+
+ });
+
+ fTextMarginBottom.addFocusListener(new FocusListener() {
+ public void focusGained(FocusEvent e) {
+ // do nothing.
+ }
+ /**
+ * Ensure we have minimum margins set.
+ */
+ public void focusLost(FocusEvent e) {
+ double marginBottom = getDblFromString(fTextMarginBottom.getText());
+ double minimumBottom = DefaultValues.MINIMUM_MARGIN_BOTTOM;
+ if (!isUnitsInInch()) {
+ marginBottom = fConvertor.convertMilimToInches(marginBottom);
+ minimumBottom = fConvertor.convertInchesToMilim(minimumBottom);
+ }
+ if (marginBottom < DefaultValues.MINIMUM_MARGIN_BOTTOM) {
+ fTextMarginBottom.setText(fNumberFormat.format(minimumBottom));
+ }
+ }
});
-
fTextMarginBottom.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
if (fTextMarginBottom.isFocusControl()) {
@@ -425,6 +478,26 @@
}
});
+
+ fTextMarginLeft.addFocusListener(new FocusListener() {
+ public void focusGained(FocusEvent e) {
+ // do nothing.
+ }
+ /**
+ * Ensure we have minimum margins set.
+ */
+ public void focusLost(FocusEvent e) {
+ double marginLeft = getDblFromString(fTextMarginLeft.getText());
+ double minimumLeft = DefaultValues.MINIMUM_MARGIN_LEFT;
+ if (!isUnitsInInch()) {
+ marginLeft = fConvertor.convertMilimToInches(marginLeft);
+ minimumLeft = fConvertor.convertInchesToMilim(minimumLeft);
+ }
+ if (marginLeft < DefaultValues.MINIMUM_MARGIN_LEFT) {
+ fTextMarginLeft.setText(fNumberFormat.format(minimumLeft));
+ }
+ }
+ });
fTextMarginLeft.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
if (fTextMarginLeft.isFocusControl()) {
@@ -433,6 +506,25 @@
}
});
+ fTextMarginRight.addFocusListener(new FocusListener() {
+ public void focusGained(FocusEvent e) {
+ // do nothing.
+ }
+ /**
+ * Ensure we have minimum margins set.
+ */
+ public void focusLost(FocusEvent e) {
+ double marginRight = getDblFromString(fTextMarginRight.getText());
+ double minimumRight = DefaultValues.MINIMUM_MARGIN_RIGHT;
+ if (!isUnitsInInch()) {
+ marginRight = fConvertor.convertMilimToInches(marginRight);
+ minimumRight = fConvertor.convertInchesToMilim(minimumRight);
+ }
+ if (marginRight < DefaultValues.MINIMUM_MARGIN_RIGHT) {
+ fTextMarginRight.setText(fNumberFormat.format(minimumRight));
+ }
+ }
+ });
fTextMarginRight.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
if (fTextMarginRight.isFocusControl()) {
@@ -828,7 +920,7 @@
Button b = (Button) e.getSource();
if (b.getSelection()) {
super.widgetSelected(e);
- if (fCurrentUnit.startsWith("inc")) { //$NON-NLS-1$
+ if (isUnitsInInch()) {
convertValuesToMillimetres();
fCurrentUnit = "mil"; //$NON-NLS-1$
}
Index: META-INF/MANIFEST.MF
===================================================================
RCS file: /cvsroot/modeling/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.diagram.ui/META-INF/MANIFEST.MF,v
retrieving revision 1.27
diff -u -r1.27 MANIFEST.MF
--- META-INF/MANIFEST.MF 21 Dec 2007 16:08:15 -0000 1.27
+++ META-INF/MANIFEST.MF 29 Feb 2008 18:52:54 -0000
@@ -25,9 +25,9 @@
org.eclipse.gmf.runtime.diagram.ui.internal.figures;x-friends:="org.eclipse.gmf.tests.runtime.diagram.ui,org.eclipse.gmf.runtime.diagram.ui.render,org.eclipse.gmf.runtime.diagram.ui.providers.ide,org.eclipse.gmf.runtime.diagram.ui.providers,org.eclipse.gmf.runtime.diagram.ui.properties,org.eclipse.gmf.runtime.diagram.ui.printing,org.eclipse.gmf.runtime.diagram.ui.geoshapes,org.eclipse.gmf.runtime.diagram.ui,org.eclipse.gmf.runtime.diagram.ui.actions",
org.eclipse.gmf.runtime.diagram.ui.internal.handles;x-friends:="org.eclipse.gmf.tests.runtime.diagram.ui,org.eclipse.gmf.runtime.diagram.ui.render,org.eclipse.gmf.runtime.diagram.ui.providers.ide,org.eclipse.gmf.runtime.diagram.ui.providers,org.eclipse.gmf.runtime.diagram.ui.properties,org.eclipse.gmf.runtime.diagram.ui.printing,org.eclipse.gmf.runtime.diagram.ui.geoshapes,org.eclipse.gmf.runtime.diagram.ui,org.eclipse.gmf.runtime.diagram.ui.actions",
org.eclipse.gmf.runtime.diagram.ui.internal.l10n;x-friends:="org.eclipse.gmf.tests.runtime.diagram.ui,org.eclipse.gmf.runtime.diagram.ui.render,org.eclipse.gmf.runtime.diagram.ui.providers.ide,org.eclipse.gmf.runtime.diagram.ui.providers,org.eclipse.gmf.runtime.diagram.ui.properties,org.eclipse.gmf.runtime.diagram.ui.printing,org.eclipse.gmf.runtime.diagram.ui.geoshapes,org.eclipse.gmf.runtime.diagram.ui,org.eclipse.gmf.runtime.diagram.ui.actions",
- org.eclipse.gmf.runtime.diagram.ui.internal.pagesetup;x-friends:="org.eclipse.gmf.tests.runtime.diagram.ui,org.eclipse.gmf.runtime.diagram.ui.render,org.eclipse.gmf.runtime.diagram.ui.providers.ide,org.eclipse.gmf.runtime.diagram.ui.providers,org.eclipse.gmf.runtime.diagram.ui.properties,org.eclipse.gmf.runtime.diagram.ui.printing,org.eclipse.gmf.runtime.diagram.ui.geoshapes,org.eclipse.gmf.runtime.diagram.ui,org.eclipse.gmf.runtime.diagram.ui.actions",
+ org.eclipse.gmf.runtime.diagram.ui.internal.pagesetup;x-friends:="org.eclipse.gmf.tests.runtime.diagram.ui,org.eclipse.gmf.runtime.diagram.ui.render,org.eclipse.gmf.runtime.diagram.ui.providers.ide,org.eclipse.gmf.runtime.diagram.ui.providers,org.eclipse.gmf.runtime.diagram.ui.properties,org.eclipse.gmf.runtime.diagram.ui.printing,org.eclipse.gmf.runtime.diagram.ui.geoshapes,org.eclipse.gmf.runtime.diagram.ui,org.eclipse.gmf.runtime.diagram.ui.actions,org.eclipse.gmf.runtime.diagram.ui.printing.render",
org.eclipse.gmf.runtime.diagram.ui.internal.parts;x-friends:="org.eclipse.gmf.tests.runtime.diagram.ui,org.eclipse.gmf.runtime.diagram.ui.render,org.eclipse.gmf.runtime.diagram.ui.providers.ide,org.eclipse.gmf.runtime.diagram.ui.providers,org.eclipse.gmf.runtime.diagram.ui.properties,org.eclipse.gmf.runtime.diagram.ui.printing,org.eclipse.gmf.runtime.diagram.ui.geoshapes,org.eclipse.gmf.runtime.diagram.ui,org.eclipse.gmf.runtime.diagram.ui.actions",
- org.eclipse.gmf.runtime.diagram.ui.internal.properties;x-friends:="org.eclipse.gmf.tests.runtime.diagram.ui,org.eclipse.gmf.runtime.diagram.ui.render,org.eclipse.gmf.runtime.diagram.ui.providers.ide,org.eclipse.gmf.runtime.diagram.ui.providers,org.eclipse.gmf.runtime.diagram.ui.properties,org.eclipse.gmf.runtime.diagram.ui.printing,org.eclipse.gmf.runtime.diagram.ui.geoshapes,org.eclipse.gmf.runtime.diagram.ui,org.eclipse.gmf.runtime.diagram.ui.actions",
+ org.eclipse.gmf.runtime.diagram.ui.internal.properties;x-friends:="org.eclipse.gmf.tests.runtime.diagram.ui,org.eclipse.gmf.runtime.diagram.ui.render,org.eclipse.gmf.runtime.diagram.ui.providers.ide,org.eclipse.gmf.runtime.diagram.ui.providers,org.eclipse.gmf.runtime.diagram.ui.properties,org.eclipse.gmf.runtime.diagram.ui.printing,org.eclipse.gmf.runtime.diagram.ui.geoshapes,org.eclipse.gmf.runtime.diagram.ui,org.eclipse.gmf.runtime.diagram.ui.actions,org.eclipse.gmf.runtime.diagram.ui.printing.render",
org.eclipse.gmf.runtime.diagram.ui.internal.requests;x-friends:="org.eclipse.gmf.tests.runtime.diagram.ui,org.eclipse.gmf.runtime.diagram.ui.render,org.eclipse.gmf.runtime.diagram.ui.providers.ide,org.eclipse.gmf.runtime.diagram.ui.providers,org.eclipse.gmf.runtime.diagram.ui.properties,org.eclipse.gmf.runtime.diagram.ui.printing,org.eclipse.gmf.runtime.diagram.ui.geoshapes,org.eclipse.gmf.runtime.diagram.ui,org.eclipse.gmf.runtime.diagram.ui.actions",
org.eclipse.gmf.runtime.diagram.ui.internal.resources;x-friends:="org.eclipse.gmf.tests.runtime.diagram.ui,org.eclipse.gmf.runtime.diagram.ui.render,org.eclipse.gmf.runtime.diagram.ui.providers.ide,org.eclipse.gmf.runtime.diagram.ui.providers,org.eclipse.gmf.runtime.diagram.ui.properties,org.eclipse.gmf.runtime.diagram.ui.printing,org.eclipse.gmf.runtime.diagram.ui.geoshapes,org.eclipse.gmf.runtime.diagram.ui,org.eclipse.gmf.runtime.diagram.ui.actions",
org.eclipse.gmf.runtime.diagram.ui.internal.ruler;x-friends:="org.eclipse.gmf.tests.runtime.diagram.ui,org.eclipse.gmf.runtime.diagram.ui.render,org.eclipse.gmf.runtime.diagram.ui.providers.ide,org.eclipse.gmf.runtime.diagram.ui.providers,org.eclipse.gmf.runtime.diagram.ui.properties,org.eclipse.gmf.runtime.diagram.ui.printing,org.eclipse.gmf.runtime.diagram.ui.geoshapes,org.eclipse.gmf.runtime.diagram.ui,org.eclipse.gmf.runtime.diagram.ui.actions",
#P org.eclipse.gmf.runtime.diagram.ui.printing
Index: src/org/eclipse/gmf/runtime/diagram/ui/printing/actions/PrintPreviewAction.java
===================================================================
RCS file: /cvsroot/modeling/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.diagram.ui.printing/src/org/eclipse/gmf/runtime/diagram/ui/printing/actions/PrintPreviewAction.java,v
retrieving revision 1.6
diff -u -r1.6 PrintPreviewAction.java
--- src/org/eclipse/gmf/runtime/diagram/ui/printing/actions/PrintPreviewAction.java 3 Oct 2006 15:03:03 -0000 1.6
+++ src/org/eclipse/gmf/runtime/diagram/ui/printing/actions/PrintPreviewAction.java 29 Feb 2008 18:52:55 -0000
@@ -1,5 +1,5 @@
/******************************************************************************
- * Copyright (c) 2002, 2006 IBM Corporation and others.
+ * Copyright (c) 2002, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -117,23 +117,6 @@
*/
protected void setPrintPreviewHelper(PrintPreviewHelper printPreviewHelper) {
this.printPreviewHelper = printPreviewHelper;
- }
-
-
- //TODO: remove the following two methods when printing on
- //other platforms is supported.
-
- /**
- * Enable the menu item if Platform is running on Windows.
- */
- public boolean isEnabled() {
- return isWindows();
- }
+ }
- private boolean isWindows() {
- if (Platform.getOS() != null)
- if (Platform.getOS().startsWith(Platform.OS_WIN32))
- return true;
- return false;
- }
}
\ No newline at end of file
Index: src/org/eclipse/gmf/runtime/diagram/ui/printing/actions/DefaultPrintActionHelper.java
===================================================================
RCS file: /cvsroot/modeling/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.diagram.ui.printing/src/org/eclipse/gmf/runtime/diagram/ui/printing/actions/DefaultPrintActionHelper.java,v
retrieving revision 1.4
diff -u -r1.4 DefaultPrintActionHelper.java
--- src/org/eclipse/gmf/runtime/diagram/ui/printing/actions/DefaultPrintActionHelper.java 25 Nov 2005 19:38:16 -0000 1.4
+++ src/org/eclipse/gmf/runtime/diagram/ui/printing/actions/DefaultPrintActionHelper.java 29 Feb 2008 18:52:55 -0000
@@ -16,7 +16,7 @@
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart;
import org.eclipse.gmf.runtime.diagram.ui.printing.internal.l10n.DiagramUIPrintingMessages;
-import org.eclipse.gmf.runtime.diagram.ui.printing.internal.util.DiagramPrinter;
+import org.eclipse.gmf.runtime.diagram.ui.printing.internal.util.SWTDiagramPrinter;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.printing.PrintDialog;
@@ -42,7 +42,7 @@
* the diagram printer that does the work of actually printing
* the diagrams
*/
- public static void doRun(IEditorPart editorPart, DiagramPrinter diagramPrinter) {
+ public static void doRun(IEditorPart editorPart, SWTDiagramPrinter diagramPrinter) {
// print the editor contents.
final PrintDialog dialog =
new PrintDialog(editorPart.getSite().getShell(), SWT.NULL);
Index: src/org/eclipse/gmf/runtime/diagram/ui/printing/util/DiagramPrinterUtil.java
===================================================================
RCS file: /cvsroot/modeling/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.diagram.ui.printing/src/org/eclipse/gmf/runtime/diagram/ui/printing/util/DiagramPrinterUtil.java,v
retrieving revision 1.6
diff -u -r1.6 DiagramPrinterUtil.java
--- src/org/eclipse/gmf/runtime/diagram/ui/printing/util/DiagramPrinterUtil.java 23 Nov 2006 21:11:22 -0000 1.6
+++ src/org/eclipse/gmf/runtime/diagram/ui/printing/util/DiagramPrinterUtil.java 29 Feb 2008 18:52:55 -0000
@@ -11,78 +11,28 @@
package org.eclipse.gmf.runtime.diagram.ui.printing.util;
-import java.text.ParseException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
import java.util.Map;
-import org.eclipse.gmf.runtime.common.core.util.Log;
-import org.eclipse.gmf.runtime.common.core.util.Trace;
-import org.eclipse.gmf.runtime.common.ui.printing.IPrintHelper;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.internal.pagesetup.PageSetupPageType;
-import org.eclipse.gmf.runtime.diagram.ui.internal.properties.WorkspaceViewerProperties;
-import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramGraphicalViewer;
-import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramGraphicalViewer;
-import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart;
-import org.eclipse.gmf.runtime.diagram.ui.printing.actions.DefaultPrintActionHelper;
-import org.eclipse.gmf.runtime.diagram.ui.printing.internal.DiagramPrintingDebugOptions;
-import org.eclipse.gmf.runtime.diagram.ui.printing.internal.DiagramPrintingPlugin;
-import org.eclipse.gmf.runtime.diagram.ui.printing.internal.DiagramPrintingStatusCodes;
-import org.eclipse.gmf.runtime.diagram.ui.printing.internal.l10n.DiagramUIPrintingMessages;
-import org.eclipse.gmf.runtime.diagram.ui.printing.internal.util.DiagramPrinter;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.util.Assert;
-import org.eclipse.swt.printing.Printer;
-import org.eclipse.swt.printing.PrinterData;
-import org.eclipse.swt.widgets.Display;
+import org.eclipse.gmf.runtime.diagram.ui.printing.internal.util.SWTDiagramPrinter;
+import org.eclipse.gmf.runtime.diagram.ui.printing.internal.util.SWTDiagramPrinterHelper;
import org.eclipse.ui.IEditorPart;
-import com.ibm.icu.text.NumberFormat;
-
/**
* Utility for using the DiagramPrinter to print diagrams after displaying
* a print dialog box to the user. Diagrams are printed using the
* DiagramPrinter and respect the settings chosen by the user in the print
* dialog.
*
+ * This class now delegates its functionality to helpers that isolate out the
+ * printing via SWT printing.
+ *
+ * This class is subject to change/deprecation in phase 2 of the printing enhancements.
+ *
* @author wdiu, Wayne Diu
*/
public class DiagramPrinterUtil {
/**
- * Prints a diagram with the settings from the helper onto the printer
- *
- * @param diagramPrinter
- * the diagram printer that does the work of actually printing the diagrams
- * @param helper
- * IPrintHelper with the user's choice of settings
- */
- private static void printDiagrams(DiagramPrinter diagramPrinter,
- IPrintHelper helper) {
-
- if (helper.getDlgPrintRangePages()) {
- diagramPrinter.setPrintRangePageSelection(true);
- diagramPrinter.setPrintRangePages(helper.getDlgPagesFrom(), helper.getDlgPagesTo());
- diagramPrinter.setFitToPage(false);
- }
-
- if (helper.getDlgScalePercent() == -1) {
- diagramPrinter.setColumns(helper.getDlgScaleFitToM());
- diagramPrinter.setRows(helper.getDlgScaleFitToN());
- diagramPrinter.setFitToPage(true);
- } else {
- diagramPrinter.setScaledPercent(helper.getDlgScalePercent());
- diagramPrinter.setFitToPage(false);
- }
-
- diagramPrinter.run();
- }
-
- /**
* Opens up the print diagrams dialog, allows the user to choose the
* settings, and prints.
*
@@ -97,192 +47,9 @@
* the diagram printer that does the work of actually printing the diagrams
*/
public static void printWithSettings(IEditorPart editorPart,
- Map diagramMap, DiagramPrinter diagramPrinter) {
-
- List diagramNames;
- PrinterData printerData;
- IPrintHelper helper;
- IPreferenceStore pref = null;
-
- try {
- Class printhelperClass = Class
- .forName(IPrintHelper.PRINT_HELPER_CLASS_NAME);
- helper = (IPrintHelper) printhelperClass.newInstance();
- diagramNames = new ArrayList(diagramMap.keySet());
-
- //get the preferences store currently in use...
-
- if (editorPart instanceof IDiagramWorkbenchPart) {
-
- IDiagramGraphicalViewer viewer = ((IDiagramWorkbenchPart)editorPart).getDiagramGraphicalViewer();
- if (viewer instanceof DiagramGraphicalViewer) {
-
- //default to diagram settings...
- pref = ((DiagramGraphicalViewer) viewer)
- .getWorkspaceViewerPreferenceStore();
-
- if (pref.getBoolean(WorkspaceViewerProperties.PREF_USE_WORKSPACE_SETTINGS)) {
-
- //get workspace settings...
- if (((IDiagramWorkbenchPart)editorPart).getDiagramEditPart().
- getDiagramPreferencesHint().getPreferenceStore() != null)
- pref = (IPreferenceStore)((IDiagramWorkbenchPart)editorPart).getDiagramEditPart().
- getDiagramPreferencesHint().getPreferenceStore();
- }
- }
- }
-
- //set the preferences for the print dialog...
- if (pref != null) {
-
- //the orientation...
- helper.setDlgOrientation(pref.getBoolean(WorkspaceViewerProperties.PREF_USE_LANDSCAPE));
-
- //the paper size...
- PageSetupPageType storedPageType = PageSetupPageType.LETTER; //default value
- String strPageType = pref.getString(WorkspaceViewerProperties.PREF_PAGE_SIZE);
- for (int i=0; i 0;
} catch (SWTError e) {
- //I cannot printer.dispose(); because it may not have been
- //initialized
Trace.catching(DiagramPrintingPlugin.getInstance(),
DiagramPrintingDebugOptions.EXCEPTIONS_CATCHING,
PrintPreviewHelper.class, "isPrinterInstalled", //$NON-NLS-1$
@@ -887,11 +902,7 @@
PrintPreviewHelper.class, "isPrinterInstalled", //$NON-NLS-1$
e);
throw e;
- }
-
- printer.dispose();
-
- return true;
+ }
}
/**
Index: src/org/eclipse/gmf/runtime/diagram/ui/printing/providers/DiagramWithPrintGlobalActionHandler.java
===================================================================
RCS file: /cvsroot/modeling/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.diagram.ui.printing/src/org/eclipse/gmf/runtime/diagram/ui/printing/providers/DiagramWithPrintGlobalActionHandler.java,v
retrieving revision 1.1
diff -u -r1.1 DiagramWithPrintGlobalActionHandler.java
--- src/org/eclipse/gmf/runtime/diagram/ui/printing/providers/DiagramWithPrintGlobalActionHandler.java 2 Nov 2005 23:30:47 -0000 1.1
+++ src/org/eclipse/gmf/runtime/diagram/ui/printing/providers/DiagramWithPrintGlobalActionHandler.java 29 Feb 2008 18:52:55 -0000
@@ -1,5 +1,5 @@
/******************************************************************************
- * Copyright (c) 2005 IBM Corporation and others.
+ * Copyright (c) 2005, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -19,7 +19,7 @@
import org.eclipse.gmf.runtime.diagram.ui.editparts.IDiagramPreferenceSupport;
import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart;
import org.eclipse.gmf.runtime.diagram.ui.printing.actions.DefaultPrintActionHelper;
-import org.eclipse.gmf.runtime.diagram.ui.printing.internal.util.DiagramPrinter;
+import org.eclipse.gmf.runtime.diagram.ui.printing.internal.util.SWTDiagramPrinter;
import org.eclipse.gmf.runtime.diagram.ui.providers.DiagramGlobalActionHandler;
import org.eclipse.ui.IEditorPart;
@@ -57,10 +57,11 @@
* @param cntxt
*/
protected void doPrint(IGlobalActionContext cntxt) {
+
DefaultPrintActionHelper.doRun((IEditorPart) cntxt.getActivePart(),
- new DiagramPrinter(getPreferencesHint((IEditorPart) cntxt
+ new SWTDiagramPrinter(getPreferencesHint((IEditorPart) cntxt
.getActivePart()), getMapMode(cntxt)));
- }
+ }
/**
* Checks if we will allow a print
Index: src/org/eclipse/gmf/runtime/diagram/ui/printing/internal/l10n/DiagramUIPrintingMessages.properties
===================================================================
RCS file: /cvsroot/modeling/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.diagram.ui.printing/src/org/eclipse/gmf/runtime/diagram/ui/printing/internal/l10n/DiagramUIPrintingMessages.properties,v
retrieving revision 1.1
diff -u -r1.1 DiagramUIPrintingMessages.properties
--- src/org/eclipse/gmf/runtime/diagram/ui/printing/internal/l10n/DiagramUIPrintingMessages.properties 25 Nov 2005 19:38:16 -0000 1.1
+++ src/org/eclipse/gmf/runtime/diagram/ui/printing/internal/l10n/DiagramUIPrintingMessages.properties 29 Feb 2008 18:52:55 -0000
@@ -1,6 +1,6 @@
# ==============================================================================
#*+------------------------------------------------------------------------+
-#*| Copyright (c) 2005 IBM Corporation and others. |
+#*| Copyright (c) 2005, 2008 IBM Corporation and others. |
#*| All rights reserved. This program and the accompanying materials |
#*| are made available under the terms of the Eclipse Public License v1.0 |
#*| which accompanies this distribution, and is available at |
@@ -33,6 +33,31 @@
Print_MessageDialogTitle=Print Diagram
Print_MessageDialogMessage=Print to fit the diagram?
+
+
+# ==============================================================================
+# Print Dialog - Translation Instruction : section to be translated
+# ==============================================================================
+JPSPrintDialog_Title=Print Diagram
+JPSPrintDialog_Button_PrintPreview=Print Preview...
+JPSPrintDialog_Copies=&Copies
+JPSPrintDialog_NumberOfCopies=&Number of copies:
+JPSPrintDialog_Collate=C&ollate
+JPSPrintDialog_Printer=Printer
+JPSPrintDialog_Name=&Name:
+JPSPrintDialog_Properties=Properties...
+JPSPrintDialog_PrintToFile=Print to &file
+JPSPrintDialog_PrintRange=Print &range
+JPSPrintDialog_All=A&ll
+JPSPrintDialog_Pages=&Pages
+JPSPrintDialog_From=Fr&om:
+JPSPrintDialog_To=&To:
+JPSPrintDialog_Scaling=&Scaling
+JPSPrintDialog_Adjust=A&djust to percentage of normal size:
+JPSPrintDialog_FitTo=Fit &to:
+JPSPrintDialog_PagesWide=Pages &wide:
+JPSPrintDialog_PagesTall=Pages &tall:
+
# DiagramPrinterUtil related resource strings
# ================================ BEGIN ==================================================
DiagramPrinterUtil_DLLErrorTitle=Error loading printing library
@@ -43,3 +68,6 @@
DiagramPrinterUtil_DLLErrorMessage_part3=This problem can be fixed by reinstalling the product.
DiagramPrinterUtil_DLLErrorMessage_part4=Would you like to continue printing with reduced functionality anyway?
# ==================================== END ================================================
+
+JPSDiagramPrinterUtil_ErrorTitle=Error printing
+JPSDiagramPrinterUtil_ErrorMessage=Please ensure that at least one printer is installed and retry.
Index: src/org/eclipse/gmf/runtime/diagram/ui/printing/internal/l10n/DiagramUIPrintingMessages.java
===================================================================
RCS file: /cvsroot/modeling/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.diagram.ui.printing/src/org/eclipse/gmf/runtime/diagram/ui/printing/internal/l10n/DiagramUIPrintingMessages.java,v
retrieving revision 1.1
diff -u -r1.1 DiagramUIPrintingMessages.java
--- src/org/eclipse/gmf/runtime/diagram/ui/printing/internal/l10n/DiagramUIPrintingMessages.java 25 Nov 2005 19:38:16 -0000 1.1
+++ src/org/eclipse/gmf/runtime/diagram/ui/printing/internal/l10n/DiagramUIPrintingMessages.java 29 Feb 2008 18:52:55 -0000
@@ -46,7 +46,28 @@
public static String DiagramPrinterUtil_DLLErrorMessage_part2;
public static String DiagramPrinterUtil_DLLErrorMessage_part3;
public static String DiagramPrinterUtil_DLLErrorMessage_part4;
-
+ public static String JPSPrintDialog_Title;
+ public static String JPSPrintDialog_Button_PrintPreview;
+ public static String JPSPrintDialog_Copies;
+ public static String JPSPrintDialog_NumberOfCopies;
+ public static String JPSPrintDialog_Collate;
+ public static String JPSPrintDialog_Printer;
+ public static String JPSPrintDialog_Name;
+ public static String JPSPrintDialog_Properties;
+ public static String JPSPrintDialog_PrintToFile;
+ public static String JPSPrintDialog_PrintRange;
+ public static String JPSPrintDialog_All;
+ public static String JPSPrintDialog_Pages;
+ public static String JPSPrintDialog_From;
+ public static String JPSPrintDialog_To;
+ public static String JPSPrintDialog_Scaling;
+ public static String JPSPrintDialog_Adjust;
+ public static String JPSPrintDialog_FitTo;
+ public static String JPSPrintDialog_PagesWide;
+ public static String JPSPrintDialog_PagesTall;
+ public static String JPSDiagramPrinterUtil_ErrorTitle;
+ public static String JPSDiagramPrinterUtil_ErrorMessage;
+
static {
NLS.initializeMessages(BUNDLE_NAME, DiagramUIPrintingMessages.class);
}
Index: src/org/eclipse/gmf/runtime/diagram/ui/printing/internal/util/PrintHelper.java
===================================================================
RCS file: src/org/eclipse/gmf/runtime/diagram/ui/printing/internal/util/PrintHelper.java
diff -N src/org/eclipse/gmf/runtime/diagram/ui/printing/internal/util/PrintHelper.java
--- src/org/eclipse/gmf/runtime/diagram/ui/printing/internal/util/PrintHelper.java 21 Sep 2007 15:39:47 -0000 1.11
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,296 +0,0 @@
-/******************************************************************************
- * Copyright (c) 2005, 2007 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- ****************************************************************************/
-
-package org.eclipse.gmf.runtime.diagram.ui.printing.internal.util;
-
-import java.io.File;
-
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.gef.RootEditPart;
-import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
-import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
-import org.eclipse.gmf.runtime.diagram.ui.OffscreenEditPartFactory;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramRootEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.internal.DiagramUIPlugin;
-import org.eclipse.gmf.runtime.diagram.ui.internal.editparts.PageBreakEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.internal.figures.PageBreaksFigure;
-import org.eclipse.gmf.runtime.diagram.ui.internal.pagesetup.PageInfoHelper;
-import org.eclipse.gmf.runtime.diagram.ui.internal.properties.WorkspaceViewerProperties;
-import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor;
-import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramGraphicalViewer;
-import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramGraphicalViewer;
-import org.eclipse.gmf.runtime.diagram.ui.util.DiagramEditorUtil;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.preference.PreferenceStore;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-
-/**
- * Helper to assist in making an offscreen diagram suitable for printing or
- * previewing.
- *
- * @author wdiu, Wayne Diu
- */
-public class PrintHelper {
- /**
- * Creates a DiagramEditPart
given the Diagram
- * without opening an editor.
- *
- * @param diagram the Diagram
- * @param preferencesHint the preferences hint to use for intiializing the
- * preferences of the root edit part
- * @return the new populated DiagramEditPart
- * @deprecated Please use
- * {@link #createDiagramEditPart(Diagram, PreferencesHint, Shell)}
- * instead as this method does not dispose the new Shell that it
- * creates.
- */
- public static DiagramEditPart createDiagramEditPart(Diagram diagram,
- PreferencesHint preferencesHint) {
-
- DiagramEditPart diagramEditPart = OffscreenEditPartFactory.getInstance().createDiagramEditPart(
- diagram, new Shell(), preferencesHint);
- // since some of the diagram updates are ASync we need to give the
- // inter-thread messages a chance to get processed processed before we
- // continue; check bugzilla 170332
- while (Display.getDefault().readAndDispatch ()){
- // nothing special to do
- }
- return diagramEditPart;
- }
-
- /**
- * Creates a DiagramEditPart
given the Diagram
- * without opening an editor.
- *
- * @param diagram the Diagram
- * @param preferencesHint the preferences hint to use for intiializing the
- * preferences of the root edit part
- * @return the new populated DiagramEditPart
- */
- public static DiagramEditPart createDiagramEditPart(Diagram diagram,
- PreferencesHint preferencesHint, Shell shell) {
- DiagramEditPart diagramEditPart = OffscreenEditPartFactory.getInstance().createDiagramEditPart(
- diagram, shell, preferencesHint);
- // since some of the diagram updates are ASync we need to give the
- // inter-thread messages a chance to get processed before we
- // continue; check bugzilla 170332
- while (Display.getDefault().readAndDispatch ()){
- // nothing special to do
- }
- return diagramEditPart;
- }
-
- /**
- * Initialize the preferences for a diagram edit part, specifically
- * including page breaks and margins.
- *
- * Typically, the diagram edit part is created using
- * createDiagramEditPart() and the diagram edit part is passed in as the
- * first parameter of this method.
- *
- * @param diagramEditPart the DiagramEditPart to pass in
- * @param preferencesHint the preferences hint to use for intiializing the preferences
- *
- * @return true if the preferences could be loaded, false if they weren't
- * loaded and defaults had to be used instead
- */
- public static boolean initializePreferences(DiagramEditPart diagramEditPart, PreferencesHint preferencesHint) {
- assert diagramEditPart.getViewer() instanceof DiagramGraphicalViewer;
-
- DiagramGraphicalViewer viewer = (DiagramGraphicalViewer)diagramEditPart.getViewer();
-
- boolean loadedPreferences = true;
-
- IPreferenceStore fPreferences = getPreferenceStoreForDiagram(diagramEditPart);
-
- if (fPreferences == null) {
- loadedPreferences = false;
- //leave at default x and y
- PreferenceStore defaults = new PreferenceStore();
- DiagramEditor.addDefaultPreferences(defaults, preferencesHint);
-
- fPreferences = getWorkspacePreferenceStore(preferencesHint);
- } else if (!fPreferences
- .getBoolean(WorkspaceViewerProperties.PREF_USE_DIAGRAM_SETTINGS)) {
- //if we aren't supposed to use the diagram settings, switch to the
- //workspace settings
-
- //we have to use the page break x and y settings from the diagram
- int x = fPreferences.getInt(WorkspaceViewerProperties.PAGEBREAK_X), y = fPreferences
- .getInt(WorkspaceViewerProperties.PAGEBREAK_Y);
-
- //minor performance optimization, use the existing
- //preferences from the workspace instead of making a new one
- fPreferences = getWorkspacePreferenceStore(preferencesHint);
- fPreferences.setValue(WorkspaceViewerProperties.PAGEBREAK_X, x);
- fPreferences.setValue(WorkspaceViewerProperties.PAGEBREAK_Y, y);
- }
-
- viewer.hookWorkspacePreferenceStore(fPreferences);
-
- diagramEditPart.refreshPageBreaks();
-
- return loadedPreferences;
- }
-
- /**
- * Returns the workspace viewer PreferenceStore
for a given diagram edit part.
- *
- * @param diagramEP the DiagramEditPart to obtain the preference store for
- *
- * @return the PreferenceStore
for the given diagram edit part
- * Could return null if it couldn't be loaded
- */
- private static IPreferenceStore getPreferenceStoreForDiagram(DiagramEditPart diagramEP) {
- // Try to load it
- String id = ViewUtil.getIdStr(diagramEP.getDiagramView());
-
- //try and get preferences from the open diagrams first
- //loadedPreferences will be set to true only if the preferences could
- // be
- //successfully loaded
- IPreferenceStore fPreferences = loadPreferencesFromOpenDiagram(id);
- if (fPreferences != null) {
- //loadPreferencesFromOpenDiagram will have set preferences
- return fPreferences;
- }
-
- IPath path = DiagramUIPlugin.getInstance().getStateLocation();
-
- String fileName = path.toString() + "/" + id;//$NON-NLS-1$
- java.io.File file = new File(fileName);
- fPreferences = new PreferenceStore(fileName);
- if (file.exists()) {
- // Load it
- try {
- ((PreferenceStore) fPreferences).load();
-
- return fPreferences;
- } catch (Exception e) {
- return null;
- }
- }
- return null; //fPreferences couldn't be loaded
- }
-
- /**
- * Load the preferences from an open diagram that has the given guid.
- *
- * @param id guid of the open diagram to load the preferences for
- */
- private static IPreferenceStore loadPreferencesFromOpenDiagram(String id) {
-
- DiagramEditor diagramEditor = DiagramEditorUtil.findOpenedDiagramEditorForID(id);
- if (diagramEditor != null) {
- IDiagramGraphicalViewer viewer = diagramEditor
- .getDiagramGraphicalViewer();
- if (diagramEditor.getDiagramEditPart().getRoot() instanceof DiagramRootEditPart) {
- PageBreakEditPart pageBreakEditPart = ((DiagramRootEditPart) diagramEditor
- .getDiagramEditPart().getRoot()).getPageBreakEditPart();
- pageBreakEditPart.resize(diagramEditor.getDiagramEditPart()
- .getChildrenBounds());
- pageBreakEditPart.updatePreferenceStore();
- }
- if (viewer instanceof DiagramGraphicalViewer) {
- DiagramGraphicalViewer diagramGraphicalViewer = (DiagramGraphicalViewer) viewer;
-
- // preferences loaded
- return diagramGraphicalViewer
- .getWorkspaceViewerPreferenceStore();
- }
- }
-
- // no matching guid found
- return null;
- }
-
- /**
- * Return the preference store for the given PreferenceHint
- * @param preferencesHint to return the preference store for.
- *
- * @return preference store for the given PreferenceHint
- */
- private static IPreferenceStore getWorkspacePreferenceStore(PreferencesHint preferencesHint) {
- return (IPreferenceStore) preferencesHint.getPreferenceStore();
- }
-
- /**
- * Returns the page break bounds on the diagram. If the bounds cannot be
- * found the diagram bounds is returned.
- *
- * @param dgrmEP the diagram edit part to return the page break bounds for
- * @param loadedPreferences true if preferences were previously loaded,
- * false if they couldn't be. For consistency when printing, we have to
- * treat page breaks differently depending on whether preferences were
- * successfully loaded or not.
- *
- * @return Rectangle with the page break bounds for the given diagram edit
- * part. If the page break bounds cannot be found the diagram bounds
- * Rectangle is returned.
- */
- public static Rectangle getPageBreakBounds(DiagramEditPart dgrmEP, boolean loadedPreferences) {
-
- Rectangle pageBreakBounds = null;
- assert dgrmEP.getViewer() instanceof DiagramGraphicalViewer;
-
-
- //get the preferences in use...
- IPreferenceStore fPreferences = ((DiagramGraphicalViewer)dgrmEP.getViewer()).getWorkspaceViewerPreferenceStore();
-
- if (fPreferences.getBoolean(WorkspaceViewerProperties.PREF_USE_WORKSPACE_SETTINGS)) {
-
- //get workspace settings...
- if (dgrmEP.getDiagramPreferencesHint().getPreferenceStore() != null)
- fPreferences = (IPreferenceStore)dgrmEP.getDiagramPreferencesHint().getPreferenceStore();
- }
-
- RootEditPart rootEditPart = dgrmEP.getRoot();
- if (rootEditPart instanceof DiagramRootEditPart) {
- DiagramRootEditPart diagramRootEditPart = (DiagramRootEditPart) rootEditPart;
- PageBreakEditPart pageBreakEditPart = diagramRootEditPart
- .getPageBreakEditPart();
-
- if (pageBreakEditPart != null) {
- //resize must be called. Otherwise you get the 64 x 32 default
- pageBreakEditPart.resize(dgrmEP.getChildrenBounds());
-
- if (loadedPreferences) {
- //if preferences were loaded, we'll always do this for
- //consistency when printing.
- //this is necessary when printing using workspace
- //preferences, which is "if (getWorkspacePreferenceStore()
- //== fPreferences)"
-
- //if preferences were not loaded, we do not set the figure
- //location. we'll just leave them at defaults.
- org.eclipse.draw2d.geometry.Point p = new org.eclipse.draw2d.geometry.Point(
- fPreferences
- .getInt(WorkspaceViewerProperties.PAGEBREAK_X),
- fPreferences
- .getInt(WorkspaceViewerProperties.PAGEBREAK_Y));
- pageBreakEditPart.set(p, PageInfoHelper.getChildrenBounds(
- (DiagramEditPart) diagramRootEditPart.getContents(),
- PageBreaksFigure.class));
- }
-
- pageBreakBounds = pageBreakEditPart.getFigure().getBounds();
- } else {
- pageBreakBounds = dgrmEP.getFigure().getBounds();
- }
- }
-
- return pageBreakBounds;
- }
-}
\ No newline at end of file
Index: src/org/eclipse/gmf/runtime/diagram/ui/printing/internal/util/DiagramPrinter.java
===================================================================
RCS file: /cvsroot/modeling/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.diagram.ui.printing/src/org/eclipse/gmf/runtime/diagram/ui/printing/internal/util/DiagramPrinter.java,v
retrieving revision 1.14
diff -u -r1.14 DiagramPrinter.java
--- src/org/eclipse/gmf/runtime/diagram/ui/printing/internal/util/DiagramPrinter.java 21 Sep 2007 15:39:47 -0000 1.14
+++ src/org/eclipse/gmf/runtime/diagram/ui/printing/internal/util/DiagramPrinter.java 29 Feb 2008 18:52:55 -0000
@@ -1,5 +1,5 @@
/******************************************************************************
- * Copyright (c) 2002, 2007 IBM Corporation and others.
+ * Copyright (c) 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -12,877 +12,168 @@
package org.eclipse.gmf.runtime.diagram.ui.printing.internal.util;
import java.util.Collection;
-import java.util.Iterator;
-import org.eclipse.core.runtime.Assert;
import org.eclipse.draw2d.Graphics;
-import org.eclipse.draw2d.SWTGraphics;
import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.gef.LayerConstants;
import org.eclipse.gef.RootEditPart;
import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
-import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramRootEditPart;
import org.eclipse.gmf.runtime.diagram.ui.internal.editparts.PageBreakEditPart;
import org.eclipse.gmf.runtime.diagram.ui.internal.figures.PageBreaksFigure;
-import org.eclipse.gmf.runtime.diagram.ui.internal.pagesetup.PageInfoHelper;
-import org.eclipse.gmf.runtime.diagram.ui.internal.pagesetup.PageInfoHelper.PageMargins;
-import org.eclipse.gmf.runtime.diagram.ui.internal.properties.WorkspaceViewerProperties;
-import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor;
-import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramGraphicalViewer;
-import org.eclipse.gmf.runtime.diagram.ui.util.DiagramEditorUtil;
import org.eclipse.gmf.runtime.draw2d.ui.internal.graphics.MapModeGraphics;
-import org.eclipse.gmf.runtime.draw2d.ui.internal.graphics.PrinterGraphics;
-import org.eclipse.gmf.runtime.draw2d.ui.internal.graphics.ScaledGraphics;
import org.eclipse.gmf.runtime.draw2d.ui.mapmode.IMapMode;
-import org.eclipse.gmf.runtime.draw2d.ui.mapmode.MapModeUtil;
import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.FontData;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.printing.Printer;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.PlatformUI;
-/*
- * @canBeSeenBy %level1
- */
-public class DiagramPrinter
- implements Runnable {
-
- protected Printer printer;
-
- private Point display_dpi;
-
- private boolean isScaledPercent = false;
-
- private int rows = 1;
-
- private int columns = 1;
-
- private boolean printRangePageSelection = false;
-
- private int pageFrom = 1, pageTo = 1;
-
- private GC gc;
-
- private Graphics swtGraphics;
-
- private Graphics graphics;
-
- private PrinterGraphics printerGraphics;
-
- protected Point printerOffset;
-
- protected Rectangle logicalClientArea;
-
- private float userScale;
-
- /**
- * Used when a Collection of Diagram objects are passed in instead of an
- * IEditorPart.
- */
- protected Collection diagrams;
-
- /**
- * The initial amount that the diagram should be translated, set by
- * printToScale or printToPages which calls drawToFitRowsColumns.
- */
- private Point translated = null;
-
- /**
- * The hint used to find the appropriate preference store from which general
- * diagramming preference values for properties of shapes, connections, and
- * diagrams can be retrieved. This hint is mapped to a preference store in
- * the {@link DiagramPreferencesRegistry}.
- */
- private PreferencesHint preferencesHint;
- private IMapMode mm;
-
- private boolean fitToPage = false;
-
- /**
- * change the fit to page state
- * @param fitToPage the new fit to page state
- */
- public void setFitToPage(boolean fitToPage){
- this.fitToPage = fitToPage;
- }
-
- /**
- * Creates a new instance. The following variables must be initialized
- * before calling run()
:
- * printer
- * display_dpi
- * diagrams
- * @param mm IMapMode
to do the coordinate mapping
- */
- public DiagramPrinter(PreferencesHint preferencesHint, IMapMode mm) {
- super();
- this.preferencesHint = preferencesHint;
- this.mm = mm;
- }
-
- /**
- * Creates a new instance. The following variables must be initialized
- * before calling run()
:
- * printer
- * display_dpi
- * diagrams
- * @param mm IMapMode
to do the coordinate mapping
- */
- public DiagramPrinter(PreferencesHint preferencesHint) {
- this(preferencesHint, MapModeUtil.getMapMode());
- }
-
- /**
- * @return IMapMode
to do the coordinate mapping
- */
- protected IMapMode getMapMode() {
- return mm;
- }
-
- /**
- * Sets the columns.
- *
- * @param columns
- * The columns to set.
- */
- public void setColumns(int columns) {
- this.columns = columns;
- }
-
- /**
- * Sets the diagrams.
- *
- * @param diagrams
- * a Collection of Diagram objects
- */
- public void setDiagrams(Collection diagrams) {
- this.diagrams = diagrams;
- }
-
- /**
- * Sets the display DPI.
- *
- * @param display_dpi
- * The display_dpi to set.
- */
- public void setDisplayDPI(Point display_dpi) {
- this.display_dpi = new Point(display_dpi.x, display_dpi.y);
- }
-
- /**
- * Sets the printer.
- *
- * @param printer
- * The printer to set.
- */
- public void setPrinter(Printer printer) {
- this.printer = printer;
- }
-
- public void setPrintRangePageSelection(boolean isPrintRangePageSelected) {
- this.printRangePageSelection = isPrintRangePageSelected;
- }
-
- public void setPrintRangePages(int pageFrom, int pageTo) {
- assert pageFrom > 0 : "From page in print range page selection must be bigger than zero."; //$NON-NLS-1$
- assert (pageTo > 0 && pageTo >= pageFrom) : "To page in print range page selection must be bigger than zero and from page."; //$NON-NLS-1$
- this.pageFrom = pageFrom;
- this.pageTo = pageTo;
- }
-
- /**
- * Sets the rows.
- *
- * @param rows
- * The rows to set.
- */
- public void setRows(int rows) {
- this.rows = rows;
- }
-
- /**
- * Sets the scaled percent.
- *
- * @param scalePercent
- */
- public void setScaledPercent(int scalePercent) {
- this.isScaledPercent = true;
- this.userScale = (scalePercent) / 100.0f;
-
- }
-
- /**
- * Prints the contents of the diagram editor part.
- */
- public void run() {
- assert null != printer : "printer must be set"; //$NON-NLS-1$
- if (!(printer.startJob("Printing"))) { //$NON-NLS-1$
- return;
- }
-
- assert diagrams != null;
- Iterator it = diagrams.iterator();
-
- Shell shell = new Shell();
- try {
- while (it.hasNext()) {
- Object obj = it.next();
- //the diagrams List is only supposed to have Diagram objects
- Assert.isTrue(obj instanceof Diagram);
- Diagram diagram = (Diagram)obj;
- DiagramEditor openedDiagramEditor = DiagramEditorUtil
- .findOpenedDiagramEditorForID(ViewUtil
- .getIdStr(diagram));
- DiagramEditPart dgrmEP = openedDiagramEditor == null ? PrintHelper
- .createDiagramEditPart(diagram, preferencesHint, shell)
- : openedDiagramEditor.getDiagramEditPart();
-
- boolean loadedPreferences = openedDiagramEditor != null || PrintHelper.initializePreferences(dgrmEP, preferencesHint);
-
- RootEditPart rep = dgrmEP.getRoot();
- if (rep instanceof DiagramRootEditPart)
- this.mm = ((DiagramRootEditPart)rep).getMapMode();
-
- initialize();
-
-
- IPreferenceStore pref = null;
-
- assert dgrmEP.getViewer() instanceof DiagramGraphicalViewer;
-
- pref = ((DiagramGraphicalViewer)dgrmEP.getViewer()).getWorkspaceViewerPreferenceStore();
-
- if (pref.getBoolean(WorkspaceViewerProperties.PREF_USE_WORKSPACE_SETTINGS)) {
-
- //get workspace settings...
- if (dgrmEP.getDiagramPreferencesHint().getPreferenceStore() != null)
- pref = (IPreferenceStore)dgrmEP.getDiagramPreferencesHint().getPreferenceStore();
- }
-
- doPrintDiagram(dgrmEP, loadedPreferences, pref);
-
- dispose();
- }
- printer.endJob();
- } finally {
- shell.dispose();
- }
- }
-
- /**
- * Calculates the row in a grid, given a page number.
- * | 1 | 2 | 3 |
- * | 4 | 5 | 6 |
- * | 7 | 8 | 9 |
- *
- * Given pageNum=5 and totalNumColumns=3, will return 2
- * (2nd row).
- *
- * @param pageNum the page number in the grid.
- * @param totalNumColumns total number of columns of the grid.
- * @return row number corresponding to the page number.
- */
- private int calculateRowFromPage(int pageNum, int totalNumColumns) {
- int row = pageNum / totalNumColumns;
- if (pageNum % totalNumColumns != 0)
- row++;
- return row;
- }
-
- /**
- * Calculates the column in a grid, given a page number.
- * | 1 | 2 | 3 |
- * | 4 | 5 | 6 |
- * | 7 | 8 | 9 |
- *
- * Given pageNum=5 and totalNumColumns=3, will return 2
- * (2nd column).
- *
- * @param pageNum the page number in the grid.
- * @param totalNumColumns total number of columns of the grid.
- * @param cRow the corresponding row of the page number.
- * @return row number corresponding to the page number.
- */
- private int calculateColumnFromPage(int pageNum, int totalNumColumns, int cRow) {
- int col = pageNum - ((cRow - 1) * totalNumColumns);
- return col;
- }
-
- /**
- * Obtains the total number of pages that span columns and rows
- * @param dgrmEP
- * @return Point.x contains the total number of pages that span in a column
- * Point.y contains the total number of pages that span in a row
- */
- private org.eclipse.draw2d.geometry.Point getPageCount(DiagramEditPart dgrmEP, Rectangle figureBounds, org.eclipse.draw2d.geometry.Point pageSize, boolean applyUserScale) {
- RootEditPart rootEditPart = dgrmEP.getRoot();
- if (rootEditPart instanceof DiagramRootEditPart) {
- //this is the most accurate way to obtain total rows and columns...
-
- DiagramRootEditPart diagramRootEditPart = (DiagramRootEditPart) rootEditPart;
- PageBreakEditPart pageBreakEditPart = diagramRootEditPart
- .getPageBreakEditPart();
- float fNumCols = ((PageBreaksFigure)pageBreakEditPart.getFigure()).getPageCount().y *
- (applyUserScale ? userScale : 1);
- float fNumRows = ((PageBreaksFigure)pageBreakEditPart.getFigure()).getPageCount().x *
- (applyUserScale ? userScale : 1);
-
- int numCols = (int) Math.ceil(fNumCols);
- int numRows = (int) Math.ceil(fNumRows);
-
- return new org.eclipse.draw2d.geometry.Point(numCols,numRows);
- }
- else {
- //otherwise, calculate manually...
-
- float fNumRows = (figureBounds.height * (applyUserScale ? userScale : 1))
- / pageSize.y;
- int numRows = (int) Math.ceil(fNumRows);
-
- float fNumCols = (figureBounds.width * (applyUserScale ? userScale : 1))
- / pageSize.x;
- int numCols = (int) Math.ceil(fNumCols);
-
- return new org.eclipse.draw2d.geometry.Point(numCols, numRows);
- }
- }
-
- /**
- * Prints to scale or prints to rows x columns pages
- */
- private void doPrintDiagram(DiagramEditPart dgrmEP, boolean loadedPreferences, IPreferenceStore fPreferences) {
- this.graphics.pushState();
- if (isScaledPercent) {
- printToScale(dgrmEP, loadedPreferences, fPreferences);
- } else {
- printToPages(dgrmEP, loadedPreferences, fPreferences);
- }
- this.graphics.popState();
- }
-
- private void initialize() {
-
- assert null != printer : "printer must be set"; //$NON-NLS-1$
-
- //check for rtl orientation...
- int style = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().getStyle();
- if ((style & SWT.MIRRORED) != 0)
- this.gc = new GC(printer, SWT.RIGHT_TO_LEFT);
- else
- this.gc = new GC(printer);
-
- gc.setXORMode(false);
-
- this.swtGraphics = new SWTGraphics(gc);
- this.printerGraphics = createPrinterGraphics(swtGraphics);
- this.graphics = createMapModeGraphics(printerGraphics);
- this.graphics.scale(computePrinterDisplayScale());
-
- this.logicalClientArea = this.graphics.getClip(new Rectangle(
- this.printer.getClientArea()));
-
- }
-
- /**
- * Usually, the printable area is less than the page.
- * This method returns the offset for each x margin and each y margin.
- * x margins are left and right
- * y margins are top and bottom
- *
- * We'll assume the left and right offsets are the same and the
- * top and bottom offsets are the same.
- *
- * @return Point with x and y offsets
- */
- protected Point getPrinterOffset() {
- if (printerOffset == null) {
- int offsetX = this.printer.getBounds().width
- - this.printer.getClientArea().width;
- int offsetY = this.printer.getBounds().height
- - this.printer.getClientArea().height;
-
- // assume half on each side
- offsetX = (int) (getMapMode()
- .DPtoLP((int) (offsetX / 2.0f * display_dpi.x / printer.getDPI().x)) / userScale);
- offsetY = (int) (getMapMode()
- .DPtoLP((int) (offsetY / 2.0f * display_dpi.y / printer.getDPI().y)) / userScale);
-
- printerOffset = new Point(offsetX, offsetY);
- }
-
- return printerOffset;
- }
-
- /**
- * Print the diagram figure using specified scale factor.
- *
- * @param dgrmEP the DiagramEditPart that will be printed
- * @param loadedPreferences true if existing prefs could be loaded
- * successfully, false if not and defaults are being used. This parameter
- * is important to obtain the correct page break bounds.
- * @param fPreferences the preferenceStore that could either contain
- * existing preferences or defaults
- */
- protected void printToScale(DiagramEditPart dgrmEP, boolean loadedPreferences, IPreferenceStore fPreferences) {
-
- assert null != printer : "printer must be set"; //$NON-NLS-1$
- Rectangle figureBounds = PrintHelper.getPageBreakBounds(dgrmEP, loadedPreferences);
- org.eclipse.draw2d.geometry.Point pageBounds = PageInfoHelper.getPageSize(fPreferences, getMapMode());
-
- //translate to offset initial figure position
- translated = new Point((int) (-figureBounds.x * userScale), (int) (-figureBounds.y * userScale));
-
- //calculate the number of page rows and columns
- int numRows = 0, numCols = 0;
-
- PageMargins margins = PageInfoHelper.getPageMargins(fPreferences, getMapMode());
- adjustMargins(margins, userScale, getPrinterOffset());
-
- GC gc_ = new GC(Display.getDefault(),this.gc.getStyle());
- gc_.setAntialias(this.gc.getAntialias());
-
- FontData fontData = JFaceResources.getDefaultFont().getFontData()[0];
- Font font = new Font(printer, fontData);
-
- org.eclipse.draw2d.geometry.Point pageCount = getPageCount(dgrmEP, figureBounds, pageBounds, true);
- numCols = pageCount.x;
- numRows = pageCount.y;
-
- //finalRow and finalColumn will be used if we are printing within a page range...
- int row = 1, col = 1, finalRow = 0, finalColumn = 0;
-
- if (this.printRangePageSelection) {
- //print only the pages specified in the page range...
- row = calculateRowFromPage(this.pageFrom, numCols);
- col = calculateColumnFromPage(this.pageFrom, numCols, row);
-
- finalRow = calculateRowFromPage(this.pageTo, numCols);
- finalColumn = calculateColumnFromPage(this.pageTo, numCols, finalRow);
- }
-
- try {
- //print the pages in row, column order
- for (; row <= numRows; row++) {
- for (; col <= numCols; col++) {
- printer.startPage();
- drawPage(gc_, dgrmEP, fPreferences, figureBounds, margins, font, row, col);
- printer.endPage();
-
- if (row == finalRow && col == finalColumn && this.printRangePageSelection == true)
- break;
- }
-
- if (row == finalRow && col == finalColumn && this.printRangePageSelection == true)
- break;
-
- col = 1;
- }
- } finally {
- //must dispose resources
- font.dispose();
- gc_.dispose();
- }
- }
-
- /**
- * Draw the header and footer
- *
- * @param gc_,
- * a graphics context that is not null which this method will use
- * for figuring ouyt the font's extent
- * @param figureBounds,
- * Rectangle with the bounds of the figure
- * @param rowIndex,
- * int
- * @param colIndex,
- * int
- */
- protected void drawHeaderAndFooter(GC gc_, DiagramEditPart dgrmEP, Rectangle figureBounds,
- Font font, int rowIndex, int colIndex) {
-
- int width = this.logicalClientArea.width;
- int height = this.logicalClientArea.height;
-
- this.graphics.pushState(); //draw text, don't make it too small or big
- this.graphics.setFont(font);
-
- this.graphics.scale(1.0f / userScale);
- this.graphics.translate(-translated.x, -translated.y);
-
- String headerOrFooter = HeaderAndFooterHelper.makeHeaderOrFooterString(
- WorkspaceViewerProperties.HEADER_PREFIX, rowIndex, colIndex,
- dgrmEP);
-
- this.graphics.drawText(headerOrFooter,
- getMapMode().DPtoLP(HeaderAndFooterHelper.LEFT_MARGIN_DP)
- + (width - getMapMode().DPtoLP(gc_.textExtent(headerOrFooter).x))
- / 2, getMapMode().DPtoLP(HeaderAndFooterHelper.TOP_MARGIN_DP));
-
- headerOrFooter = HeaderAndFooterHelper.makeHeaderOrFooterString(
- WorkspaceViewerProperties.FOOTER_PREFIX, rowIndex, colIndex,
- dgrmEP);
-
- this.graphics.drawText(headerOrFooter,
- getMapMode().DPtoLP(HeaderAndFooterHelper.LEFT_MARGIN_DP)
- + (width - getMapMode().DPtoLP(gc_.textExtent(headerOrFooter).x))
- / 2, height - getMapMode().DPtoLP(HeaderAndFooterHelper.BOTTOM_MARGIN_DP));
-
- this.graphics.popState(); //for drawing the text
- }
-
- /**
- * This method paints a portion of the diagram. (The area painted
- * representing one page.)
- *
- * @param gc_ a graphics context that is not null which this method will use
- * for figuring out the font's extent
- * @param dgrmEP the DiagramEditPart that will be printed
- * @param fPreferences the preferenceStore that could either contain
- * existing preferences or defaults
- * @param figureBounds the page break bounds we'll have to offset by
- * @param font the Font to print the header or footer with
- * @param rowIndex index of row we're printing
- * @param colIndex index of column we're priniting
- * to check if it is the first time the method is getting called for the current
- * print.
- */
- protected void drawPage(GC gc_, DiagramEditPart dgrmEP,
- IPreferenceStore fPreferences, Rectangle figureBounds,
- PageMargins margins, Font font, int rowIndex, int colIndex) {
-
- org.eclipse.draw2d.geometry.Point pageSize = PageInfoHelper
- .getPageSize(fPreferences, false, getMapMode());
- boolean rtlEnabled = ((this.gc.getStyle() & SWT.MIRRORED) != 0);
- if (rtlEnabled)
- {
- // draw everything on an offscreen image first and then draw that image
- // onto the printer gc...this takes care of certain drawing bugs.
- // This causes issues with printing resolution as it uses a display image
- // which is typically 72dpi
- // This code should be removed when a resolution to Bugzilla 162459 is found
-
- Image image = new Image(Display.getDefault(), getMapMode().LPtoDP(pageSize.x), getMapMode().LPtoDP(pageSize.y));
-
- GC imgGC = new GC(image, (rtlEnabled) ? SWT.RIGHT_TO_LEFT : SWT.LEFT_TO_RIGHT);
- imgGC.setXORMode(false);
-
- SWTGraphics sg = new SWTGraphics(imgGC);
-
- //for scaling
- ScaledGraphics g1 = new ScaledGraphics(sg);
-
- //for himetrics and svg
- MapModeGraphics mmg = createMapModeGraphics(g1);
-
- //if mmg's font is null, gc.setFont will use a default font
- imgGC.setFont(mmg.getFont());
-
- internalDrawPage(dgrmEP,figureBounds,fPreferences,margins,mmg,rowIndex, colIndex,true);
-
- this.graphics.pushState();
-
- this.graphics.drawImage(image, 0, 0);
-
- this.graphics.popState();
-
- //draw the header and footer after drawing the image to avoid getting the image getting drawn over them
- drawHeaderAndFooter(gc_, dgrmEP, figureBounds, font, rowIndex, colIndex);
- disposeImageVars(imgGC, image, sg, g1, mmg);
- } else {
- internalDrawPage(dgrmEP,figureBounds,fPreferences,margins,this.graphics,rowIndex, colIndex,false);
- //draw the header and footer after drawing the image to avoid getting the image getting drawn over them
- drawHeaderAndFooter(gc_, dgrmEP, figureBounds, font, rowIndex, colIndex);
- }
- }
-
- private void internalDrawPage(DiagramEditPart dgrmEP,
- Rectangle figureBounds, IPreferenceStore fPreferences,
- PageMargins margins, Graphics g, int rowIndex, int colIndex,
- boolean RTL_ENABLED) {
- org.eclipse.draw2d.geometry.Point pageSize = PageInfoHelper
- .getPageSize(fPreferences, false, getMapMode());
-
- int width = pageSize.x, height = pageSize.y;
-
- g.pushState();
-
- g.translate(translated.x, translated.y);
- g.scale(userScale);
-
- int translateX = -(width * (colIndex - 1));
- int translateY = -(height * (rowIndex - 1));
-
- int scaledTranslateX = (int) (translateX / userScale);
- int scaledTranslateY = (int) (translateY / userScale);
-
- int scaledWidth = (int) (width / userScale);
- int scaledHeight = (int) (height / userScale);
-
- if (RTL_ENABLED) {
- scaledTranslateX += (margins.left * (colIndex - 1))
- + (margins.right * (colIndex));
- scaledTranslateY += ((margins.top * rowIndex) + (margins.bottom * (rowIndex - 1)));
- } else {
- scaledTranslateX += ((margins.left * colIndex) + (margins.right * (colIndex - 1)));
- scaledTranslateY += ((margins.top * rowIndex) + (margins.bottom * (rowIndex - 1)));
- }
-
- g.translate(scaledTranslateX, scaledTranslateY);
-
- Rectangle clip = new Rectangle(
- (scaledWidth - margins.left - margins.right) * (colIndex - 1)
- + figureBounds.x, (scaledHeight - margins.bottom - margins.top)
- * (rowIndex - 1) + figureBounds.y, scaledWidth - margins.right
- - margins.left, scaledHeight - margins.top - margins.bottom);
- g.clipRect(clip);
-
- dgrmEP.getLayer(LayerConstants.PRINTABLE_LAYERS).paint(g);
-
- g.popState();
- }
+/**
+ * Basic page calculation operations have been factored out into this class.
+ * This class was derived from the previous DiagramPrinter.
+ *
+ * @author James Bruck (jbruck)
+ */
+public abstract class DiagramPrinter implements Runnable {
- /**
- * Print the diagram figure to fit the number and rows and columns
- * specified by the user.
- *
- * @param dgrmEP the DiagramEditPart that will be printed
- * @param loadedPreferences true if existing prefs could be loaded
- * successfully, false if not and defaults are being used. This parameter
- * is important to obtain the correct page break bounds.
- * @param fPreferences the preferenceStore that could either contain
- * existing preferences or defaults
- */
- protected void printToPages(DiagramEditPart dgrmEP,
- boolean loadedPreferences, IPreferenceStore fPreferences) {
- assert null != printer : "printer must be set"; //$NON-NLS-1$
-
- Rectangle figureBounds = PrintHelper.getPageBreakBounds(dgrmEP,
- loadedPreferences);
-
- PageMargins margins = PageInfoHelper.getPageMargins(fPreferences, getMapMode());
- //do not include margins
- org.eclipse.draw2d.geometry.Point pageBounds = PageInfoHelper
- .getPageSize(fPreferences, getMapMode());
- org.eclipse.draw2d.geometry.Point pageCount = getPageCount(dgrmEP, figureBounds, pageBounds, false);
- int numCols = pageCount.x;
- int numRows = pageCount.y;
-
- float actualWidth = 0;
- float actualHeight = 0;
- if (this.rows==1 && this.columns==1 && fitToPage){
- figureBounds = dgrmEP.getChildrenBounds();
- actualWidth = figureBounds.width;
- actualHeight = figureBounds.height;
- }else {
- actualWidth = numCols * pageBounds.x;
- actualHeight = numRows * pageBounds.y;
- }
-
- int totalHeight = (this.rows * pageBounds.y);
- int totalWidth = (this.columns * pageBounds.x);
-
- float vScale = totalHeight / actualHeight;
- float hScale = totalWidth / actualWidth;
-
- this.userScale = Math.min(hScale, vScale);
-
- // translate to offset figure position
- translated = new Point((int) (-figureBounds.x * userScale),
- (int) (-figureBounds.y * userScale));
-
- adjustMargins(margins, userScale, getPrinterOffset());
-
- GC gc_ = new GC(Display.getDefault());
-
- FontData fontData = JFaceResources.getDefaultFont().getFontData()[0];
- Font font = new Font(printer, fontData);
-
- int row = 1, col = 1, finalRow = 0, finalColumn = 0;
-
- if (this.printRangePageSelection) {
- //print only the pages specified in the page range
- //this corresponds to the physical pages, not the print range of pages on one physical page.
- row = calculateRowFromPage(this.pageFrom, this.columns);
- col = calculateColumnFromPage(this.pageFrom, this.columns, row);
-
- finalRow = calculateRowFromPage(this.pageTo, this.columns);
- finalColumn = calculateColumnFromPage(this.pageTo, this.columns, finalRow);
- }
-
- try {
- // print the pages in row, column order
- for (; row <= rows; row++) {
- for (; col <= columns; col++) {
- printer.startPage();
- drawPage(gc_, dgrmEP, fPreferences, figureBounds, margins,
- font, row, col);
- printer.endPage();
-
- if (row == finalRow && col == finalColumn && this.printRangePageSelection == true)
- break;
- }
-
- if (row == finalRow && col == finalColumn && this.printRangePageSelection == true)
- break;
-
- col = 1;
- }
- } finally {
- // must dispose resources
- font.dispose();
- gc_.dispose();
- }
- }
+ protected Point display_dpi;
+ protected Collection diagrams;
+ protected PreferencesHint preferencesHint;
+ protected IMapMode mapMode;
+ protected Point translated;
+
+ protected float userScale;
+ protected boolean isScaledPercent = false;
+ protected boolean fitToPage = false;
+ protected boolean printRangePageSelection = false;
+
+ protected int pageFrom = 1, pageTo = 1;
+ protected int rows = 1;
+
+ protected int columns = 1;
+
+ protected Graphics swtGraphics;
+ protected Graphics graphics;
+
+ public DiagramPrinter(PreferencesHint preferencesHint, IMapMode mm) {
+ super();
+ this.preferencesHint = preferencesHint;
+ this.mapMode = mm;
+ }
+
+ /**
+ * Obtains the total number of pages that span columns and rows
+ * @param dgrmEP
+ * @return Point.x contains the total number of pages that span in a column
+ * Point.y contains the total number of pages that span in a row
+ */
+ protected org.eclipse.draw2d.geometry.Point getPageCount(
+ DiagramEditPart dgrmEP, Rectangle figureBounds,
+ org.eclipse.draw2d.geometry.Point pageSize, boolean applyUserScale) {
+ RootEditPart rootEditPart = dgrmEP.getRoot();
+
+ if (rootEditPart instanceof DiagramRootEditPart) {
+
+ DiagramRootEditPart diagramRootEditPart = (DiagramRootEditPart) rootEditPart;
+ PageBreakEditPart pageBreakEditPart = diagramRootEditPart
+ .getPageBreakEditPart();
+
+ float fNumCols = ((PageBreaksFigure) pageBreakEditPart.getFigure())
+ .getPageCount().y
+ * (applyUserScale ? userScale : 1);
+
+ float fNumRows = ((PageBreaksFigure) pageBreakEditPart.getFigure())
+ .getPageCount().x
+ * (applyUserScale ? userScale : 1);
+
+ int numCols = (int) Math.ceil(fNumCols);
+ int numRows = (int) Math.ceil(fNumRows);
+
+ return new org.eclipse.draw2d.geometry.Point(numCols, numRows);
+
+ } else {
+
+ float fNumRows = (figureBounds.height * (applyUserScale ? userScale
+ : 1))
+ / pageSize.y;
+ int numRows = (int) Math.ceil(fNumRows);
+
+ float fNumCols = (figureBounds.width * (applyUserScale ? userScale
+ : 1))
+ / pageSize.x;
+ int numCols = (int) Math.ceil(fNumCols);
+
+ return new org.eclipse.draw2d.geometry.Point(numCols, numRows);
+ }
+ }
+
+ /**
+ * Calculates the row in a grid, given a page number.
+ * | 1 | 2 | 3 |
+ * | 4 | 5 | 6 |
+ * | 7 | 8 | 9 |
+ *
+ * Given pageNum=5 and totalNumColumns=3, will return 2
+ * (2nd row).
+ *
+ * @param pageNum the page number in the grid.
+ * @param totalNumColumns total number of columns of the grid.
+ * @return row number corresponding to the page number.
+ */
+ protected int calculateRowFromPage(int pageNum, int totalNumColumns) {
+ int row = pageNum / totalNumColumns;
+ if (pageNum % totalNumColumns != 0) {
+ row++;
+ }
+ return row;
+ }
+
+ /**
+ * Calculates the column in a grid, given a page number.
+ * | 1 | 2 | 3 |
+ * | 4 | 5 | 6 |
+ * | 7 | 8 | 9 |
+ *
+ * Given pageNum=5 and totalNumColumns=3, will return 2
+ * (2nd column).
+ *
+ * @param pageNum the page number in the grid.
+ * @param totalNumColumns total number of columns of the grid.
+ * @param cRow the corresponding row of the page number.
+ * @return row number corresponding to the page number.
+ */
+ protected int calculateColumnFromPage(int pageNum, int totalNumColumns,
+ int cRow) {
+
+ return (pageNum - ((cRow - 1) * totalNumColumns));
+ }
+
+
+ /**
+ * Disposes of the resources.
+ */
+ protected void dispose() {
+ if (this.graphics != null) {
+ try {
+ this.graphics.dispose();
+ } catch (NullPointerException e) {
+ //do nothing
+ } finally {
+ this.graphics = null;
+ }
+ }
+
+ if (this.swtGraphics != null) {
+ try {
+ this.swtGraphics.dispose();
+ } catch (NullPointerException e) {
+ //do nothing
+ } finally {
+ this.swtGraphics = null;
+ }
+ }
+ }
- /**
- * Return scale factor between printer and display.
- *
- * @return float
- */
- private float computePrinterDisplayScale() {
- assert null != printer : "printer must be set"; //$NON-NLS-1$
- assert null != display_dpi : "display_dpi must be set"; //$NON-NLS-1$
-
- Point dpi = printer.getDPI();
- float scale = dpi.x / (float) display_dpi.x;
-
- return scale;
- }
-
- /**
- * Disposes of the resources.
- */
- private void dispose() {
- if (this.graphics != null) {
- try {
- this.graphics.dispose();
- }
- catch (NullPointerException e) {
- //do nothing
- }
- finally {
- this.graphics = null;
- }
- }
-
- if (this.printerGraphics != null) {
- try {
- this.printerGraphics.dispose();
- }
- catch (NullPointerException e) {
- //do nothing
- }
- finally {
- this.printerGraphics = null;
- }
- }
-
- if (this.swtGraphics != null) {
- try {
- this.swtGraphics.dispose();
- }
- catch (NullPointerException e) {
- //do nothing
- }
- finally {
- this.swtGraphics = null;
- }
- }
-
- if (this.gc != null) {
- try {
- this.gc.dispose();
- }
- catch (NullPointerException e) {
- //do nothing
- }
- finally {
- this.gc = null;
- }
- }
-
- //reset the printer offset, just in case the next diagram to be printed
- //uses a different map mode.
- printerOffset = null;
-
- }
-
- private void disposeImageVars(GC imgGC, Image image, SWTGraphics sg,
- ScaledGraphics g1, MapModeGraphics mmg) {
-
- if (mmg != null) {
- try {
- mmg.dispose();
- }
- catch (NullPointerException e) {
- //do nothing
- }
- finally {
- mmg = null;
- }
- }
-
- if (g1 != null) {
- try {
- g1.dispose();
- }
- catch (NullPointerException e) {
- //do nothing
- }
- finally {
- g1 = null;
- }
- }
-
- if (sg != null) {
- try {
- sg.dispose();
- }
- catch (NullPointerException e) {
- //do nothing
- }
- finally {
- sg = null;
- }
- }
-
- if (imgGC != null) {
- try {
- imgGC.dispose();
- }
- catch (NullPointerException e) {
- //do nothing
- }
- finally {
- imgGC = null;
- }
- }
-
- if (image != null) {
- try {
- image.dispose();
- }
- catch (NullPointerException e) {
- //do nothing
- }
- finally {
- image = null;
- }
- }
- }
-
- /**
+ /**
* Creates the MapModeGraphics
.
*
* @param theGraphics
@@ -893,57 +184,128 @@
return new MapModeGraphics(theGraphics, getMapMode());
}
- /**
- * Creates the PrinterGraphics
.
- *
- * @param theGraphics
- * the Graphics
object
- * @return the new PrinterGraphics
- */
- protected PrinterGraphics createPrinterGraphics(Graphics theGraphics) {
- return new PrinterGraphics(theGraphics, printer, true);
- }
-
- /**
- * Gets the preferences hint that is to be used to find the appropriate
- * preference store from which to retrieve diagram preference values. The
- * preference hint is mapped to a preference store in the preference
- * registry <@link DiagramPreferencesRegistry>.
- *
- * @return the preferences hint
- */
- protected PreferencesHint getPreferencesHint() {
- return preferencesHint;
- }
-
- /**
- * Adjust the given PageMargins by the scale and offset
- *
- * @param margins PageMargins to adjust
- * @param scale margins will be scaled by this amount
- * @param offset to adjust margins by
- */
- protected void adjustMargins(PageMargins margins, float scale, Point offset) {
- //scale
- margins.left /= scale;
- margins.top /= scale;
- margins.right /= scale;
- margins.bottom /= scale;
-
- //offsets
- margins.left -= offset.x;
- margins.right += offset.x;
- margins.top -= offset.y;
- margins.bottom += offset.y;
-
- // this is more readable than doing Math.min for all the above
- if (margins.left < 0)
- margins.left = 0;
- if (margins.right < 0)
- margins.right = 0;
- if (margins.top < 0)
- margins.top = 0;
- if (margins.bottom < 0)
- margins.bottom = 0;
- }
-}
\ No newline at end of file
+ public void setPrintRangePages(int pageFrom, int pageTo) {
+ assert pageFrom > 0 : "From page in print range page selection must be bigger than zero."; //$NON-NLS-1$
+ assert (pageTo > 0 && pageTo >= pageFrom) : "To page in print range page selection must be bigger than zero and from page."; //$NON-NLS-1$
+ this.pageFrom = pageFrom;
+ this.pageTo = pageTo;
+ }
+
+ public Point getDisplayDPI() {
+ return display_dpi;
+ }
+
+ public void setDisplayDPI(Point display_dpi) {
+ this.display_dpi = display_dpi;
+ }
+
+ public PreferencesHint getPreferencesHint() {
+ return preferencesHint;
+ }
+
+ public void setPreferencesHint(PreferencesHint preferencesHint) {
+ this.preferencesHint = preferencesHint;
+ }
+
+ public IMapMode getMapMode() {
+ return mapMode;
+ }
+
+ public void setMapMode(IMapMode mm) {
+ this.mapMode = mm;
+ }
+
+ public Point getTranslated() {
+ return translated;
+ }
+
+ public void setTranslated(Point translated) {
+ this.translated = translated;
+ }
+
+ public float getUserScale() {
+ return userScale;
+ }
+
+ public void setScaledPercent(int scalePercent) {
+ this.isScaledPercent = true;
+ this.userScale = (scalePercent) / 100.0f;
+ }
+
+ public void setScaledPercent(boolean isScaledPercent) {
+ this.isScaledPercent = isScaledPercent;
+ }
+
+ public boolean isFitToPage() {
+ return fitToPage;
+ }
+
+ public void setFitToPage(boolean fitToPage) {
+ this.fitToPage = fitToPage;
+ }
+
+ public boolean isPrintRangePageSelection() {
+ return printRangePageSelection;
+ }
+
+ public void setPrintRangePageSelection(boolean printRangePageSelection) {
+ this.printRangePageSelection = printRangePageSelection;
+ }
+
+ public int getPageFrom() {
+ return pageFrom;
+ }
+
+ public void setPageFrom(int pageFrom) {
+ this.pageFrom = pageFrom;
+ }
+
+ public int getPageTo() {
+ return pageTo;
+ }
+
+ public void setPageTo(int pageTo) {
+ this.pageTo = pageTo;
+ }
+
+ public int getRows() {
+ return rows;
+ }
+
+ public void setRows(int rows) {
+ this.rows = rows;
+ }
+
+ public int getColumns() {
+ return columns;
+ }
+
+ public void setColumns(int columns) {
+ this.columns = columns;
+ }
+
+ public Graphics getSwtGraphics() {
+ return swtGraphics;
+ }
+
+ public void setSwtGraphics(Graphics swtGraphics) {
+ this.swtGraphics = swtGraphics;
+ }
+
+ public Graphics getGraphics() {
+ return graphics;
+ }
+
+ public void setGraphics(Graphics graphics) {
+ this.graphics = graphics;
+ }
+
+ public void setDiagrams(Collection diagrams) {
+ this.diagrams = diagrams;
+ }
+
+ public Collection getDiagrams() {
+ return diagrams;
+ }
+
+}
Index: src/org/eclipse/gmf/runtime/diagram/ui/printing/internal/util/SWTDiagramPrinter.java
===================================================================
RCS file: src/org/eclipse/gmf/runtime/diagram/ui/printing/internal/util/SWTDiagramPrinter.java
diff -N src/org/eclipse/gmf/runtime/diagram/ui/printing/internal/util/SWTDiagramPrinter.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/gmf/runtime/diagram/ui/printing/internal/util/SWTDiagramPrinter.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,732 @@
+/******************************************************************************
+ * Copyright (c) 2002, 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ****************************************************************************/
+
+package org.eclipse.gmf.runtime.diagram.ui.printing.internal.util;
+
+import java.util.Iterator;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.draw2d.Graphics;
+import org.eclipse.draw2d.SWTGraphics;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gef.LayerConstants;
+import org.eclipse.gef.RootEditPart;
+import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
+import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramRootEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.internal.pagesetup.PageInfoHelper;
+import org.eclipse.gmf.runtime.diagram.ui.internal.pagesetup.PageInfoHelper.PageMargins;
+import org.eclipse.gmf.runtime.diagram.ui.internal.properties.WorkspaceViewerProperties;
+import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor;
+import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramGraphicalViewer;
+import org.eclipse.gmf.runtime.diagram.ui.util.DiagramEditorUtil;
+import org.eclipse.gmf.runtime.draw2d.ui.internal.graphics.MapModeGraphics;
+import org.eclipse.gmf.runtime.draw2d.ui.internal.graphics.PrinterGraphics;
+import org.eclipse.gmf.runtime.draw2d.ui.internal.graphics.ScaledGraphics;
+import org.eclipse.gmf.runtime.draw2d.ui.mapmode.IMapMode;
+import org.eclipse.gmf.runtime.draw2d.ui.mapmode.MapModeUtil;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.printing.Printer;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * This class supports printing using the SWT printing constructs.
+ * Much of the paging code was derived from the previous DiagramPrinter
.
+ *
+ * @author James Bruck (jbruck)
+ */
+public class SWTDiagramPrinter extends DiagramPrinter
+ implements Runnable {
+
+ protected Printer printer;
+
+ private GC gc;
+
+ private PrinterGraphics printerGraphics;
+
+ private Point printerOffset;
+
+ private Rectangle logicalClientArea;
+
+
+ /**
+ * Creates a new instance. The following variables must be initialized
+ * before calling run()
:
+ * printer
+ * display_dpi
+ * diagrams
+ * @param mm IMapMode
to do the coordinate mapping
+ */
+ public SWTDiagramPrinter(PreferencesHint preferencesHint, IMapMode mm) {
+ super(preferencesHint, mm);
+ }
+
+ /**
+ * Creates a new instance. The following variables must be initialized
+ * before calling run()
:
+ * printer
+ * display_dpi
+ * diagrams
+ * @param mapMode IMapMode
to do the coordinate mapping
+ */
+ public SWTDiagramPrinter(PreferencesHint preferencesHint) {
+ this(preferencesHint, MapModeUtil.getMapMode());
+ }
+ /**
+ * Sets the printer.
+ *
+ * @param printer
+ * The printer to set.
+ */
+ public void setPrinter(Printer printer) {
+ this.printer = printer;
+ }
+
+
+ /**
+ * Prints the contents of the diagram editor part.
+ */
+ public void run() {
+ assert null != printer : "printer must be set"; //$NON-NLS-1$
+ if (!(printer.startJob("Printing"))) { //$NON-NLS-1$
+ return;
+ }
+
+ assert diagrams != null;
+ Iterator it = diagrams.iterator();
+
+ Shell shell = new Shell();
+ try {
+ while (it.hasNext()) {
+ Object obj = it.next();
+ //the diagrams List is only supposed to have Diagram objects
+ Assert.isTrue(obj instanceof Diagram);
+ Diagram diagram = (Diagram)obj;
+ DiagramEditor openedDiagramEditor = DiagramEditorUtil
+ .findOpenedDiagramEditorForID(ViewUtil
+ .getIdStr(diagram));
+ DiagramEditPart dgrmEP = openedDiagramEditor == null ? PrintHelperUtil
+ .createDiagramEditPart(diagram, preferencesHint, shell)
+ : openedDiagramEditor.getDiagramEditPart();
+
+ boolean loadedPreferences = openedDiagramEditor != null || PrintHelperUtil.initializePreferences(dgrmEP, preferencesHint);
+
+ RootEditPart rep = dgrmEP.getRoot();
+ if (rep instanceof DiagramRootEditPart)
+ this.mapMode = ((DiagramRootEditPart)rep).getMapMode();
+
+ initialize();
+
+
+ IPreferenceStore pref = null;
+
+ assert dgrmEP.getViewer() instanceof DiagramGraphicalViewer;
+
+ pref = ((DiagramGraphicalViewer)dgrmEP.getViewer()).getWorkspaceViewerPreferenceStore();
+
+ if (pref.getBoolean(WorkspaceViewerProperties.PREF_USE_WORKSPACE_SETTINGS)) {
+
+ //get workspace settings...
+ if (dgrmEP.getDiagramPreferencesHint().getPreferenceStore() != null)
+ pref = (IPreferenceStore)dgrmEP.getDiagramPreferencesHint().getPreferenceStore();
+ }
+
+ doPrintDiagram(dgrmEP, loadedPreferences, pref);
+
+ dispose();
+ }
+ printer.endJob();
+ } finally {
+ shell.dispose();
+ }
+ }
+
+
+ /**
+ * Prints to scale or prints to rows x columns pages
+ */
+ protected void doPrintDiagram(DiagramEditPart dgrmEP, boolean loadedPreferences, IPreferenceStore fPreferences) {
+ this.graphics.pushState();
+ if (isScaledPercent) {
+ printToScale(dgrmEP, loadedPreferences, fPreferences);
+ } else {
+ printToPages(dgrmEP, loadedPreferences, fPreferences);
+ }
+ this.graphics.popState();
+ }
+
+ protected void initialize() {
+
+ assert null != printer : "printer must be set"; //$NON-NLS-1$
+
+ //check for rtl orientation...
+ int style = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().getStyle();
+ if ((style & SWT.MIRRORED) != 0)
+ this.gc = new GC(printer, SWT.RIGHT_TO_LEFT);
+ else
+ this.gc = new GC(printer);
+
+ gc.setXORMode(false);
+
+ this.swtGraphics = new SWTGraphics(gc);
+ this.printerGraphics = createPrinterGraphics(swtGraphics);
+ this.graphics = createMapModeGraphics(printerGraphics);
+ this.graphics.scale(computePrinterDisplayScale());
+
+ this.logicalClientArea = this.graphics.getClip(new Rectangle(
+ this.printer.getClientArea()));
+
+ }
+
+ /**
+ * Usually, the printable area is less than the page.
+ * This method returns the offset for each x margin and each y margin.
+ * x margins are left and right
+ * y margins are top and bottom
+ *
+ * We'll assume the left and right offsets are the same and the
+ * top and bottom offsets are the same.
+ *
+ * @return Point with x and y offsets
+ */
+ protected Point getPrinterOffset() {
+ if (printerOffset == null) {
+ int offsetX = this.printer.getBounds().width
+ - this.printer.getClientArea().width;
+ int offsetY = this.printer.getBounds().height
+ - this.printer.getClientArea().height;
+
+ // assume half on each side
+ offsetX = (int) (getMapMode()
+ .DPtoLP((int) (offsetX / 2.0f * display_dpi.x / printer.getDPI().x)) / userScale);
+ offsetY = (int) (getMapMode()
+ .DPtoLP((int) (offsetY / 2.0f * display_dpi.y / printer.getDPI().y)) / userScale);
+
+ printerOffset = new Point(offsetX, offsetY);
+ }
+
+ return printerOffset;
+ }
+
+ /**
+ * Print the diagram figure using specified scale factor.
+ *
+ * @param dgrmEP the DiagramEditPart that will be printed
+ * @param loadedPreferences true if existing prefs could be loaded
+ * successfully, false if not and defaults are being used. This parameter
+ * is important to obtain the correct page break bounds.
+ * @param fPreferences the preferenceStore that could either contain
+ * existing preferences or defaults
+ */
+ protected void printToScale(DiagramEditPart dgrmEP, boolean loadedPreferences, IPreferenceStore fPreferences) {
+
+ assert null != printer : "printer must be set"; //$NON-NLS-1$
+ Rectangle figureBounds = PrintHelperUtil.getPageBreakBounds(dgrmEP, loadedPreferences);
+ org.eclipse.draw2d.geometry.Point pageBounds = PageInfoHelper.getPageSize(fPreferences, getMapMode());
+
+ //translate to offset initial figure position
+ translated = new Point((int) (-figureBounds.x * userScale), (int) (-figureBounds.y * userScale));
+
+ //calculate the number of page rows and columns
+ int numRows = 0, numCols = 0;
+
+ PageMargins margins = PageInfoHelper.getPageMargins(fPreferences, getMapMode());
+ adjustMargins(margins, userScale, getPrinterOffset());
+
+ GC gc_ = new GC(Display.getDefault(),this.gc.getStyle());
+ gc_.setAntialias(this.gc.getAntialias());
+
+ FontData fontData = JFaceResources.getDefaultFont().getFontData()[0];
+ Font font = new Font(printer, fontData);
+
+ org.eclipse.draw2d.geometry.Point pageCount = getPageCount(dgrmEP, figureBounds, pageBounds, true);
+ numCols = pageCount.x;
+ numRows = pageCount.y;
+
+ //finalRow and finalColumn will be used if we are printing within a page range...
+ int row = 1, col = 1, finalRow = 0, finalColumn = 0;
+
+ if (this.printRangePageSelection) {
+ //print only the pages specified in the page range...
+ row = calculateRowFromPage(this.pageFrom, numCols);
+ col = calculateColumnFromPage(this.pageFrom, numCols, row);
+
+ finalRow = calculateRowFromPage(this.pageTo, numCols);
+ finalColumn = calculateColumnFromPage(this.pageTo, numCols, finalRow);
+ }
+
+ try {
+ //print the pages in row, column order
+ for (; row <= numRows; row++) {
+ for (; col <= numCols; col++) {
+ printer.startPage();
+ drawPage(gc_, dgrmEP, fPreferences, figureBounds, margins, font, row, col);
+ printer.endPage();
+
+ if (row == finalRow && col == finalColumn && this.printRangePageSelection == true)
+ break;
+ }
+
+ if (row == finalRow && col == finalColumn && this.printRangePageSelection == true)
+ break;
+
+ col = 1;
+ }
+ } finally {
+ //must dispose resources
+ font.dispose();
+ gc_.dispose();
+ }
+ }
+
+ /**
+ * Draw the header and footer
+ *
+ * @param gc_,
+ * a graphics context that is not null which this method will use
+ * for figuring ouyt the font's extent
+ * @param figureBounds,
+ * Rectangle with the bounds of the figure
+ * @param rowIndex,
+ * int
+ * @param colIndex,
+ * int
+ */
+ protected void drawHeaderAndFooter(GC gc_, DiagramEditPart dgrmEP, Rectangle figureBounds,
+ Font font, int rowIndex, int colIndex) {
+
+ int width = this.logicalClientArea.width;
+ int height = this.logicalClientArea.height;
+
+ this.graphics.pushState(); //draw text, don't make it too small or big
+ this.graphics.setFont(font);
+
+ this.graphics.scale(1.0f / userScale);
+ this.graphics.translate(-translated.x, -translated.y);
+
+ String headerOrFooter = HeaderAndFooterHelper.makeHeaderOrFooterString(
+ WorkspaceViewerProperties.HEADER_PREFIX, rowIndex, colIndex,
+ dgrmEP);
+
+ this.graphics.drawText(headerOrFooter,
+ getMapMode().DPtoLP(HeaderAndFooterHelper.LEFT_MARGIN_DP)
+ + (width - getMapMode().DPtoLP(gc_.textExtent(headerOrFooter).x))
+ / 2, getMapMode().DPtoLP(HeaderAndFooterHelper.TOP_MARGIN_DP));
+
+ headerOrFooter = HeaderAndFooterHelper.makeHeaderOrFooterString(
+ WorkspaceViewerProperties.FOOTER_PREFIX, rowIndex, colIndex,
+ dgrmEP);
+
+ this.graphics.drawText(headerOrFooter,
+ getMapMode().DPtoLP(HeaderAndFooterHelper.LEFT_MARGIN_DP)
+ + (width - getMapMode().DPtoLP(gc_.textExtent(headerOrFooter).x))
+ / 2, height - getMapMode().DPtoLP(HeaderAndFooterHelper.BOTTOM_MARGIN_DP));
+
+ this.graphics.popState(); //for drawing the text
+
+ }
+
+ /**
+ * This method paints a portion of the diagram. (The area painted
+ * representing one page.)
+ *
+ * @param gc_ a graphics context that is not null which this method will use
+ * for figuring out the font's extent
+ * @param dgrmEP the DiagramEditPart that will be printed
+ * @param fPreferences the preferenceStore that could either contain
+ * existing preferences or defaults
+ * @param figureBounds the page break bounds we'll have to offset by
+ * @param font the Font to print the header or footer with
+ * @param rowIndex index of row we're printing
+ * @param colIndex index of column we're priniting
+ * to check if it is the first time the method is getting called for the current
+ * print.
+ */
+ protected void drawPage(GC gc_, DiagramEditPart dgrmEP,
+ IPreferenceStore fPreferences, Rectangle figureBounds,
+ PageMargins margins, Font font, int rowIndex, int colIndex) {
+
+ org.eclipse.draw2d.geometry.Point pageSize = PageInfoHelper
+ .getPageSize(fPreferences, false, getMapMode());
+ boolean rtlEnabled = ( this.gc !=null) && ((this.gc.getStyle() & SWT.MIRRORED) != 0);
+ if (rtlEnabled)
+ {
+ // draw everything on an offscreen image first and then draw that image
+ // onto the printer gc...this takes care of certain drawing bugs.
+ // This causes issues with printing resolution as it uses a display image
+ // which is typically 72dpi
+ // This code should be removed when a resolution to Bugzilla 162459 is found
+
+ Image image = new Image(Display.getDefault(), getMapMode().LPtoDP(pageSize.x), getMapMode().LPtoDP(pageSize.y));
+
+ GC imgGC = new GC(image, (rtlEnabled) ? SWT.RIGHT_TO_LEFT : SWT.LEFT_TO_RIGHT);
+ imgGC.setXORMode(false);
+
+ SWTGraphics sg = new SWTGraphics(imgGC);
+
+ //for scaling
+ ScaledGraphics g1 = new ScaledGraphics(sg);
+
+ //for himetrics and svg
+ MapModeGraphics mmg = createMapModeGraphics(g1);
+
+ //if mmg's font is null, gc.setFont will use a default font
+ imgGC.setFont(mmg.getFont());
+
+ internalDrawPage(dgrmEP,figureBounds,fPreferences,margins,mmg,rowIndex, colIndex,true);
+
+ this.graphics.pushState();
+
+ this.graphics.drawImage(image, 0, 0);
+
+ this.graphics.popState();
+
+ //draw the header and footer after drawing the image to avoid getting the image getting drawn over them
+ drawHeaderAndFooter(gc_, dgrmEP, figureBounds, font, rowIndex, colIndex);
+ disposeImageVars(imgGC, image, sg, g1, mmg);
+ } else {
+ internalDrawPage(dgrmEP,figureBounds,fPreferences,margins,this.graphics,rowIndex, colIndex,false);
+ //draw the header and footer after drawing the image to avoid getting the image getting drawn over them
+ drawHeaderAndFooter(gc_, dgrmEP, figureBounds, font, rowIndex, colIndex);
+ }
+ }
+
+ protected void internalDrawPage(DiagramEditPart dgrmEP,
+ Rectangle figureBounds, IPreferenceStore fPreferences,
+ PageMargins margins, Graphics g, int rowIndex, int colIndex,
+ boolean RTL_ENABLED) {
+ org.eclipse.draw2d.geometry.Point pageSize = PageInfoHelper
+ .getPageSize(fPreferences, false, getMapMode());
+
+ int width = pageSize.x, height = pageSize.y;
+
+ g.pushState();
+
+ g.translate(translated.x, translated.y);
+ g.scale(userScale);
+
+ int translateX = -(width * (colIndex - 1));
+ int translateY = -(height * (rowIndex - 1));
+
+ int scaledTranslateX = (int) (translateX / userScale);
+ int scaledTranslateY = (int) (translateY / userScale);
+
+ int scaledWidth = (int) (width / userScale);
+ int scaledHeight = (int) (height / userScale);
+
+ if (RTL_ENABLED) {
+ scaledTranslateX += (margins.left * (colIndex - 1))
+ + (margins.right * (colIndex));
+ scaledTranslateY += ((margins.top * rowIndex) + (margins.bottom * (rowIndex - 1)));
+ } else {
+ scaledTranslateX += ((margins.left * colIndex) + (margins.right * (colIndex - 1)));
+ scaledTranslateY += ((margins.top * rowIndex) + (margins.bottom * (rowIndex - 1)));
+ }
+
+ g.translate(scaledTranslateX, scaledTranslateY);
+
+ Rectangle clip = new Rectangle(
+ (scaledWidth - margins.left - margins.right) * (colIndex - 1)
+ + figureBounds.x, (scaledHeight - margins.bottom - margins.top)
+ * (rowIndex - 1) + figureBounds.y, scaledWidth - margins.right
+ - margins.left, scaledHeight - margins.top - margins.bottom);
+ g.clipRect(clip);
+
+ dgrmEP.getLayer(LayerConstants.PRINTABLE_LAYERS).paint(g);
+
+ g.popState();
+ }
+
+ /**
+ * Print the diagram figure to fit the number and rows and columns
+ * specified by the user.
+ *
+ * @param dgrmEP the DiagramEditPart that will be printed
+ * @param loadedPreferences true if existing prefs could be loaded
+ * successfully, false if not and defaults are being used. This parameter
+ * is important to obtain the correct page break bounds.
+ * @param fPreferences the preferenceStore that could either contain
+ * existing preferences or defaults
+ */
+ protected void printToPages(DiagramEditPart dgrmEP,
+ boolean loadedPreferences, IPreferenceStore fPreferences) {
+ assert null != printer : "printer must be set"; //$NON-NLS-1$
+
+ Rectangle figureBounds = PrintHelperUtil.getPageBreakBounds(dgrmEP,
+ loadedPreferences);
+
+ PageMargins margins = PageInfoHelper.getPageMargins(fPreferences, getMapMode());
+ //do not include margins
+ org.eclipse.draw2d.geometry.Point pageBounds = PageInfoHelper
+ .getPageSize(fPreferences, getMapMode());
+ org.eclipse.draw2d.geometry.Point pageCount = getPageCount(dgrmEP, figureBounds, pageBounds, false);
+ int numCols = pageCount.x;
+ int numRows = pageCount.y;
+
+ float actualWidth = 0;
+ float actualHeight = 0;
+ if (this.rows==1 && this.columns==1 && fitToPage){
+ figureBounds = dgrmEP.getChildrenBounds();
+ actualWidth = figureBounds.width;
+ actualHeight = figureBounds.height;
+ }else {
+ actualWidth = numCols * pageBounds.x;
+ actualHeight = numRows * pageBounds.y;
+ }
+
+ int totalHeight = (this.rows * pageBounds.y);
+ int totalWidth = (this.columns * pageBounds.x);
+
+ float vScale = totalHeight / actualHeight;
+ float hScale = totalWidth / actualWidth;
+
+ this.userScale = Math.min(hScale, vScale);
+
+ // translate to offset figure position
+ translated = new Point((int) (-figureBounds.x * userScale),
+ (int) (-figureBounds.y * userScale));
+
+ adjustMargins(margins, userScale, getPrinterOffset());
+
+ GC gc_ = new GC(Display.getDefault());
+
+ FontData fontData = JFaceResources.getDefaultFont().getFontData()[0];
+ Font font = new Font(printer, fontData);
+
+ int row = 1, col = 1, finalRow = 0, finalColumn = 0;
+
+ if (this.printRangePageSelection) {
+ //print only the pages specified in the page range
+ //this corresponds to the physical pages, not the print range of pages on one physical page.
+ row = calculateRowFromPage(this.pageFrom, this.columns);
+ col = calculateColumnFromPage(this.pageFrom, this.columns, row);
+
+ finalRow = calculateRowFromPage(this.pageTo, this.columns);
+ finalColumn = calculateColumnFromPage(this.pageTo, this.columns, finalRow);
+ }
+
+ try {
+ // print the pages in row, column order
+ for (; row <= rows; row++) {
+ for (; col <= columns; col++) {
+ printer.startPage();
+ drawPage(gc_, dgrmEP, fPreferences, figureBounds, margins,
+ font, row, col);
+ printer.endPage();
+
+ if (row == finalRow && col == finalColumn && this.printRangePageSelection == true)
+ break;
+ }
+
+ if (row == finalRow && col == finalColumn && this.printRangePageSelection == true)
+ break;
+
+ col = 1;
+ }
+ } finally {
+ // must dispose resources
+ font.dispose();
+ gc_.dispose();
+ }
+ }
+
+ /**
+ * Return scale factor between printer and display.
+ *
+ * @return float
+ */
+ private float computePrinterDisplayScale() {
+ assert null != printer : "printer must be set"; //$NON-NLS-1$
+ assert null != display_dpi : "display_dpi must be set"; //$NON-NLS-1$
+
+ Point dpi = printer.getDPI();
+ float scale = dpi.x / (float) display_dpi.x;
+
+ return scale;
+ }
+
+ /**
+ * Disposes of the resources.
+ */
+ protected void dispose() {
+ if (this.graphics != null) {
+ try {
+ this.graphics.dispose();
+ }
+ catch (NullPointerException e) {
+ //do nothing
+ }
+ finally {
+ this.graphics = null;
+ }
+ }
+
+ if (this.printerGraphics != null) {
+ try {
+ this.printerGraphics.dispose();
+ }
+ catch (NullPointerException e) {
+ //do nothing
+ }
+ finally {
+ this.printerGraphics = null;
+ }
+ }
+
+ if (this.swtGraphics != null) {
+ try {
+ this.swtGraphics.dispose();
+ }
+ catch (NullPointerException e) {
+ //do nothing
+ }
+ finally {
+ this.swtGraphics = null;
+ }
+ }
+
+ if (this.gc != null) {
+ try {
+ this.gc.dispose();
+ }
+ catch (NullPointerException e) {
+ //do nothing
+ }
+ finally {
+ this.gc = null;
+ }
+ }
+
+ //reset the printer offset, just in case the next diagram to be printed
+ //uses a different map mode.
+ printerOffset = null;
+
+ }
+
+ private void disposeImageVars(GC imgGC, Image image, SWTGraphics sg,
+ ScaledGraphics g1, MapModeGraphics mmg) {
+
+ if (mmg != null) {
+ try {
+ mmg.dispose();
+ }
+ catch (NullPointerException e) {
+ //do nothing
+ }
+ finally {
+ mmg = null;
+ }
+ }
+
+ if (g1 != null) {
+ try {
+ g1.dispose();
+ }
+ catch (NullPointerException e) {
+ //do nothing
+ }
+ finally {
+ g1 = null;
+ }
+ }
+
+ if (sg != null) {
+ try {
+ sg.dispose();
+ }
+ catch (NullPointerException e) {
+ //do nothing
+ }
+ finally {
+ sg = null;
+ }
+ }
+
+ if (imgGC != null) {
+ try {
+ imgGC.dispose();
+ }
+ catch (NullPointerException e) {
+ //do nothing
+ }
+ finally {
+ imgGC = null;
+ }
+ }
+
+ if (image != null) {
+ try {
+ image.dispose();
+ }
+ catch (NullPointerException e) {
+ //do nothing
+ }
+ finally {
+ image = null;
+ }
+ }
+ }
+
+
+ /**
+ * Creates the PrinterGraphics
.
+ *
+ * @param theGraphics
+ * the Graphics
object
+ * @return the new PrinterGraphics
+ */
+ protected PrinterGraphics createPrinterGraphics(Graphics theGraphics) {
+ return new PrinterGraphics(theGraphics, printer, true);
+ }
+
+
+ /**
+ * Adjust the given PageMargins by the scale and offset
+ *
+ * @param margins PageMargins to adjust
+ * @param scale margins will be scaled by this amount
+ * @param offset to adjust margins by
+ */
+ protected void adjustMargins(PageMargins margins, float scale, Point offset) {
+ //scale
+ margins.left /= scale;
+ margins.top /= scale;
+ margins.right /= scale;
+ margins.bottom /= scale;
+
+ //offsets
+ margins.left -= offset.x;
+ margins.right += offset.x;
+ margins.top -= offset.y;
+ margins.bottom += offset.y;
+
+ // this is more readable than doing Math.min for all the above
+ if (margins.left < 0)
+ margins.left = 0;
+ if (margins.right < 0)
+ margins.right = 0;
+ if (margins.top < 0)
+ margins.top = 0;
+ if (margins.bottom < 0)
+ margins.bottom = 0;
+ }
+}
Index: src/org/eclipse/gmf/runtime/diagram/ui/printing/internal/util/PrintHelperUtil.java
===================================================================
RCS file: src/org/eclipse/gmf/runtime/diagram/ui/printing/internal/util/PrintHelperUtil.java
diff -N src/org/eclipse/gmf/runtime/diagram/ui/printing/internal/util/PrintHelperUtil.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/gmf/runtime/diagram/ui/printing/internal/util/PrintHelperUtil.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,296 @@
+/******************************************************************************
+ * Copyright (c) 2005, 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ****************************************************************************/
+
+package org.eclipse.gmf.runtime.diagram.ui.printing.internal.util;
+
+import java.io.File;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gef.RootEditPart;
+import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
+import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
+import org.eclipse.gmf.runtime.diagram.ui.OffscreenEditPartFactory;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramRootEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.internal.DiagramUIPlugin;
+import org.eclipse.gmf.runtime.diagram.ui.internal.editparts.PageBreakEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.internal.figures.PageBreaksFigure;
+import org.eclipse.gmf.runtime.diagram.ui.internal.pagesetup.PageInfoHelper;
+import org.eclipse.gmf.runtime.diagram.ui.internal.properties.WorkspaceViewerProperties;
+import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor;
+import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramGraphicalViewer;
+import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramGraphicalViewer;
+import org.eclipse.gmf.runtime.diagram.ui.util.DiagramEditorUtil;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.PreferenceStore;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * Helper to assist in making an offscreen diagram suitable for printing or
+ * previewing.
+ *
+ * @author wdiu, Wayne Diu
+ */
+public class PrintHelperUtil {
+ /**
+ * Creates a DiagramEditPart
given the Diagram
+ * without opening an editor.
+ *
+ * @param diagram the Diagram
+ * @param preferencesHint the preferences hint to use for intiializing the
+ * preferences of the root edit part
+ * @return the new populated DiagramEditPart
+ * @deprecated Please use
+ * {@link #createDiagramEditPart(Diagram, PreferencesHint, Shell)}
+ * instead as this method does not dispose the new Shell that it
+ * creates.
+ */
+ public static DiagramEditPart createDiagramEditPart(Diagram diagram,
+ PreferencesHint preferencesHint) {
+
+ DiagramEditPart diagramEditPart = OffscreenEditPartFactory.getInstance().createDiagramEditPart(
+ diagram, new Shell(), preferencesHint);
+ // since some of the diagram updates are ASync we need to give the
+ // inter-thread messages a chance to get processed processed before we
+ // continue; check bugzilla 170332
+ while (Display.getDefault().readAndDispatch ()){
+ // nothing special to do
+ }
+ return diagramEditPart;
+ }
+
+ /**
+ * Creates a DiagramEditPart
given the Diagram
+ * without opening an editor.
+ *
+ * @param diagram the Diagram
+ * @param preferencesHint the preferences hint to use for intiializing the
+ * preferences of the root edit part
+ * @return the new populated DiagramEditPart
+ */
+ public static DiagramEditPart createDiagramEditPart(Diagram diagram,
+ PreferencesHint preferencesHint, Shell shell) {
+ DiagramEditPart diagramEditPart = OffscreenEditPartFactory.getInstance().createDiagramEditPart(
+ diagram, shell, preferencesHint);
+ // since some of the diagram updates are ASync we need to give the
+ // inter-thread messages a chance to get processed before we
+ // continue; check bugzilla 170332
+ while (Display.getDefault().readAndDispatch ()){
+ // nothing special to do
+ }
+ return diagramEditPart;
+ }
+
+ /**
+ * Initialize the preferences for a diagram edit part, specifically
+ * including page breaks and margins.
+ *
+ * Typically, the diagram edit part is created using
+ * createDiagramEditPart() and the diagram edit part is passed in as the
+ * first parameter of this method.
+ *
+ * @param diagramEditPart the DiagramEditPart to pass in
+ * @param preferencesHint the preferences hint to use for intiializing the preferences
+ *
+ * @return true if the preferences could be loaded, false if they weren't
+ * loaded and defaults had to be used instead
+ */
+ public static boolean initializePreferences(DiagramEditPart diagramEditPart, PreferencesHint preferencesHint) {
+ assert diagramEditPart.getViewer() instanceof DiagramGraphicalViewer;
+
+ DiagramGraphicalViewer viewer = (DiagramGraphicalViewer)diagramEditPart.getViewer();
+
+ boolean loadedPreferences = true;
+
+ IPreferenceStore fPreferences = getPreferenceStoreForDiagram(diagramEditPart);
+
+ if (fPreferences == null) {
+ loadedPreferences = false;
+ //leave at default x and y
+ PreferenceStore defaults = new PreferenceStore();
+ DiagramEditor.addDefaultPreferences(defaults, preferencesHint);
+
+ fPreferences = getWorkspacePreferenceStore(preferencesHint);
+ } else if (!fPreferences
+ .getBoolean(WorkspaceViewerProperties.PREF_USE_DIAGRAM_SETTINGS)) {
+ //if we aren't supposed to use the diagram settings, switch to the
+ //workspace settings
+
+ //we have to use the page break x and y settings from the diagram
+ int x = fPreferences.getInt(WorkspaceViewerProperties.PAGEBREAK_X), y = fPreferences
+ .getInt(WorkspaceViewerProperties.PAGEBREAK_Y);
+
+ //minor performance optimization, use the existing
+ //preferences from the workspace instead of making a new one
+ fPreferences = getWorkspacePreferenceStore(preferencesHint);
+ fPreferences.setValue(WorkspaceViewerProperties.PAGEBREAK_X, x);
+ fPreferences.setValue(WorkspaceViewerProperties.PAGEBREAK_Y, y);
+ }
+
+ viewer.hookWorkspacePreferenceStore(fPreferences);
+
+ diagramEditPart.refreshPageBreaks();
+
+ return loadedPreferences;
+ }
+
+ /**
+ * Returns the workspace viewer PreferenceStore
for a given diagram edit part.
+ *
+ * @param diagramEP the DiagramEditPart to obtain the preference store for
+ *
+ * @return the PreferenceStore
for the given diagram edit part
+ * Could return null if it couldn't be loaded
+ */
+ private static IPreferenceStore getPreferenceStoreForDiagram(DiagramEditPart diagramEP) {
+ // Try to load it
+ String id = ViewUtil.getIdStr(diagramEP.getDiagramView());
+
+ //try and get preferences from the open diagrams first
+ //loadedPreferences will be set to true only if the preferences could
+ // be
+ //successfully loaded
+ IPreferenceStore fPreferences = loadPreferencesFromOpenDiagram(id);
+ if (fPreferences != null) {
+ //loadPreferencesFromOpenDiagram will have set preferences
+ return fPreferences;
+ }
+
+ IPath path = DiagramUIPlugin.getInstance().getStateLocation();
+
+ String fileName = path.toString() + "/" + id;//$NON-NLS-1$
+ java.io.File file = new File(fileName);
+ fPreferences = new PreferenceStore(fileName);
+ if (file.exists()) {
+ // Load it
+ try {
+ ((PreferenceStore) fPreferences).load();
+
+ return fPreferences;
+ } catch (Exception e) {
+ return null;
+ }
+ }
+ return null; //fPreferences couldn't be loaded
+ }
+
+ /**
+ * Load the preferences from an open diagram that has the given guid.
+ *
+ * @param id guid of the open diagram to load the preferences for
+ */
+ private static IPreferenceStore loadPreferencesFromOpenDiagram(String id) {
+
+ DiagramEditor diagramEditor = DiagramEditorUtil.findOpenedDiagramEditorForID(id);
+ if (diagramEditor != null) {
+ IDiagramGraphicalViewer viewer = diagramEditor
+ .getDiagramGraphicalViewer();
+ if (diagramEditor.getDiagramEditPart().getRoot() instanceof DiagramRootEditPart) {
+ PageBreakEditPart pageBreakEditPart = ((DiagramRootEditPart) diagramEditor
+ .getDiagramEditPart().getRoot()).getPageBreakEditPart();
+ pageBreakEditPart.resize(diagramEditor.getDiagramEditPart()
+ .getChildrenBounds());
+ pageBreakEditPart.updatePreferenceStore();
+ }
+ if (viewer instanceof DiagramGraphicalViewer) {
+ DiagramGraphicalViewer diagramGraphicalViewer = (DiagramGraphicalViewer) viewer;
+
+ // preferences loaded
+ return diagramGraphicalViewer
+ .getWorkspaceViewerPreferenceStore();
+ }
+ }
+
+ // no matching guid found
+ return null;
+ }
+
+ /**
+ * Return the preference store for the given PreferenceHint
+ * @param preferencesHint to return the preference store for.
+ *
+ * @return preference store for the given PreferenceHint
+ */
+ private static IPreferenceStore getWorkspacePreferenceStore(PreferencesHint preferencesHint) {
+ return (IPreferenceStore) preferencesHint.getPreferenceStore();
+ }
+
+ /**
+ * Returns the page break bounds on the diagram. If the bounds cannot be
+ * found the diagram bounds is returned.
+ *
+ * @param dgrmEP the diagram edit part to return the page break bounds for
+ * @param loadedPreferences true if preferences were previously loaded,
+ * false if they couldn't be. For consistency when printing, we have to
+ * treat page breaks differently depending on whether preferences were
+ * successfully loaded or not.
+ *
+ * @return Rectangle with the page break bounds for the given diagram edit
+ * part. If the page break bounds cannot be found the diagram bounds
+ * Rectangle is returned.
+ */
+ public static Rectangle getPageBreakBounds(DiagramEditPart dgrmEP, boolean loadedPreferences) {
+
+ Rectangle pageBreakBounds = null;
+ assert dgrmEP.getViewer() instanceof DiagramGraphicalViewer;
+
+
+ //get the preferences in use...
+ IPreferenceStore fPreferences = ((DiagramGraphicalViewer)dgrmEP.getViewer()).getWorkspaceViewerPreferenceStore();
+
+ if (fPreferences.getBoolean(WorkspaceViewerProperties.PREF_USE_WORKSPACE_SETTINGS)) {
+
+ //get workspace settings...
+ if (dgrmEP.getDiagramPreferencesHint().getPreferenceStore() != null)
+ fPreferences = (IPreferenceStore)dgrmEP.getDiagramPreferencesHint().getPreferenceStore();
+ }
+
+ RootEditPart rootEditPart = dgrmEP.getRoot();
+ if (rootEditPart instanceof DiagramRootEditPart) {
+ DiagramRootEditPart diagramRootEditPart = (DiagramRootEditPart) rootEditPart;
+ PageBreakEditPart pageBreakEditPart = diagramRootEditPart
+ .getPageBreakEditPart();
+
+ if (pageBreakEditPart != null) {
+ //resize must be called. Otherwise you get the 64 x 32 default
+ pageBreakEditPart.resize(dgrmEP.getChildrenBounds());
+
+ if (loadedPreferences) {
+ //if preferences were loaded, we'll always do this for
+ //consistency when printing.
+ //this is necessary when printing using workspace
+ //preferences, which is "if (getWorkspacePreferenceStore()
+ //== fPreferences)"
+
+ //if preferences were not loaded, we do not set the figure
+ //location. we'll just leave them at defaults.
+ org.eclipse.draw2d.geometry.Point p = new org.eclipse.draw2d.geometry.Point(
+ fPreferences
+ .getInt(WorkspaceViewerProperties.PAGEBREAK_X),
+ fPreferences
+ .getInt(WorkspaceViewerProperties.PAGEBREAK_Y));
+ pageBreakEditPart.set(p, PageInfoHelper.getChildrenBounds(
+ (DiagramEditPart) diagramRootEditPart.getContents(),
+ PageBreaksFigure.class));
+ }
+
+ pageBreakBounds = pageBreakEditPart.getFigure().getBounds();
+ } else {
+ pageBreakBounds = dgrmEP.getFigure().getBounds();
+ }
+ }
+
+ return pageBreakBounds;
+ }
+}
Index: src/org/eclipse/gmf/runtime/diagram/ui/printing/internal/util/DiagramPrinterHelper.java
===================================================================
RCS file: src/org/eclipse/gmf/runtime/diagram/ui/printing/internal/util/DiagramPrinterHelper.java
diff -N src/org/eclipse/gmf/runtime/diagram/ui/printing/internal/util/DiagramPrinterHelper.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/gmf/runtime/diagram/ui/printing/internal/util/DiagramPrinterHelper.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,169 @@
+/******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ****************************************************************************/
+
+package org.eclipse.gmf.runtime.diagram.ui.printing.internal.util;
+
+import java.text.NumberFormat;
+import java.text.ParseException;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.gmf.runtime.common.core.util.Log;
+import org.eclipse.gmf.runtime.common.ui.printing.IPrintHelper;
+import org.eclipse.gmf.runtime.diagram.ui.internal.pagesetup.PageSetupPageType;
+import org.eclipse.gmf.runtime.diagram.ui.internal.properties.WorkspaceViewerProperties;
+import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramGraphicalViewer;
+import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramGraphicalViewer;
+import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart;
+import org.eclipse.gmf.runtime.diagram.ui.printing.internal.DiagramPrintingPlugin;
+import org.eclipse.gmf.runtime.diagram.ui.printing.internal.DiagramPrintingStatusCodes;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.swt.printing.PrinterData;
+import org.eclipse.ui.IEditorPart;
+
+/**
+ * Utility for using the DiagramPrinter to print diagrams after displaying
+ * a print dialog box to the user. Diagrams are printed using the
+ * DiagramPrinter and respect the settings chosen by the user in the print
+ * dialog.
+ *
+ * Basic functionality was factored into this class from the DiagramPrinterUtil.
+ * This class and its specializing classes:
+ * JPSDiagramPrinterHelper and SWTDiagramPrinterHelper will be subject to change
+ * during phase 2 of printing enhancement changes.
+ *
+ */
+public class DiagramPrinterHelper {
+
+ /**
+ * Prints a diagram with the settings from the helper onto the printer
+ *
+ * @param diagramPrinter
+ * the diagram printer that does the work of actually
+ * printing the diagrams
+ * @param helper
+ * IPrintHelper with the user's choice of settings
+ */
+ protected void printDiagrams(DiagramPrinter diagramPrinter,
+ IPrintHelper helper) {
+
+ if (helper.getDlgPrintRangePages()) {
+ diagramPrinter.setPrintRangePageSelection(true);
+ diagramPrinter.setPrintRangePages(helper.getDlgPagesFrom(), helper
+ .getDlgPagesTo());
+ diagramPrinter.setFitToPage(false);
+ }
+
+ if (helper.getDlgScalePercent() == -1) {
+ diagramPrinter.setColumns(helper.getDlgScaleFitToM());
+ diagramPrinter.setRows(helper.getDlgScaleFitToN());
+ diagramPrinter.setFitToPage(true);
+ } else {
+ diagramPrinter.setScaledPercent(helper.getDlgScalePercent());
+ diagramPrinter.setFitToPage(false);
+ }
+
+ diagramPrinter.run();
+ }
+
+ /**
+ * A helper that simply collects printing information.
+ *
+ * @param diagramPrinter
+ * @param helper
+ * @param diagramNames
+ * @param editorPart
+ * @param diagramMap
+ * @return
+ */
+ protected PrinterData collectPrintInformation(
+ DiagramPrinter diagramPrinter, IPrintHelper helper,
+ List diagramNames, IEditorPart editorPart, Map diagramMap) {
+
+ PrinterData printerData;
+
+ IPreferenceStore pref = null;
+
+ if (editorPart instanceof IDiagramWorkbenchPart) {
+
+ IDiagramGraphicalViewer viewer = ((IDiagramWorkbenchPart) editorPart)
+ .getDiagramGraphicalViewer();
+ if (viewer instanceof DiagramGraphicalViewer) {
+
+ pref = ((DiagramGraphicalViewer) viewer)
+ .getWorkspaceViewerPreferenceStore();
+
+ if (pref
+ .getBoolean(WorkspaceViewerProperties.PREF_USE_WORKSPACE_SETTINGS)) {
+
+ if (((IDiagramWorkbenchPart) editorPart)
+ .getDiagramEditPart().getDiagramPreferencesHint()
+ .getPreferenceStore() != null) {
+ pref = (IPreferenceStore) ((IDiagramWorkbenchPart) editorPart)
+ .getDiagramEditPart()
+ .getDiagramPreferencesHint()
+ .getPreferenceStore();
+ }
+ }
+ }
+ }
+ if (pref != null) {
+ helper.setDlgOrientation(pref
+ .getBoolean(WorkspaceViewerProperties.PREF_USE_LANDSCAPE));
+
+ PageSetupPageType storedPageType = PageSetupPageType.LETTER; //default value
+ String strPageType = pref
+ .getString(WorkspaceViewerProperties.PREF_PAGE_SIZE);
+ for (int i = 0; i < PageSetupPageType.pages.length; i++) {
+ if (strPageType
+ .startsWith(PageSetupPageType.pages[i].getName())) {
+ storedPageType = PageSetupPageType.pages[i];
+ break;
+ }
+ }
+ if (storedPageType.getIndex() == PageSetupPageType.USER_DEFINED
+ .getIndex()) {
+
+ NumberFormat fNumberFormat = NumberFormat.getNumberInstance();
+
+ String strWidth = pref
+ .getString(WorkspaceViewerProperties.PREF_PAGE_WIDTH);
+ String strHeight = pref
+ .getString(WorkspaceViewerProperties.PREF_PAGE_HEIGHT);
+ double width = 0, height = 0;
+
+ try {
+ Number num = fNumberFormat.parse(strWidth);
+ width = num.doubleValue() / 0.0394d; //convert from inches to mm
+
+ num = fNumberFormat.parse(strHeight);
+ height = num.doubleValue() / 0.0394d;
+
+ helper.setDlgPaperSize(PageSetupPageType.USER_DEFINED
+ .getIndex(), width, height);
+ } catch (ParseException e) {
+ Log
+ .warning(
+ DiagramPrintingPlugin.getInstance(),
+ DiagramPrintingStatusCodes.IGNORED_EXCEPTION_WARNING,
+ e.getMessage(), e);
+ }
+ } else {
+ helper.setDlgPaperSize(storedPageType.getIndex(), 0, 0);
+ }
+ }
+
+ printerData = helper.openPrintDlg(diagramNames);
+
+ return printerData;
+ }
+
+}
Index: src/org/eclipse/gmf/runtime/diagram/ui/printing/internal/util/SWTDiagramPrinterHelper.java
===================================================================
RCS file: src/org/eclipse/gmf/runtime/diagram/ui/printing/internal/util/SWTDiagramPrinterHelper.java
diff -N src/org/eclipse/gmf/runtime/diagram/ui/printing/internal/util/SWTDiagramPrinterHelper.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/gmf/runtime/diagram/ui/printing/internal/util/SWTDiagramPrinterHelper.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,209 @@
+/******************************************************************************
+ * Copyright (c) 2004,2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ****************************************************************************/
+
+package org.eclipse.gmf.runtime.diagram.ui.printing.internal.util;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.gmf.runtime.common.core.util.Log;
+import org.eclipse.gmf.runtime.common.core.util.Trace;
+import org.eclipse.gmf.runtime.common.ui.printing.IPrintHelper;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart;
+import org.eclipse.gmf.runtime.diagram.ui.printing.actions.DefaultPrintActionHelper;
+import org.eclipse.gmf.runtime.diagram.ui.printing.internal.DiagramPrintingDebugOptions;
+import org.eclipse.gmf.runtime.diagram.ui.printing.internal.DiagramPrintingPlugin;
+import org.eclipse.gmf.runtime.diagram.ui.printing.internal.DiagramPrintingStatusCodes;
+import org.eclipse.gmf.runtime.diagram.ui.printing.internal.l10n.DiagramUIPrintingMessages;
+import org.eclipse.gmf.runtime.diagram.ui.printing.util.DiagramPrinterUtil;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.printing.Printer;
+import org.eclipse.swt.printing.PrinterData;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorPart;
+
+/**
+ * Utility for using the DiagramPrinter to print diagrams after displaying a
+ * print dialog box to the user. Diagrams are printed using the DiagramPrinter
+ * and respect the settings chosen by the user in the print dialog.
+ *
+ * This class uses the SWT printing to accomplish its task. This class was
+ * derived from
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.printing.util.DiagramPrinterUtil
+ *
+ * This class is subject to change/removal during phase 2 of printing
+ * enhancements
+ *
+ */
+public class SWTDiagramPrinterHelper extends DiagramPrinterHelper {
+
+ private static SWTDiagramPrinterHelper diagramPrinterHelper;
+
+ public static SWTDiagramPrinterHelper getDiagramPrinterHelper() {
+ if (diagramPrinterHelper == null) {
+ diagramPrinterHelper = new SWTDiagramPrinterHelper();
+ }
+ return diagramPrinterHelper;
+ }
+
+ /**
+ * Prevent instantiation.
+ */
+ private SWTDiagramPrinterHelper() {
+ }
+
+ /**
+ * Opens up the print diagrams dialog, allows the user to choose the
+ * settings, and prints.
+ *
+ * @param editorPart
+ * current editor part
+ * @param diagramMap
+ * map of String names to Diagram objects. Should be initialized
+ * by caller of this method. String names will show up in the
+ * print dialog that allows the user to choose which diagrams to
+ * print from a list.
+ * @param diagramPrinter
+ * the diagram printer that does the work of actually printing
+ * the diagrams
+ */
+ public void printWithSettings(IEditorPart editorPart, Map diagramMap,
+ SWTDiagramPrinter diagramPrinter) {
+
+ List diagramNames;
+ PrinterData printerData;
+ IPrintHelper helper;
+
+ try {
+ Class printhelperClass = Class
+ .forName(IPrintHelper.PRINT_HELPER_CLASS_NAME);
+ helper = (IPrintHelper) printhelperClass.newInstance();
+ diagramNames = new ArrayList(diagramMap.keySet());
+
+ printerData = collectPrintInformation(diagramPrinter, helper,
+ diagramNames, editorPart, diagramMap);
+
+ if (printerData != null) {
+
+ final Printer printer = new Printer(printerData);
+
+ diagramPrinter.setPrinter(printer);
+ diagramPrinter.setDisplayDPI(Display.getDefault().getDPI());
+
+ if (helper.getDlgDiagramPrintRangeCurrent()) {
+ DiagramEditPart dgrmEP = ((IDiagramWorkbenchPart) editorPart)
+ .getDiagramEditPart();
+ assert dgrmEP != null;
+ diagramPrinter.setDiagrams(Collections.singletonList(dgrmEP
+ .getDiagramView().getDiagram()));
+ } else if (helper.getDlgDiagramPrintRangeAll()) {
+ diagramPrinter.setDiagrams(diagramMap.values());
+ } else if (helper.getDlgDiagramPrintRangeSelection()) {
+ Object obj;
+ List list = new ArrayList();
+ for (int i = 0; i < diagramNames.size(); i++) {
+ // is the diagram selected?
+ // we are only printing the selected ones
+ if (helper.isDlgDiagramSelected(i)) {
+
+ obj = diagramMap.get(diagramNames.get(i));
+ if (obj instanceof Diagram) {
+
+ list.add(obj);
+ }
+ }
+ }
+ diagramPrinter.setDiagrams(list);
+ }
+
+ printDiagrams(diagramPrinter, helper);
+
+ printer.dispose();
+ }
+ } catch (Throwable e) {
+ // if there's a problem with the fragment, try doing the default
+ // this is better than nothing
+ Trace.catching(DiagramPrintingPlugin.getInstance(),
+ DiagramPrintingDebugOptions.EXCEPTIONS_CATCHING,
+ DiagramPrinterUtil.class, e.getMessage(), e);
+ Log.warning(DiagramPrintingPlugin.getInstance(),
+ DiagramPrintingStatusCodes.RESOURCE_FAILURE,
+ e.getMessage(), e);
+
+ if (MessageDialog
+ .openQuestion(
+ Display.getDefault().getActiveShell(),
+ DiagramUIPrintingMessages.DiagramPrinterUtil_DLLErrorTitle,
+ DiagramUIPrintingMessages.DiagramPrinterUtil_DLLErrorMessage_part1
+ + "\n" //$NON-NLS-1$
+ + DiagramUIPrintingMessages.DiagramPrinterUtil_DLLErrorMessage_part2
+ + "\n" //$NON-NLS-1$
+ + DiagramUIPrintingMessages.DiagramPrinterUtil_DLLErrorMessage_part3
+ + "\n\n" //$NON-NLS-1$
+ + DiagramUIPrintingMessages.DiagramPrinterUtil_DLLErrorMessage_part4)) {
+ DefaultPrintActionHelper.doRun(editorPart, diagramPrinter);
+ }
+
+ return;
+ }
+
+ }
+
+ /**
+ * A helper that simply collects printing information.
+ *
+ * @param diagramPrinter
+ * @param helper
+ * @param diagramNames
+ * @param editorPart
+ * @param diagramMap
+ * @return
+ */
+ private PrinterData collectPrintInformation(
+ SWTDiagramPrinter diagramPrinter, IPrintHelper helper,
+ List diagramNames, IEditorPart editorPart, Map diagramMap) {
+
+ PrinterData printerData = null;
+ try {
+ printerData = super.collectPrintInformation(diagramPrinter, helper,
+ diagramNames, editorPart, diagramMap);
+ } catch (Throwable e) {
+ // if there's a problem with the fragment, try doing the default
+ // this is better than nothing
+ Trace.catching(DiagramPrintingPlugin.getInstance(),
+ DiagramPrintingDebugOptions.EXCEPTIONS_CATCHING,
+ DiagramPrinterUtil.class, e.getMessage(), e);
+ Log.warning(DiagramPrintingPlugin.getInstance(),
+ DiagramPrintingStatusCodes.RESOURCE_FAILURE,
+ e.getMessage(), e);
+
+ if (MessageDialog
+ .openQuestion(
+ Display.getDefault().getActiveShell(),
+ DiagramUIPrintingMessages.DiagramPrinterUtil_DLLErrorTitle,
+ DiagramUIPrintingMessages.DiagramPrinterUtil_DLLErrorMessage_part1
+ + "\n" //$NON-NLS-1$
+ + DiagramUIPrintingMessages.DiagramPrinterUtil_DLLErrorMessage_part2
+ + "\n" //$NON-NLS-1$
+ + DiagramUIPrintingMessages.DiagramPrinterUtil_DLLErrorMessage_part3
+ + "\n\n" //$NON-NLS-1$
+ + DiagramUIPrintingMessages.DiagramPrinterUtil_DLLErrorMessage_part4)) {
+ DefaultPrintActionHelper.doRun(editorPart, diagramPrinter);
+ }
+ }
+ return printerData;
+ }
+}
#P org.eclipse.gmf.runtime.common.ui.action
Index: src/org/eclipse/gmf/runtime/common/ui/action/actions/global/GlobalPrintAction.java
===================================================================
RCS file: /cvsroot/modeling/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.common.ui.action/src/org/eclipse/gmf/runtime/common/ui/action/actions/global/GlobalPrintAction.java,v
retrieving revision 1.6
diff -u -r1.6 GlobalPrintAction.java
--- src/org/eclipse/gmf/runtime/common/ui/action/actions/global/GlobalPrintAction.java 22 Nov 2005 04:15:46 -0000 1.6
+++ src/org/eclipse/gmf/runtime/common/ui/action/actions/global/GlobalPrintAction.java 29 Feb 2008 18:52:56 -0000
@@ -1,5 +1,5 @@
/******************************************************************************
- * Copyright (c) 2002, 2005 IBM Corporation and others.
+ * Copyright (c) 2002, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,17 +10,16 @@
****************************************************************************/
package org.eclipse.gmf.runtime.common.ui.action.actions.global;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.PlatformUI;
-
import org.eclipse.gmf.runtime.common.ui.action.global.GlobalAction;
import org.eclipse.gmf.runtime.common.ui.action.global.GlobalActionId;
import org.eclipse.gmf.runtime.common.ui.action.internal.CommonUIActionPlugin;
import org.eclipse.gmf.runtime.common.ui.action.internal.IHelpContextIds;
import org.eclipse.gmf.runtime.common.ui.action.internal.l10n.CommonUIActionMessages;
import org.eclipse.gmf.runtime.common.ui.action.internal.l10n.CommonUIActionPluginImages;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
/**
* Global action for printing
@@ -88,12 +87,13 @@
* @see org.eclipse.gmf.runtime.common.ui.action.IRepeatableAction#refresh()
*/
public void refresh() {
- //also only allows printing for windows, don't test for windows in the
- //global action handler's canHandle, because that's for selection
- //changes
+ //
+ // In phase 2 of printing enhancements we will remove the OS restriction.
+ //
setEnabled(!getGlobalActionHandlerData().isEmpty() && System.getProperty("os.name").toUpperCase().startsWith("WIN")); //$NON-NLS-1$ //$NON-NLS-2$
+
}
-
+
/* (non-Javadoc)
* @see org.eclipse.gmf.runtime.common.ui.action.AbstractActionHandler#isSelectionListener()
*/