]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.charts/src/org/simantics/charts/editor/ExportToPdfHandler.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.charts / src / org / simantics / charts / editor / ExportToPdfHandler.java
index ef7cb521ce0fc7ead6ba3560790695ef073644d6..eda89cc5e389db98ca3999a9da7361dbb15286b4 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2011 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.charts.editor;\r
-\r
-import java.awt.Toolkit;\r
-import java.awt.datatransfer.Clipboard;\r
-import java.awt.datatransfer.StringSelection;\r
-import java.io.File;\r
-import java.io.IOException;\r
-import java.lang.reflect.InvocationTargetException;\r
-\r
-import org.eclipse.core.commands.AbstractHandler;\r
-import org.eclipse.core.commands.ExecutionEvent;\r
-import org.eclipse.core.commands.ExecutionException;\r
-import org.eclipse.core.runtime.IProgressMonitor;\r
-import org.eclipse.core.runtime.IStatus;\r
-import org.eclipse.core.runtime.Status;\r
-import org.eclipse.jface.operation.IRunnableWithProgress;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.widgets.Display;\r
-import org.eclipse.swt.widgets.FileDialog;\r
-import org.eclipse.swt.widgets.Shell;\r
-import org.eclipse.ui.PlatformUI;\r
-import org.eclipse.ui.handlers.HandlerUtil;\r
-import org.simantics.charts.Activator;\r
-import org.simantics.trend.impl.TrendNode;\r
-import org.simantics.trend.util.PrintUtil;\r
-import org.simantics.utils.ui.dialogs.ShowMessage;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public class ExportToPdfHandler extends AbstractHandler {\r
-\r
-    FileDialog fd;\r
-    Display display;\r
-\r
-    public ExportToPdfHandler() \r
-    {\r
-        super();\r
-        display = PlatformUI.createDisplay();\r
-        Shell shell = display.getActiveShell();\r
-        fd = new FileDialog( shell, SWT.SAVE );\r
-        fd.setText("Select PDF File");\r
-        fd.setFilterExtensions(new String[] {"*.pdf"});\r
-        fd.setFilterNames(new String[] {"PDF Documents"});\r
-    }\r
-\r
-    @Override\r
-    public Object execute(ExecutionEvent event) throws ExecutionException {\r
-        final TimeSeriesEditor editor = (TimeSeriesEditor) HandlerUtil.getActiveEditor(event);\r
-        final TrendNode trend = editor.trendNode;\r
-\r
-        // TODO: query file name from user, preferably create a wizard.\r
-        String name = trend.getTrendSpec().name;\r
-        fd.setText("Export "+name+" to PDF");\r
-\r
-        String filename = fd.open();\r
-        if (filename == null) return null;\r
-        final File f = new File( filename );\r
-\r
-        IRunnableWithProgress r = new IRunnableWithProgress() {\r
-            @Override\r
-            public void run(IProgressMonitor monitor)\r
-                    throws InvocationTargetException, InterruptedException {\r
-                try {\r
-                    // Ensure all views are built.\r
-                    monitor.setTaskName("Exporting");\r
-                    PrintUtil pu = new PrintUtil();\r
-                    pu.addTrendPage(trend);\r
-                    try {\r
-                        //File f = File.createTempFile("Trend", ".pdf");\r
-                        pu.printPdf(f);\r
-                        System.out.println("Printed Trend to "+f);\r
-                    } catch (IOException e1) {\r
-                       throw new InvocationTargetException( e1 );\r
-                    } \r
-                    monitor.setTaskName("Done");\r
-\r
-                    // Put exported file name into clipboard.\r
-                    Toolkit toolkit = Toolkit.getDefaultToolkit();\r
-                    Clipboard clipboard = toolkit.getSystemClipboard();\r
-                    StringSelection strSel = new StringSelection(f.getAbsolutePath());\r
-                    clipboard.setContents(strSel, null);\r
-                    \r
-                } finally {\r
-                    monitor.done();\r
-                }\r
-            }\r
-        };\r
-\r
-        try {\r
-            PlatformUI.getWorkbench().getProgressService().busyCursorWhile( r );\r
-        } catch (InvocationTargetException e) {\r
-               ShowMessage.showError(e.getCause().getClass().getName(), e.getCause().getMessage());            \r
-               Status s = new Status(IStatus.ERROR, Activator.PLUGIN_ID, "PDF Export failed: "+e.getCause().getMessage(), e.getCause());\r
-               Activator.getDefault().getLog().log(s);\r
-        } catch (InterruptedException e) {\r
-               Status s = new Status(IStatus.ERROR, Activator.PLUGIN_ID, "PDF Export failed: "+e.getCause().getMessage(), e.getCause());\r
-               Activator.getDefault().getLog().log(s);\r
-        }\r
-\r
-        return null;\r
-    }\r
-    \r
-    @Override\r
-    public void dispose() {\r
-       if (display!=null) {\r
-//             display.dispose();\r
-               display = null;\r
-       }\r
-       super.dispose();        \r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2011 Association for Decentralized Information Management in
+ * Industry THTH ry.
+ * 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:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.charts.editor;
+
+import java.awt.Toolkit;
+import java.awt.datatransfer.Clipboard;
+import java.awt.datatransfer.StringSelection;
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.simantics.charts.Activator;
+import org.simantics.trend.impl.TrendNode;
+import org.simantics.trend.util.PrintUtil;
+import org.simantics.utils.ui.dialogs.ShowMessage;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public class ExportToPdfHandler extends AbstractHandler {
+
+    FileDialog fd;
+    Display display;
+
+    public ExportToPdfHandler() 
+    {
+        super();
+        display = PlatformUI.createDisplay();
+        Shell shell = display.getActiveShell();
+        fd = new FileDialog( shell, SWT.SAVE );
+        fd.setText("Select PDF File");
+        fd.setFilterExtensions(new String[] {"*.pdf"});
+        fd.setFilterNames(new String[] {"PDF Documents"});
+    }
+
+    @Override
+    public Object execute(ExecutionEvent event) throws ExecutionException {
+        final TimeSeriesEditor editor = (TimeSeriesEditor) HandlerUtil.getActiveEditor(event);
+        final TrendNode trend = editor.trendNode;
+
+        // TODO: query file name from user, preferably create a wizard.
+        String name = trend.getTrendSpec().name;
+        fd.setText("Export "+name+" to PDF");
+
+        String filename = fd.open();
+        if (filename == null) return null;
+        final File f = new File( filename );
+
+        IRunnableWithProgress r = new IRunnableWithProgress() {
+            @Override
+            public void run(IProgressMonitor monitor)
+                    throws InvocationTargetException, InterruptedException {
+                try {
+                    // Ensure all views are built.
+                    monitor.setTaskName("Exporting");
+                    PrintUtil pu = new PrintUtil();
+                    pu.addTrendPage(trend);
+                    try {
+                        //File f = File.createTempFile("Trend", ".pdf");
+                        pu.printPdf(f);
+                        System.out.println("Printed Trend to "+f);
+                    } catch (IOException e1) {
+                       throw new InvocationTargetException( e1 );
+                    } 
+                    monitor.setTaskName("Done");
+
+                    // Put exported file name into clipboard.
+                    Toolkit toolkit = Toolkit.getDefaultToolkit();
+                    Clipboard clipboard = toolkit.getSystemClipboard();
+                    StringSelection strSel = new StringSelection(f.getAbsolutePath());
+                    clipboard.setContents(strSel, null);
+                    
+                } finally {
+                    monitor.done();
+                }
+            }
+        };
+
+        try {
+            PlatformUI.getWorkbench().getProgressService().busyCursorWhile( r );
+        } catch (InvocationTargetException e) {
+               ShowMessage.showError(e.getCause().getClass().getName(), e.getCause().getMessage());            
+               Status s = new Status(IStatus.ERROR, Activator.PLUGIN_ID, "PDF Export failed: "+e.getCause().getMessage(), e.getCause());
+               Activator.getDefault().getLog().log(s);
+        } catch (InterruptedException e) {
+               Status s = new Status(IStatus.ERROR, Activator.PLUGIN_ID, "PDF Export failed: "+e.getCause().getMessage(), e.getCause());
+               Activator.getDefault().getLog().log(s);
+        }
+
+        return null;
+    }
+    
+    @Override
+    public void dispose() {
+       if (display!=null) {
+//             display.dispose();
+               display = null;
+       }
+       super.dispose();        
+    }
+
+}