View Javadoc

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   * Menu of <b>telescope</b>.
17   * @author Jean-Philippe MINETTI
18   */
19  public final class SwtTelescopeMenu
20  {
21  
22     /**
23      * Listener for each sub-menu showing.
24      */
25     protected final class ShowListener
26              implements Listener
27     {
28  
29        /**
30         * <code>MenuItem</code> list of telescope selections.
31         */
32        private final List<MenuItem> menuItemList = new ArrayList<MenuItem> ();
33  
34        /**
35         * {@inheritDoc}
36         * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
37         */
38        public void handleEvent (final Event event)
39        {
40  
41           // Removing
42           for (final MenuItem menuItem : this.menuItemList) {
43              menuItem.dispose ();
44           }
45           this.menuItemList.clear ();
46  
47           // Separator
48           this.menuItemList.add (new MenuItem (SwtTelescopeMenu.this.telescopeMenu, SWT.SEPARATOR));
49  
50           // Telescope selections
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      * Listener for each telescope item selection.
67      */
68     protected final class TelescopeSelectionListener
69              implements Listener
70     {
71  
72        /**
73         * Telescope (as entity).
74         */
75        private final Entity entity;
76  
77        /**
78         * Constructor.
79         * @param entity Telescope (as entity).
80         */
81        protected TelescopeSelectionListener (final Entity entity)
82        {
83           super ();
84           this.entity = entity;
85        }
86  
87        /**
88         * {@inheritDoc}
89         * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
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              // TODO changement de télescope
98  
99           }
100       }
101 
102    }
103 
104    /**
105     * Process on telescopes.
106     */
107    protected final TelescopeProcess telescopeProcess = new TelescopeProcess ();
108 
109    /**
110     * Menu of telescope.
111     */
112    protected Menu telescopeMenu;
113 
114    /**
115     * Builds the menu of telescope.
116     * @param shell SWT shell.
117     * @param contextMenu Context menu.
118     */
119    public void build (final Shell shell, final Menu contextMenu)
120    {
121 
122       // Sub-menu
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       // Tour
130       buildTour (shell);
131 
132       // Tracking
133       buildTracking (shell);
134 
135       // Separator
136       menuItem = new MenuItem (this.telescopeMenu, SWT.SEPARATOR);
137 
138       // Scope parked
139       menuItem = new MenuItem (this.telescopeMenu, SWT.CHECK);
140       menuItem.setText (I18n.getGui ().getString ("menu.telescope.parked.text"));
141       // menuItem.addListener (SWT.Selection, new ObservingSiteSelectionListener (entity));
142 
143       // Installation wizard
144       menuItem = new MenuItem (this.telescopeMenu, SWT.PUSH);
145       menuItem.setText (I18n.getGui ().getString ("menu.telescope.installation.text"));
146       // menuItem.addListener (SWT.Selection, new ObservingSiteSelectionListener (entity));
147 
148       // Alignment/Sync
149       buildAlignment (shell);
150 
151       // Separator
152       menuItem = new MenuItem (this.telescopeMenu, SWT.SEPARATOR);
153 
154       // Limits enabled
155       menuItem = new MenuItem (this.telescopeMenu, SWT.CHECK);
156       menuItem.setText (I18n.getGui ().getString ("menu.telescope.limits.text"));
157       // menuItem.addListener (SWT.Selection, new ObservingSiteSelectionListener (entity));
158 
159       // Pulse guide settings
160       menuItem = new MenuItem (this.telescopeMenu, SWT.PUSH);
161       menuItem.setText (I18n.getGui ().getString ("menu.telescope.pulseguide.text"));
162       // menuItem.addListener (SWT.Selection, new ObservingSiteSelectionListener (entity));
163 
164       // ST4 port guide settings
165       menuItem = new MenuItem (this.telescopeMenu, SWT.PUSH);
166       menuItem.setText (I18n.getGui ().getString ("menu.telescope.st4guide.text"));
167       // menuItem.addListener (SWT.Selection, new ObservingSiteSelectionListener (entity));
168 
169       // PEC settings
170       menuItem = new MenuItem (this.telescopeMenu, SWT.PUSH);
171       menuItem.setText (I18n.getGui ().getString ("menu.telescope.pec.text"));
172       // menuItem.addListener (SWT.Selection, new ObservingSiteSelectionListener (entity));
173 
174       // Drift compensation settings
175       menuItem = new MenuItem (this.telescopeMenu, SWT.PUSH);
176       menuItem.setText (I18n.getGui ().getString ("menu.telescope.driftcompensation.text"));
177       // menuItem.addListener (SWT.Selection, new ObservingSiteSelectionListener (entity));
178 
179    }
180 
181    /**
182     * Builds the menu of telescope/tour.
183     * @param shell SWT shell.
184     */
185    private void buildTour (final Shell shell)
186    {
187 
188       // Sub-menu
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       // TODO
195 
196    }
197 
198    /**
199     * Builds the menu of telescope/tracking.
200     * @param shell SWT shell.
201     */
202    private void buildTracking (final Shell shell)
203    {
204 
205       // Sub-menu
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       // TODO
212 
213    }
214 
215    /**
216     * Builds the menu of telescope/alignment.
217     * @param shell SWT shell.
218     */
219    private void buildAlignment (final Shell shell)
220    {
221 
222       // Sub-menu
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       // TODO
229 
230    }
231 
232 
233 }