View Javadoc

1   /*
2    * @(#)$Id: MainView.java 777 2010-03-11 19:45:18Z bpuype $
3    *
4    * Author   : Ueli Kurmann, igesture@uelikurmann.ch
5    *                                   
6    *                                   
7    * Purpose  : The main view of the iGesture tool.
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;
27  
28  import java.awt.Frame;
29  import java.io.File;
30  
31  import javax.swing.JMenu;
32  import javax.swing.JMenuBar;
33  import javax.swing.JTabbedPane;
34  import javax.swing.event.ChangeEvent;
35  import javax.swing.event.ChangeListener;
36  
37  import org.sigtec.graphix.widget.BasicMenu;
38  import org.sigtec.graphix.widget.BasicMenuItem;
39  import org.ximtec.igesture.tool.GestureConstants;
40  import org.ximtec.igesture.tool.core.Command;
41  import org.ximtec.igesture.tool.core.Controller;
42  import org.ximtec.igesture.tool.core.DefaultView;
43  import org.ximtec.igesture.tool.core.TabbedView;
44  import org.ximtec.igesture.tool.service.GuiBundleService;
45  
46  /**
47   * The main view of the iGesture tool.
48   * 
49   * @version 1.0 Mar 23, 2008
50   * @author Ueli Kurmann, igesture@uelikurmann.ch
51   * @author Beat Signer, signer@inf.ethz.ch
52   */
53  @SuppressWarnings("serial")
54  public class MainView extends DefaultView implements IMainView {
55  
56    private static final String TITLE_DELIMITER = " - ";
57    private JTabbedPane tabbedPane;
58    private JMenuBar menuBar;
59    private String titlePrefix;
60  
61    public MainView(Controller controller) {
62      super(controller);
63      initMenu();
64      initView();
65    }
66  
67    private void initView() {
68      setBounds(100, 100, 900, 650);
69      setDefaultCloseOperation(Frame.NORMAL);
70      titlePrefix = getComponentFactory().getGuiBundle().getName(GestureConstants.APPLICATION_ROOT);
71      setTitle(titlePrefix);
72      setIconImage(getComponentFactory().getGuiBundle().getSmallIcon(GestureConstants.APPLICATION_ROOT).getImage());
73      setVisible(true);
74      tabbedPane = new JTabbedPane();
75      this.add(tabbedPane);
76  
77      tabbedPane.addChangeListener(new ChangeListener() {
78  
79        @Override
80        public void stateChanged(ChangeEvent arg0) {
81          getController().execute(new Command(MainController.CMD_CHANGE_TAB, this));
82  
83        }
84  
85      });
86    }
87  
88    private void initMenu() {
89      menuBar = new JMenuBar();
90      setJMenuBar(menuBar);
91  
92      JMenu fileMenu = new BasicMenu(GestureConstants.FILE_MENU, getController().getLocator().getService(
93          GuiBundleService.IDENTIFIER, GuiBundleService.class));
94      menuBar.add(fileMenu);
95      
96      JMenu deviceMenu = new BasicMenu(GestureConstants.DEVICE_MENU, getController().getLocator().getService(
97      	GuiBundleService.IDENTIFIER, GuiBundleService.class));
98      menuBar.add(deviceMenu);
99      
100     JMenu helpMenu = new BasicMenu(GestureConstants.HELP_MENU, getController().getLocator().getService(
101         GuiBundleService.IDENTIFIER, GuiBundleService.class));
102     menuBar.add(helpMenu);
103 
104     fileMenu.add(createMenuItem(MainController.CMD_LOAD));
105     fileMenu.add(createMenuItem(MainController.CMD_CLOSE_WS));
106     fileMenu.addSeparator();
107     fileMenu.add(createMenuItem(MainController.CMD_SAVE));
108     fileMenu.add(createMenuItem(MainController.CMD_SAVE_AS));
109     fileMenu.addSeparator();
110     fileMenu.add(createMenuItem(MainController.CMD_EXIT));
111 
112     BasicMenuItem deviceManagerItem = new BasicMenuItem();
113     deviceManagerItem.setAction(getController().getAction(MainController.CMD_SHOW_DEVICE_MANAGER));
114     deviceMenu.add(deviceManagerItem);
115     
116     BasicMenuItem aboutItem = new BasicMenuItem();
117     aboutItem.setAction(getController().getAction(MainController.CMD_SHOW_ABOUT_DIALOG));
118     helpMenu.add(aboutItem);
119   }
120 
121   /* (non-Javadoc)
122    * @see org.ximtec.igesture.tool.view.IMainView#addTab(org.ximtec.igesture.tool.core.TabbedView)
123    */
124   public void addTab(TabbedView view) {
125     tabbedPane.add(view.getTabName(), view.getPane());
126   } // addTab
127 
128   /* (non-Javadoc)
129    * @see org.ximtec.igesture.tool.view.IMainView#removeAllTabs()
130    */
131   public void removeAllTabs() {
132     tabbedPane.removeAll();
133   } // removeAllTabs
134 
135   /**
136    * Creates a menu item. The action is identified with action string and part
137    * of the controller.
138    * 
139    * @param action
140    * @return the menu item
141    */
142   private BasicMenuItem createMenuItem(String action) {
143     BasicMenuItem item = new BasicMenuItem();
144     item.setAction(getController().getAction(action));
145     return item;
146   }
147 
148   /* (non-Javadoc)
149    * @see org.ximtec.igesture.tool.view.IMainView#setTitlePostfix(java.io.File)
150    */
151   public void setTitlePostfix(File file) {
152     if (file == null) {
153       setTitle(titlePrefix);
154     } else {
155       setTitle(titlePrefix + TITLE_DELIMITER + file.getAbsolutePath());
156     }
157 
158   }
159 
160 }