use of jmri.Logix in project JMRI by JMRI.
the class LogixTableAction method createModel.
// *********** Methods for Logix Table Window ********************
/**
* Create the JTable DataModel, along with the changes (overrides of
* BeanTableDataModel) for the specific case of a Logix table.
* <p>
* Note: Table Models for the Conditional table in the Edit Logix window,
* and the State Variable table in the Edit Conditional window are at
* the end of this module.
*/
@Override
protected void createModel() {
m = new BeanTableDataModel() {
// overlay the state column with the edit column
public static final int ENABLECOL = VALUECOL;
public static final int EDITCOL = DELETECOL;
protected String enabledString = Bundle.getMessage("ColumnHeadEnabled");
@Override
public String getColumnName(int col) {
if (col == EDITCOL) {
// no heading on "Edit"
return "";
}
if (col == ENABLECOL) {
return enabledString;
}
return super.getColumnName(col);
}
@Override
public Class<?> getColumnClass(int col) {
if (col == EDITCOL) {
return String.class;
}
if (col == ENABLECOL) {
return Boolean.class;
}
return super.getColumnClass(col);
}
@Override
public int getPreferredWidth(int col) {
// override default value for SystemName and UserName columns
if (col == SYSNAMECOL) {
return new JTextField(12).getPreferredSize().width;
}
if (col == USERNAMECOL) {
return new JTextField(17).getPreferredSize().width;
}
if (col == EDITCOL) {
return new JTextField(12).getPreferredSize().width;
}
if (col == ENABLECOL) {
return new JTextField(5).getPreferredSize().width;
}
return super.getPreferredWidth(col);
}
@Override
public boolean isCellEditable(int row, int col) {
if (col == EDITCOL) {
return true;
}
if (col == ENABLECOL) {
return true;
}
return super.isCellEditable(row, col);
}
@Override
public Object getValueAt(int row, int col) {
if (col == EDITCOL) {
return Bundle.getMessage("ButtonSelect");
} else if (col == ENABLECOL) {
Logix logix = (Logix) getBySystemName((String) getValueAt(row, SYSNAMECOL));
if (logix == null) {
return null;
}
return Boolean.valueOf(logix.getEnabled());
} else {
return super.getValueAt(row, col);
}
}
@Override
public void setValueAt(Object value, int row, int col) {
if (col == EDITCOL) {
// set up to edit
String sName = (String) getValueAt(row, SYSNAMECOL);
if (Bundle.getMessage("ButtonEdit").equals(value)) {
editPressed(sName);
} else if (rbx.getString("BrowserButton").equals(value)) {
conditionalRowNumber = row;
browserPressed(sName);
} else if (Bundle.getMessage("ButtonCopy").equals(value)) {
copyPressed(sName);
} else if (Bundle.getMessage("ButtonDelete").equals(value)) {
deletePressed(sName);
}
} else if (col == ENABLECOL) {
// alternate
Logix x = (Logix) getBySystemName((String) getValueAt(row, SYSNAMECOL));
boolean v = x.getEnabled();
x.setEnabled(!v);
} else {
super.setValueAt(value, row, col);
}
}
/**
* Delete the bean after all the checking has been done.
* <p>
* Deactivates the Logix and remove it's conditionals.
*
* @param bean of the Logix to delete
*/
@Override
void doDelete(NamedBean bean) {
Logix l = (Logix) bean;
l.deActivateLogix();
// delete the Logix and all its Conditionals
_logixManager.deleteLogix(l);
}
@Override
protected boolean matchPropertyName(java.beans.PropertyChangeEvent e) {
if (e.getPropertyName().equals(enabledString)) {
return true;
}
return super.matchPropertyName(e);
}
@Override
public Manager getManager() {
return InstanceManager.getDefault(jmri.LogixManager.class);
}
@Override
public NamedBean getBySystemName(String name) {
return InstanceManager.getDefault(jmri.LogixManager.class).getBySystemName(name);
}
@Override
public NamedBean getByUserName(String name) {
return InstanceManager.getDefault(jmri.LogixManager.class).getByUserName(name);
}
@Override
protected String getMasterClassName() {
return getClassName();
}
@Override
public void configureTable(JTable table) {
table.setDefaultRenderer(Boolean.class, new EnablingCheckboxRenderer());
table.setDefaultRenderer(JComboBox.class, new jmri.jmrit.symbolicprog.ValueRenderer());
table.setDefaultEditor(JComboBox.class, new jmri.jmrit.symbolicprog.ValueEditor());
super.configureTable(table);
}
/**
* Replace delete button with comboBox to edit/delete/copy/select Logix.
*
* @param table name of the Logix JTable holding the column
*/
@Override
protected void configDeleteColumn(JTable table) {
JComboBox<String> editCombo = new JComboBox<String>();
editCombo.addItem(Bundle.getMessage("ButtonSelect"));
editCombo.addItem(Bundle.getMessage("ButtonEdit"));
editCombo.addItem(rbx.getString("BrowserButton"));
editCombo.addItem(Bundle.getMessage("ButtonCopy"));
editCombo.addItem(Bundle.getMessage("ButtonDelete"));
TableColumn col = table.getColumnModel().getColumn(BeanTableDataModel.DELETECOL);
col.setCellEditor(new DefaultCellEditor(editCombo));
}
// Not needed - here for interface compatibility
@Override
public void clickOn(NamedBean t) {
}
@Override
public String getValue(String s) {
return "";
}
@Override
protected String getBeanType() {
return Bundle.getMessage("BeanNameLogix");
}
};
}
use of jmri.Logix in project JMRI by JMRI.
the class LogixTableAction method deletePressed.
/**
* Respond to the Delete combo selection Logix window.
*
* @param sName system name of bean to be deleted
*/
void deletePressed(String sName) {
if (!checkFlags(sName)) {
return;
}
if (!checkConditionalReferences(sName)) {
return;
}
final Logix x = _logixManager.getBySystemName(sName);
final jmri.UserPreferencesManager p;
p = jmri.InstanceManager.getNullableDefault(jmri.UserPreferencesManager.class);
if (p != null && p.getMultipleChoiceOption(getClassName(), "delete") == 0x02) {
if (x != null) {
_logixManager.deleteLogix(x);
deleteSourceWhereUsed();
}
} else {
final JDialog dialog = new JDialog();
String msg;
dialog.setTitle(rbx.getString("ConfirmTitle"));
dialog.setLocationRelativeTo(null);
dialog.setDefaultCloseOperation(javax.swing.JFrame.DISPOSE_ON_CLOSE);
JPanel container = new JPanel();
container.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS));
msg = java.text.MessageFormat.format(rbx.getString("ConfirmLogixDelete"), sName);
JLabel question = new JLabel(msg);
question.setAlignmentX(Component.CENTER_ALIGNMENT);
container.add(question);
final JCheckBox remember = new JCheckBox(Bundle.getMessage("MessageRememberSetting"));
remember.setFont(remember.getFont().deriveFont(10f));
remember.setAlignmentX(Component.CENTER_ALIGNMENT);
JButton yesButton = new JButton(Bundle.getMessage("ButtonYes"));
JButton noButton = new JButton(Bundle.getMessage("ButtonNo"));
JPanel button = new JPanel();
button.setAlignmentX(Component.CENTER_ALIGNMENT);
button.add(yesButton);
button.add(noButton);
container.add(button);
noButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//there is no point in remebering this the user will never be
//able to delete a bean!
/*if(remember.isSelected()){
setDisplayDeleteMsg(0x01);
}*/
dialog.dispose();
}
});
yesButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (p != null && remember.isSelected()) {
p.setMultipleChoiceOption(getClassName(), "delete", 0x02);
}
if (x != null) {
_logixManager.deleteLogix(x);
deleteSourceWhereUsed();
}
dialog.dispose();
}
});
container.add(remember);
container.setAlignmentX(Component.CENTER_ALIGNMENT);
container.setAlignmentY(Component.CENTER_ALIGNMENT);
dialog.getContentPane().add(container);
dialog.pack();
dialog.setModal(true);
dialog.setVisible(true);
}
/*if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(f, java.text.MessageFormat.format(
rbx.getString("ConfirmLogixDelete"), sName),
rbx.getString("ConfirmTitle"), JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE) )
{
Logix x = _logixManager.getBySystemName(sName);
if (x != null) {
_logixManager.deleteLogix(x);
}
}*/
f.setVisible(true);
}
use of jmri.Logix in project JMRI by JMRI.
the class LogixTableAction method loadSelectConditionalBox.
/**
* Load the Conditional selection box. The first row is a prompt
* @since 4.7.4
* @param logixName The Logix system name for selecting the owned Conditionals
*/
void loadSelectConditionalBox(String logixName) {
// Get the current Conditional name for selecting the current combo box row
String cdlName = _curVariable.getName();
_selectConditionalBox.removeAllItems();
_selectConditionalList.clear();
// Create the first row
String itemKey = rbx.getString("SelectFirstRow");
_selectConditionalBox.addItem(itemKey);
_selectConditionalList.add("-None-");
Logix x = _logixManager.getBySystemName(logixName);
if (x == null) {
log.error("Logix '{}' not found while building the conditional list", logixName);
return;
}
if (x.getNumConditionals() == 0) {
return;
}
for (String cName : _conditionalManager.getSystemNameListForLogix(x)) {
Conditional c = _conditionalManager.getConditional(cName);
if (_curConditional.getSystemName().equals(c.getSystemName())) {
// Don't add myself to the list
continue;
}
String uName = c.getUserName();
String itemName = "";
if (uName == null || uName.length() < 1) {
itemName = cName;
} else {
itemName = uName + " ( " + cName + " )";
}
_selectConditionalBox.addItem(itemName);
_selectConditionalList.add(cName);
if (cdlName.equals(cName)) {
itemKey = itemName;
}
}
_selectConditionalBox.setSelectedItem(itemKey);
}
use of jmri.Logix in project JMRI by JMRI.
the class LogixTableAction method createPressed.
/**
* Respond to the Create Logix button in Add Logix window.
*
* @param e The event heard
*/
void createPressed(ActionEvent e) {
// possible change
_showReminder = true;
// N11N
String uName = _addUserName.getText().trim();
if (uName.length() == 0) {
uName = null;
}
if (_autoSystemName.isSelected()) {
if (!checkLogixUserName(uName)) {
return;
}
_curLogix = _logixManager.createNewLogix(uName);
} else {
if (!checkLogixSysName()) {
return;
}
// Get validated system name
// N11N
String sName = _systemName.getText();
// check if a Logix with this name already exists
Logix x = null;
try {
x = _logixManager.getBySystemName(sName);
} catch (Exception ex) {
// user input no good
handleCreateException(sName);
// without creating
return;
}
if (x != null) {
// Logix already exists
javax.swing.JOptionPane.showMessageDialog(addLogixFrame, rbx.getString("Error1"), Bundle.getMessage("ErrorTitle"), javax.swing.JOptionPane.ERROR_MESSAGE);
return;
}
if (!checkLogixUserName(uName)) {
return;
}
// Create the new Logix
_curLogix = _logixManager.createNewLogix(sName, uName);
if (_curLogix == null) {
// should never get here unless there is an assignment conflict
log.error("Failure to create Logix with System Name: " + sName);
return;
}
}
numConditionals = 0;
cancelAddPressed(null);
// create the Edit Logix Window
makeEditLogixWindow();
InstanceManager.getOptionalDefault(UserPreferencesManager.class).ifPresent((prefMgr) -> {
prefMgr.setSimplePreferenceState(systemNameAuto, _autoSystemName.isSelected());
});
}
use of jmri.Logix in project JMRI by JMRI.
the class RouteTableAction method exportPressed.
/////////////////////// Export to Logix ////////////////////////////
/**
* Responds to the Export button - export to Logix.
*
* @param e the action event
*/
void exportPressed(ActionEvent e) {
curRoute = checkNamesOK();
String sName = _systemName.getText();
if (sName.length() == 0) {
sName = fixedSystemName.getText();
}
String uName = _userName.getText();
String logixSystemName = LOGIX_SYS_NAME + sName;
Logix logix = InstanceManager.getDefault(jmri.LogixManager.class).getBySystemName(logixSystemName);
if (logix == null) {
logix = InstanceManager.getDefault(jmri.LogixManager.class).createNewLogix(logixSystemName, uName);
if (logix == null) {
log.error("Failed to create Logix " + logixSystemName + ", " + uName);
return;
}
}
logix.deActivateLogix();
initializeIncludedList();
/////////////////// Construct output actions for change to true //////////////////////
ArrayList<ConditionalAction> actionList = new ArrayList<>();
for (int i = 0; i < _includedSensorList.size(); i++) {
RouteSensor rSensor = _includedSensorList.get(i);
String name = rSensor.getUserName();
if (name == null || name.length() == 0) {
name = rSensor.getSysName();
}
actionList.add(new DefaultConditionalAction(Conditional.ACTION_OPTION_ON_CHANGE_TO_TRUE, Conditional.ACTION_SET_SENSOR, name, rSensor.getState(), ""));
}
for (int i = 0; i < _includedTurnoutList.size(); i++) {
RouteTurnout rTurnout = _includedTurnoutList.get(i);
String name = rTurnout.getUserName();
if (name == null || name.length() == 0) {
name = rTurnout.getSysName();
}
actionList.add(new DefaultConditionalAction(Conditional.ACTION_OPTION_ON_CHANGE_TO_TRUE, Conditional.ACTION_SET_TURNOUT, name, rTurnout.getState(), ""));
}
String file = soundFile.getText();
if (file.length() > 0) {
actionList.add(new DefaultConditionalAction(Conditional.ACTION_OPTION_ON_CHANGE_TO_TRUE, Conditional.ACTION_RUN_SCRIPT, "", -1, file));
}
file = scriptFile.getText();
if (file.length() > 0) {
actionList.add(new DefaultConditionalAction(Conditional.ACTION_OPTION_ON_CHANGE_TO_TRUE, Conditional.ACTION_PLAY_SOUND, "", -1, file));
}
///// Construct 'AND' clause from 'VETO' controls ////////
ArrayList<ConditionalVariable> vetoList = new ArrayList<>();
// String andClause = null;
ConditionalVariable cVar = makeCtrlSensorVar(sensor1, sensor1mode, true, false);
if (cVar != null) {
vetoList.add(cVar);
}
cVar = makeCtrlSensorVar(sensor2, sensor2mode, true, false);
if (cVar != null) {
vetoList.add(cVar);
}
cVar = makeCtrlSensorVar(sensor3, sensor3mode, true, false);
if (cVar != null) {
vetoList.add(cVar);
}
cVar = makeCtrlTurnoutVar(cTurnout, cTurnoutStateBox, true, false);
if (cVar != null) {
vetoList.add(cVar);
}
// remove old Conditionals for actions (ver 2.5.2 only -remove a bad idea)
char[] ch = sName.toCharArray();
int hash = 0;
for (int i = 0; i < ch.length; i++) {
hash += ch[i];
}
String cSystemName = CONDITIONAL_SYS_PREFIX + "T" + hash;
removeConditionals(cSystemName, logix);
cSystemName = CONDITIONAL_SYS_PREFIX + "F" + hash;
removeConditionals(cSystemName, logix);
cSystemName = CONDITIONAL_SYS_PREFIX + "A" + hash;
removeConditionals(cSystemName, logix);
cSystemName = CONDITIONAL_SYS_PREFIX + "L" + hash;
removeConditionals(cSystemName, logix);
int n = 0;
do {
n++;
cSystemName = logixSystemName + n + "A";
} while (removeConditionals(cSystemName, logix));
n = 0;
do {
n++;
cSystemName = logixSystemName + n + "T";
} while (removeConditionals(cSystemName, logix));
cSystemName = logixSystemName + "L";
removeConditionals(cSystemName, logix);
String cUserName;
///////////////// Make Trigger Conditionals //////////////////////
//ArrayList <ConditionalVariable> onChangeList = new ArrayList<ConditionalVariable>();
// passed through all these, with new value returned each time
int numConds = 1;
numConds = makeSensorConditional(sensor1, sensor1mode, numConds, false, actionList, vetoList, logix, logixSystemName, uName);
numConds = makeSensorConditional(sensor2, sensor2mode, numConds, false, actionList, vetoList, logix, logixSystemName, uName);
numConds = makeSensorConditional(sensor3, sensor3mode, numConds, false, actionList, vetoList, logix, logixSystemName, uName);
numConds = makeTurnoutConditional(cTurnout, cTurnoutStateBox, numConds, false, actionList, vetoList, logix, logixSystemName, uName);
////// Construct actions for false from the 'any change' controls ////////////
numConds = makeSensorConditional(sensor1, sensor1mode, numConds, true, actionList, vetoList, logix, logixSystemName, uName);
numConds = makeSensorConditional(sensor2, sensor2mode, numConds, true, actionList, vetoList, logix, logixSystemName, uName);
numConds = makeSensorConditional(sensor3, sensor3mode, numConds, true, actionList, vetoList, logix, logixSystemName, uName);
numConds = makeTurnoutConditional(cTurnout, cTurnoutStateBox, numConds, true, actionList, vetoList, logix, logixSystemName, uName);
log.debug("Final number of conditionals: {}", numConds);
//String sensorSystemName = turnoutsAlignedSensor.getText();
if (turnoutsAlignedSensor.getSelectedBean() != null) {
// verify name (logix doesn't use "provideXXX")
//Sensor s = turnoutsAlignedSensor.getSelectedBean();
/*if (s == null) {
s = InstanceManager.sensorManagerInstance().getBySystemName(sensorSystemName);
}*/
//if (s != null) {
String sensorSystemName = turnoutsAlignedSensor.getSelectedDisplayName();
// NOI18N
cSystemName = logixSystemName + "1A";
// NOI18N
cUserName = turnoutsAlignedSensor.getSelectedDisplayName() + "A " + uName;
ArrayList<ConditionalVariable> variableList = new ArrayList<>();
for (int i = 0; i < _includedTurnoutList.size(); i++) {
RouteTurnout rTurnout = _includedTurnoutList.get(i);
String name = rTurnout.getUserName();
if (name == null || name.length() == 0) {
name = rTurnout.getSysName();
}
// exclude toggled outputs
switch(rTurnout.getState()) {
case Turnout.CLOSED:
variableList.add(new ConditionalVariable(false, Conditional.OPERATOR_AND, Conditional.TYPE_TURNOUT_CLOSED, name, true));
break;
case Turnout.THROWN:
variableList.add(new ConditionalVariable(false, Conditional.OPERATOR_AND, Conditional.TYPE_TURNOUT_THROWN, name, true));
break;
default:
// NOI18N
log.warn("Turnout {} was {}, neither CLOSED nor THROWN; not handled", name, rTurnout.getState());
}
}
actionList = new ArrayList<>();
actionList.add(new DefaultConditionalAction(Conditional.ACTION_OPTION_ON_CHANGE_TO_TRUE, Conditional.ACTION_SET_SENSOR, sensorSystemName, Sensor.ACTIVE, ""));
actionList.add(new DefaultConditionalAction(Conditional.ACTION_OPTION_ON_CHANGE_TO_FALSE, Conditional.ACTION_SET_SENSOR, sensorSystemName, Sensor.INACTIVE, ""));
Conditional c = InstanceManager.getDefault(jmri.ConditionalManager.class).createNewConditional(cSystemName, cUserName);
c.setStateVariables(variableList);
c.setLogicType(Conditional.ALL_AND, "");
c.setAction(actionList);
logix.addConditional(cSystemName, 0);
c.calculate(true, null);
//}
}
///////////////// Set lock turnout information if there is any //////////////////////////
if (cLockTurnout.getSelectedBean() != null) {
String turnoutLockSystemName = cLockTurnout.getSelectedDisplayName();
// verify name (logix doesn't use "provideXXX")
// NOI18N
cSystemName = logixSystemName + "1L";
// NOI18N
cUserName = turnoutLockSystemName + "L " + uName;
ArrayList<ConditionalVariable> variableList = new ArrayList<>();
//String devName = cTurnout.getText();
int mode = turnoutModeFromBox(cTurnoutStateBox);
int type = Conditional.TYPE_TURNOUT_CLOSED;
if (mode == Route.ONTHROWN) {
type = Conditional.TYPE_TURNOUT_THROWN;
}
variableList.add(new ConditionalVariable(false, Conditional.OPERATOR_NONE, type, turnoutLockSystemName, true));
actionList = new ArrayList<>();
int option = Conditional.ACTION_OPTION_ON_CHANGE_TO_TRUE;
type = Turnout.LOCKED;
if (mode == Route.ONCHANGE) {
option = Conditional.ACTION_OPTION_ON_CHANGE;
type = Route.TOGGLE;
}
for (int i = 0; i < _includedTurnoutList.size(); i++) {
RouteTurnout rTurnout = _includedTurnoutList.get(i);
String name = rTurnout.getUserName();
if (name == null || name.length() == 0) {
name = rTurnout.getSysName();
}
actionList.add(new DefaultConditionalAction(option, Conditional.ACTION_LOCK_TURNOUT, name, type, ""));
}
if (mode != Route.ONCHANGE) {
// add non-toggle actions on
option = Conditional.ACTION_OPTION_ON_CHANGE_TO_FALSE;
type = Turnout.UNLOCKED;
for (int i = 0; i < _includedTurnoutList.size(); i++) {
RouteTurnout rTurnout = _includedTurnoutList.get(i);
String name = rTurnout.getUserName();
if (name == null || name.length() == 0) {
name = rTurnout.getSysName();
}
actionList.add(new DefaultConditionalAction(option, Conditional.ACTION_LOCK_TURNOUT, name, type, ""));
}
}
// add new Conditionals for action on 'locks'
Conditional c = InstanceManager.getDefault(jmri.ConditionalManager.class).createNewConditional(cSystemName, cUserName);
c.setStateVariables(variableList);
c.setLogicType(Conditional.ALL_AND, "");
c.setAction(actionList);
logix.addConditional(cSystemName, 0);
c.calculate(true, null);
}
logix.activateLogix();
if (curRoute != null) {
jmri.InstanceManager.getDefault(jmri.RouteManager.class).deleteRoute(curRoute);
curRoute = null;
}
status1.setText(Bundle.getMessage("BeanNameRoute") + "\"" + uName + "\" " + Bundle.getMessage("RouteAddStatusExported") + " (" + _includedTurnoutList.size() + Bundle.getMessage("Turnouts") + ", " + _includedSensorList.size() + " " + Bundle.getMessage("Sensors") + ")");
finishUpdate();
}
Aggregations