001package jmri.jmrit.dispatcher; 002 003import java.awt.BorderLayout; 004import java.awt.Container; 005import java.awt.FlowLayout; 006import java.awt.event.ActionEvent; 007import java.awt.event.ActionListener; 008import java.util.ArrayList; 009import java.util.Enumeration; 010 011import javax.swing.BorderFactory; 012import javax.swing.BoxLayout; 013import javax.swing.ButtonGroup; 014import javax.swing.JButton; 015import javax.swing.JCheckBox; 016import javax.swing.JCheckBoxMenuItem; 017import javax.swing.JComboBox; 018import javax.swing.JLabel; 019import javax.swing.JMenu; 020import javax.swing.JMenuItem; 021import javax.swing.JPanel; 022import javax.swing.JRadioButton; 023import javax.swing.JScrollPane; 024import javax.swing.JSeparator; 025import javax.swing.JSpinner; 026import javax.swing.SpinnerNumberModel; 027 028import jmri.InstanceManager; 029import jmri.Scale; 030import jmri.ScaleManager; 031import jmri.implementation.SignalSpeedMap; 032import jmri.jmrit.dispatcher.DispatcherFrame.TrainsFrom; 033import jmri.jmrit.display.EditorManager; 034import jmri.jmrit.display.layoutEditor.LayoutEditor; 035import jmri.util.JmriJFrame; 036import jmri.util.swing.JmriJOptionPane; 037 038/** 039 * Set up and processes items in the Dispatcher Options menu. 040 * 041 * @author Dave Duchamp Copyright (C) 2008 042 */ 043public class OptionsMenu extends JMenu { 044 045 // Empty constructor for class based preferences when "Skip message in future?" is enabled. 046 public OptionsMenu() { 047 } 048 049 public OptionsMenu(DispatcherFrame f) { 050 dispatcher = f; 051 this.setText(Bundle.getMessage("MenuOptions")); 052 autoDispatchItem = new JCheckBoxMenuItem(Bundle.getMessage("AutoDispatchItem")); 053 this.add(autoDispatchItem); 054 autoDispatchItem.addActionListener(new ActionListener() { 055 @Override 056 public void actionPerformed(ActionEvent event) { 057 handleAutoDispatch(event); 058 } 059 }); 060 autoTurnoutsItem = new JCheckBoxMenuItem(Bundle.getMessage("AutoTurnoutsItem")); 061 this.add(autoTurnoutsItem); 062 autoTurnoutsItem.addActionListener(new ActionListener() { 063 @Override 064 public void actionPerformed(ActionEvent event) { 065 handleAutoTurnouts(event); 066 } 067 }); 068 JMenuItem optionWindowItem = new JMenuItem(Bundle.getMessage("OptionWindowItem") + "..."); 069 this.add(optionWindowItem); 070 optionWindowItem.addActionListener(new ActionListener() { 071 @Override 072 public void actionPerformed(ActionEvent event) { 073 optionWindowRequested(event); 074 } 075 }); 076 JMenuItem saveOptionsItem = new JMenuItem(Bundle.getMessage("SaveOptionsItem")); 077 this.add(saveOptionsItem); 078 saveOptionsItem.addActionListener(new ActionListener() { 079 @Override 080 public void actionPerformed(ActionEvent event) { 081 saveRequested(event); 082 } 083 }); 084 initializeMenu(); 085 } 086 087 protected DispatcherFrame dispatcher = null; 088 089 // Option menu items 090 private JCheckBoxMenuItem autoDispatchItem = null; 091 private JCheckBoxMenuItem autoTurnoutsItem = null; 092 093 // Initialize check box items in menu from Dispatcher 094 public void initializeMenu() { 095 autoDispatchItem.setSelected(dispatcher.getAutoAllocate()); 096 autoTurnoutsItem.setSelected(dispatcher.getAutoTurnouts()); 097 } 098 099 private void handleAutoDispatch(ActionEvent e) { 100 boolean set = autoDispatchItem.isSelected(); 101 dispatcher.setAutoAllocate(set); 102 } 103 104 private void handleAutoTurnouts(ActionEvent e) { 105 boolean set = autoTurnoutsItem.isSelected(); 106 dispatcher.setAutoTurnouts(set); 107 } 108 109 // options window items 110 JmriJFrame optionsFrame = null; 111 Container optionsContainer = null; 112 JPanel optionsPane = null; 113 JCheckBox useConnectivityCheckBox = new JCheckBox(Bundle.getMessage("UseConnectivity")); 114 ArrayList<LayoutEditor> layoutEditorList = new ArrayList<>(); 115 116 JCheckBox autoAllocateCheckBox = new JCheckBox(Bundle.getMessage("AutoAllocateBox")); 117 JCheckBox autoTurnoutsCheckBox = new JCheckBox(Bundle.getMessage("AutoTurnoutsBox")); 118 JRadioButton trainsFromRoster = new JRadioButton(Bundle.getMessage("TrainsFromRoster")); 119 JRadioButton trainsFromTrains = new JRadioButton(Bundle.getMessage("TrainsFromTrains")); 120 JRadioButton trainsFromUser = new JRadioButton(Bundle.getMessage("TrainsFromUser")); 121 JComboBox<String> signalTypeBox; 122 JCheckBox detectionCheckBox = new JCheckBox(Bundle.getMessage("DetectionBox")); 123 JCheckBox setSSLDirectionalSensorsCheckBox = new JCheckBox(Bundle.getMessage("SetSSLDirectionSensorsBox")); 124 JCheckBox shortNameCheckBox = new JCheckBox(Bundle.getMessage("ShortNameBox")); 125 JCheckBox nameInBlockCheckBox = new JCheckBox(Bundle.getMessage("NameInBlockBox")); 126 JCheckBox rosterInBlockCheckBox = new JCheckBox(Bundle.getMessage("RosterInBlockBox")); 127 JCheckBox extraColorForAllocatedCheckBox = new JCheckBox(Bundle.getMessage("ExtraColorForAllocatedBox")); 128 JCheckBox nameInAllocatedBlockCheckBox = new JCheckBox(Bundle.getMessage("NameInAllocatedBlockBox")); 129 JCheckBox supportVSDecoderCheckBox = new JCheckBox(Bundle.getMessage("SupportVSDecoder")); 130 JComboBox<Scale> layoutScaleBox = new JComboBox<>(); 131 JRadioButton scaleFeet = new JRadioButton(Bundle.getMessage("ScaleFeet")); 132 JRadioButton scaleMeters = new JRadioButton(Bundle.getMessage("ScaleMeters")); 133 JCheckBox openDispatcherWithPanel = new JCheckBox(Bundle.getMessage("OpenDispatcherWithPanelBox")); 134 JSpinner minThrottleIntervalSpinner = new JSpinner(new SpinnerNumberModel(100, 20, 1000, 1)); 135 JSpinner fullRampTimeSpinner = new JSpinner(new SpinnerNumberModel(5000, 1000, 20000, 1)); 136 JCheckBox trustKnownTurnoutsCheckBox = new JCheckBox(Bundle.getMessage("trustKnownTurnouts")); 137 JCheckBox useTurnoutConnectionDelayCheckBox = new JCheckBox(Bundle.getMessage("useTurnoutConnectionDelay")); 138 JComboBox<String> stoppingSpeedBox = new JComboBox<>(); 139 JCheckBox useOccupiedTrackSpeedCheckBox = new JCheckBox(Bundle.getMessage("useOccupiedTrackSpeed")); 140 JCheckBox useStrictTrainTrackingBox = new JCheckBox(Bundle.getMessage("useStrictTrackChecking")); 141 142 String[] signalTypes = {Bundle.getMessage("SignalType1"), Bundle.getMessage("SignalType2"), Bundle.getMessage("SignalType3")}; 143 144 private void optionWindowRequested(ActionEvent e) { 145 if (optionsFrame == null) { 146 optionsFrame = new JmriJFrame(Bundle.getMessage("OptionWindowItem"), false, true); 147 optionsFrame.addHelpMenu("package.jmri.jmrit.dispatcher.Options", true); 148 optionsContainer = optionsFrame.getContentPane(); 149 optionsPane = new JPanel(); 150 optionsPane.setLayout(new BoxLayout(optionsPane, BoxLayout.Y_AXIS)); 151 JPanel p1 = new JPanel(); 152 p1.setLayout(new FlowLayout()); 153 p1.add(useConnectivityCheckBox); 154 useConnectivityCheckBox.setToolTipText(Bundle.getMessage("UseConnectivityHint")); 155 signalTypeBox = new JComboBox<>(signalTypes); 156 p1.add(signalTypeBox); 157 signalTypeBox.setToolTipText(Bundle.getMessage("SignalTypeHint")); 158 optionsPane.add(p1); 159 JPanel p2 = new JPanel(); 160 p2.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("TrainsFrom"))); 161 p2.setLayout(new FlowLayout()); 162 ButtonGroup trainsGroup = new ButtonGroup(); 163 p2.add(trainsFromRoster); 164 trainsFromRoster.setToolTipText(Bundle.getMessage("TrainsFromRosterHint")); 165 trainsGroup.add(trainsFromRoster); 166 167 ActionListener useRosterEntryListener = new ActionListener() { 168 @Override 169 public void actionPerformed(ActionEvent e) { 170 if (trainsFromRoster.isSelected()) { 171 rosterInBlockCheckBox.setEnabled(true); 172 if (nameInBlockCheckBox.isSelected() && e.getSource() == nameInBlockCheckBox) { 173 rosterInBlockCheckBox.setSelected(false); 174 } else if (rosterInBlockCheckBox.isSelected() && e.getSource() == rosterInBlockCheckBox) { 175 nameInBlockCheckBox.setSelected(false); 176 } 177 } else { 178 rosterInBlockCheckBox.setEnabled(false); 179 } 180 } 181 }; 182 trainsFromRoster.addActionListener(useRosterEntryListener); 183 p2.add(new JLabel(" ")); 184 p2.add(trainsFromTrains); 185 trainsFromTrains.setToolTipText(Bundle.getMessage("TrainsFromTrainsHint")); 186 trainsFromTrains.addActionListener(useRosterEntryListener); 187 trainsGroup.add(trainsFromTrains); 188 p2.add(new JLabel(" ")); 189 p2.add(trainsFromUser); 190 trainsFromUser.setToolTipText(Bundle.getMessage("TrainsFromUserHint")); 191 trainsFromUser.addActionListener(useRosterEntryListener); 192 trainsGroup.add(trainsFromUser); 193 optionsPane.add(p2); 194 JPanel p3 = new JPanel(); 195 p3.setLayout(new FlowLayout()); 196 p3.add(detectionCheckBox); 197 detectionCheckBox.setToolTipText(Bundle.getMessage("DetectionBoxHint")); 198 optionsPane.add(p3); 199 JPanel p3A = new JPanel(); 200 p3A.setLayout(new FlowLayout()); 201 p3A.add(setSSLDirectionalSensorsCheckBox); 202 setSSLDirectionalSensorsCheckBox.setToolTipText(Bundle.getMessage("SetSSLDirectionSensorsBoxHint")); 203 optionsPane.add(p3A); 204 JPanel p4 = new JPanel(); 205 p4.setLayout(new FlowLayout()); 206 p4.add(autoAllocateCheckBox); 207 autoAllocateCheckBox.setToolTipText(Bundle.getMessage("AutoAllocateBoxHint")); 208 optionsPane.add(p4); 209 JPanel p5 = new JPanel(); 210 p5.setLayout(new FlowLayout()); 211 p5.add(autoTurnoutsCheckBox); 212 autoTurnoutsCheckBox.setToolTipText(Bundle.getMessage("AutoTurnoutsBoxHint")); 213 optionsPane.add(p5); 214 JPanel p16 = new JPanel(); 215 p16.setLayout(new FlowLayout()); 216 p16.add(trustKnownTurnoutsCheckBox); 217 trustKnownTurnoutsCheckBox.setToolTipText(Bundle.getMessage("trustKnownTurnoutsHint")); 218 optionsPane.add(p16); 219 JPanel p16a = new JPanel(); 220 p16a.setLayout(new FlowLayout()); 221 p16a.add(useTurnoutConnectionDelayCheckBox); 222 useTurnoutConnectionDelayCheckBox.setToolTipText(Bundle.getMessage("trustKnownTurnoutsHint")); 223 optionsPane.add(p16a); 224 JPanel p16b = new JPanel(); 225 p16b.setLayout(new FlowLayout()); 226 p16b.add(useOccupiedTrackSpeedCheckBox); 227 useOccupiedTrackSpeedCheckBox.setToolTipText(Bundle.getMessage("useOccupiedTrackSpeedHint")); 228 optionsPane.add(p16b); 229 JPanel p16c = new JPanel(); 230 p16c.setLayout(new FlowLayout()); 231 p16c.add(useStrictTrainTrackingBox); 232 useStrictTrainTrackingBox.setToolTipText(Bundle.getMessage("useStrictTrackCheckingHint")); 233 optionsPane.add(p16c); 234 JPanel p6 = new JPanel(); 235 p6.setLayout(new FlowLayout()); 236 p6.add(shortNameCheckBox); 237 shortNameCheckBox.setToolTipText(Bundle.getMessage("ShortNameBoxHint")); 238 optionsPane.add(p6); 239 JPanel p7 = new JPanel(); 240 p7.setLayout(new FlowLayout()); 241 p7.add(nameInBlockCheckBox); 242 nameInBlockCheckBox.setToolTipText(Bundle.getMessage("NameInBlockBoxHint")); 243 nameInBlockCheckBox.addActionListener(useRosterEntryListener); 244 optionsPane.add(p7); 245 JPanel p7b = new JPanel(); 246 p7b.setLayout(new FlowLayout()); 247 p7b.add(rosterInBlockCheckBox); 248 rosterInBlockCheckBox.setToolTipText(Bundle.getMessage("RosterInBlockBoxHint")); 249 rosterInBlockCheckBox.addActionListener(useRosterEntryListener); 250 optionsPane.add(p7b); 251 252 JPanel p10 = new JPanel(); 253 p10.setLayout(new FlowLayout()); 254 p10.add(extraColorForAllocatedCheckBox); 255 extraColorForAllocatedCheckBox.setToolTipText(Bundle.getMessage("ExtraColorForAllocatedBoxHint")); 256 optionsPane.add(p10); 257 JPanel p11 = new JPanel(); 258 p11.setLayout(new FlowLayout()); 259 p11.add(nameInAllocatedBlockCheckBox); 260 nameInAllocatedBlockCheckBox.setToolTipText(Bundle.getMessage("NameInAllocatedBlockBoxHint")); 261 optionsPane.add(p11); 262 JPanel p13 = new JPanel(); 263 p13.setLayout(new FlowLayout()); 264 p13.add(supportVSDecoderCheckBox); 265 supportVSDecoderCheckBox.setToolTipText(Bundle.getMessage("SupportVSDecoderBoxHint")); 266 optionsPane.add(p13); 267 JPanel p8 = new JPanel(); 268 initializeScaleCombo(); 269 p8.add(new JLabel(Bundle.getMessage("LabelLayoutScale"))); 270 p8.add(layoutScaleBox); 271 layoutScaleBox.setToolTipText(Bundle.getMessage("ScaleBoxHint")); 272 optionsPane.add(p8); 273 JPanel p12 = new JPanel(); 274 p12.setLayout(new FlowLayout()); 275 p12.add(new JLabel(Bundle.getMessage("Units") + " ")); 276 ButtonGroup scaleGroup = new ButtonGroup(); 277 p12.add(scaleFeet); 278 scaleFeet.setToolTipText(Bundle.getMessage("ScaleFeetHint")); 279 scaleGroup.add(scaleFeet); 280 p12.add(new JLabel(" ")); 281 p12.add(scaleMeters); 282 scaleMeters.setToolTipText(Bundle.getMessage("ScaleMetersHint")); 283 scaleGroup.add(scaleMeters); 284 optionsPane.add(p12); 285 286 JPanel p14 = new JPanel(); 287 initializeStoppingSpeedCombo(); 288 p14.add(new JLabel(Bundle.getMessage("LabelStoppingSpeed"))); 289 p14.add(stoppingSpeedBox); 290 stoppingSpeedBox.setToolTipText(Bundle.getMessage("StoppingSpeedHint")); 291 optionsPane.add(p14); 292 293 JPanel p15 = new JPanel(); 294 p15.setLayout(new FlowLayout()); 295 p15.add(new JLabel(Bundle.getMessage("minThrottleInterval") + ":")); 296 minThrottleIntervalSpinner.setToolTipText(Bundle.getMessage("minThrottleIntervalHint")); 297 p15.add(minThrottleIntervalSpinner); 298 p15.add(new JLabel(Bundle.getMessage("LabelMilliseconds"))); 299 optionsPane.add(p15); 300 301 JPanel p17 = new JPanel(); 302 p17.setLayout(new FlowLayout()); 303 p17.add(new JLabel(Bundle.getMessage("fullRampTime") + " :")); 304 fullRampTimeSpinner.setToolTipText(Bundle.getMessage("fullRampTimeHint", Bundle.getMessage("RAMP_FAST"))); 305 p17.add(fullRampTimeSpinner); 306 p17.add(new JLabel(Bundle.getMessage("LabelMilliseconds"))); 307 optionsPane.add(p17); 308 309 JPanel p18 = new JPanel(); 310 p18.setLayout(new FlowLayout()); 311 p18.add(openDispatcherWithPanel); 312 openDispatcherWithPanel.setToolTipText(Bundle.getMessage("OpenDispatcherWithPanelBoxHint")); 313 optionsPane.add(p18); 314 315 optionsPane.add(new JSeparator()); 316 JPanel ftr = new JPanel(); 317 JPanel p9 = new JPanel(); 318 p9.setLayout(new FlowLayout()); 319 JButton cancelButton = null; 320 p9.add(cancelButton = new JButton(Bundle.getMessage("ButtonCancel"))); 321 cancelButton.addActionListener(new ActionListener() { 322 @Override 323 public void actionPerformed(ActionEvent e) { 324 cancelOptions(e); 325 } 326 }); 327 cancelButton.setToolTipText(Bundle.getMessage("CancelButtonHint2")); 328 p9.add(new JLabel(" ")); 329 JButton applyButton = null; 330 p9.add(applyButton = new JButton(Bundle.getMessage("ButtonApply"))); 331 applyButton.addActionListener(new ActionListener() { 332 @Override 333 public void actionPerformed(ActionEvent e) { 334 applyOptions(e); 335 } 336 }); 337 applyButton.setToolTipText(Bundle.getMessage("ApplyButtonHint")); 338 ftr.add(p9); 339 JScrollPane scrPane = new JScrollPane(optionsPane); 340 optionsContainer.add(scrPane, BorderLayout.CENTER); 341 optionsContainer.add(ftr, BorderLayout.SOUTH); 342 343 } 344 345 initializeLayoutEditorList(); 346 useConnectivityCheckBox.setEnabled(!layoutEditorList.isEmpty()); 347 useConnectivityCheckBox.setSelected(dispatcher.getUseConnectivity()); 348 349 signalTypeBox.setSelectedIndex(dispatcher.getSignalType()); 350 switch (dispatcher.getTrainsFrom()) { 351 case TRAINSFROMROSTER: 352 trainsFromRoster.setSelected(true); 353 break; 354 case TRAINSFROMOPS: 355 trainsFromTrains.setSelected(true); 356 break; 357 case TRAINSFROMUSER: 358 default: 359 trainsFromUser.setSelected(true); 360 } 361 detectionCheckBox.setSelected(dispatcher.getHasOccupancyDetection()); 362 setSSLDirectionalSensorsCheckBox.setSelected(dispatcher.getSetSSLDirectionalSensors()); 363 autoAllocateCheckBox.setSelected(dispatcher.getAutoAllocate()); 364 autoTurnoutsCheckBox.setSelected(dispatcher.getAutoTurnouts()); 365 trustKnownTurnoutsCheckBox.setSelected(dispatcher.getTrustKnownTurnouts()); 366 useOccupiedTrackSpeedCheckBox.setSelected(dispatcher.getUseOccupiedTrackSpeed()); 367 useStrictTrainTrackingBox.setSelected(dispatcher.getUseStrictTrainTracking()); 368 useTurnoutConnectionDelayCheckBox.setSelected(dispatcher.getUseTurnoutConnectionDelay()); 369 shortNameCheckBox.setSelected(dispatcher.getShortActiveTrainNames()); 370 nameInBlockCheckBox.setSelected(dispatcher.getShortNameInBlock()); 371 rosterInBlockCheckBox.setSelected(dispatcher.getRosterEntryInBlock()); 372 extraColorForAllocatedCheckBox.setSelected(dispatcher.getExtraColorForAllocated()); 373 nameInAllocatedBlockCheckBox.setSelected(dispatcher.getNameInAllocatedBlock()); 374 supportVSDecoderCheckBox.setSelected(dispatcher.getSupportVSDecoder()); 375 scaleMeters.setSelected(dispatcher.getUseScaleMeters()); 376 scaleFeet.setSelected(!dispatcher.getUseScaleMeters()); 377 minThrottleIntervalSpinner.setValue(dispatcher.getMinThrottleInterval()); 378 fullRampTimeSpinner.setValue(dispatcher.getFullRampTime()); 379 380 boolean openDispatcher = false; 381 for (LayoutEditor panel : layoutEditorList) { 382 if (panel.getOpenDispatcherOnLoad()) { 383 openDispatcher = true; 384 } 385 } 386 openDispatcherWithPanel.setSelected(openDispatcher); 387 openDispatcherWithPanel.setEnabled(!layoutEditorList.isEmpty()); 388 389 optionsFrame.pack(); 390 optionsFrame.setVisible(true); 391 } 392 393 private void applyOptions(ActionEvent e) { 394 dispatcher.setUseConnectivity(useConnectivityCheckBox.isSelected()); 395 dispatcher.setSetSSLDirectionalSensors(setSSLDirectionalSensorsCheckBox.isSelected()); 396 if (trainsFromRoster.isSelected()) { 397 dispatcher.setTrainsFrom(TrainsFrom.TRAINSFROMROSTER); 398 } else if (trainsFromTrains.isSelected()) { 399 dispatcher.setTrainsFrom(TrainsFrom.TRAINSFROMOPS); 400 } else { 401 dispatcher.setTrainsFrom(TrainsFrom.TRAINSFROMUSER); 402 } 403 dispatcher.setHasOccupancyDetection(detectionCheckBox.isSelected()); 404 dispatcher.setAutoAllocate(autoAllocateCheckBox.isSelected()); 405 autoDispatchItem.setSelected(autoAllocateCheckBox.isSelected()); 406 dispatcher.setAutoTurnouts(autoTurnoutsCheckBox.isSelected()); 407 autoTurnoutsItem.setSelected(autoTurnoutsCheckBox.isSelected()); 408 dispatcher.setTrustKnownTurnouts(trustKnownTurnoutsCheckBox.isSelected()); 409 dispatcher.setUseOccupiedTrackSpeed(useOccupiedTrackSpeedCheckBox.isSelected()); 410 dispatcher.setUseStrictTrainTracking(useStrictTrainTrackingBox.isSelected()); 411 dispatcher.setUseTurnoutConnectionDelay(useTurnoutConnectionDelayCheckBox.isSelected()); 412 dispatcher.setSignalType(signalTypeBox.getSelectedIndex()); 413 if (autoTurnoutsCheckBox.isSelected() && ((layoutEditorList.size() == 0) 414 || (!useConnectivityCheckBox.isSelected()))) { 415 JmriJOptionPane.showMessageDialog(optionsFrame, Bundle.getMessage( 416 "AutoTurnoutsWarn"), Bundle.getMessage("WarningTitle"), JmriJOptionPane.WARNING_MESSAGE); 417 } 418 dispatcher.setShortActiveTrainNames(shortNameCheckBox.isSelected()); 419 dispatcher.setShortNameInBlock(nameInBlockCheckBox.isSelected()); 420 dispatcher.setExtraColorForAllocated(extraColorForAllocatedCheckBox.isSelected()); 421 dispatcher.setNameInAllocatedBlock(nameInAllocatedBlockCheckBox.isSelected()); 422 dispatcher.setRosterEntryInBlock(rosterInBlockCheckBox.isSelected()); 423 dispatcher.setSupportVSDecoder(supportVSDecoderCheckBox.isSelected()); 424 dispatcher.setScale((Scale) layoutScaleBox.getSelectedItem()); 425 dispatcher.setUseScaleMeters(scaleMeters.isSelected()); 426 dispatcher.setMinThrottleInterval((int) minThrottleIntervalSpinner.getValue()); 427 dispatcher.setFullRampTime((int) fullRampTimeSpinner.getValue()); 428 429 for (LayoutEditor panel : layoutEditorList) { 430 panel.setOpenDispatcherOnLoad(openDispatcherWithPanel.isSelected()); 431 } 432 433 dispatcher.setStoppingSpeedName( (String) stoppingSpeedBox.getSelectedItem()); 434 optionsFrame.setVisible(false); 435 optionsFrame.dispose(); // prevent this window from being listed in the Window menu. 436 optionsFrame = null; 437 // display save options reminder 438 InstanceManager.getDefault(jmri.UserPreferencesManager.class). 439 showInfoMessage(this,Bundle.getMessage("ReminderTitle"), Bundle.getMessage("ReminderSaveOptions"), 440 OptionsMenu.class.getName(), 441 "remindSaveDispatcherOptions"); // NOI18N 442 initializeMenu(); 443 } 444 445 /** 446 * Get the class description for the UserMessagePreferencesPane. 447 * @return The class description 448 */ 449 public String getClassDescription() { 450 return Bundle.getMessage("OptionWindowItem"); 451 } 452 453 /** 454 * Set the item details for the UserMessagePreferencesPane. 455 */ 456 public void setMessagePreferencesDetails() { 457 InstanceManager.getDefault(jmri.UserPreferencesManager.class). 458 setPreferenceItemDetails(OptionsMenu.class.getName(), "remindSaveDispatcherOptions", Bundle.getMessage("HideSaveReminder")); // NOI18N 459 } 460 461 private void cancelOptions(ActionEvent e) { 462 optionsFrame.setVisible(false); 463 optionsFrame.dispose(); // prevent this window from being listed in the Window menu. 464 optionsFrame = null; 465 } 466 467 /** 468 * Save Dispatcher Option settings from pane to xml file. 469 * 470 * @param e the calling actionevent 471 */ 472 private void saveRequested(ActionEvent e) { 473 try { 474 InstanceManager.getDefault(OptionsFile.class).writeDispatcherOptions(dispatcher); 475 } catch (java.io.IOException ioe) { 476 log.error("Exception writing Dispatcher options", ioe); 477 } 478 } 479 480 private void initializeLayoutEditorList() { 481 // get list of Layout Editor panels 482 layoutEditorList = new ArrayList<>(InstanceManager.getDefault(EditorManager.class).getAll(LayoutEditor.class)); 483 } 484 485 private void initializeScaleCombo() { 486 layoutScaleBox.removeAllItems(); 487 for (Scale scale : ScaleManager.getScales()) { 488 if (scale.getScaleName().equals("CUSTOM")) { // No custom support yet, don't show. 489 continue; 490 } 491 layoutScaleBox.addItem(scale); 492 } 493 jmri.util.swing.JComboBoxUtil.setupComboBoxMaxRows(layoutScaleBox); 494 layoutScaleBox.setSelectedItem(dispatcher.getScale()); 495 } 496 497 private void initializeStoppingSpeedCombo() { 498 stoppingSpeedBox.removeAllItems(); 499 Enumeration<String> speedNamesList = jmri.InstanceManager.getDefault(SignalSpeedMap.class).getSpeedIterator(); 500 while (speedNamesList.hasMoreElements()) { 501 stoppingSpeedBox.addItem(speedNamesList.nextElement()); 502 } 503 stoppingSpeedBox.setSelectedItem(dispatcher.getStoppingSpeedName()); 504 } 505 506 private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(OptionsMenu.class); 507 508}