mirror of https://github.com/rusefi/RomRaider.git
user profile support started
git-svn-id: http://svn.3splooges.com/romraider-arch/trunk@311 d2e2e1cd-ba16-0410-be16-b7c4453c7c2d
This commit is contained in:
parent
9e9b932ebc
commit
5cb44dbd92
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!ELEMENT parameter EMPTY >
|
||||
<!ATTLIST parameter id ID #REQUIRED >
|
||||
|
||||
<!ELEMENT parameters ( parameter+ ) >
|
||||
|
||||
<!ELEMENT switch EMPTY >
|
||||
<!ATTLIST switch id ID #REQUIRED >
|
||||
|
||||
<!ELEMENT switches ( switch+ ) >
|
||||
|
||||
<!ELEMENT profile ( parameters*, switches* ) >
|
|
@ -0,0 +1,171 @@
|
|||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<!DOCTYPE profile SYSTEM "profile.dtd">
|
||||
|
||||
<profile>
|
||||
|
||||
<parameters>
|
||||
<parameter id="P1"/>
|
||||
<parameter id="P2"/>
|
||||
<parameter id="P3"/>
|
||||
<parameter id="P4"/>
|
||||
<parameter id="P5"/>
|
||||
<parameter id="P6"/>
|
||||
<parameter id="P7"/>
|
||||
<parameter id="P8"/>
|
||||
<parameter id="P9"/>
|
||||
<parameter id="P10"/>
|
||||
<parameter id="P11"/>
|
||||
<parameter id="P12"/>
|
||||
<parameter id="P13"/>
|
||||
<parameter id="P14"/>
|
||||
<parameter id="P15"/>
|
||||
<parameter id="P16"/>
|
||||
<parameter id="P17"/>
|
||||
<parameter id="P18"/>
|
||||
<parameter id="P19"/>
|
||||
<parameter id="P20"/>
|
||||
<parameter id="P21"/>
|
||||
<parameter id="P22"/>
|
||||
<parameter id="P23"/>
|
||||
<parameter id="P24"/>
|
||||
<parameter id="P25"/>
|
||||
<parameter id="P26"/>
|
||||
<parameter id="P27"/>
|
||||
<parameter id="P28"/>
|
||||
<parameter id="P29"/>
|
||||
<parameter id="P30"/>
|
||||
<parameter id="P31"/>
|
||||
<parameter id="P32"/>
|
||||
<parameter id="P33"/>
|
||||
<parameter id="P34"/>
|
||||
<parameter id="P35"/>
|
||||
<parameter id="P36"/>
|
||||
<parameter id="P37"/>
|
||||
<parameter id="P38"/>
|
||||
<parameter id="P39"/>
|
||||
<parameter id="P40"/>
|
||||
<parameter id="P41"/>
|
||||
<parameter id="P42"/>
|
||||
<parameter id="P43"/>
|
||||
<parameter id="P44"/>
|
||||
<parameter id="P45"/>
|
||||
<parameter id="P46"/>
|
||||
<parameter id="P47"/>
|
||||
<parameter id="P48"/>
|
||||
<parameter id="P49"/>
|
||||
<parameter id="P50"/>
|
||||
<parameter id="P51"/>
|
||||
<parameter id="P52"/>
|
||||
<parameter id="P53"/>
|
||||
<parameter id="P54"/>
|
||||
<parameter id="P55"/>
|
||||
<parameter id="P56"/>
|
||||
<parameter id="P57"/>
|
||||
<parameter id="P58"/>
|
||||
<parameter id="P59"/>
|
||||
<parameter id="P60"/>
|
||||
<parameter id="P61"/>
|
||||
<parameter id="P62"/>
|
||||
<parameter id="P63"/>
|
||||
<parameter id="P64"/>
|
||||
<parameter id="P65"/>
|
||||
<parameter id="P66"/>
|
||||
<parameter id="P67"/>
|
||||
<parameter id="P68"/>
|
||||
<parameter id="P69"/>
|
||||
<parameter id="P70"/>
|
||||
<parameter id="P71"/>
|
||||
<parameter id="P72"/>
|
||||
<parameter id="P73"/>
|
||||
<parameter id="P74"/>
|
||||
<parameter id="P75"/>
|
||||
<parameter id="P76"/>
|
||||
<parameter id="P77"/>
|
||||
<parameter id="P78"/>
|
||||
<parameter id="P79"/>
|
||||
<parameter id="P80"/>
|
||||
<parameter id="P81"/>
|
||||
<parameter id="P82"/>
|
||||
<parameter id="P83"/>
|
||||
<parameter id="P84"/>
|
||||
<parameter id="P85"/>
|
||||
<parameter id="P86"/>
|
||||
<parameter id="P87"/>
|
||||
<parameter id="P88"/>
|
||||
<parameter id="P89"/>
|
||||
<parameter id="P90"/>
|
||||
<parameter id="P91"/>
|
||||
</parameters>
|
||||
|
||||
<switches>
|
||||
<switch id="S1"/>
|
||||
<switch id="S2"/>
|
||||
<switch id="S3"/>
|
||||
<switch id="S4"/>
|
||||
<switch id="S5"/>
|
||||
<switch id="S6"/>
|
||||
<switch id="S7"/>
|
||||
<switch id="S8"/>
|
||||
<switch id="S9"/>
|
||||
<switch id="S10"/>
|
||||
<switch id="S11"/>
|
||||
<switch id="S12"/>
|
||||
<switch id="S13"/>
|
||||
<switch id="S14"/>
|
||||
<switch id="S15"/>
|
||||
<switch id="S16"/>
|
||||
<switch id="S17"/>
|
||||
<switch id="S18"/>
|
||||
<switch id="S19"/>
|
||||
<switch id="S20"/>
|
||||
<switch id="S21"/>
|
||||
<switch id="S22"/>
|
||||
<switch id="S23"/>
|
||||
<switch id="S24"/>
|
||||
<switch id="S25"/>
|
||||
<switch id="S26"/>
|
||||
<switch id="S27"/>
|
||||
<switch id="S28"/>
|
||||
<switch id="S29"/>
|
||||
<switch id="S30"/>
|
||||
<switch id="S31"/>
|
||||
<switch id="S32"/>
|
||||
<switch id="S33"/>
|
||||
<switch id="S34"/>
|
||||
<switch id="S35"/>
|
||||
<switch id="S36"/>
|
||||
<switch id="S37"/>
|
||||
<switch id="S38"/>
|
||||
<switch id="S39"/>
|
||||
<switch id="S40"/>
|
||||
<switch id="S41"/>
|
||||
<switch id="S42"/>
|
||||
<switch id="S43"/>
|
||||
<switch id="S44"/>
|
||||
<switch id="S45"/>
|
||||
<switch id="S46"/>
|
||||
<switch id="S47"/>
|
||||
<switch id="S48"/>
|
||||
<switch id="S49"/>
|
||||
<switch id="S50"/>
|
||||
<switch id="S51"/>
|
||||
<switch id="S52"/>
|
||||
<switch id="S53"/>
|
||||
<switch id="S54"/>
|
||||
<switch id="S55"/>
|
||||
<switch id="S56"/>
|
||||
<switch id="S57"/>
|
||||
<switch id="S58"/>
|
||||
<switch id="S59"/>
|
||||
<switch id="S60"/>
|
||||
<switch id="S61"/>
|
||||
<switch id="S62"/>
|
||||
<switch id="S63"/>
|
||||
<switch id="S64"/>
|
||||
<switch id="S65"/>
|
||||
<switch id="S66"/>
|
||||
<switch id="S67"/>
|
||||
<switch id="S68"/>
|
||||
</switches>
|
||||
|
||||
</profile>
|
|
@ -41,6 +41,7 @@ public class Settings implements Serializable {
|
|||
private String loggerPort = "COM4";
|
||||
private String loggerProtocol = "SSM";
|
||||
private String loggerConfigFilePath = "./logger.xml";
|
||||
private String loggerProfileFilePath = "./profile.xml";
|
||||
private File loggerOutputDir = new File(".");
|
||||
|
||||
private Dimension loggerWindowSize = new Dimension(1000, 600);
|
||||
|
@ -317,4 +318,12 @@ public class Settings implements Serializable {
|
|||
public void setLoggerWindowSize(Dimension loggerWindowSize) {
|
||||
this.loggerWindowSize = loggerWindowSize;
|
||||
}
|
||||
|
||||
public String getLoggerProfileFilePath() {
|
||||
return loggerProfileFilePath;
|
||||
}
|
||||
|
||||
public void setLoggerProfileFilePath(String loggerProfileFilePath) {
|
||||
this.loggerProfileFilePath = loggerProfileFilePath;
|
||||
}
|
||||
}
|
|
@ -15,6 +15,9 @@ import enginuity.logger.ui.ParameterListTableModel;
|
|||
import enginuity.logger.ui.ParameterRegistrationBroker;
|
||||
import enginuity.logger.ui.ParameterRegistrationBrokerImpl;
|
||||
import enginuity.logger.ui.SerialPortComboBox;
|
||||
import enginuity.logger.ui.UserProfile;
|
||||
import enginuity.logger.ui.UserProfileLoader;
|
||||
import enginuity.logger.ui.UserProfileLoaderImpl;
|
||||
import enginuity.logger.ui.handler.DashboardUpdateHandler;
|
||||
import enginuity.logger.ui.handler.DataUpdateHandler;
|
||||
import enginuity.logger.ui.handler.DataUpdateHandlerManager;
|
||||
|
@ -93,8 +96,8 @@ public final class EcuLogger extends JFrame implements WindowListener, PropertyC
|
|||
initControllerListeners();
|
||||
startPortRefresherThread();
|
||||
initUserInterface();
|
||||
initParameterUpdateHandlers();
|
||||
loadEcuParamsFromConfig();
|
||||
initDataUpdateHandlers();
|
||||
loadEcuDataFromConfig(loadUserProfile(settings));
|
||||
}
|
||||
|
||||
private void bootstrap(String title, Settings settings) {
|
||||
|
@ -151,24 +154,31 @@ public final class EcuLogger extends JFrame implements WindowListener, PropertyC
|
|||
getContentPane().add(mainPanel);
|
||||
}
|
||||
|
||||
private void loadEcuParamsFromConfig() {
|
||||
private UserProfile loadUserProfile(Settings settings) {
|
||||
UserProfileLoader profileLoader = new UserProfileLoaderImpl();
|
||||
return profileLoader.loadProfile(settings.getLoggerProfileFilePath());
|
||||
}
|
||||
|
||||
private void loadEcuDataFromConfig(UserProfile profile) {
|
||||
try {
|
||||
EcuDataLoader dataLoader = new EcuDataLoaderImpl();
|
||||
dataLoader.loadFromXml(settings.getLoggerConfigFilePath(), settings.getLoggerProtocol());
|
||||
loadEcuParams(dataLoader.getEcuParameters());
|
||||
loadEcuSwitches(dataLoader.getEcuSwitches());
|
||||
loadEcuData(dataLoader, profile);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
reportError(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadEcuParams(List<EcuParameter> ecuParams) {
|
||||
sort(ecuParams, new EcuDataComparator());
|
||||
private void loadEcuData(EcuDataLoader dataLoader, UserProfile profile) {
|
||||
List<EcuParameter> ecuParams = dataLoader.getEcuParameters();
|
||||
addConvertorUpdateListeners(ecuParams);
|
||||
loadEcuParams(ecuParams, profile);
|
||||
loadEcuSwitches(dataLoader.getEcuSwitches(), profile);
|
||||
}
|
||||
|
||||
private void addConvertorUpdateListeners(List<EcuParameter> ecuParams) {
|
||||
for (EcuParameter ecuParam : ecuParams) {
|
||||
dataTabParamListTableModel.addParam(ecuParam);
|
||||
graphTabParamListTableModel.addParam(ecuParam);
|
||||
dashboardTabParamListTableModel.addParam(ecuParam);
|
||||
ecuParam.addConvertorUpdateListener(fileUpdateHandler);
|
||||
ecuParam.addConvertorUpdateListener(liveDataUpdateHandler);
|
||||
ecuParam.addConvertorUpdateListener(graphUpdateHandler);
|
||||
|
@ -176,16 +186,43 @@ public final class EcuLogger extends JFrame implements WindowListener, PropertyC
|
|||
}
|
||||
}
|
||||
|
||||
private void loadEcuSwitches(List<EcuSwitch> ecuSwitches) {
|
||||
private void loadEcuParams(List<EcuParameter> ecuParams, UserProfile profile) {
|
||||
clearParamTableModels();
|
||||
sort(ecuParams, new EcuDataComparator());
|
||||
for (EcuParameter ecuParam : ecuParams) {
|
||||
if (profile.contains(ecuParam)) {
|
||||
dataTabParamListTableModel.addParam(ecuParam);
|
||||
graphTabParamListTableModel.addParam(ecuParam);
|
||||
dashboardTabParamListTableModel.addParam(ecuParam);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void clearParamTableModels() {
|
||||
dataTabParamListTableModel.clear();
|
||||
graphTabParamListTableModel.clear();
|
||||
dashboardTabParamListTableModel.clear();
|
||||
}
|
||||
|
||||
private void loadEcuSwitches(List<EcuSwitch> ecuSwitches, UserProfile profile) {
|
||||
clearSwitchTableModels();
|
||||
sort(ecuSwitches, new EcuDataComparator());
|
||||
for (EcuSwitch ecuSwitch : ecuSwitches) {
|
||||
if (profile.contains(ecuSwitch)) {
|
||||
dataTabSwitchListTableModel.addParam(ecuSwitch);
|
||||
graphTabSwitchListTableModel.addParam(ecuSwitch);
|
||||
dashboardTabSwitchListTableModel.addParam(ecuSwitch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void initParameterUpdateHandlers() {
|
||||
private void clearSwitchTableModels() {
|
||||
dataTabSwitchListTableModel.clear();
|
||||
graphTabSwitchListTableModel.clear();
|
||||
dashboardTabSwitchListTableModel.clear();
|
||||
}
|
||||
|
||||
private void initDataUpdateHandlers() {
|
||||
DataUpdateHandler threadedFileUpdateHandler = startHandlerInThread(fileUpdateHandler);
|
||||
dataHandlerManager.addHandler(startHandlerInThread(liveDataUpdateHandler));
|
||||
dataHandlerManager.addHandler(threadedFileUpdateHandler);
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package enginuity.logger.definition;
|
||||
|
||||
import enginuity.logger.exception.ConfigurationException;
|
||||
import static enginuity.logger.xml.SaxParserFactory.getSaxParser;
|
||||
import static enginuity.util.ParamChecker.checkNotNullOrEmpty;
|
||||
|
||||
import javax.xml.parsers.SAXParser;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
@ -21,7 +21,7 @@ public final class EcuDataLoaderImpl implements EcuDataLoader {
|
|||
try {
|
||||
InputStream inputStream = new BufferedInputStream(new FileInputStream(new File(loggerConfigFilePath)));
|
||||
try {
|
||||
SAXParser parser = getSaxParserFactory().newSAXParser();
|
||||
SAXParser parser = getSaxParser();
|
||||
LoggerDefinitionHandler handler = new LoggerDefinitionHandler(protocol);
|
||||
parser.parse(inputStream, handler);
|
||||
ecuParameters = handler.getEcuParameters();
|
||||
|
@ -42,12 +42,4 @@ public final class EcuDataLoaderImpl implements EcuDataLoader {
|
|||
return ecuSwitches;
|
||||
}
|
||||
|
||||
private SAXParserFactory getSaxParserFactory() {
|
||||
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
|
||||
parserFactory.setNamespaceAware(false);
|
||||
parserFactory.setValidating(true);
|
||||
parserFactory.setXIncludeAware(false);
|
||||
return parserFactory;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package enginuity.logger.definition;
|
||||
|
||||
import enginuity.util.ParamChecker;
|
||||
import static enginuity.util.ParamChecker.checkNotNullOrEmpty;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
|
||||
|
@ -50,7 +50,7 @@ public final class LoggerDefinitionHandler extends DefaultHandler {
|
|||
private boolean parseProtocol;
|
||||
|
||||
public LoggerDefinitionHandler(String protocol) {
|
||||
ParamChecker.checkNotNullOrEmpty(protocol, "protocol");
|
||||
checkNotNullOrEmpty(protocol, "protocol");
|
||||
this.protocol = protocol;
|
||||
}
|
||||
|
||||
|
|
|
@ -77,4 +77,10 @@ public final class ParameterListTableModel extends AbstractTableModel {
|
|||
fireTableDataChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void clear() {
|
||||
paramRowMap.clear();
|
||||
registeredEcuData.clear();
|
||||
fireTableDataChanged();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
package enginuity.logger.ui;
|
||||
|
||||
import enginuity.logger.definition.EcuParameter;
|
||||
import enginuity.logger.definition.EcuSwitch;
|
||||
|
||||
public interface UserProfile {
|
||||
|
||||
boolean contains(EcuParameter ecuParam);
|
||||
|
||||
boolean contains(EcuSwitch ecuSwitch);
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package enginuity.logger.ui;
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public final class UserProfileHandler extends DefaultHandler {
|
||||
private static final String TAG_PARAMETER = "parameter";
|
||||
private static final String TAG_SWITCH = "switch";
|
||||
private static final String ATTR_ID = "id";
|
||||
private UserProfile profile;
|
||||
private Set<String> params;
|
||||
private Set<String> switches;
|
||||
|
||||
public void startDocument() {
|
||||
params = new HashSet<String>();
|
||||
switches = new HashSet<String>();
|
||||
profile = new UserProfileImpl(params, switches);
|
||||
}
|
||||
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) {
|
||||
if (TAG_PARAMETER.equals(qName)) {
|
||||
params.add(attributes.getValue(ATTR_ID));
|
||||
} else if (TAG_SWITCH.equals(qName)) {
|
||||
switches.add(attributes.getValue(ATTR_ID));
|
||||
}
|
||||
}
|
||||
|
||||
public UserProfile getUserProfile() {
|
||||
return profile;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package enginuity.logger.ui;
|
||||
|
||||
import enginuity.logger.definition.EcuParameter;
|
||||
import enginuity.logger.definition.EcuSwitch;
|
||||
import static enginuity.util.ParamChecker.checkNotNull;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public final class UserProfileImpl implements UserProfile {
|
||||
private final Set<String> params;
|
||||
private final Set<String> switches;
|
||||
|
||||
public UserProfileImpl(Set<String> params, Set<String> switches) {
|
||||
checkNotNull(params, "params");
|
||||
checkNotNull(switches, "switches");
|
||||
this.params = params;
|
||||
this.switches = switches;
|
||||
}
|
||||
|
||||
public boolean contains(EcuParameter ecuParam) {
|
||||
return params.contains(ecuParam.getId());
|
||||
}
|
||||
|
||||
public boolean contains(EcuSwitch ecuSwitch) {
|
||||
return switches.contains(ecuSwitch.getId());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package enginuity.logger.ui;
|
||||
|
||||
public interface UserProfileLoader {
|
||||
UserProfile loadProfile(String filePath);
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package enginuity.logger.ui;
|
||||
|
||||
import enginuity.logger.exception.ConfigurationException;
|
||||
import static enginuity.logger.xml.SaxParserFactory.getSaxParser;
|
||||
import static enginuity.util.ParamChecker.checkNotNullOrEmpty;
|
||||
|
||||
import javax.xml.parsers.SAXParser;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
public final class UserProfileLoaderImpl implements UserProfileLoader {
|
||||
|
||||
public UserProfile loadProfile(String userProfileFilePath) {
|
||||
checkNotNullOrEmpty(userProfileFilePath, "userProfileFilePath");
|
||||
try {
|
||||
InputStream inputStream = new BufferedInputStream(new FileInputStream(new File(userProfileFilePath)));
|
||||
try {
|
||||
SAXParser parser = getSaxParser();
|
||||
UserProfileHandler handler = new UserProfileHandler();
|
||||
parser.parse(inputStream, handler);
|
||||
return handler.getUserProfile();
|
||||
} finally {
|
||||
inputStream.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new ConfigurationException(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package enginuity.logger.xml;
|
||||
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.parsers.SAXParser;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
|
||||
public final class SaxParserFactory {
|
||||
|
||||
private SaxParserFactory() {
|
||||
}
|
||||
|
||||
public static SAXParser getSaxParser() throws ParserConfigurationException, SAXException {
|
||||
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
|
||||
parserFactory.setNamespaceAware(false);
|
||||
parserFactory.setValidating(true);
|
||||
parserFactory.setXIncludeAware(false);
|
||||
return parserFactory.newSAXParser();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue