@@ -145,20 +145,10 @@ public void actionPerformed(ActionEvent e) {
145145 }
146146 }
147147 });
148-
148+
149149 // create a submenu for well-known events
150150 popup .add (makeWellKnownEventMenu (textfield ));
151-
152- // Add the time events
153- popup .add ( makeClockEventMenuItem (textfield ));
154151
155- // Add the accessory decoder events
156- popup .add (makeDccAccessoryEventMenuItem (textfield ));
157-
158- // popup.add("Extended DCC accessory decoder events ...");
159- // popup.add("DCC turnout feedback events ...");
160- // popup.add("DCC system sensor feedback events ...");
161-
162152 return popup ;
163153 }
164154
@@ -179,6 +169,18 @@ public static JMenu makeWellKnownEventMenu(JTextComponent textfield) {
179169 wkeMenu .add (new EventIdInserter (
180170 "Stop Default Fast Clock" , "01.01.00.00.01.00.F0.01" , textfield ));
181171
172+ // Add the time events
173+ wkeMenu .add ( makeClockEventMenuItem (textfield ));
174+
175+ // Add the accessory decoder events
176+ wkeMenu .add (makeDccAccessoryEventMenuItem (textfield ));
177+
178+ // Add the sensor events
179+ wkeMenu .add (makeDccSensorEventMenuItem (textfield ));
180+
181+ // wkeMenu.add("Extended DCC accessory decoder events ...");
182+ // wkeMenu.add("DCC turnout feedback events ...");
183+
182184 return wkeMenu ;
183185 }
184186
@@ -232,7 +234,7 @@ public static JMenuItem makeDccAccessoryEventMenuItem(JTextComponent textfield)
232234 @ Override
233235 public void actionPerformed (ActionEvent e ) {
234236 JDialog dialog = new JDialog ();
235- dialog .setTitle ("Select DCC Accessory Decoder" );
237+ dialog .setTitle ("Select DCC Accessory Decoder Address " );
236238
237239 JPanel innerPanel = new JPanel (new FlowLayout ());
238240
@@ -254,11 +256,11 @@ public void actionPerformed(ActionEvent e) {
254256 public void actionPerformed (ActionEvent e ) {
255257 int from = Integer .parseInt (number .getText ().trim ());
256258
257- // See JMRI OlcnAddress line 89 for Event ID coding
258- int DD = ( from - 1 ) & 0x3 ;
259- int aaaaaa = (( ( from - 1 ) >> 2 )+ 1 ) & 0x3F ;
260- int AAA = ( (from ) >> 8 ) & 0x7 ;
261- long event = 0x0101020000FF0000L | ( AAA << 9 ) | ( aaaaaa << 3 ) | ( DD << 1 );
259+ // See JMRI OlcnAddress line 111 for Event ID coding
260+ if ( from >= 2045 ) from = from - 2045 ;
261+ else from = from + 3 ;
262+ long event = 0x0101020000FF0000L | (from << 1 ) ;
263+
262264 event |= onOffBox .getSelectedIndex ();
263265
264266 EventID id = new EventID (String .format ("%016X" , event ));
@@ -278,6 +280,59 @@ public void actionPerformed(ActionEvent e) {
278280 return menuItem ;
279281 }
280282
283+ public static JMenuItem makeDccSensorEventMenuItem (JTextComponent textfield ) {
284+ JMenuItem menuItem = new JMenuItem ("Insert DCC sensor events ..." );
285+ menuItem .addActionListener (new ActionListener () {
286+ @ Override
287+ public void actionPerformed (ActionEvent e ) {
288+ JDialog dialog = new JDialog ();
289+ dialog .setTitle ("Select DCC Sensor Address" );
290+
291+ JPanel innerPanel = new JPanel (new FlowLayout ());
292+
293+ JTextField number = new JTextField (12 );
294+ number .setText ("1" );
295+ innerPanel .add (number );
296+
297+ JComboBox <String > onOffBox = new JComboBox <String >(
298+ new String []{
299+ "Inactive/Off" ,
300+ "Active/On"
301+ });
302+ innerPanel .add (onOffBox );
303+
304+ JButton setButton = new JButton ("Set" );
305+ innerPanel .add (setButton );
306+ setButton .addActionListener (new ActionListener () {
307+ @ Override
308+ public void actionPerformed (ActionEvent e ) {
309+ int from = Integer .parseInt (number .getText ().trim ());
310+
311+ // See JMRI OlcnAddress line 126 for Event ID coding
312+ from = 0xFFF & (from - 1 ); // 1 based name to 0 based network, 12 bit value
313+
314+ long eventActive = 0x0101020000FB0000L | from ; // active/on
315+ long eventInactive = 0x0101020000FA0000L | from ; // inactive/off
316+
317+ long event = onOffBox .getSelectedIndex () == 0 ? eventInactive : eventActive ;
318+
319+ EventID id = new EventID (String .format ("%016X" , event ));
320+ textfield .setText (id .toShortString ());
321+ dialog .dispatchEvent (new WindowEvent (dialog , WindowEvent .WINDOW_CLOSING ));
322+ }
323+ });
324+
325+ dialog .add (innerPanel );
326+ dialog .setModal (true );
327+ dialog .pack ();
328+ dialog .setDefaultCloseOperation (JFrame .DISPOSE_ON_CLOSE );
329+
330+ dialog .setVisible (true );
331+ }
332+ });
333+ return menuItem ;
334+ }
335+
281336 private static class EventIdInserter extends JMenuItem {
282337 public EventIdInserter (String name , String value , JTextComponent target ) {
283338 super (name );
0 commit comments