use of de.neemann.digital.analyse.TruthTable in project Digital by hneemann.
the class ReorderInputs method reorder.
/**
* Creates a new table matching the actual state of the items
*
* @return the new table
* @throws ExpressionException ExpressionException
*/
public TruthTable reorder() throws ExpressionException {
ArrayList<Variable> newVars = new ArrayList<>();
ArrayList<Variable> deletedVars = new ArrayList<>();
deletedVars.addAll(table.getVars());
for (String name : names) {
Variable found = null;
for (Variable v : deletedVars) if (v.getIdentifier().equals(name)) {
found = v;
break;
}
if (found != null) {
newVars.add(found);
deletedVars.remove(found);
}
}
if (newVars.size() < 2)
throw new ExpressionException(Lang.get("err_tableBecomesToSmall"));
TruthTable newTable = new TruthTable(newVars);
for (int j = 0; j < table.getResultCount(); j++) newTable.addResult(table.getResultName(j));
ContextFiller fc = new ContextFiller(newTable.getVars());
for (Variable v : deletedVars) fc.set(v, false);
for (int row = 0; row < newTable.getRows(); row++) {
fc.setContextTo(row);
for (int t = 0; t < newTable.getResultCount(); t++) newTable.setByContext(t, fc, table.getByContext(t, fc));
}
return newTable;
}
use of de.neemann.digital.analyse.TruthTable in project Digital by hneemann.
the class TableDialog method createSetMenu.
private JMenu createSetMenu() {
JMenu setMenu = new JMenu(Lang.get("menu_table_set"));
setMenu.add(new ToolTipAction(Lang.get("menu_table_setXTo0")) {
@Override
public void actionPerformed(ActionEvent e) {
TruthTable t = model.getTable();
t.setXto(false);
setModel(new TruthTableTableModel(t));
}
}.setToolTip(Lang.get("menu_table_setXTo0_tt")).createJMenuItem());
setMenu.add(new ToolTipAction(Lang.get("menu_table_setXTo1")) {
@Override
public void actionPerformed(ActionEvent e) {
TruthTable t = model.getTable();
t.setXto(true);
setModel(new TruthTableTableModel(t));
}
}.setToolTip(Lang.get("menu_table_setXTo1_tt")).createJMenuItem());
setMenu.add(new ToolTipAction(Lang.get("menu_table_setAllToX")) {
@Override
public void actionPerformed(ActionEvent e) {
setAllValuesTo(2);
}
}.setToolTip(Lang.get("menu_table_setAllToX_tt")).createJMenuItem());
setMenu.add(new ToolTipAction(Lang.get("menu_table_setAllTo0")) {
@Override
public void actionPerformed(ActionEvent e) {
setAllValuesTo(0);
}
}.setToolTip(Lang.get("menu_table_setAllTo0_tt")).createJMenuItem());
setMenu.add(new ToolTipAction(Lang.get("menu_table_setAllTo1")) {
@Override
public void actionPerformed(ActionEvent e) {
setAllValuesTo(1);
}
}.setToolTip(Lang.get("menu_table_setAllTo1_tt")).createJMenuItem());
return setMenu;
}
use of de.neemann.digital.analyse.TruthTable in project Digital by hneemann.
the class TableReorderManager method checkReorder.
private void checkReorder(TruthTableTableModel model) {
ArrayList<Variable> varList = model.getTable().getVars();
ArrayList<String> vars = new ArrayList<>();
ArrayList<String> results = new ArrayList<>();
boolean wasChange = false;
for (int i = 0; i < model.getColumnCount(); i++) {
String name = table.getTableHeader().getColumnModel().getColumn(i).getHeaderValue().toString();
if (!name.equals(table.getModel().getColumnName(i)))
wasChange = true;
BoolTable r = model.getTable().getResult(name);
if (r != null && varList.contains(new Variable(name)))
return;
if (r != null)
results.add(name);
else
vars.add(name);
}
if (wasChange) {
if (isVarChange(varList, vars)) {
try {
TruthTable tt = new ReorderInputs(model.getTable(), vars).reorder();
tableDialog.setModel(new TruthTableTableModel(tt));
} catch (ExpressionException e) {
// can't happen because no columns are removed
e.printStackTrace();
}
} else if (isResultChange(model.getTable(), results)) {
try {
TruthTable tt = new ReorderOutputs(model.getTable(), results).reorder();
tableDialog.setModel(new TruthTableTableModel(tt));
} catch (ExpressionException e) {
// can't happen because no columns are removed
e.printStackTrace();
}
} else
tableDialog.setModel(new TruthTableTableModel(model.getTable()));
}
}
Aggregations