mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 09:42:08 +10:00
keep defaults for variants separate
This commit is contained in:
@@ -28,6 +28,7 @@ import org.diylc.core.Template;
|
||||
public interface ITemplateProcessor {
|
||||
|
||||
public static final String TEMPLATES_KEY = "templates";
|
||||
public static final String DEFAULT_TEMPLATES_KEY = "defaultTemplates";
|
||||
|
||||
void saveSelectedComponentAsTemplate(String templateName);
|
||||
|
||||
@@ -39,7 +40,9 @@ public interface ITemplateProcessor {
|
||||
|
||||
void deleteTemplate(String categoryName, String componentTypeName, String templateName);
|
||||
|
||||
void setTemplateDefault(String categoryName, String componentTypeName, String templateName, boolean defaultFlag);
|
||||
void setTemplateDefault(String categoryName, String componentTypeName, String templateName);
|
||||
|
||||
String getDefaultTemplate(String categoryName, String componentTypeName);
|
||||
|
||||
public class TemplateAlreadyExistsException extends Exception {
|
||||
|
||||
|
||||
@@ -30,14 +30,14 @@ public class Template {
|
||||
private String name;
|
||||
private Map<String, Object> values;
|
||||
private List<Point> points;
|
||||
@Deprecated
|
||||
private boolean defaultFlag;
|
||||
|
||||
public Template(String name, Map<String, Object> values, List<Point> points, boolean defaultFlag) {
|
||||
public Template(String name, Map<String, Object> values, List<Point> points) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.values = values;
|
||||
this.points = points;
|
||||
this.defaultFlag = defaultFlag;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@@ -64,19 +64,10 @@ public class Template {
|
||||
this.points = points;
|
||||
}
|
||||
|
||||
public boolean isDefaultFlag() {
|
||||
return defaultFlag;
|
||||
}
|
||||
|
||||
public void setDefaultFlag(boolean defaultFlag) {
|
||||
this.defaultFlag = defaultFlag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + (defaultFlag ? 1231 : 1237);
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((points == null) ? 0 : points.hashCode());
|
||||
result = prime * result + ((values == null) ? 0 : values.hashCode());
|
||||
@@ -92,8 +83,6 @@ public class Template {
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Template other = (Template) obj;
|
||||
if (defaultFlag != other.defaultFlag)
|
||||
return false;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
|
||||
@@ -2091,10 +2091,11 @@ public class Presenter implements IPlugInPort {
|
||||
|
||||
// try to find a default template if none is provided
|
||||
if (componentType != null && template == null) {
|
||||
String defaultTemplate = getDefaultTemplate(componentType.getCategory(), componentType.getName());
|
||||
List<Template> templates = getTemplatesFor(componentType.getCategory(), componentType.getName());
|
||||
if (templates != null)
|
||||
if (templates != null && defaultTemplate != null)
|
||||
for (Template t : templates) {
|
||||
if (t.isDefaultFlag()) {
|
||||
if (t.getName().equals(defaultTemplate)) {
|
||||
template = t;
|
||||
break;
|
||||
}
|
||||
@@ -2165,7 +2166,7 @@ public class Presenter implements IPlugInPort {
|
||||
point.translate(-x, -y);
|
||||
}
|
||||
|
||||
Template template = new Template(templateName, values, points, false);
|
||||
Template template = new Template(templateName, values, points);
|
||||
boolean exists = false;
|
||||
for (Template t : templates) {
|
||||
if (t.getName().equalsIgnoreCase(templateName)) {
|
||||
@@ -2309,21 +2310,27 @@ public class Presenter implements IPlugInPort {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void setTemplateDefault(String categoryName, String componentTypeName, String templateName, boolean defaultFlag) {
|
||||
LOG.debug(String.format("setTemplateDefault(%s, %s, %s, %s)", categoryName, componentTypeName, templateName,
|
||||
defaultFlag));
|
||||
Map<String, List<Template>> templateMap =
|
||||
(Map<String, List<Template>>) ConfigurationManager.getInstance().readObject(TEMPLATES_KEY, null);
|
||||
if (templateMap != null) {
|
||||
List<Template> templates = templateMap.get(categoryName + "." + componentTypeName);
|
||||
if (templates != null) {
|
||||
for (Template template : templates)
|
||||
template.setDefaultFlag(defaultFlag && templateName.equals(template.getName()));
|
||||
ConfigurationManager.getInstance().writeValue(TEMPLATES_KEY, templateMap);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("Could not find the specified template.");
|
||||
public void setTemplateDefault(String categoryName, String componentTypeName, String templateName) {
|
||||
LOG.debug(String.format("setTemplateDefault(%s, %s, %s)", categoryName, componentTypeName, templateName));
|
||||
Map<String, String> defaultTemplateMap =
|
||||
(Map<String, String>) ConfigurationManager.getInstance().readObject(DEFAULT_TEMPLATES_KEY, null);
|
||||
if (defaultTemplateMap == null)
|
||||
defaultTemplateMap = new HashMap<String, String>();
|
||||
if (templateName.equals(defaultTemplateMap.get(categoryName + "." + componentTypeName)))
|
||||
defaultTemplateMap.remove(categoryName + "." + componentTypeName);
|
||||
else
|
||||
defaultTemplateMap.put(categoryName + "." + componentTypeName, templateName);
|
||||
ConfigurationManager.getInstance().writeValue(DEFAULT_TEMPLATES_KEY, defaultTemplateMap);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public String getDefaultTemplate(String categoryName, String componentTypeName) {
|
||||
Map<String, String> defaultTemplateMap =
|
||||
(Map<String, String>) ConfigurationManager.getInstance().readObject(DEFAULT_TEMPLATES_KEY, null);
|
||||
if (defaultTemplateMap == null)
|
||||
return null;
|
||||
return defaultTemplateMap.get(categoryName + "." + componentTypeName);
|
||||
}
|
||||
|
||||
private Set<IDIYComponent<?>> getLockedComponents() {
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -126,8 +126,10 @@ public class ComponentButtonFactory {
|
||||
}
|
||||
});
|
||||
|
||||
JLabel label = new JLabel(template.isDefaultFlag() ? IconLoader.PinGreen.getIcon() : IconLoader.PinGrey.getIcon());
|
||||
label.setToolTipText(template.isDefaultFlag() ? "Remove default variant" : "Set default variant");
|
||||
String defaultVariant = plugInPort.getDefaultTemplate(componentType.getCategory(), componentType.getName());
|
||||
|
||||
JLabel label = new JLabel(template.getName().equals(defaultVariant) ? IconLoader.PinGreen.getIcon() : IconLoader.PinGrey.getIcon());
|
||||
label.setToolTipText(template.getName().equals(defaultVariant) ? "Remove default variant" : "Set default variant");
|
||||
label.addMouseListener(new MouseAdapter() {
|
||||
|
||||
@Override
|
||||
@@ -138,8 +140,7 @@ public class ComponentButtonFactory {
|
||||
JPopupMenu m = (JPopupMenu) c;
|
||||
m.setVisible(false);
|
||||
}
|
||||
plugInPort.setTemplateDefault(componentType.getCategory(), componentType.getName(), template.getName(),
|
||||
!template.isDefaultFlag());
|
||||
plugInPort.setTemplateDefault(componentType.getCategory(), componentType.getName(), template.getName());
|
||||
e.consume();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -2104,7 +2104,7 @@
|
||||
</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>
|
||||
<description>DIYLC now comes with predefined component variants out-of-the box, in addition to user-specific variants</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>BUG_FIX</changeType>
|
||||
@@ -2114,6 +2114,10 @@
|
||||
<changeType>BUG_FIX</changeType>
|
||||
<description>Inlude Themes (under Config menu) in the Windows installer version</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>BUG_FIX</changeType>
|
||||
<description>Covered humbucker pickup throwing errors when rotated</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
</changes>
|
||||
<url>https://github.com/bancika/diy-layout-creator/releases</url>
|
||||
</org.diylc.appframework.update.Version>
|
||||
|
||||
Reference in New Issue
Block a user