mirror of https://github.com/rusefi/RomRaider.git
default units per parameter added to user profile
git-svn-id: http://svn.3splooges.com/romraider-arch/trunk@315 d2e2e1cd-ba16-0410-be16-b7c4453c7c2d
This commit is contained in:
parent
06630e37fa
commit
42c2aee137
|
@ -5,6 +5,7 @@
|
|||
<!ATTLIST parameter livedata ( selected ) #IMPLIED >
|
||||
<!ATTLIST parameter graph ( selected ) #IMPLIED >
|
||||
<!ATTLIST parameter dash ( selected ) #IMPLIED >
|
||||
<!ATTLIST parameter units CDATA #IMPLIED >
|
||||
|
||||
<!ELEMENT parameters ( parameter+ ) >
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
<parameter id="P22"/>
|
||||
<parameter id="P23"/>
|
||||
<parameter id="P24"/>
|
||||
<parameter id="P25"/>
|
||||
<parameter id="P25" livedata="selected" units="psi"/>
|
||||
<parameter id="P26"/>
|
||||
<parameter id="P27"/>
|
||||
<parameter id="P28"/>
|
||||
|
|
|
@ -205,6 +205,7 @@ public final class EcuLogger extends JFrame implements WindowListener, PropertyC
|
|||
sort(ecuParams, new EcuDataComparator());
|
||||
for (EcuParameter ecuParam : ecuParams) {
|
||||
if (profile == null || profile.contains(ecuParam)) {
|
||||
setDefaultUnits(profile, ecuParam);
|
||||
dataTabParamListTableModel.addParam(ecuParam, isSelectedOnLiveDataTab(profile, ecuParam));
|
||||
graphTabParamListTableModel.addParam(ecuParam, isSelectedOnGraphTab(profile, ecuParam));
|
||||
dashboardTabParamListTableModel.addParam(ecuParam, isSelectedOnDashTab(profile, ecuParam));
|
||||
|
@ -223,6 +224,16 @@ public final class EcuLogger extends JFrame implements WindowListener, PropertyC
|
|||
}
|
||||
}
|
||||
|
||||
private void setDefaultUnits(UserProfile profile, EcuParameter ecuParam) {
|
||||
if (profile != null) {
|
||||
try {
|
||||
ecuParam.selectConvertor(profile.getSelectedConvertor(ecuParam));
|
||||
} catch (Exception e) {
|
||||
reportError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isSelectedOnLiveDataTab(UserProfile profile, EcuData ecuData) {
|
||||
return profile != null && profile.isSelectedOnLiveDataTab(ecuData);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package enginuity.logger.ui;
|
||||
|
||||
import enginuity.logger.definition.EcuData;
|
||||
import enginuity.logger.definition.EcuDataConvertor;
|
||||
|
||||
public interface UserProfile {
|
||||
|
||||
|
@ -12,4 +13,5 @@ public interface UserProfile {
|
|||
|
||||
boolean isSelectedOnDashTab(EcuData ecuData);
|
||||
|
||||
EcuDataConvertor getSelectedConvertor(EcuData ecuData);
|
||||
}
|
||||
|
|
|
@ -10,24 +10,25 @@ 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 static final String ATTR_UNITS = "units";
|
||||
private static final String ATTR_LIVE_DATA = "livedata";
|
||||
private static final String ATTR_GRAPH = "graph";
|
||||
private static final String ATTR_DASH = "dash";
|
||||
private UserProfile profile;
|
||||
private HashMap<String, Boolean[]> params;
|
||||
private HashMap<String, Boolean[]> switches;
|
||||
private HashMap<String, UserProfileItem> params;
|
||||
private HashMap<String, UserProfileItem> switches;
|
||||
|
||||
public void startDocument() {
|
||||
params = new HashMap<String, Boolean[]>();
|
||||
switches = new HashMap<String, Boolean[]>();
|
||||
params = new HashMap<String, UserProfileItem>();
|
||||
switches = new HashMap<String, UserProfileItem>();
|
||||
profile = new UserProfileImpl(params, switches);
|
||||
}
|
||||
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) {
|
||||
if (TAG_PARAMETER.equals(qName)) {
|
||||
params.put(attributes.getValue(ATTR_ID), getSelectedValues(attributes));
|
||||
params.put(attributes.getValue(ATTR_ID), getUserProfileItem(attributes));
|
||||
} else if (TAG_SWITCH.equals(qName)) {
|
||||
switches.put(attributes.getValue(ATTR_ID), getSelectedValues(attributes));
|
||||
switches.put(attributes.getValue(ATTR_ID), getUserProfileItem(attributes));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,12 +36,13 @@ public final class UserProfileHandler extends DefaultHandler {
|
|||
return profile;
|
||||
}
|
||||
|
||||
private Boolean[] getSelectedValues(Attributes attributes) {
|
||||
return new Boolean[]{
|
||||
private UserProfileItem getUserProfileItem(Attributes attributes) {
|
||||
return new UserProfileItemImpl(
|
||||
attributes.getValue(ATTR_UNITS),
|
||||
SELECTED.equalsIgnoreCase(attributes.getValue(ATTR_LIVE_DATA)),
|
||||
SELECTED.equalsIgnoreCase(attributes.getValue(ATTR_GRAPH)),
|
||||
SELECTED.equalsIgnoreCase(attributes.getValue(ATTR_DASH))
|
||||
};
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,18 +1,20 @@
|
|||
package enginuity.logger.ui;
|
||||
|
||||
import enginuity.logger.definition.EcuData;
|
||||
import enginuity.logger.definition.EcuDataConvertor;
|
||||
import enginuity.logger.definition.EcuParameter;
|
||||
import enginuity.logger.definition.EcuSwitch;
|
||||
import enginuity.logger.exception.ConfigurationException;
|
||||
import static enginuity.util.ParamChecker.checkNotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class UserProfileImpl implements UserProfile {
|
||||
private final HashMap<String, Boolean[]> params;
|
||||
private final HashMap<String, Boolean[]> switches;
|
||||
private final HashMap<String, UserProfileItem> params;
|
||||
private final HashMap<String, UserProfileItem> switches;
|
||||
|
||||
public UserProfileImpl(HashMap<String, Boolean[]> params, HashMap<String, Boolean[]> switches) {
|
||||
public UserProfileImpl(HashMap<String, UserProfileItem> params, HashMap<String, UserProfileItem> switches) {
|
||||
checkNotNull(params, "params");
|
||||
checkNotNull(switches, "switches");
|
||||
this.params = params;
|
||||
|
@ -20,26 +22,45 @@ public final class UserProfileImpl implements UserProfile {
|
|||
}
|
||||
|
||||
public boolean contains(EcuData ecuData) {
|
||||
checkNotNull(ecuData, "ecuData");
|
||||
return getMap(ecuData).keySet().contains(ecuData.getId());
|
||||
}
|
||||
|
||||
public boolean isSelectedOnLiveDataTab(EcuData ecuData) {
|
||||
return getSelectedArray(ecuData)[0];
|
||||
checkNotNull(ecuData, "ecuData");
|
||||
return getUserProfileItem(ecuData).isLiveDataSelected();
|
||||
}
|
||||
|
||||
public boolean isSelectedOnGraphTab(EcuData ecuData) {
|
||||
return getSelectedArray(ecuData)[1];
|
||||
checkNotNull(ecuData, "ecuData");
|
||||
return getUserProfileItem(ecuData).isGraphSelected();
|
||||
}
|
||||
|
||||
public boolean isSelectedOnDashTab(EcuData ecuData) {
|
||||
return getSelectedArray(ecuData)[2];
|
||||
checkNotNull(ecuData, "ecuData");
|
||||
return getUserProfileItem(ecuData).isDashSelected();
|
||||
}
|
||||
|
||||
private Boolean[] getSelectedArray(EcuData ecuData) {
|
||||
public EcuDataConvertor getSelectedConvertor(EcuData ecuData) {
|
||||
checkNotNull(ecuData, "ecuData");
|
||||
String defaultUnits = getUserProfileItem(ecuData).getUnits();
|
||||
if (defaultUnits != null && ecuData.getConvertors().length > 1) {
|
||||
for (EcuDataConvertor convertor : ecuData.getConvertors()) {
|
||||
if (defaultUnits.equals(convertor.getUnits())) {
|
||||
return convertor;
|
||||
}
|
||||
}
|
||||
throw new ConfigurationException("Unknown default units, '" + defaultUnits + "', specified for " + ecuData.getName());
|
||||
} else {
|
||||
return ecuData.getSelectedConvertor();
|
||||
}
|
||||
}
|
||||
|
||||
private UserProfileItem getUserProfileItem(EcuData ecuData) {
|
||||
return getMap(ecuData).get(ecuData.getId());
|
||||
}
|
||||
|
||||
private Map<String, Boolean[]> getMap(EcuData ecuData) {
|
||||
private Map<String, UserProfileItem> getMap(EcuData ecuData) {
|
||||
if (ecuData instanceof EcuParameter) {
|
||||
return params;
|
||||
} else if (ecuData instanceof EcuSwitch) {
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package enginuity.logger.ui;
|
||||
|
||||
public interface UserProfileItem {
|
||||
|
||||
boolean isDashSelected();
|
||||
|
||||
boolean isGraphSelected();
|
||||
|
||||
boolean isLiveDataSelected();
|
||||
|
||||
String getUnits();
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package enginuity.logger.ui;
|
||||
|
||||
public final class UserProfileItemImpl implements UserProfileItem {
|
||||
private final String units;
|
||||
private final boolean liveDataSelected;
|
||||
private final boolean graphSelected;
|
||||
private final boolean dashSelected;
|
||||
|
||||
public UserProfileItemImpl(String units, boolean liveDataSelected, boolean graphSelected, boolean dashSelected) {
|
||||
this.units = units;
|
||||
this.liveDataSelected = liveDataSelected;
|
||||
this.graphSelected = graphSelected;
|
||||
this.dashSelected = dashSelected;
|
||||
}
|
||||
|
||||
public boolean isDashSelected() {
|
||||
return dashSelected;
|
||||
}
|
||||
|
||||
public boolean isGraphSelected() {
|
||||
return graphSelected;
|
||||
}
|
||||
|
||||
public boolean isLiveDataSelected() {
|
||||
return liveDataSelected;
|
||||
}
|
||||
|
||||
public String getUnits() {
|
||||
return units;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue