mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
added default templates
This commit is contained in:
@@ -18,6 +18,8 @@ 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);
|
||||||
|
|
||||||
public class TemplateAlreadyExistsException extends Exception {
|
public class TemplateAlreadyExistsException extends Exception {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|||||||
@@ -9,12 +9,14 @@ 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;
|
||||||
|
private boolean defaultFlag;
|
||||||
|
|
||||||
public Template(String name, Map<String, Object> values, List<Point> points) {
|
public Template(String name, Map<String, Object> values, List<Point> points, boolean defaultFlag) {
|
||||||
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() {
|
||||||
@@ -41,10 +43,19 @@ 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());
|
||||||
@@ -60,6 +71,8 @@ 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;
|
||||||
@@ -77,4 +90,9 @@ public class Template {
|
|||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1790,6 +1790,18 @@ public class Presenter implements IPlugInPort {
|
|||||||
setNewComponentTypeSlot(null, null);
|
setNewComponentTypeSlot(null, null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// try to find a default template if none is provided
|
||||||
|
if (componentType != null && template == null) {
|
||||||
|
List<Template> templates = getTemplatesFor(componentType.getCategory(), componentType.getName());
|
||||||
|
for (Template t : templates) {
|
||||||
|
if (t.isDefaultFlag()) {
|
||||||
|
template = t;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
instantiationManager.setComponentTypeSlot(componentType, template, currentProject);
|
instantiationManager.setComponentTypeSlot(componentType, template, currentProject);
|
||||||
if (componentType != null) {
|
if (componentType != null) {
|
||||||
@@ -1854,7 +1866,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
point.translate(-x, -y);
|
point.translate(-x, -y);
|
||||||
}
|
}
|
||||||
|
|
||||||
Template template = new Template(templateName, values, points);
|
Template template = new Template(templateName, values, points, false);
|
||||||
boolean exists = false;
|
boolean exists = false;
|
||||||
for (Template t : templates) {
|
for (Template t : templates) {
|
||||||
if (t.getName().equalsIgnoreCase(templateName)) {
|
if (t.getName().equalsIgnoreCase(templateName)) {
|
||||||
@@ -1958,6 +1970,24 @@ public class Presenter implements IPlugInPort {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ConfigurationManager.getInstance().saveConfigration();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public void setTemplateDefault(String categoryName, String componentTypeName, String templateName, boolean 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.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<IDIYComponent<?>> getLockedComponents() {
|
private Set<IDIYComponent<?>> getLockedComponents() {
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -36,8 +36,9 @@ public enum IconLoader {
|
|||||||
"cloud_edit.png"), CloudUpload("cloud_upload.png"), NavLeftBlue("nav_left_blue.png"), NavRightBlue(
|
"cloud_edit.png"), CloudUpload("cloud_upload.png"), NavLeftBlue("nav_left_blue.png"), NavRightBlue(
|
||||||
"nav_right_blue.png"), MissingImage("missing_image.png"), CloudBg("cloud_bg.png"), CloudBig("cloud_big.png"), CloudWait(
|
"nav_right_blue.png"), MissingImage("missing_image.png"), CloudBg("cloud_bg.png"), CloudBig("cloud_big.png"), CloudWait(
|
||||||
"cloud_wait.png"), Spinning("spinning.gif"), Megaphone("megaphone.png"), Download("download.png"), Eye("eye.png"), Messages(
|
"cloud_wait.png"), Spinning("spinning.gif"), Megaphone("megaphone.png"), Download("download.png"), Eye("eye.png"), Messages(
|
||||||
"messages.png"), SearchBox("search-box.png"), Screwdriver("screwdriver.png"), Hammer("hammer.png"), FlipHorizontal("flip_horizontal.png"),
|
"messages.png"), SearchBox("search-box.png"), Screwdriver("screwdriver.png"), Hammer("hammer.png"), FlipHorizontal(
|
||||||
FlipVertical("flip_vertical.png"), MagicWand("magic_wand.png");
|
"flip_horizontal.png"), FlipVertical("flip_vertical.png"), MagicWand("magic_wand.png"), PinGrey("pin_grey.png"), PinGreen(
|
||||||
|
"pin_green.png");
|
||||||
|
|
||||||
protected String name;
|
protected String name;
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 722 B |
Binary file not shown.
|
After Width: | Height: | Size: 708 B |
@@ -97,7 +97,7 @@ public class ComponentButtonFactory {
|
|||||||
// Customize item size to fit the delete button
|
// Customize item size to fit the delete button
|
||||||
public java.awt.Dimension getPreferredSize() {
|
public java.awt.Dimension getPreferredSize() {
|
||||||
Dimension d = super.getPreferredSize();
|
Dimension d = super.getPreferredSize();
|
||||||
return new Dimension(d.width + 18, d.height);
|
return new Dimension(d.width + 32, d.height);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
item.addActionListener(new ActionListener() {
|
item.addActionListener(new ActionListener() {
|
||||||
@@ -107,7 +107,30 @@ public class ComponentButtonFactory {
|
|||||||
plugInPort.setNewComponentTypeSlot(componentType, template);
|
plugInPort.setNewComponentTypeSlot(componentType, template);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
JLabel label = new JLabel(IconLoader.Garbage.getIcon());
|
|
||||||
|
JLabel label = new JLabel(template.isDefaultFlag() ? IconLoader.PinGreen.getIcon() : IconLoader.PinGrey.getIcon());
|
||||||
|
label.setToolTipText(template.isDefaultFlag() ? "Remove default template" : "Set default template");
|
||||||
|
label.addMouseListener(new MouseAdapter() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
// Hide the menu
|
||||||
|
Container c = item.getParent();
|
||||||
|
if (c != null && c instanceof JPopupMenu) {
|
||||||
|
JPopupMenu m = (JPopupMenu) c;
|
||||||
|
m.setVisible(false);
|
||||||
|
}
|
||||||
|
plugInPort.setTemplateDefault(componentType.getCategory(), componentType.getName(), template.getName(),
|
||||||
|
!template.isDefaultFlag());
|
||||||
|
e.consume();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Border margin = new EmptyBorder(4, 0, 0, 0);
|
||||||
|
label.setBorder(margin);
|
||||||
|
item.setLayout(new FlowLayout(FlowLayout.RIGHT, 0, 0));
|
||||||
|
item.add(label);
|
||||||
|
|
||||||
|
label = new JLabel(IconLoader.Garbage.getIcon());
|
||||||
label.setToolTipText("Delete template");
|
label.setToolTipText("Delete template");
|
||||||
label.addMouseListener(new MouseAdapter() {
|
label.addMouseListener(new MouseAdapter() {
|
||||||
|
|
||||||
@@ -129,7 +152,7 @@ public class ComponentButtonFactory {
|
|||||||
e.consume();
|
e.consume();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Border margin = new EmptyBorder(4, 0, 0, 0);
|
margin = new EmptyBorder(4, 2, 0, 0);
|
||||||
label.setBorder(margin);
|
label.setBorder(margin);
|
||||||
item.setLayout(new FlowLayout(FlowLayout.RIGHT, 0, 0));
|
item.setLayout(new FlowLayout(FlowLayout.RIGHT, 0, 0));
|
||||||
item.add(label);
|
item.add(label);
|
||||||
|
|||||||
@@ -1522,6 +1522,10 @@
|
|||||||
<changeType>NEW_FEATURE</changeType>
|
<changeType>NEW_FEATURE</changeType>
|
||||||
<description>Mirror selection horizontally and vertically</description>
|
<description>Mirror selection horizontally and vertically</description>
|
||||||
</org.diylc.appframework.update.Change>
|
</org.diylc.appframework.update.Change>
|
||||||
|
<org.diylc.appframework.update.Change>
|
||||||
|
<changeType>NEW_FEATURE</changeType>
|
||||||
|
<description>Ability to set a default template for component type (grey "pin" icon in the template popup)</description>
|
||||||
|
</org.diylc.appframework.update.Change>
|
||||||
<org.diylc.appframework.update.Change>
|
<org.diylc.appframework.update.Change>
|
||||||
<changeType>IMPROVEMENT</changeType>
|
<changeType>IMPROVEMENT</changeType>
|
||||||
<description>Default focus on "Text" field for label</description>
|
<description>Default focus on "Text" field for label</description>
|
||||||
|
|||||||
Reference in New Issue
Block a user