java console: option not to remember latest used port

This commit is contained in:
rusefi 2023-08-29 13:46:23 -04:00
parent 720ba01d04
commit 29df5a635d
3 changed files with 31 additions and 2 deletions

View File

@ -44,6 +44,14 @@ public class PersistentConfiguration {
}));
}
public static boolean getBoolProperty(String name) {
return getConfig().getRoot().getBoolProperty(name);
}
public static void setBoolProperty(String name, boolean value) {
getConfig().getRoot().setBoolProperty(name, value);
}
@SuppressWarnings("unchecked")
public void load() {
if (!config.isEmpty()) {

View File

@ -6,7 +6,7 @@ import java.net.URL;
import java.util.concurrent.atomic.AtomicReference;
public class rusEFIVersion {
public static final int CONSOLE_VERSION = 20230805;
public static final int CONSOLE_VERSION = 20230829;
public static AtomicReference<String> firmwareVersion = new AtomicReference<>("N/A");
public static long classBuildTimeMillis() {

View File

@ -4,6 +4,7 @@ import com.devexperts.logging.Logging;
import com.rusefi.autodetect.PortDetector;
import com.rusefi.autodetect.SerialAutoChecker;
import com.rusefi.core.io.BundleUtil;
import com.rusefi.core.preferences.storage.PersistentConfiguration;
import com.rusefi.core.ui.AutoupdateUtil;
import com.rusefi.io.LinkManager;
import com.rusefi.io.serial.BaudRateHolder;
@ -45,6 +46,7 @@ import static javax.swing.JOptionPane.YES_NO_OPTION;
*/
public class StartupFrame {
private static final Logging log = getLogging(Launcher.class);
public static final String ALWAYS_AUTO_PORT = "always_auto_port";
// private static final int RUSEFI_ORANGE = 0xff7d03;
@ -112,6 +114,22 @@ public class StartupFrame {
final JButton connectButton = new JButton("Connect", new ImageIcon(getClass().getResource("/com/rusefi/connect48.png")));
//connectButton.setBackground(new Color(RUSEFI_ORANGE)); // custom orange
setToolTip(connectButton, "Connect to real hardware");
JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem("Always auto-connect port");
menuItem.setState(PersistentConfiguration.getBoolProperty(ALWAYS_AUTO_PORT));
menuItem.addActionListener(e -> PersistentConfiguration.setBoolProperty(ALWAYS_AUTO_PORT, menuItem.getState()));
connectButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
if (!SwingUtilities.isRightMouseButton(e))
return;
JPopupMenu menu = new JPopupMenu();
menu.add(menuItem);
menu.show(connectButton, e.getX(), e.getY());
}
});
connectPanel.add(connectButton);
connectPanel.setVisible(false);
@ -319,7 +337,10 @@ public class StartupFrame {
for (final String port : ports)
comboPorts.addItem(port);
String defaultPort = getConfig().getRoot().getProperty(ConsoleUI.PORT_KEY);
comboPorts.setSelectedItem(defaultPort);
if (!PersistentConfiguration.getBoolProperty(ALWAYS_AUTO_PORT)) {
comboPorts.setSelectedItem(defaultPort);
}
trueLayout(comboPorts);
}