added builder to TableFrames menu

This commit is contained in:
hneemann 2016-05-09 20:24:19 +02:00
parent 7b42d3e0f9
commit 6ac73c718d
5 changed files with 51 additions and 8 deletions

View File

@ -136,9 +136,10 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
final boolean normalMode = savedListener == null;
if (circuit != null) {
circuitComponent = new CircuitComponent(circuit, library, shapeFactory, savedListener);
circuitComponent = new CircuitComponent(library, shapeFactory, savedListener);
SwingUtilities.invokeLater(() -> circuitComponent.setCircuit(circuit));
} else {
circuitComponent = new CircuitComponent(new Circuit(), library, shapeFactory, savedListener);
circuitComponent = new CircuitComponent(library, shapeFactory, savedListener);
if (fileToOpen != null) {
SwingUtilities.invokeLater(() -> loadFile(fileToOpen, false));
} else {
@ -427,7 +428,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
public void actionPerformed(ActionEvent e) {
try {
Model model = new ModelDescription(circuitComponent.getCircuit(), library).createModel(false);
new TableFrame(Main.this, new ModelAnalyser(model).analyse()).setVisible(true);
new TableFrame(Main.this, new ModelAnalyser(model).analyse(), shapeFactory).setVisible(true);
elementState.activate();
} catch (PinException | NodeException | AnalyseException e1) {
showErrorAndStopModel(Lang.get("msg_annalyseErr"), e1);
@ -441,7 +442,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
@Override
public void actionPerformed(ActionEvent e) {
TruthTable tt = new TruthTable(3).addResult();
new TableFrame(Main.this, tt).setVisible(true);
new TableFrame(Main.this, tt, shapeFactory).setVisible(true);
elementState.activate();
}
}

View File

@ -65,11 +65,10 @@ public class CircuitComponent extends JComponent {
/**
* Creates a new instance
*
* @param aCircuit the circuit to show
* @param library the library used to edit the attributes of the elements
* @param shapeFactory the shapeFactory used for copied elements
*/
public CircuitComponent(Circuit aCircuit, ElementLibrary library, ShapeFactory shapeFactory, SavedListener parentsSavedListener) {
public CircuitComponent(ElementLibrary library, ShapeFactory shapeFactory, SavedListener parentsSavedListener) {
this.library = library;
this.shapeFactory = shapeFactory;
this.parentsSavedListener = parentsSavedListener;
@ -108,7 +107,7 @@ public class CircuitComponent extends JComponent {
mouseCopySelected = new MouseControllerCopySelected(moveCursor);
mouseRun = new MouseControllerRun(normalCursor);
setCircuit(aCircuit);
setCircuit(new Circuit());
MouseDispatcher disp = new MouseDispatcher();
addMouseMotionListener(disp);

View File

@ -6,6 +6,10 @@ import de.neemann.digital.analyse.expression.Expression;
import de.neemann.digital.analyse.expression.ExpressionException;
import de.neemann.digital.analyse.expression.format.FormatToExpression;
import de.neemann.digital.analyse.expression.format.FormatterException;
import de.neemann.digital.draw.builder.Builder;
import de.neemann.digital.draw.elements.Circuit;
import de.neemann.digital.draw.shapes.ShapeFactory;
import de.neemann.digital.gui.Main;
import de.neemann.digital.lang.Lang;
import de.neemann.gui.ErrorMessage;
import de.neemann.gui.ToolTipAction;
@ -22,6 +26,7 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.HashSet;
/**
* @author hneemann
@ -35,6 +40,7 @@ public class TableFrame extends JFrame {
private final JPopupMenu renamePopup;
private final Font font;
private final JMenu reorderMenu;
private final ShapeFactory shapeFactory;
private TruthTableTableModel model;
private TableColumn column;
private int columnIndex;
@ -46,8 +52,9 @@ public class TableFrame extends JFrame {
* @param parent the parent frame
* @param truthTable the table to show
*/
public TableFrame(JFrame parent, TruthTable truthTable) {
public TableFrame(JFrame parent, TruthTable truthTable, ShapeFactory shapeFactory) {
super(Lang.get("win_table"));
this.shapeFactory = shapeFactory;
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
@ -109,6 +116,16 @@ public class TableFrame extends JFrame {
}.setToolTip(Lang.get("menu_table_columnsAdd_tt")).createJMenuItem());
bar.add(colsMenu);
JMenu createMenu = new JMenu(Lang.get("menu_table_create"));
createMenu.add(new ToolTipAction(Lang.get("menu_table_create")) {
@Override
public void actionPerformed(ActionEvent actionEvent) {
createCircuit();
}
}.setToolTip(Lang.get("menu_table_create_tt")).createJMenuItem());
bar.add(createMenu);
setJMenuBar(bar);
setModel(new TruthTableTableModel(truthTable));
@ -119,6 +136,28 @@ public class TableFrame extends JFrame {
setLocationRelativeTo(parent);
}
private void createCircuit() {
try {
Builder builder = new Builder(shapeFactory);
HashSet<String> contained = new HashSet<>();
new ExpressionCreator(model.getTable()) {
@Override
public void resultFound(String name, Expression expression) throws FormatterException {
if (!contained.contains(name)) {
contained.add(name);
builder.addExpression(name, expression);
}
}
}.create();
Circuit circuit = builder.createCircuit();
SwingUtilities.invokeLater(() -> new Main(null, circuit).setVisible(true));
} catch (ExpressionException | FormatterException e) {
new ErrorMessage(Lang.get("msg_errorDuringCalculation")).addCause(e).show();
}
}
private void editColumnAt(Point p) {
columnIndex = header.columnAtPoint(p);

View File

@ -264,6 +264,8 @@ menu_table_swap_N1_N2=Tausche Variable {0} und {1}
menu_table_columns=Spalten
menu_table_columnsAdd=hinzuf\u00FCgen
menu_table_columnsAdd_tt=F\u00FCgt der Tabelle eine Ergebnisspalte hinzu.
menu_table_create=Model erzeugen
menu_table_create_tt=Erzeugt ein Model, welches der Wahrheitstabelle entspricht.
menu_about=\u00DCber Digital

View File

@ -244,6 +244,8 @@ menu_table_swap_N1_N2=Swap Variables {0} and {1}
menu_table_columns=Columns
menu_table_columnsAdd=Add a Column
menu_table_columnsAdd_tt=Adds a new result column.
menu_table_create=create circuit
menu_table_create_tt=Creates a circuit which reproduces the truth table.
win_saveChanges=Save Changes?
win_confirmExit=Confirm Exit!