Made it possible for DIYLC to come with predefined component variants in

addition to user-specific variants
This commit is contained in:
Branislav Stojkovic
2019-01-07 10:50:59 +01:00
parent 8be8c23213
commit e541026656
5 changed files with 500 additions and 4 deletions
@@ -98,6 +98,19 @@ public class Presenter implements IPlugInPort {
} }
} }
public static final String DEFAULTS_KEY_PREFIX = "default."; public static final String DEFAULTS_KEY_PREFIX = "default.";
private static Map<String, List<Template>> defaultVariantMap = null;
static {
try {
BufferedInputStream in = new BufferedInputStream(new FileInputStream("variants.xml"));
XStream xStream = new XStream(new DomDriver());
defaultVariantMap = (Map<String, List<Template>>) xStream.fromXML(in);
in.close();
LOG.info(String.format("Loaded default variants for %d components", defaultVariantMap == null ? 0 : defaultVariantMap.size()));
} catch (IOException e) {
LOG.error("Could not load default variants", e);
}
}
public static final List<IDIYComponent<?>> EMPTY_SELECTION = Collections.emptyList(); public static final List<IDIYComponent<?>> EMPTY_SELECTION = Collections.emptyList();
@@ -2184,12 +2197,20 @@ public class Presenter implements IPlugInPort {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public List<Template> getTemplatesFor(String categoryName, String componentTypeName) { public List<Template> getTemplatesFor(String categoryName, String componentTypeName) {
Map<String, List<Template>> templateMap = Map<String, List<Template>> variantMap =
(Map<String, List<Template>>) ConfigurationManager.getInstance().readObject(TEMPLATES_KEY, null); (Map<String, List<Template>>) ConfigurationManager.getInstance().readObject(TEMPLATES_KEY, null);
if (templateMap != null) { List<Template> variants = new ArrayList<Template>();
return templateMap.get(categoryName + "." + componentTypeName); if (variantMap != null) {
List<Template> userVariants = variantMap.get(categoryName + "." + componentTypeName);
if (userVariants != null && !userVariants.isEmpty())
variants.addAll(userVariants);
} }
return null; if (defaultVariantMap != null) {
List<Template> defaultVariants = defaultVariantMap.get(categoryName + "." + componentTypeName);
if (defaultVariants != null && !defaultVariants.isEmpty())
variants.addAll(defaultVariants);
}
return variants;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Binary file not shown.
Binary file not shown.
+4
View File
@@ -2102,6 +2102,10 @@
<changeType>NEW_FEATURE</changeType> <changeType>NEW_FEATURE</changeType>
<description>Added visual indicator to the component tree showing how many variants, if any, exist for a component</description> <description>Added visual indicator to the component tree showing how many variants, if any, exist for a component</description>
</org.diylc.appframework.update.Change> </org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>NEW_FEATURE</changeType>
<description>Made it possible for DIYLC to come with predefined component variants in addition to user-specific variants</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change> <org.diylc.appframework.update.Change>
<changeType>BUG_FIX</changeType> <changeType>BUG_FIX</changeType>
<description>Fix "Mouse Wheel Zoom" feature that got broken in 3.46.1</description> <description>Fix "Mouse Wheel Zoom" feature that got broken in 3.46.1</description>
+471
View File
@@ -0,0 +1,471 @@
<map>
<entry>
<string>Passive.Electrolytic Capacitor (radial)</string>
<list>
<org.diylc.core.Template>
<name>xxx</name>
<values>
<entry>
<string>Alpha</string>
<byte>127</byte>
</entry>
<entry>
<string>Value</string>
<null/>
</entry>
<entry>
<string>Pin spacing</string>
<org.diylc.core.measures.Size>
<value>0.1</value>
<unit class="org.diylc.core.measures.SizeUnit">in</unit>
</org.diylc.core.measures.Size>
</entry>
<entry>
<string>Border</string>
<awt-color>
<red>74</red>
<green>76</green>
<blue>144</blue>
<alpha>255</alpha>
</awt-color>
</entry>
<entry>
<string>Display</string>
<org.diylc.common.Display>NAME</org.diylc.common.Display>
</entry>
<entry>
<string>Height</string>
<org.diylc.core.measures.Size>
<value>0.4</value>
<unit class="org.diylc.core.measures.SizeUnit">in</unit>
</org.diylc.core.measures.Size>
</entry>
<entry>
<string>Label color</string>
<awt-color>
<red>255</red>
<green>255</green>
<blue>255</blue>
<alpha>255</alpha>
</awt-color>
</entry>
<entry>
<string>Folded</string>
<boolean>false</boolean>
</entry>
<entry>
<string>Color</string>
<awt-color>
<red>107</red>
<green>109</green>
<blue>206</blue>
<alpha>255</alpha>
</awt-color>
</entry>
<entry>
<string>Diameter</string>
<org.diylc.core.measures.Size>
<value>0.25</value>
<unit class="org.diylc.core.measures.SizeUnit">in</unit>
</org.diylc.core.measures.Size>
</entry>
<entry>
<string>Tick</string>
<awt-color reference="../../entry[7]/awt-color"/>
</entry>
<entry>
<string>Voltage</string>
<null/>
</entry>
<entry>
<string>Polarized</string>
<boolean>true</boolean>
</entry>
<entry>
<string>Invert polarity</string>
<boolean>false</boolean>
</entry>
<entry>
<string>Lead color</string>
<awt-color>
<red>204</red>
<green>204</green>
<blue>204</blue>
<alpha>255</alpha>
</awt-color>
</entry>
<entry>
<string>Marker</string>
<awt-color>
<red>140</red>
<green>172</green>
<blue>234</blue>
<alpha>255</alpha>
</awt-color>
</entry>
</values>
<points>
<java.awt.Point>
<x>0</x>
<y>0</y>
</java.awt.Point>
<java.awt.Point>
<x>80</x>
<y>0</y>
</java.awt.Point>
</points>
<defaultFlag>false</defaultFlag>
</org.diylc.core.Template>
</list>
</entry>
<entry>
<string>Passive.Ceramic Capacitor (radial)</string>
<list>
<org.diylc.core.Template>
<name>test</name>
<values>
<entry>
<string>Pin spacing</string>
<org.diylc.core.measures.Size>
<value>0.1</value>
<unit class="org.diylc.core.measures.SizeUnit">in</unit>
</org.diylc.core.measures.Size>
</entry>
<entry>
<string>Value</string>
<null/>
</entry>
<entry>
<string>Alpha</string>
<byte>127</byte>
</entry>
<entry>
<string>Border</string>
<awt-color>
<red>168</red>
<green>161</green>
<blue>98</blue>
<alpha>255</alpha>
</awt-color>
</entry>
<entry>
<string>Display</string>
<org.diylc.common.Display>NAME</org.diylc.common.Display>
</entry>
<entry>
<string>Voltage</string>
<null/>
</entry>
<entry>
<string>Length</string>
<org.diylc.core.measures.Size>
<value>0.25</value>
<unit class="org.diylc.core.measures.SizeUnit">in</unit>
</org.diylc.core.measures.Size>
</entry>
<entry>
<string>Lead color</string>
<awt-color>
<red>204</red>
<green>204</green>
<blue>204</blue>
<alpha>255</alpha>
</awt-color>
</entry>
<entry>
<string>Width</string>
<org.diylc.core.measures.Size>
<value>0.125</value>
<unit class="org.diylc.core.measures.SizeUnit">in</unit>
</org.diylc.core.measures.Size>
</entry>
<entry>
<string>Label color</string>
<awt-color>
<red>0</red>
<green>0</green>
<blue>0</blue>
<alpha>255</alpha>
</awt-color>
</entry>
<entry>
<string>Color</string>
<awt-color>
<red>240</red>
<green>230</green>
<blue>140</blue>
<alpha>255</alpha>
</awt-color>
</entry>
</values>
<points>
<java.awt.Point>
<x>0</x>
<y>0</y>
</java.awt.Point>
<java.awt.Point>
<x>0</x>
<y>100</y>
</java.awt.Point>
</points>
<defaultFlag>false</defaultFlag>
</org.diylc.core.Template>
</list>
</entry>
<entry>
<string>Passive.Potentiometer</string>
<list>
<org.diylc.core.Template>
<name>25mm</name>
<values>
<entry>
<string>Lug size</string>
<org.diylc.core.measures.Size>
<value>0.15</value>
<unit class="org.diylc.core.measures.SizeUnit">in</unit>
</org.diylc.core.measures.Size>
</entry>
<entry>
<string>Body</string>
<awt-color>
<red>192</red>
<green>192</green>
<blue>192</blue>
<alpha>255</alpha>
</awt-color>
</entry>
<entry>
<string>Value</string>
<null/>
</entry>
<entry>
<string>Alpha</string>
<byte>127</byte>
</entry>
<entry>
<string>Orientation</string>
<org.diylc.common.Orientation>DEFAULT</org.diylc.common.Orientation>
</entry>
<entry>
<string>Type</string>
<org.diylc.components.passive.PotentiometerPanel_-Type>ThroughHole</org.diylc.components.passive.PotentiometerPanel_-Type>
</entry>
<entry>
<string>Border</string>
<awt-color>
<red>128</red>
<green>128</green>
<blue>128</blue>
<alpha>255</alpha>
</awt-color>
</entry>
<entry>
<string>Spacing</string>
<org.diylc.core.measures.Size>
<value>0.3</value>
<unit class="org.diylc.core.measures.SizeUnit">in</unit>
</org.diylc.core.measures.Size>
</entry>
<entry>
<string>Nut</string>
<awt-color>
<red>203</red>
<green>213</green>
<blue>219</blue>
<alpha>255</alpha>
</awt-color>
</entry>
<entry>
<string>Diameter</string>
<org.diylc.core.measures.Size>
<value>1.0</value>
<unit class="org.diylc.core.measures.SizeUnit">in</unit>
</org.diylc.core.measures.Size>
</entry>
<entry>
<string>Taper</string>
<org.diylc.components.passive.Taper>LIN</org.diylc.components.passive.Taper>
</entry>
<entry>
<string>Wafer</string>
<awt-color>
<red>205</red>
<green>133</green>
<blue>0</blue>
<alpha>255</alpha>
</awt-color>
</entry>
<entry>
<string>Show shaft</string>
<boolean>false</boolean>
</entry>
</values>
<points>
<java.awt.Point>
<x>0</x>
<y>0</y>
</java.awt.Point>
<java.awt.Point>
<x>60</x>
<y>0</y>
</java.awt.Point>
<java.awt.Point>
<x>120</x>
<y>0</y>
</java.awt.Point>
</points>
<defaultFlag>false</defaultFlag>
</org.diylc.core.Template>
<org.diylc.core.Template>
<name>16mm</name>
<values>
<entry>
<string>Lug size</string>
<org.diylc.core.measures.Size reference="../../../../org.diylc.core.Template/values/entry/org.diylc.core.measures.Size"/>
</entry>
<entry>
<string>Body</string>
<awt-color reference="../../../../org.diylc.core.Template/values/entry[2]/awt-color"/>
</entry>
<entry>
<string>Value</string>
<null/>
</entry>
<entry>
<string>Alpha</string>
<byte>127</byte>
</entry>
<entry>
<string>Orientation</string>
<org.diylc.common.Orientation>DEFAULT</org.diylc.common.Orientation>
</entry>
<entry>
<string>Type</string>
<org.diylc.components.passive.PotentiometerPanel_-Type>ThroughHole</org.diylc.components.passive.PotentiometerPanel_-Type>
</entry>
<entry>
<string>Border</string>
<awt-color reference="../../../../org.diylc.core.Template/values/entry[7]/awt-color"/>
</entry>
<entry>
<string>Spacing</string>
<org.diylc.core.measures.Size>
<value>0.2</value>
<unit class="org.diylc.core.measures.SizeUnit">in</unit>
</org.diylc.core.measures.Size>
</entry>
<entry>
<string>Nut</string>
<awt-color reference="../../../../org.diylc.core.Template/values/entry[9]/awt-color"/>
</entry>
<entry>
<string>Diameter</string>
<org.diylc.core.measures.Size>
<value>16.0</value>
<unit class="org.diylc.core.measures.SizeUnit">mm</unit>
</org.diylc.core.measures.Size>
</entry>
<entry>
<string>Taper</string>
<org.diylc.components.passive.Taper>LIN</org.diylc.components.passive.Taper>
</entry>
<entry>
<string>Wafer</string>
<awt-color reference="../../../../org.diylc.core.Template/values/entry[12]/awt-color"/>
</entry>
<entry>
<string>Show shaft</string>
<boolean>false</boolean>
</entry>
</values>
<points>
<java.awt.Point>
<x>0</x>
<y>0</y>
</java.awt.Point>
<java.awt.Point>
<x>40</x>
<y>0</y>
</java.awt.Point>
<java.awt.Point>
<x>80</x>
<y>0</y>
</java.awt.Point>
</points>
<defaultFlag>false</defaultFlag>
</org.diylc.core.Template>
<org.diylc.core.Template>
<name>16mm2</name>
<values>
<entry>
<string>Lug size</string>
<org.diylc.core.measures.Size reference="../../../../org.diylc.core.Template/values/entry/org.diylc.core.measures.Size"/>
</entry>
<entry>
<string>Body</string>
<awt-color reference="../../../../org.diylc.core.Template/values/entry[2]/awt-color"/>
</entry>
<entry>
<string>Value</string>
<null/>
</entry>
<entry>
<string>Alpha</string>
<byte>127</byte>
</entry>
<entry>
<string>Orientation</string>
<org.diylc.common.Orientation>DEFAULT</org.diylc.common.Orientation>
</entry>
<entry>
<string>Type</string>
<org.diylc.components.passive.PotentiometerPanel_-Type>ThroughHole</org.diylc.components.passive.PotentiometerPanel_-Type>
</entry>
<entry>
<string>Border</string>
<awt-color reference="../../../../org.diylc.core.Template/values/entry[7]/awt-color"/>
</entry>
<entry>
<string>Spacing</string>
<org.diylc.core.measures.Size reference="../../../../org.diylc.core.Template[2]/values/entry[8]/org.diylc.core.measures.Size"/>
</entry>
<entry>
<string>Nut</string>
<awt-color reference="../../../../org.diylc.core.Template/values/entry[9]/awt-color"/>
</entry>
<entry>
<string>Diameter</string>
<org.diylc.core.measures.Size reference="../../../../org.diylc.core.Template[2]/values/entry[10]/org.diylc.core.measures.Size"/>
</entry>
<entry>
<string>Taper</string>
<org.diylc.components.passive.Taper>LIN</org.diylc.components.passive.Taper>
</entry>
<entry>
<string>Wafer</string>
<awt-color reference="../../../../org.diylc.core.Template/values/entry[12]/awt-color"/>
</entry>
<entry>
<string>Show shaft</string>
<boolean>false</boolean>
</entry>
</values>
<points>
<java.awt.Point>
<x>0</x>
<y>0</y>
</java.awt.Point>
<java.awt.Point>
<x>40</x>
<y>0</y>
</java.awt.Point>
<java.awt.Point>
<x>80</x>
<y>0</y>
</java.awt.Point>
</points>
<defaultFlag>false</defaultFlag>
</org.diylc.core.Template>
</list>
</entry>
</map>