From c20afa585bffe518afbb0e9929fed4633c719e76 Mon Sep 17 00:00:00 2001 From: Robin Date: Fri, 1 Oct 2021 19:12:23 +0200 Subject: [PATCH] Fixed BitwiseSwitch not closing. Added better error messages for logger definition --- .../romraider/logger/ecu/EcuLogger.properties | 1 + .../com/romraider/logger/ecu/EcuLogger.java | 16 +++++++++++++-- .../ecu/definition/EcuDataLoaderImpl.java | 4 ++-- .../java/com/romraider/maps/DataCell.java | 1 - src/main/java/com/romraider/maps/Table.java | 14 ++++++++++++- src/main/java/com/romraider/maps/Table1D.java | 13 +----------- .../romraider/maps/TableBitwiseSwitch.java | 14 ++++++------- .../maps/TableBitwiseSwitchView.java | 8 +++----- .../java/com/romraider/maps/TableView.java | 20 +++++++++---------- 9 files changed, 50 insertions(+), 41 deletions(-) diff --git a/i18n/com/romraider/logger/ecu/EcuLogger.properties b/i18n/com/romraider/logger/ecu/EcuLogger.properties index 8f8ded8c..fd48095a 100644 --- a/i18n/com/romraider/logger/ecu/EcuLogger.properties +++ b/i18n/com/romraider/logger/ecu/EcuLogger.properties @@ -16,6 +16,7 @@ COMPLETE = Complete ... READY = Ready ... YES = Yes NO = No +LOGGERDEFERROR = Error loading definition: LOGGERDEFNOTCFG = Logger definition not configured.\nGo online to download the latest definition file? LOGGERCONFIG = Logger Configuration CFGEDFSMENU = The Logger definition file needs to be configured before connecting to the ECU.\nMenu: Settings > Logger Definition Location ...\nOnce configured, restart the Logger application. diff --git a/src/main/java/com/romraider/logger/ecu/EcuLogger.java b/src/main/java/com/romraider/logger/ecu/EcuLogger.java index a7c136f7..a379a031 100644 --- a/src/main/java/com/romraider/logger/ecu/EcuLogger.java +++ b/src/main/java/com/romraider/logger/ecu/EcuLogger.java @@ -593,14 +593,26 @@ public final class EcuLogger extends AbstractFrame implements MessageListener { LOGGER.info(loadResult); } catch (ConfigurationException cfe) { reportError(cfe); - showMissingConfigDialog(); + showErrorConfigDialog(cfe); } catch (Exception e) { reportError(e); } } } - + + private void showErrorConfigDialog(Exception e) { + Object[] options = {"OK"}; + showOptionDialog(this, + rb.getString("LOGGERDEFERROR") + e.getMessage(), + rb.getString("LOGGERCONFIG"), + DEFAULT_OPTION, + ERROR_MESSAGE, + null, + options, + options[0]); + } + private void showMissingConfigDialog() { Object[] options = {rb.getString("YES"), rb.getString("NO")}; int answer = showOptionDialog(this, diff --git a/src/main/java/com/romraider/logger/ecu/definition/EcuDataLoaderImpl.java b/src/main/java/com/romraider/logger/ecu/definition/EcuDataLoaderImpl.java index fbe8b0de..97eaef5b 100644 --- a/src/main/java/com/romraider/logger/ecu/definition/EcuDataLoaderImpl.java +++ b/src/main/java/com/romraider/logger/ecu/definition/EcuDataLoaderImpl.java @@ -136,7 +136,7 @@ public final class EcuDataLoaderImpl implements EcuDataLoader { } finally { inputStream.close(); } - } catch (FileNotFoundException fnfe) { + }/* catch (FileNotFoundException fnfe) { throw new ConfigurationException(MessageFormat.format( rb.getString("LOGFNF"), loggerConfigFilePath)); } catch (SAXParseException spe) { @@ -144,7 +144,7 @@ public final class EcuDataLoaderImpl implements EcuDataLoader { // unzip the defs that a better error message is in order throw new ConfigurationException(MessageFormat.format( rb.getString("UNZIPLOG"), loggerConfigFilePath)); - } catch (Exception e) { + } */catch (Exception e) { throw new ConfigurationException(e); } diff --git a/src/main/java/com/romraider/maps/DataCell.java b/src/main/java/com/romraider/maps/DataCell.java index 22a76f27..3402c657 100644 --- a/src/main/java/com/romraider/maps/DataCell.java +++ b/src/main/java/com/romraider/maps/DataCell.java @@ -66,7 +66,6 @@ public class DataCell { if (st.hasMoreTokens()) { this.staticText = st.nextToken(); } - table.setStaticDataTable(true); } public DataCell(Table table, int index, Rom rom) { diff --git a/src/main/java/com/romraider/maps/Table.java b/src/main/java/com/romraider/maps/Table.java index 3759e116..edb5edd6 100644 --- a/src/main/java/com/romraider/maps/Table.java +++ b/src/main/java/com/romraider/maps/Table.java @@ -103,7 +103,19 @@ public abstract class Table implements Serializable { public DataCell[] getData() { return data; } - + + public void addStaticDataCell(String s) { + setStaticDataTable(true); + DataCell c = new DataCell(this, s, null); + + for(int i = 0; i < data.length; i++) { + if(data[i] == null) { + data[i] = c; + break; + } + } + } + //Cleans up all references to avoid data leaks public void clearData() { diff --git a/src/main/java/com/romraider/maps/Table1D.java b/src/main/java/com/romraider/maps/Table1D.java index 590d565b..ae383be0 100644 --- a/src/main/java/com/romraider/maps/Table1D.java +++ b/src/main/java/com/romraider/maps/Table1D.java @@ -55,18 +55,7 @@ public class Table1D extends Table { public byte[] saveFile(byte[] binData) { return binData; } - - public void addStaticDataCell(String s) { - DataCell c = new DataCell(this, s, null); - - for(int i = 0; i < data.length; i++) { - if(data[i] == null) { - data[i] = c; - break; - } - } - } - + @Override public StringBuffer getTableAsString() { if(isStaticDataTable()) { diff --git a/src/main/java/com/romraider/maps/TableBitwiseSwitch.java b/src/main/java/com/romraider/maps/TableBitwiseSwitch.java index 27cb684d..458bf98d 100644 --- a/src/main/java/com/romraider/maps/TableBitwiseSwitch.java +++ b/src/main/java/com/romraider/maps/TableBitwiseSwitch.java @@ -1,6 +1,6 @@ /* * RomRaider Open-Source Tuning, Logging and Reflashing - * Copyright (C) 2006-2020 RomRaider.com + * Copyright (C) 2006-2021 RomRaider.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,7 +19,6 @@ package com.romraider.maps; -import java.awt.GridLayout; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; @@ -30,9 +29,6 @@ import java.util.Map; import java.util.Map.Entry; import javax.swing.JCheckBox; -import javax.swing.JLabel; -import javax.swing.JPanel; - import com.romraider.util.ByteUtil; public class TableBitwiseSwitch extends Table { @@ -58,11 +54,13 @@ public class TableBitwiseSwitch extends Table { bits_array[((dataSize - 1 - i) *8)+ j] = byte_values[7-j]; } } - - JPanel radioPanel = new JPanel(new GridLayout(0, 1)); - radioPanel.add(new JLabel(" " + getName())); } + //Cleans up all references to avoid data leaks + public void clearData() { + controlBits.clear(); + } + public Map getControlBits() { return controlBits; } diff --git a/src/main/java/com/romraider/maps/TableBitwiseSwitchView.java b/src/main/java/com/romraider/maps/TableBitwiseSwitchView.java index 91157b85..2f12970b 100644 --- a/src/main/java/com/romraider/maps/TableBitwiseSwitchView.java +++ b/src/main/java/com/romraider/maps/TableBitwiseSwitchView.java @@ -1,6 +1,6 @@ /* * RomRaider Open-Source Tuning, Logging and Reflashing - * Copyright (C) 2006-2020 RomRaider.com + * Copyright (C) 2006-2021 RomRaider.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -45,7 +45,6 @@ public class TableBitwiseSwitchView extends TableView { private ArrayList checkboxes; private TableBitwiseSwitch table; - public TableBitwiseSwitchView(TableBitwiseSwitch table) { super(table); this.table = table; @@ -56,8 +55,7 @@ public class TableBitwiseSwitchView extends TableView { } @Override - public void populateTableVisual() - throws ArrayIndexOutOfBoundsException, IndexOutOfBoundsException { + public void populateTableVisual() { int maxBitPosition = ((table.getDataSize() * 8) - 1); JPanel radioPanel = new JPanel(new GridLayout(0, 1)); radioPanel.add(new JLabel(" " + getName())); @@ -65,7 +63,7 @@ public class TableBitwiseSwitchView extends TableView { for (Entry entry : TableBitwiseSwitch.sortByValue(table.getControlBits()).entrySet()) { if (entry.getValue() > maxBitPosition) { String mismatch = MessageFormat.format( - rb.getString("OUTOFRANGE"), super.getName()); + rb.getString("OUTOFRANGE"), table.getName()); showMessageDialog(this, mismatch, rb.getString("DEFERROR"), ERROR_MESSAGE); break; diff --git a/src/main/java/com/romraider/maps/TableView.java b/src/main/java/com/romraider/maps/TableView.java index bb7c69d3..2b2c94e3 100644 --- a/src/main/java/com/romraider/maps/TableView.java +++ b/src/main/java/com/romraider/maps/TableView.java @@ -601,8 +601,6 @@ public abstract class TableView extends JPanel implements Serializable { return new Dimension(width, height); } - - public void startHighlight(int x, int y) { this.highlightBeginY = y; this.highlightBeginX = x; @@ -896,14 +894,16 @@ public abstract class TableView extends JPanel implements Serializable { public void updateTableLabel() { - if(null == table.name || table.name.isEmpty()) { - ;// Do not update label. - } else if(null == table.getCurrentScale () || "0x" == table.getCurrentScale().getUnit()) { - // static or no scale exists. - tableLabel.setText(getName()); - } else { - tableLabel.setText(getName() + " (" + table.getCurrentScale().getUnit() + ")"); - } + if(tableLabel != null) { + if(null == table.name || table.name.isEmpty()) { + ;// Do not update label. + } else if(null == table.getCurrentScale () || "0x" == table.getCurrentScale().getUnit()) { + // static or no scale exists. + tableLabel.setText(getName()); + } else { + tableLabel.setText(getName() + " (" + table.getCurrentScale().getUnit() + ")"); + } + } } public String getName() {