1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
48
49
50
51
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
122
123
124 public void addTab(TabbedView view) {
125 tabbedPane.add(view.getTabName(), view.getPane());
126 }
127
128
129
130
131 public void removeAllTabs() {
132 tabbedPane.removeAll();
133 }
134
135
136
137
138
139
140
141
142 private BasicMenuItem createMenuItem(String action) {
143 BasicMenuItem item = new BasicMenuItem();
144 item.setAction(getController().getAction(action));
145 return item;
146 }
147
148
149
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 }