001package jmri.jmrit.signalling;
002
003import jmri.InstanceManager;
004import jmri.SignalMast;
005import jmri.util.JmriJFrame;
006import jmri.util.swing.JmriJOptionPane;
007
008/**
009 * @author Kevin Dickerson Copyright (C) 2011
010 */
011public class SignallingGuiTools {
012
013    private SignallingGuiTools() {
014    }
015
016    /**
017     * Display a message to the user asking them to
018     * confirm they wish to update the Signal Mast Logic from the old signal
019     * mast to the new one.
020     *
021     * @param frame the frame initiating the dialog
022     * @param oldMast original signal mast (object) for this SML
023     * @param newMast new main signal mast (object) to attach to SML
024     */
025    static public void updateSignalMastLogic(JmriJFrame frame, SignalMast oldMast, SignalMast newMast) {
026        Object[] options = {Bundle.getMessage("ButtonUpdate"), Bundle.getMessage("LeaveButton")};
027        int n = JmriJOptionPane.showOptionDialog(frame,
028                java.text.MessageFormat.format(Bundle.getMessage("UpdateLogic"),  // NOI18N
029                        new Object[]{oldMast.getDisplayName(), newMast.getDisplayName()}),
030                Bundle.getMessage("UpdateLogicTitle"),
031                JmriJOptionPane.DEFAULT_OPTION,
032                JmriJOptionPane.QUESTION_MESSAGE,
033                null,
034                options,
035                options[0]);
036        if (n == 0) { // array position 0, ButtonUpdate 
037            InstanceManager.getDefault(jmri.SignalMastLogicManager.class).replaceSignalMast(oldMast, newMast);
038        }
039    }
040
041    /**
042     * Display a message to the user asking them to confirm they wish to update
043     * the Signal Mast Logic by swapping two signal masts.
044     *
045     * @param frame the frame initiating the dialog
046     * @param oldMast signal mast (object) #1
047     * @param newMast signal mast (object) #2
048     */
049    static public void swapSignalMastLogic(JmriJFrame frame, SignalMast oldMast, SignalMast newMast) {
050        Object[] options = {Bundle.getMessage("ButtonUpdate"), Bundle.getMessage("LeaveButton")};
051        int n = JmriJOptionPane.showOptionDialog(frame,
052                java.text.MessageFormat.format(Bundle.getMessage("SwapLogic"),  // NOI18N
053                        new Object[]{oldMast.getDisplayName(), newMast.getDisplayName()}),
054                Bundle.getMessage("UpdateLogicTitle"),  // NOI18N
055                JmriJOptionPane.DEFAULT_OPTION,
056                JmriJOptionPane.QUESTION_MESSAGE,
057                null,
058                options,
059                options[0]);
060        if (n == 0) { // array position 0, ButtonUpdate
061            InstanceManager.getDefault(jmri.SignalMastLogicManager.class).swapSignalMasts(oldMast, newMast);
062        }
063    }
064
065    /**
066     * Display a message to the user asking them to
067     * confirm they wish to remove the Signal Mast Logic for a given signal.
068     *
069     * @param frame the frame initiating the dialog
070     * @param mast the main signal mast (object) selected on that frame
071     * @return true if user confirmed delete request
072     */
073    static public boolean removeSignalMastLogic(JmriJFrame frame, SignalMast mast) {
074        Object[] options = {Bundle.getMessage("RemoveButton"), Bundle.getMessage("LeaveButton")};
075        int n = JmriJOptionPane.showOptionDialog(frame,
076                java.text.MessageFormat.format(Bundle.getMessage("RemoveLogic"),  // NOI18N
077                        new Object[]{mast.getDisplayName()}),
078                Bundle.getMessage("RemoveLogicTitle"),  // NOI18N
079                JmriJOptionPane.DEFAULT_OPTION,
080                JmriJOptionPane.QUESTION_MESSAGE,
081                null,
082                options,
083                options[0]);
084        if (n == 0) { // array position 0, RemoveButton
085            InstanceManager.getDefault(jmri.SignalMastLogicManager.class).removeSignalMast(mast);
086            return true;
087        }
088        return false;
089    }
090
091    /**
092     * Display a message to the user asking them to
093     * confirm they wish to remove the Signal Mast Logic for a given Signal Mast.
094     * <p>
095     * This is the same as removeSignalMastLogic, but with different text.
096     *
097     * @param frame the frame initiating the dialog
098     * @param mast the main signal mast (object) selected on that frame
099     */
100    static public void removeAlreadyAssignedSignalMastLogic(JmriJFrame frame, SignalMast mast) {
101        Object[] options = {Bundle.getMessage("RemoveButton"),  // NOI18N
102            Bundle.getMessage("LeaveButton")};  // NOI18N
103        int n = JmriJOptionPane.showOptionDialog(frame,
104                java.text.MessageFormat.format(Bundle.getMessage("RemoveAlreadyAssignedLogic"),  // NOI18N
105                        new Object[]{mast.getDisplayName()}),
106                Bundle.getMessage("RemoveLogicTitle"),  // NOI18N
107                JmriJOptionPane.DEFAULT_OPTION,
108                JmriJOptionPane.QUESTION_MESSAGE,
109                null,
110                options,
111                options[0]);
112        if (n == 0) { // array position 0, RemoveButton
113            InstanceManager.getDefault(jmri.SignalMastLogicManager.class).removeSignalMast(mast);
114        }
115    }
116}