use of jmri.SignalGroup in project JMRI by JMRI.
the class SignalGroupTableAction method checkNamesOK.
/**
* Check name and return a new or existing SignalGroup object
* with the name as entered in the _systemName field on the addFrame pane.
* @return The new/updated SignalGroup object
*/
SignalGroup checkNamesOK() {
// Get system name and user name
String sName = _systemName.getText().toUpperCase();
String uName = _userName.getText();
if (sName.length() == 0) {
javax.swing.JOptionPane.showMessageDialog(null, Bundle.getMessage("RouteAddStatusEnter"), Bundle.getMessage("ErrorTitle"), javax.swing.JOptionPane.WARNING_MESSAGE);
// Reuse a key with general wording
return null;
}
try {
SignalGroup g = jmri.InstanceManager.getDefault(jmri.SignalGroupManager.class).provideSignalGroup(sName, uName);
return g;
} catch (IllegalArgumentException ex) {
// should never get here
log.error("checkNamesOK; Unknown failure to create Signal Group with System Name: {}", sName);
throw ex;
}
}
use of jmri.SignalGroup in project JMRI by JMRI.
the class SignalGroupTableAction method checkNewNamesOK.
/**
* Check name for a new SignalGroup object using the _systemName field on the addFrame pane
* @return Whether name is allowed
*/
boolean checkNewNamesOK() {
// Get system name and user name from Add Signal Group pane
// N11N
String sName = _systemName.getText().toUpperCase().trim();
// seems field _systemName is not properly filled in when editing an existing mast
// so prevent it from being called (in line 900)
// may be empty // N11N
String uName = _userName.getText();
if (sName.length() == 0) {
javax.swing.JOptionPane.showMessageDialog(null, "System Name field can not be left blank.", Bundle.getMessage("ErrorTitle"), javax.swing.JOptionPane.WARNING_MESSAGE);
log.debug("Empty system name field for Signal Group [{}]", sName);
return false;
}
SignalGroup g = null;
// check if a SignalGroup with the same user name exists
if (!uName.equals("")) {
g = jmri.InstanceManager.getDefault(jmri.SignalGroupManager.class).getByUserName(uName);
if (g != null) {
// SignalGroup with this user name already exists
javax.swing.JOptionPane.showMessageDialog(null, Bundle.getMessage("SignalGroupDuplicateUserNameWarning", uName), Bundle.getMessage("ErrorTitle"), javax.swing.JOptionPane.WARNING_MESSAGE);
return false;
} else {
return true;
}
}
// check if a SignalGroup with this system name already exists
g = jmri.InstanceManager.getDefault(jmri.SignalGroupManager.class).getBySystemName(sName);
if (g != null) {
// SignalGroup already exists
javax.swing.JOptionPane.showMessageDialog(null, Bundle.getMessage("SignalGroupDuplicateSystemNameWarning", sName), Bundle.getMessage("ErrorTitle"), javax.swing.JOptionPane.WARNING_MESSAGE);
return false;
}
return true;
}
use of jmri.SignalGroup in project JMRI by JMRI.
the class SignalGroupTableAction method editPressed.
/**
* Respond to the Edit button in the Signal Group Table
* after creating the Add/Edit pane with AddPressed supplying _SystemName.
* Hides the editable _systemName field on the Add Group pane and displays the value as a label instead.
* @param e Event from origin, null if invoked by clicking the Edit button in a Signal Group Table row
*/
void editPressed(ActionEvent e) {
// identify the Signal Group with this name if it already exists
// is already filled in from the Signal Group table by addPressed()
String sName = _systemName.getText().toUpperCase();
SignalGroup g = jmri.InstanceManager.getDefault(jmri.SignalGroupManager.class).getBySystemName(sName);
if (g == null) {
// Signal Group does not exist, so cannot be edited
return;
}
g.addPropertyChangeListener(this);
// Signal Group was found, make its system name not changeable
curSignalGroup = g;
log.debug("curSignalGroup was set");
jmri.SignalMast sm = jmri.InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast(g.getSignalMastName());
if (sm != null) {
java.util.Vector<String> aspects = sm.getValidAspects();
_mastAspectsList = new ArrayList<SignalMastAspect>(aspects.size());
for (int i = 0; i < aspects.size(); i++) {
_mastAspectsList.add(new SignalMastAspect(aspects.get(i)));
}
} else {
// false indicates Can't find mast (but quoted name stands for a head) TODO
log.error("Failed to get signal mast {}", g.getSignalMastName());
}
fixedSystemName.setText(sName);
fixedSystemName.setVisible(true);
_systemName.setVisible(false);
mainSignalComboBox.setSelectedBean(g.getSignalMast());
_userName.setText(g.getUserName());
int setRow = 0;
for (int i = _signalHeadsList.size() - 1; i >= 0; i--) {
SignalGroupSignalHead sgsh = _signalHeadsList.get(i);
SignalHead sigBean = sgsh.getBean();
if (g.isHeadIncluded(sigBean)) {
sgsh.setIncluded(true);
sgsh.setOnState(g.getHeadOnState(sigBean));
sgsh.setOffState(g.getHeadOffState(sigBean));
setRow = i;
} else {
sgsh.setIncluded(false);
}
}
_SignalGroupHeadScrollPane.getVerticalScrollBar().setValue(setRow * ROW_HEIGHT);
_SignalGroupHeadModel.fireTableDataChanged();
for (int i = 0; i < _mastAspectsList.size(); i++) {
SignalMastAspect _aspect = _mastAspectsList.get(i);
String asp = _aspect.getAspect();
if (g.isSignalMastAspectIncluded(asp)) {
_aspect.setIncluded(true);
setRow = i;
} else {
_aspect.setIncluded(false);
}
}
_SignalAppearanceScrollPane.getVerticalScrollBar().setValue(setRow * ROW_HEIGHT);
_AspectModel.fireTableDataChanged();
initializeIncludedList();
// to fire reminder to save work
SignalGroupDirty = true;
updateButton.setVisible(true);
fixedSystemName.setVisible(true);
_systemName.setVisible(false);
addFrame.setTitle(Bundle.getMessage("EditSignalGroup"));
// to block opening another edit session
inEditMode = true;
}
use of jmri.SignalGroup in project JMRI by JMRI.
the class SignalGroupTableAction method updatePressed.
/**
* Respond to the Update button on the Edit Signal Group pane - store new properties in the Signal Group.
* @param e Event from origin, null if invoked by clicking the Edit button in a Signal Group Table row
* @param newSignalGroup False when called as Update, True after editing Signal Head details
* @param close True if the pane is closing, False if it stays open
*/
void updatePressed(ActionEvent e, boolean newSignalGroup, boolean close) {
log.debug("Update found Signal Group system name: {}/{}", _systemName.getText(), fixedSystemName.getText());
if (_systemName.getText().isEmpty()) {
_systemName.setText(fixedSystemName.getText());
// NPE in checkNewNamesOK() because the _systemName field seems to be empty
}
String uName = _userName.getText();
if (curSignalGroup == null) {
log.debug("Catch NPE during Update. curSignalGroup = null");
// for which a system name is visibly filled in
if (!checkNewNamesOK()) {
return;
}
}
if (!checkValidSignalMast()) {
return;
}
// if this fails, we are stuck
SignalGroup g = checkNamesOK();
if (g == null) {
// error logging/dialog handled in checkNamesOK()
return;
}
curSignalGroup = g;
// user name is unique, change it
g.setUserName(uName);
initializeIncludedList();
setHeadInformation(g);
setMastAspectInformation(g);
g.setSignalMast((SignalMast) mainSignalComboBox.getSelectedBean(), mainSignalComboBox.getSelectedDisplayName());
// to fire reminder to save work
SignalGroupDirty = true;
if (close) {
finishUpdate();
inEditMode = false;
}
}
use of jmri.SignalGroup in project JMRI by JMRI.
the class DefaultSignalGroupManager method newSignalGroup.
@Override
public SignalGroup newSignalGroup(String sys) {
SignalGroup g;
g = new DefaultSignalGroup(sys);
register(g);
return g;
}
Aggregations