Added i18n strings, added warning popups for conversion layers, moved tabletree creation into main thread

This commit is contained in:
Robin 2022-01-23 18:34:20 +01:00
parent d657378445
commit e0822c9e0a
10 changed files with 565 additions and 507 deletions

View File

@ -8,3 +8,5 @@ SAVE = Save
CANCEL = Cancel
APPLY = Apply
UNDO = Undo
CONVERSIONTITLE = Conversion Layer Warning

View File

@ -0,0 +1,5 @@
MISSINGFILE = Failed to find
ERRORFILE = Failed to open
ERRORFILESTART = Failed to find start of file for
NCSHINT = Are you loading this CXX file from the original SP-Daten structure?
LOADINGWARNING = Warning: The identification procedure for NCS Expert files is auto-generated. This is not always reliable, especially on small files.\nIt is recommended that you select the binary first and load the correct Cxx file. You can then convert it to a RomRaider definition and add the identification manually.

View File

@ -0,0 +1,6 @@
NOXDFHEADER = XDF file does not have an XDFHEADER element!
NOXDFFORMAT = XDF file does not have an XDFFORMAT element!
ONLYXML = Sorry, only XML XDFs are currently supported!
LOADINGWARNING = Warning: XDF files do not have an identification component. This means this definition will always be chosen if no previous definition is found first.\nIt is recommended to load the binary first and manually select the definition. You can then export it as a RomRaider definition and add the identification component.

View File

@ -54,6 +54,7 @@ import com.romraider.xml.ConversionLayer.ConversionLayerFactory;
public class OpenImageWorker extends SwingWorker<Void, Void> {
private static final Logger LOGGER = Logger.getLogger(OpenImageWorker.class);
private final File inputFile;
private Rom rom;
private String finalStatus;
public OpenImageWorker(File inputFile) {
@ -73,24 +74,22 @@ public class OpenImageWorker extends SwingWorker<Void, Void> {
ECUEditor.rb.getString("FINALIZING"));
setProgress(90);
editor.addRom(rom);
editor.getStatusPanel().setStatus(
ECUEditor.rb.getString("DONELOAD"));
setProgress(95);
editor.getStatusPanel().setStatus(
ECUEditor.rb.getString("CHECKSUM"));
int validChecksums = rom.validateChecksum();
if(rom.getNumChecksumsManagers() == 0) {
finalStatus = ECUEditor.rb.getString("STATUSREADY");
}
else {
editor.getStatusPanel().setStatus(
ECUEditor.rb.getString("CHECKSUM"));
finalStatus = String.format(ECUEditor.rb.getString("CHECKSUMSTATE"),
validChecksums, rom.getNumChecksumsManagers());
}
rom.validateChecksum(), rom.getNumChecksumsManagers());
}
this.rom = rom;
}
private Document createDocument(File f) throws Exception {
@ -114,7 +113,7 @@ public class OpenImageWorker extends SwingWorker<Void, Void> {
doc = l.convertToDocumentTree(f);
if(doc == null)
throw new SAXParseException("Unknown file format!", null);
throw new SAXParseException(ECUEditor.rb.getString("UNREADABLEDEF"), null);
}
//Default case
else {
@ -316,11 +315,21 @@ public class OpenImageWorker extends SwingWorker<Void, Void> {
@Override
public void done() {
ECUEditor editor = ECUEditorManager.getECUEditor();
editor.getStatusPanel().update(finalStatus, 0);
editor.refreshTableCompareMenus();
editor.setCursor(null);
editor.refreshUI();
System.gc();
ECUEditor editor = ECUEditorManager.getECUEditor();
//Add the rom in the main thread
if(rom != null) {
editor.addRom(rom);
rom = null;
editor.getStatusPanel().update(finalStatus, 0);
editor.refreshTableCompareMenus();
editor.setCursor(null);
editor.refreshUI();
System.gc();
}
else {
editor.getStatusPanel().update(ECUEditor.rb.getString("STATUSREADY"), 0);
}
}
}

View File

@ -434,8 +434,12 @@ public class Rom extends DefaultMutableTreeNode implements Serializable {
for(TableTreeNode tableTreeNode : tableNodes.values()) {
TableFrame frame = tableTreeNode.getFrame();
TableUpdateHandler.getInstance().deregisterTable(tableTreeNode.getTable());
tableTreeNode.getTable().clearData();
TableUpdateHandler.getInstance().deregisterTable(tableTreeNode.getTable());
// Quite slow and doesn't seem to be necessary after testing,
// uncomment if you disagree
//tableTreeNode.getTable().clearData();
if(frame != null) {

View File

@ -41,13 +41,13 @@ public class DefinitionFilter extends FileFilter {
new XDFConversionLayer().getRegexFileNameFilter()
};
private String[] filterDescr = {".xml", ".Cxx", ".xdf"};
private String[] filterDescr = {".xml", ".Cxx (NCS Expert)", ".xdf (Tuner Pro)"};
private String startDescription;
public DefinitionFilter() {
startDescription = rb.getString("DESC");
}
public boolean accept(File f) {
if (f != null) {
if (f.isDirectory()) {

View File

@ -32,6 +32,8 @@ import com.romraider.Settings;
import com.romraider.editor.ecu.ECUEditorManager;
import com.romraider.util.ResourceUtil;
import com.romraider.util.SettingsManager;
import com.romraider.xml.ConversionLayer.ConversionLayer;
import com.romraider.xml.ConversionLayer.ConversionLayerFactory;
public class DefinitionManager extends javax.swing.JFrame implements ActionListener {
@ -228,7 +230,20 @@ public class DefinitionManager extends javax.swing.JFrame implements ActionListe
}
}
if(!alreadyAdded) fileNames.add(f.getAbsolutePath());
if(!alreadyAdded) {
//If its a file that needs to be converted sometimes a warning
//should be displayed to the user
if(ConversionLayerFactory.requiresConversionLayer(f)) {
ConversionLayer layer = ConversionLayerFactory.getConversionLayerForFile(f);
if(layer.getDefinitionPickerInfo() != null) {
JOptionPane.showMessageDialog(null, layer.getDefinitionPickerInfo(),
rb.getString("CONVERSIONTITLE"), JOptionPane.WARNING_MESSAGE);
}
}
fileNames.add(f.getAbsolutePath());
}
settings.setLastDefinitionDir(f.getParentFile());
}

View File

@ -33,6 +33,8 @@ public abstract class ConversionLayer {
public final static String xmlRegexFileNameFilter = "^.*\\.(xml|XML)$";
public abstract String getDefinitionPickerInfo();
public abstract String getRegexFileNameFilter();
/*

View File

@ -31,6 +31,7 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.ResourceBundle;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@ -46,9 +47,12 @@ import com.romraider.Settings;
import com.romraider.editor.ecu.ECUEditor;
import com.romraider.editor.ecu.OpenImageWorker;
import com.romraider.util.HexUtil;
import com.romraider.util.ResourceUtil;
import com.romraider.util.SettingsManager;;
public class XDFConversionLayer extends ConversionLayer {
protected static final ResourceBundle rb = new ResourceUtil().getBundle(
XDFConversionLayer.class.getName());
private static final Logger LOGGER = Logger.getLogger(XDFConversionLayer.class);
private HashMap<Integer, String> categoryMap = new HashMap<Integer, String>();
@ -65,6 +69,11 @@ public class XDFConversionLayer extends ConversionLayer {
// Defaults
String defaultDataType;
@Override
public String getDefinitionPickerInfo() {
return rb.getString("LOADINGWARNING");
}
@Override
public String getRegexFileNameFilter() {
return "^.*xdf";
@ -84,8 +93,7 @@ public class XDFConversionLayer extends ConversionLayer {
if (firstLine.equalsIgnoreCase("XDF")) {
br.close();
// TODO: Add i18n
throw new SAXException("Sorry, only XML XDFs are currently supported!");
throw new SAXException(rb.getString("ONLYXML"));
} else {
br.close();
}
@ -495,8 +503,7 @@ public class XDFConversionLayer extends ConversionLayer {
}
if (baseNode == xdfDoc) {
//TODO: Add i18n
throw new SAXException("XDF file does not have an XDFFORMAT element!");
throw new SAXException(rb.getString("NOXDFFORMAT"));
}
nodeCount = baseNode.getChildNodes().getLength();
@ -522,8 +529,7 @@ public class XDFConversionLayer extends ConversionLayer {
}
if (header == null) {
//TODO:Add i18n
throw new SAXException("XDF file does not have an XDFHEADER element!");
throw new SAXException(rb.getString("NOXDFHEADER"));
}
// Go through all tables and create RR tables