Search in sources :

Example 1 with TruthTableTableModel

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));
}
Also used : TruthTable(de.neemann.digital.analyse.TruthTable) TruthTableTableModel(de.neemann.digital.analyse.TruthTableTableModel)

Example 2 with TruthTableTableModel

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;
}
Also used : Gal22v10JEDECExporter(de.neemann.digital.builder.Gal22v10.Gal22v10JEDECExporter) AttributeDialog(de.neemann.digital.gui.components.AttributeDialog) BoolTableByteArray(de.neemann.digital.analyse.quinemc.BoolTableByteArray) ExpressionToFileExporter(de.neemann.digital.builder.ExpressionToFileExporter) CuplExporter(de.neemann.digital.builder.Gal16v8.CuplExporter) JTableHeader(javax.swing.table.JTableHeader) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) KarnaughMapDialog(de.neemann.digital.gui.components.karnaugh.KarnaughMapDialog) TruthTableFormatterLaTeX(de.neemann.digital.analyse.format.TruthTableFormatterLaTeX) ExpressionModifier(de.neemann.digital.analyse.expression.modify.ExpressionModifier) TruthTableTableModel(de.neemann.digital.analyse.TruthTableTableModel) MouseAdapter(java.awt.event.MouseAdapter) MyFileChooser(de.neemann.gui.MyFileChooser) Main(de.neemann.digital.gui.Main) FormatToExpression(de.neemann.digital.analyse.expression.format.FormatToExpression) TableModelEvent(javax.swing.event.TableModelEvent) GenerateCUPL(de.neemann.digital.gui.components.table.hardware.GenerateCUPL) Lang(de.neemann.digital.lang.Lang) Key(de.neemann.digital.core.element.Key) NAnd(de.neemann.digital.analyse.expression.modify.NAnd) Circuit(de.neemann.digital.draw.elements.Circuit) ToolTipAction(de.neemann.gui.ToolTipAction) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) List(java.util.List) Gal16v8JEDECExporter(de.neemann.digital.builder.Gal16v8.Gal16v8JEDECExporter) ExpressionException(de.neemann.digital.analyse.expression.ExpressionException) NOr(de.neemann.digital.analyse.expression.modify.NOr) Screen(de.neemann.gui.Screen) Gal22v10CuplExporter(de.neemann.digital.builder.Gal22v10.Gal22v10CuplExporter) TwoInputs(de.neemann.digital.analyse.expression.modify.TwoInputs) HashMap(java.util.HashMap) TableModelListener(javax.swing.event.TableModelListener) ArrayList(java.util.ArrayList) Expression(de.neemann.digital.analyse.expression.Expression) FormatterException(de.neemann.digital.analyse.expression.format.FormatterException) StringTokenizer(java.util.StringTokenizer) FormatToTableLatex(de.neemann.digital.analyse.expression.format.FormatToTableLatex) ErrorMessage(de.neemann.gui.ErrorMessage) HardwareDescriptionGenerator(de.neemann.digital.gui.components.table.hardware.HardwareDescriptionGenerator) Keys(de.neemann.digital.core.element.Keys) TruthTable(de.neemann.digital.analyse.TruthTable) ElementOrderer(de.neemann.digital.gui.components.ElementOrderer) IOException(java.io.IOException) ActionEvent(java.awt.event.ActionEvent) MouseEvent(java.awt.event.MouseEvent) File(java.io.File) Preferences(java.util.prefs.Preferences) ATFDevice(de.neemann.digital.builder.ATF150x.ATFDevice) CircuitBuilder(de.neemann.digital.builder.circuit.CircuitBuilder) java.awt(java.awt) AnalyseException(de.neemann.digital.analyse.AnalyseException) Variable(de.neemann.digital.analyse.expression.Variable) SaveAsHelper(de.neemann.digital.gui.SaveAsHelper) ElementLibrary(de.neemann.digital.draw.library.ElementLibrary) GenerateFile(de.neemann.digital.gui.components.table.hardware.GenerateFile) ShapeFactory(de.neemann.digital.draw.shapes.ShapeFactory) javax.swing(javax.swing) ActionEvent(java.awt.event.ActionEvent) IOException(java.io.IOException) SaveAsHelper(de.neemann.digital.gui.SaveAsHelper) ToolTipAction(de.neemann.gui.ToolTipAction) MyFileChooser(de.neemann.gui.MyFileChooser) TruthTable(de.neemann.digital.analyse.TruthTable) ErrorMessage(de.neemann.gui.ErrorMessage) File(java.io.File) GenerateFile(de.neemann.digital.gui.components.table.hardware.GenerateFile) TruthTableTableModel(de.neemann.digital.analyse.TruthTableTableModel)

Example 3 with TruthTableTableModel

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;
}
Also used : ToolTipAction(de.neemann.gui.ToolTipAction) ActionEvent(java.awt.event.ActionEvent) TruthTable(de.neemann.digital.analyse.TruthTable) TruthTableTableModel(de.neemann.digital.analyse.TruthTableTableModel)

Example 4 with TruthTableTableModel

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()));
    }
}
Also used : Variable(de.neemann.digital.analyse.expression.Variable) ArrayList(java.util.ArrayList) ExpressionException(de.neemann.digital.analyse.expression.ExpressionException) BoolTable(de.neemann.digital.analyse.quinemc.BoolTable) TruthTable(de.neemann.digital.analyse.TruthTable) TruthTableTableModel(de.neemann.digital.analyse.TruthTableTableModel)

Aggregations

TruthTable (de.neemann.digital.analyse.TruthTable)4 TruthTableTableModel (de.neemann.digital.analyse.TruthTableTableModel)4 ExpressionException (de.neemann.digital.analyse.expression.ExpressionException)2 Variable (de.neemann.digital.analyse.expression.Variable)2 AnalyseException (de.neemann.digital.analyse.AnalyseException)1 Expression (de.neemann.digital.analyse.expression.Expression)1 FormatToExpression (de.neemann.digital.analyse.expression.format.FormatToExpression)1 FormatToTableLatex (de.neemann.digital.analyse.expression.format.FormatToTableLatex)1 FormatterException (de.neemann.digital.analyse.expression.format.FormatterException)1 ExpressionModifier (de.neemann.digital.analyse.expression.modify.ExpressionModifier)1 NAnd (de.neemann.digital.analyse.expression.modify.NAnd)1 NOr (de.neemann.digital.analyse.expression.modify.NOr)1 TwoInputs (de.neemann.digital.analyse.expression.modify.TwoInputs)1 TruthTableFormatterLaTeX (de.neemann.digital.analyse.format.TruthTableFormatterLaTeX)1 BoolTable (de.neemann.digital.analyse.quinemc.BoolTable)1 BoolTableByteArray (de.neemann.digital.analyse.quinemc.BoolTableByteArray)1 ATFDevice (de.neemann.digital.builder.ATF150x.ATFDevice)1 ExpressionToFileExporter (de.neemann.digital.builder.ExpressionToFileExporter)1 CuplExporter (de.neemann.digital.builder.Gal16v8.CuplExporter)1 Gal16v8JEDECExporter (de.neemann.digital.builder.Gal16v8.Gal16v8JEDECExporter)1