Skip to content

Commit e1c4c67

Browse files
committed
UX: disable plot2d/3d buttons for empty soln point
also * adds visibility control in UIInput (UIInput.visible() methods), * hides equation entry fields 2 and 3 in function plot modes, looks neater.
1 parent 977c046 commit e1c4c67

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

src/main/java/com/babai/ssplot/ui/SystemInputFrame.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ public class SystemInputFrame extends UIFrame {
6060
private StateVar<SystemMode> curMode;
6161
private EquationSystem.Builder builder;
6262
private PlotData curData;
63-
6463
private Consumer<PlotData> updater;
64+
65+
private int solnPointNum = 0;
6566
private UIInput[] inputEqns;
6667

6768
public SystemInputFrame() {
@@ -104,13 +105,13 @@ private void initInputDialog() {
104105

105106
private JToolBar createToolbarUI(final List<Axis> axes) {
106107
var plot2dCondition = curMode.when(mode ->
107-
(mode == SystemMode.ODE && noOfEqns() == 2)
108+
(mode == SystemMode.ODE && noOfEqns() == 2 && solnPointNum == 2)
108109
|| (mode == SystemMode.DFE && noOfEqns() >= 1)
109110
|| (mode == SystemMode.FN1 && noOfEqns() == 1)
110111
);
111112

112113
var plot3dCondition = curMode.when(mode ->
113-
(mode == SystemMode.ODE && noOfEqns() == 3)
114+
(mode == SystemMode.ODE && noOfEqns() == 3 && solnPointNum == 3)
114115
|| (mode == SystemMode.FN2 && noOfEqns() == 1)
115116
);
116117

@@ -235,7 +236,7 @@ private UIGrid createEqnInputUIPanel(final List<Axis> axes) {
235236
.column(
236237
inputEqns[i] = input()
237238
.chars(10)
238-
.enabled(eqnCondition.get(idx))
239+
.visible(eqnCondition.get(idx))
239240
.onChange(text -> {
240241
builder.eqn(idx, text);
241242
// FIXME find a better way than this to update UI
@@ -255,7 +256,18 @@ private UIGrid createEqnInputUIPanel(final List<Axis> axes) {
255256
input()
256257
.chars(3)
257258
.enabled(inputConditions.get(idx))
258-
.onChange(text -> builder.solnPoint(idx, Double.parseDouble(text)))
259+
.onChange(text -> {
260+
if (!text.isEmpty()) {
261+
solnPointNum++;
262+
builder.solnPoint(idx, Double.parseDouble(text));
263+
} else {
264+
solnPointNum--;
265+
builder.solnPoint(idx, 0.0);
266+
}
267+
268+
// FIXME find a better way than this to update UI
269+
curMode.set(curMode.get());
270+
})
259271
))
260272
)
261273
)

src/main/java/com/babai/ssplot/ui/controls/UIInput.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ public UIInput enabled(boolean enabled) {
6363
return this;
6464
}
6565

66+
// statevar change -> visible property change
67+
public UIInput visible(StateVar<Boolean> visible) {
68+
setEnabled(visible.get());
69+
visible.onChange(() -> setVisible(visible.get()));
70+
return this;
71+
}
72+
73+
public UIInput visible(boolean visible) {
74+
setVisible(visible);
75+
return this;
76+
}
77+
6678
public UIInput numeric(boolean numeric) {
6779
var keyListener = new KeyAdapter() {
6880
public void keyTyped(KeyEvent e) {
@@ -135,10 +147,10 @@ public void changedUpdate(DocumentEvent e) {
135147
}
136148

137149
private void runUpdateActions() {
138-
String text = getText();
139-
if (!text.isEmpty()) {
150+
// String text = getText();
151+
// if (!text.isEmpty()) {
140152
textAction.accept(getText());
141-
}
153+
// }
142154
}
143155
});
144156
return this;

0 commit comments

Comments
 (0)