From 76da2e8281a5d232512b175ac559e29c3216d234 Mon Sep 17 00:00:00 2001 From: Paul Falstad Date: Mon, 9 Dec 2024 11:33:20 -0800 Subject: [PATCH] fix toolbar selection when ESC is pressed (#126) de-select a mode by clicking on toolbar item a second time --- .../circuitjs1/client/CirSim.java | 26 +++++++++---------- .../circuitjs1/client/Toolbar.java | 7 +++-- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/com/lushprojects/circuitjs1/client/CirSim.java b/src/com/lushprojects/circuitjs1/client/CirSim.java index e459aa52..20f06d2a 100644 --- a/src/com/lushprojects/circuitjs1/client/CirSim.java +++ b/src/com/lushprojects/circuitjs1/client/CirSim.java @@ -3581,10 +3581,7 @@ else if (s.compareTo("DragPost") == 0) else if (s.compareTo("Select") == 0) setMouseMode(MODE_SELECT); - String label = classToLabelMap.get(item); - if (label != null) - toolbar.setModeLabel(label); - toolbar.highlightButton(mouseModeStr); + updateToolbar(); // else if (s.length() > 0) { // try { @@ -5584,6 +5581,7 @@ public void onPreviewNativeEvent(NativePreviewEvent e) { if (code==KEY_ESCAPE){ setMouseMode(MODE_SELECT); mouseModeStr = "Select"; + updateToolbar(); tempMouseMode = mouseMode; e.cancel(); } @@ -5646,22 +5644,24 @@ public void onPreviewNativeEvent(NativePreviewEvent e) { return; setMouseMode(MODE_ADD_ELM); mouseModeStr=c; - toolbar.highlightButton(mouseModeStr); - String label = classToLabelMap.get(c); - if (label != null) - toolbar.setModeLabel(label); + updateToolbar(); tempMouseMode = mouseMode; } if (cc==32) { - setMouseMode(MODE_SELECT); - mouseModeStr = "Select"; - toolbar.setModeLabel(classToLabelMap.get(mouseModeStr)); - tempMouseMode = mouseMode; - e.cancel(); + setMouseMode(MODE_SELECT); + mouseModeStr = "Select"; + updateToolbar(); + tempMouseMode = mouseMode; + e.cancel(); } } } + void updateToolbar() { + toolbar.setModeLabel(classToLabelMap.get(mouseModeStr)); + toolbar.highlightButton(mouseModeStr); + } + // factors a matrix into upper and lower triangular matrices by // gaussian elimination. On entry, a[0..n-1][0..n-1] is the // matrix to be factored. ipvt[] returns an integer vector of pivot diff --git a/src/com/lushprojects/circuitjs1/client/Toolbar.java b/src/com/lushprojects/circuitjs1/client/Toolbar.java index 0e053734..813bf8f2 100644 --- a/src/com/lushprojects/circuitjs1/client/Toolbar.java +++ b/src/com/lushprojects/circuitjs1/client/Toolbar.java @@ -112,7 +112,10 @@ private Label createIconButton(String iconClass, String tooltip, MyCommand comma public void onClick(ClickEvent event) { // un-highlight iconLabel.getElement().getStyle().setColor("#333"); - command.execute(); + if (iconLabel == activeButton) + new MyCommand("main", "Select").execute(); + else + command.execute(); } }); @@ -263,7 +266,7 @@ public void setEuroResistors(boolean euro) { final String inductIcon = ""; - final String railIcon = "+5V"; + final String railIcon = "+5V"; final String andIcon = ""; final String orIcon = "";