use of de.neemann.digital.analyse.TruthTable in project Digital by hneemann.
the class TableDialog method setAllValuesTo.
private void setAllValuesTo(int value) {
TruthTable t = model.getTable();
t.setAllTo(value);
setModel(new TruthTableTableModel(t));
}
use of de.neemann.digital.analyse.TruthTable in project Digital by hneemann.
the class TableDialog method createFileMenu.
private JMenu createFileMenu() {
JMenu fileMenu = new JMenu(Lang.get("menu_file"));
fileMenu.add(new ToolTipAction(Lang.get("menu_open")) {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fc = new MyFileChooser();
if (TableDialog.this.filename != null)
fc.setSelectedFile(SaveAsHelper.checkSuffix(TableDialog.this.filename, "tru"));
if (fc.showOpenDialog(TableDialog.this) == JFileChooser.APPROVE_OPTION) {
try {
File file = fc.getSelectedFile();
TruthTable truthTable = TruthTable.readFromFile(file);
setModel(new TruthTableTableModel(truthTable));
TableDialog.this.filename = file;
} catch (IOException e1) {
new ErrorMessage().addCause(e1).show(TableDialog.this);
}
}
}
});
fileMenu.add(new ToolTipAction(Lang.get("menu_save")) {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fc = new MyFileChooser();
if (TableDialog.this.filename != null)
fc.setSelectedFile(SaveAsHelper.checkSuffix(TableDialog.this.filename, "tru"));
new SaveAsHelper(TableDialog.this, fc, "tru").checkOverwrite(file -> {
model.getTable().save(file);
TableDialog.this.filename = file;
});
}
});
fileMenu.add(new ToolTipAction(Lang.get("menu_table_exportTableLaTeX")) {
@Override
public void actionPerformed(ActionEvent e) {
try {
ExpressionListener expressionListener = new LaTeXExpressionListener(model);
if (createJK.isSelected())
expressionListener = new ExpressionListenerJK(expressionListener);
lastGeneratedExpressions.replayTo(expressionListener);
} catch (ExpressionException | FormatterException e1) {
new ErrorMessage(Lang.get("msg_errorDuringCalculation")).addCause(e1).show(TableDialog.this);
}
}
});
fileMenu.add(new ToolTipAction(Lang.get("menu_table_exportHex")) {
@Override
public void actionPerformed(ActionEvent e) {
int res = JOptionPane.OK_OPTION;
if (model.getTable().getVars().size() > 20)
res = JOptionPane.showConfirmDialog(TableDialog.this, Lang.get("msg_tableHasManyRowsConfirm"));
if (res == JOptionPane.OK_OPTION) {
JFileChooser fc = new MyFileChooser();
if (TableDialog.this.filename != null)
fc.setSelectedFile(SaveAsHelper.checkSuffix(TableDialog.this.filename, "hex"));
new SaveAsHelper(TableDialog.this, fc, "hex").checkOverwrite(file -> model.getTable().saveHex(file));
}
}
}.setToolTip(Lang.get("menu_table_exportHex_tt")).createJMenuItem());
createJK = new JCheckBoxMenuItem(Lang.get("menu_table_JK"));
createJK.addActionListener(e -> calculateExpressions());
fileMenu.add(createJK);
return fileMenu;
}
use of de.neemann.digital.analyse.TruthTable in project Digital by hneemann.
the class BuilderExpressionCreatorTest method check.
private void check(Model m) throws AnalyseException, NodeException, BacktrackException, PinException {
TruthTable tt = new ModelAnalyser(m).analyse();
m.close();
assertEquals(1, tt.getResultCount());
BoolTable r = tt.getResult(0);
assertEquals(4, r.size());
assertEquals(ThreeStateValue.zero, r.get(0));
assertEquals(ThreeStateValue.one, r.get(1));
assertEquals(ThreeStateValue.one, r.get(2));
assertEquals(ThreeStateValue.zero, r.get(3));
}
use of de.neemann.digital.analyse.TruthTable in project Digital by hneemann.
the class TestReorderInputs method testDeleteVar.
public void testDeleteVar() throws Exception {
TruthTable t = new TruthTable(3).addResult();
BoolTableByteArray col = (BoolTableByteArray) t.getResult(0);
for (int i = 0; i < t.getRows(); i++) col.set(i, i + 1);
ReorderInputs reorderInputs = new ReorderInputs(t);
reorderInputs.getItems().delete(2);
TruthTable newTable = reorderInputs.reorder();
assertEquals(2, newTable.getVars().size());
assertEquals(1, newTable.getResultCount());
ContextFiller cf = new ContextFiller(newTable.getVars());
cf.set(t.getVars().get(2), false);
for (int i = 0; i < newTable.getRows(); i++) {
cf.setContextTo(i);
assertEquals(newTable.getByContext(0, cf), t.getByContext(0, cf));
}
}
use of de.neemann.digital.analyse.TruthTable in project Digital by hneemann.
the class TestReorderInputs method testReorder.
public void testReorder() throws Exception {
TruthTable t = new TruthTable(5).addResult();
BoolTableByteArray col = (BoolTableByteArray) t.getResult(0);
for (int i = 0; i < t.getRows(); i++) col.set(i, i + 1);
ReorderInputs reorderInputs = new ReorderInputs(t);
reorderInputs.getItems().swap(1, 2);
TruthTable newTable = reorderInputs.reorder();
ContextFiller cf = new ContextFiller(t.getVars());
for (int i = 0; i < t.getRows(); i++) {
cf.setContextTo(i);
assertEquals(newTable.getByContext(0, cf), t.getByContext(0, cf));
}
}
Aggregations