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