View Javadoc

1   /*
2    * @(#)$Id: ImportGestureSetAction.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  
27  package org.ximtec.igesture.tool.view.admin.action;
28  
29  import java.awt.event.ActionEvent;
30  import java.io.File;
31  import java.util.logging.Logger;
32  
33  import javax.swing.JFileChooser;
34  import javax.swing.JMenuItem;
35  import javax.swing.tree.TreePath;
36  
37  import org.ximtec.igesture.core.GestureSet;
38  import org.ximtec.igesture.tool.GestureConstants;
39  import org.ximtec.igesture.tool.core.Controller;
40  import org.ximtec.igesture.tool.core.TreePathAction;
41  import org.ximtec.igesture.tool.util.FileType;
42  import org.ximtec.igesture.tool.view.admin.wrapper.GestureSetList;
43  import org.ximtec.igesture.util.XMLTool;
44  
45  
46  public class ImportGestureSetAction extends TreePathAction {
47  
48     private static final Logger LOG = Logger
49           .getLogger(ImportGestureSetAction.class.getName());
50  
51  
52  
53     public ImportGestureSetAction(Controller controller, TreePath treePath) {
54        super(GestureConstants.GESTURE_SET_IMPORT, controller, treePath);
55     }
56  
57  
58     public void actionPerformed(ActionEvent event) {
59        LOG.info("Import Gesture Set...");
60        GestureSetList rootSet = (GestureSetList)getTreePath().getLastPathComponent();
61  
62        JFileChooser fileChooser = new JFileChooser();
63        fileChooser.setFileFilter(FileType.gestureSet.getFilter());
64        fileChooser.showOpenDialog((JMenuItem)event.getSource());
65        File selectedFile = fileChooser.getSelectedFile();
66  
67        if (selectedFile != null) {
68           GestureSet gestureSet = XMLTool.importGestureSet(selectedFile);
69  
70           if (gestureSet != null) {
71              rootSet.addGestureSet(gestureSet);
72           }
73        }
74        LOG.info("Gesture Set imported...");
75     } // actionPerformed
76  }