001package jmri.jmrit.ussctc;
002
003import javax.swing.JPanel;
004import jmri.*;
005
006/**
007 * Refactored common routines and data for the GUI panels in this package.
008 *
009 * @author Bob Jacobsen Copyright (C) 2007
010 */
011public class BasePanel extends JPanel implements Constants {
012
013    BasePanel() {
014    }
015
016    void complain(String message, String value) {
017        jmri.util.swing.JmriJOptionPane.showMessageDialog(this,
018                java.text.MessageFormat.format(
019                        Bundle.getMessage(message),
020                        new Object[]{value}),
021                Bundle.getMessage("ErrorTitle"),
022                javax.swing.JOptionPane.ERROR_MESSAGE);
023    }
024
025    boolean validateTurnout(String name) {
026        Turnout t = null;
027        try {
028            t = InstanceManager.turnoutManagerInstance().provideTurnout(name);
029        } catch (IllegalArgumentException e) {
030            // no action taken; will recover later when t is null
031            log.debug("could not create turnout \"{}\"", name);
032        }
033        if (t == null) {
034            complain("ErrorNoTurnoutMatch", name);
035            return false;
036        }
037        return true;
038    }
039
040    boolean validateSensor(String name) {
041        Sensor t = null;
042        try {
043            t = InstanceManager.sensorManagerInstance().provideSensor(name);
044        } catch (IllegalArgumentException e) {
045            // no action taken; will recover later when t is null
046            log.debug("could not create sensor \"{}\"", name);
047        }
048        if (t == null) {
049            complain("ErrorNoSensorMatch", name);
050            return false;
051        }
052        return true;
053    }
054
055    boolean validateMemory(String name) {
056        Memory t = null;
057        try {
058            t = InstanceManager.memoryManagerInstance().provideMemory(name);
059        } catch (IllegalArgumentException e) {
060            // no action taken; will recover later when t is null
061            log.debug("could not create memory \"{}\"", name);
062        }
063        if (t == null) {
064            complain("ErrorNoMemoryMatch", name);
065            return false;
066        }
067        return true;
068    }
069
070    private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(BasePanel.class);
071}