mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-15 15:58:41 -04:00
adds a plain text export in the table dialog, closes #475
This commit is contained in:
parent
bb5e9241f9
commit
49e5e39795
@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Helmut Neemann.
|
||||||
|
* Use of this source code is governed by the GPL v3 license
|
||||||
|
* that can be found in the LICENSE file.
|
||||||
|
*/
|
||||||
|
package de.neemann.digital.gui.components.table;
|
||||||
|
|
||||||
|
import de.neemann.digital.analyse.expression.Expression;
|
||||||
|
import de.neemann.digital.analyse.expression.format.FormatToExpression;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formats expressions to plain text
|
||||||
|
*/
|
||||||
|
public class PlainTextExpressionListener implements ExpressionListener {
|
||||||
|
private final StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resultFound(String name, Expression expression) {
|
||||||
|
String exp = FormatToExpression.defaultFormat(expression);
|
||||||
|
sb.append(name);
|
||||||
|
sb.append(" = ");
|
||||||
|
sb.append(exp);
|
||||||
|
sb.append('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
@ -107,15 +107,15 @@ public class TableDialog extends JDialog {
|
|||||||
private final HashMap<String, HardwareDescriptionGenerator> availGenerators = new HashMap<>();
|
private final HashMap<String, HardwareDescriptionGenerator> availGenerators = new HashMap<>();
|
||||||
private final JMenu hardwareMenu;
|
private final JMenu hardwareMenu;
|
||||||
private final TruthTableTableModel model;
|
private final TruthTableTableModel model;
|
||||||
|
private final AllSolutionsDialog allSolutionsDialog;
|
||||||
|
private final KarnaughMapDialog kvMap;
|
||||||
|
private final Mouse mouse = Mouse.getMouse();
|
||||||
|
private final UndoManager<TruthTable> undoManager;
|
||||||
private JCheckBoxMenuItem createJK;
|
private JCheckBoxMenuItem createJK;
|
||||||
private File filename;
|
private File filename;
|
||||||
private int columnIndex;
|
private int columnIndex;
|
||||||
private AllSolutionsDialog allSolutionsDialog;
|
|
||||||
private ExpressionListenerStore lastGeneratedExpressions;
|
private ExpressionListenerStore lastGeneratedExpressions;
|
||||||
private KarnaughMapDialog kvMap;
|
|
||||||
private JMenuItem lastUsedGenratorMenuItem;
|
private JMenuItem lastUsedGenratorMenuItem;
|
||||||
private Mouse mouse = Mouse.getMouse();
|
|
||||||
private UndoManager<TruthTable> undoManager;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance
|
* Creates a new instance
|
||||||
@ -136,7 +136,7 @@ public class TableDialog extends JDialog {
|
|||||||
model = new TruthTableTableModel(undoManager);
|
model = new TruthTableTableModel(undoManager);
|
||||||
model.addTableModelListener(new CalculationTableModelListener());
|
model.addTableModelListener(new CalculationTableModelListener());
|
||||||
|
|
||||||
kvMap = new KarnaughMapDialog(this, (boolTable, row) -> model.incValue(boolTable, row));
|
kvMap = new KarnaughMapDialog(this, model::incValue);
|
||||||
|
|
||||||
statusBar = new ExpressionComponent();
|
statusBar = new ExpressionComponent();
|
||||||
font = Screen.getInstance().getFont(1.66f);
|
font = Screen.getInstance().getFont(1.66f);
|
||||||
@ -403,23 +403,17 @@ public class TableDialog extends JDialog {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
fileMenu.add(new TextExportAction(Lang.get("menu_table_exportTablePlainText")) {
|
||||||
fileMenu.add(new ToolTipAction(Lang.get("menu_table_exportTableLaTeX")) {
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
ExpressionListener createExpressionListener() {
|
||||||
try {
|
return new PlainTextExpressionListener();
|
||||||
final LaTeXExpressionListener laTeXExpressionListener = new LaTeXExpressionListener(undoManager.getActual());
|
}
|
||||||
ExpressionListener expressionListener = laTeXExpressionListener;
|
});
|
||||||
if (createJK.isSelected())
|
|
||||||
expressionListener = new ExpressionListenerJK(expressionListener);
|
|
||||||
lastGeneratedExpressions.replayTo(expressionListener);
|
|
||||||
expressionListener.close();
|
|
||||||
|
|
||||||
new ShowStringDialog(TableDialog.this, Lang.get("win_table_exportDialog"),
|
fileMenu.add(new TextExportAction(Lang.get("menu_table_exportTableLaTeX")) {
|
||||||
laTeXExpressionListener.toString()).setVisible(true);
|
@Override
|
||||||
} catch (ExpressionException | FormatterException e1) {
|
ExpressionListener createExpressionListener() throws ExpressionException {
|
||||||
new ErrorMessage(Lang.get("msg_errorDuringCalculation")).addCause(e1).show(TableDialog.this);
|
return new LaTeXExpressionListener(undoManager.getActual());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -770,7 +764,7 @@ public class TableDialog extends JDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final class SizeAction extends AbstractAction {
|
private final class SizeAction extends AbstractAction {
|
||||||
private int n;
|
private final int n;
|
||||||
|
|
||||||
private SizeAction(int n) {
|
private SizeAction(int n) {
|
||||||
super(Lang.get("menu_table_N_variables", n));
|
super(Lang.get("menu_table_N_variables", n));
|
||||||
@ -785,7 +779,7 @@ public class TableDialog extends JDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final class SizeSequentialAction extends AbstractAction {
|
private final class SizeSequentialAction extends AbstractAction {
|
||||||
private int n;
|
private final int n;
|
||||||
|
|
||||||
private SizeSequentialAction(int n) {
|
private SizeSequentialAction(int n) {
|
||||||
super(Lang.get("menu_table_N_variables", n));
|
super(Lang.get("menu_table_N_variables", n));
|
||||||
@ -814,7 +808,7 @@ public class TableDialog extends JDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final class SizeSequentialBidirectionalAction extends AbstractAction {
|
private final class SizeSequentialBidirectionalAction extends AbstractAction {
|
||||||
private int n;
|
private final int n;
|
||||||
|
|
||||||
private SizeSequentialBidirectionalAction(int n) {
|
private SizeSequentialBidirectionalAction(int n) {
|
||||||
super(Lang.get("menu_table_N_variables", n));
|
super(Lang.get("menu_table_N_variables", n));
|
||||||
@ -974,4 +968,29 @@ public class TableDialog extends JDialog {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private abstract class TextExportAction extends ToolTipAction {
|
||||||
|
private TextExportAction(String name) {
|
||||||
|
super(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
try {
|
||||||
|
final ExpressionListener laTeXExpressionListener = createExpressionListener();
|
||||||
|
ExpressionListener expressionListener = laTeXExpressionListener;
|
||||||
|
if (createJK.isSelected())
|
||||||
|
expressionListener = new ExpressionListenerJK(expressionListener);
|
||||||
|
lastGeneratedExpressions.replayTo(expressionListener);
|
||||||
|
expressionListener.close();
|
||||||
|
|
||||||
|
new ShowStringDialog(TableDialog.this, Lang.get("win_table_exportDialog"),
|
||||||
|
laTeXExpressionListener.toString()).setVisible(true);
|
||||||
|
} catch (ExpressionException | FormatterException e1) {
|
||||||
|
new ErrorMessage(Lang.get("msg_errorDuringCalculation")).addCause(e1).show(TableDialog.this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract ExpressionListener createExpressionListener() throws ExpressionException;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1639,6 +1639,7 @@ Sind evtl. die Namen der Variablen nicht eindeutig?</string>
|
|||||||
<string name="menu_table_create_hardware">Bausteine</string>
|
<string name="menu_table_create_hardware">Bausteine</string>
|
||||||
<string name="menu_table_create_jedec_tt">Erzeugt eine JEDEC Datei für den Baustein</string>
|
<string name="menu_table_create_jedec_tt">Erzeugt eine JEDEC Datei für den Baustein</string>
|
||||||
<string name="menu_table_exportTableLaTeX">Erzeuge LaTeX</string>
|
<string name="menu_table_exportTableLaTeX">Erzeuge LaTeX</string>
|
||||||
|
<string name="menu_table_exportTablePlainText">Erzeuge einfachen Text</string>
|
||||||
<string name="menu_table_createFunctionFixture">Erzeuge Testfall</string>
|
<string name="menu_table_createFunctionFixture">Erzeuge Testfall</string>
|
||||||
<string name="menu_table_createFunctionFixture_tt">Erzeugt eine Testfallbeschreibung, welche in einen Testfall
|
<string name="menu_table_createFunctionFixture_tt">Erzeugt eine Testfallbeschreibung, welche in einen Testfall
|
||||||
übernommen werden kann.
|
übernommen werden kann.
|
||||||
|
@ -1602,6 +1602,7 @@
|
|||||||
<string name="menu_table_create_hardware">Device</string>
|
<string name="menu_table_create_hardware">Device</string>
|
||||||
<string name="menu_table_create_jedec_tt">Creates a JEDEC file for the device</string>
|
<string name="menu_table_create_jedec_tt">Creates a JEDEC file for the device</string>
|
||||||
<string name="menu_table_exportTableLaTeX">Export LaTeX</string>
|
<string name="menu_table_exportTableLaTeX">Export LaTeX</string>
|
||||||
|
<string name="menu_table_exportTablePlainText">Export Plain Text</string>
|
||||||
<string name="menu_table_createFunctionFixture">Export Test Case</string>
|
<string name="menu_table_createFunctionFixture">Export Test Case</string>
|
||||||
<string name="menu_table_createFunctionFixture_tt">Creates a test case description that can be used in a test
|
<string name="menu_table_createFunctionFixture_tt">Creates a test case description that can be used in a test
|
||||||
case.
|
case.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user