simplified the input shape and dialog

This commit is contained in:
hneemann 2020-04-12 10:19:33 +02:00
parent 3694f78c5b
commit 191d9b55e9
3 changed files with 16 additions and 21 deletions

View File

@ -45,9 +45,9 @@ public class In implements Element {
private final String label;
private final String pinNumber;
private final IntFormat format;
private final boolean showInGraph;
private Model model;
private ObservableValue input;
private boolean showInGraph;
/**
* Create a new instance

View File

@ -165,7 +165,7 @@ public class InputShape implements Shape {
} else {
if (dialog == null || !dialog.isVisible()) {
Model model = ((In) element).getModel();
dialog = new SingleValueDialog(model.getWindowPosManager().getMainFrame(), pos, label, value, isHighZ, cc, model);
dialog = new SingleValueDialog(model.getWindowPosManager().getMainFrame(), pos, label, value, isHighZ, model);
dialog.setVisible(true);
} else
dialog.requestFocus();

View File

@ -27,8 +27,7 @@ import java.util.Arrays;
public final class SingleValueDialog extends JDialog implements ModelStateObserverTyped {
private final ObservableValue value;
private final CircuitComponent circuitComponent;
private final SyncAccess model;
private final SyncAccess syncAccess;
private enum InMode {
HEX(Lang.get("attr_dialogHex")),
@ -38,7 +37,7 @@ public final class SingleValueDialog extends JDialog implements ModelStateObserv
// highZ needs to be the last entry!! See InMode#values(boolean)
HIGHZ(Lang.get("attr_dialogHighz"));
private String langText;
private final String langText;
InMode(String langKey) {
this.langText = langKey;
@ -69,21 +68,18 @@ public final class SingleValueDialog extends JDialog implements ModelStateObserv
/**
* Edits a single value
*
* @param parent the parent frame
* @param pos the position to pop up the dialog
* @param label the name of the value
* @param value the value to edit
* @param supportsHighZ true is high z is supported
* @param circuitComponent the component which contains the circuit
* @param model the model
* @param parent the parent frame
* @param pos the position to pop up the dialog
* @param label the name of the value
* @param value the value to edit
* @param supportsHighZ true is high z is supported
* @param model the model
*/
//CHECKSTYLE.OFF: ParameterNumberCheck
public SingleValueDialog(JFrame parent, Point pos, String label, ObservableValue value, boolean supportsHighZ, CircuitComponent circuitComponent, Model model) {
public SingleValueDialog(JFrame parent, Point pos, String label, ObservableValue value, boolean supportsHighZ, Model model) {
super(parent, Lang.get("win_valueInputTitle_N", label), false);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.value = value;
this.circuitComponent = circuitComponent;
this.model = model;
this.syncAccess = model;
editValue = value.getValue();
this.supportsHighZ = supportsHighZ;
@ -160,13 +156,12 @@ public final class SingleValueDialog extends JDialog implements ModelStateObserv
textField.requestFocus();
textField.select(0, Integer.MAX_VALUE);
}
//CHECKSTYLE.ON: ParameterNumberCheck
private void apply() {
if (getSelectedFormat().equals(InMode.HIGHZ)) {
model.modify(value::setToHighZ);
syncAccess.modify(value::setToHighZ);
} else {
model.modify(() -> value.setValue(editValue));
syncAccess.modify(() -> value.setValue(editValue));
}
}
@ -211,7 +206,7 @@ public final class SingleValueDialog extends JDialog implements ModelStateObserv
switch (getSelectedFormat()) {
case ASCII:
char val = (char) (editValue);
textField.setText("\'" + val + "\'");
textField.setText("'" + val + "'");
textField.setCaretPosition(1);
break;
case DECIMAL:
@ -305,7 +300,7 @@ public final class SingleValueDialog extends JDialog implements ModelStateObserv
@Override
public void setValue(Object o) {
if (o != null && o instanceof Number) {
if (o instanceof Number) {
editValue = ((Number) o).longValue();
setLongToDialog(editValue);
apply();