View Javadoc

1   /*
2    * @(#)$Id: ExportPDFGestureSetAction.java 775 2009-11-27 16:22:42Z kurmannu $
3    *
4    * Author   : Ueli Kurmann, igesture@uelikurmann.ch
5    *                                   
6    *                                   
7    * Purpose  : 
8    *
9    * -----------------------------------------------------------------------
10   *
11   * Revision Information:
12   *
13   * Date       Who     Reason
14   *
15   * 23.03.2008 ukurmann  Initial Release
16   *
17   * -----------------------------------------------------------------------
18   *
19   * Copyright 1999-2009 ETH Zurich. All Rights Reserved.
20   *
21   * This software is the proprietary information of ETH Zurich.
22   * Use is subject to license terms.
23   * 
24   */
25  
26  package org.ximtec.igesture.tool.view.admin.action;
27  
28  import hacks.PDFTool;
29  
30  import java.awt.event.ActionEvent;
31  import java.io.File;
32  import java.util.logging.Level;
33  import java.util.logging.Logger;
34  
35  import javax.swing.JFileChooser;
36  import javax.swing.JMenuItem;
37  import javax.swing.tree.TreePath;
38  
39  import org.sigtec.util.Constant;
40  import org.ximtec.igesture.core.GestureSet;
41  import org.ximtec.igesture.tool.GestureConstants;
42  import org.ximtec.igesture.tool.core.Controller;
43  import org.ximtec.igesture.tool.core.TreePathAction;
44  import org.ximtec.igesture.tool.util.FileType;
45  
46  import com.lowagie.text.Document;
47  import com.lowagie.text.DocumentException;
48  
49  
50  public class ExportPDFGestureSetAction extends TreePathAction {
51  
52     private static final Logger LOG = Logger
53           .getLogger(ExportPDFGestureSetAction.class.getName());
54  
55     public ExportPDFGestureSetAction(Controller controller, TreePath treePath) {
56        super(GestureConstants.GESTURE_SET_PDF, controller, treePath);
57     }
58  
59  
60     public void actionPerformed(ActionEvent event) {
61  
62        GestureSet gestureSet = (GestureSet)getTreePath().getLastPathComponent();
63  
64        Document.compress = false;
65        JFileChooser fileChooser = new JFileChooser();
66        fileChooser.setFileFilter(FileType.pdf.getFilter());
67        fileChooser.showSaveDialog((JMenuItem)event.getSource());
68        File selectedFile = fileChooser.getSelectedFile();
69  
70        if (selectedFile != null) {
71           Document document = PDFTool.createDocument(selectedFile);
72           document.open();
73  
74           try {
75              document.add(PDFTool.createGestureSetTable(gestureSet));
76           }
77           catch (DocumentException e) {
78              LOG.log(Level.SEVERE, Constant.EMPTY_STRING, e);
79           }
80  
81           document.close();
82        }
83  
84     } // actionPerformed
85  
86  }