use of de.neemann.digital.analyse.TruthTableTableModel 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.TruthTableTableModel 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.TruthTableTableModel 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.TruthTableTableModel 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