1 package org.minetti.astrodevice.client.gui.menu;
2
3 import java.util.ArrayList;
4 import java.util.List;
5 import org.eclipse.swt.SWT;
6 import org.eclipse.swt.widgets.Event;
7 import org.eclipse.swt.widgets.Listener;
8 import org.eclipse.swt.widgets.Menu;
9 import org.eclipse.swt.widgets.MenuItem;
10 import org.eclipse.swt.widgets.Shell;
11 import org.minetti.astrodevice.client.business.process.TelescopeProcess;
12 import org.minetti.astrodevice.client.i18n.I18n;
13 import org.minetti.astrodevice.common.object.Entity;
14
15
16
17
18
19 public final class SwtTelescopeMenu
20 {
21
22
23
24
25 protected final class ShowListener
26 implements Listener
27 {
28
29
30
31
32 private final List<MenuItem> menuItemList = new ArrayList<MenuItem> ();
33
34
35
36
37
38 public void handleEvent (final Event event)
39 {
40
41
42 for (final MenuItem menuItem : this.menuItemList) {
43 menuItem.dispose ();
44 }
45 this.menuItemList.clear ();
46
47
48 this.menuItemList.add (new MenuItem (SwtTelescopeMenu.this.telescopeMenu, SWT.SEPARATOR));
49
50
51 final Entity selectedTelescope = SwtTelescopeMenu.this.telescopeProcess.getSelectedTelescope ();
52 final List<Entity> entityList = SwtTelescopeMenu.this.telescopeProcess.getTelescopeList ();
53 for (final Entity entity : entityList) {
54 final MenuItem menuItem = new MenuItem (SwtTelescopeMenu.this.telescopeMenu, SWT.RADIO);
55 menuItem.setText (entity.getName ());
56 menuItem.addListener (SWT.Selection, new TelescopeSelectionListener (entity));
57 menuItem.setSelection ((selectedTelescope != null) && (selectedTelescope.getId () == entity.getId ()));
58 this.menuItemList.add (menuItem);
59 }
60
61 }
62
63 }
64
65
66
67
68 protected final class TelescopeSelectionListener
69 implements Listener
70 {
71
72
73
74
75 private final Entity entity;
76
77
78
79
80
81 protected TelescopeSelectionListener (final Entity entity)
82 {
83 super ();
84 this.entity = entity;
85 }
86
87
88
89
90
91 public void handleEvent (final Event event)
92 {
93 final MenuItem menuItem = (MenuItem) event.widget;
94 if (menuItem.getSelection ()) {
95 SwtTelescopeMenu.this.telescopeProcess.setSelectedTelescope (this.entity);
96
97
98
99 }
100 }
101
102 }
103
104
105
106
107 protected final TelescopeProcess telescopeProcess = new TelescopeProcess ();
108
109
110
111
112 protected Menu telescopeMenu;
113
114
115
116
117
118
119 public void build (final Shell shell, final Menu contextMenu)
120 {
121
122
123 MenuItem menuItem = new MenuItem (contextMenu, SWT.CASCADE);
124 menuItem.setText (I18n.getGui ().getString ("menu.telescope.text"));
125 this.telescopeMenu = new Menu (shell, SWT.DROP_DOWN);
126 this.telescopeMenu.addListener (SWT.Show, new ShowListener ());
127 menuItem.setMenu (this.telescopeMenu);
128
129
130 buildTour (shell);
131
132
133 buildTracking (shell);
134
135
136 menuItem = new MenuItem (this.telescopeMenu, SWT.SEPARATOR);
137
138
139 menuItem = new MenuItem (this.telescopeMenu, SWT.CHECK);
140 menuItem.setText (I18n.getGui ().getString ("menu.telescope.parked.text"));
141
142
143
144 menuItem = new MenuItem (this.telescopeMenu, SWT.PUSH);
145 menuItem.setText (I18n.getGui ().getString ("menu.telescope.installation.text"));
146
147
148
149 buildAlignment (shell);
150
151
152 menuItem = new MenuItem (this.telescopeMenu, SWT.SEPARATOR);
153
154
155 menuItem = new MenuItem (this.telescopeMenu, SWT.CHECK);
156 menuItem.setText (I18n.getGui ().getString ("menu.telescope.limits.text"));
157
158
159
160 menuItem = new MenuItem (this.telescopeMenu, SWT.PUSH);
161 menuItem.setText (I18n.getGui ().getString ("menu.telescope.pulseguide.text"));
162
163
164
165 menuItem = new MenuItem (this.telescopeMenu, SWT.PUSH);
166 menuItem.setText (I18n.getGui ().getString ("menu.telescope.st4guide.text"));
167
168
169
170 menuItem = new MenuItem (this.telescopeMenu, SWT.PUSH);
171 menuItem.setText (I18n.getGui ().getString ("menu.telescope.pec.text"));
172
173
174
175 menuItem = new MenuItem (this.telescopeMenu, SWT.PUSH);
176 menuItem.setText (I18n.getGui ().getString ("menu.telescope.driftcompensation.text"));
177
178
179 }
180
181
182
183
184
185 private void buildTour (final Shell shell)
186 {
187
188
189 MenuItem menuItem = new MenuItem (this.telescopeMenu, SWT.CASCADE);
190 menuItem.setText (I18n.getGui ().getString ("menu.telescope.tour.text"));
191 final Menu subMenu = new Menu (shell, SWT.DROP_DOWN);
192 menuItem.setMenu (subMenu);
193
194
195
196 }
197
198
199
200
201
202 private void buildTracking (final Shell shell)
203 {
204
205
206 MenuItem menuItem = new MenuItem (this.telescopeMenu, SWT.CASCADE);
207 menuItem.setText (I18n.getGui ().getString ("menu.telescope.tracking.text"));
208 final Menu subMenu = new Menu (shell, SWT.DROP_DOWN);
209 menuItem.setMenu (subMenu);
210
211
212
213 }
214
215
216
217
218
219 private void buildAlignment (final Shell shell)
220 {
221
222
223 MenuItem menuItem = new MenuItem (this.telescopeMenu, SWT.CASCADE);
224 menuItem.setText (I18n.getGui ().getString ("menu.telescope.alignment.text"));
225 final Menu subMenu = new Menu (shell, SWT.DROP_DOWN);
226 menuItem.setMenu (subMenu);
227
228
229
230 }
231
232
233 }