mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
simplified component framework
This commit is contained in:
+2
-2
@@ -18,7 +18,7 @@ import org.diylc.core.IDIYComponent;
|
||||
*
|
||||
* @author Branislav Stojkovic
|
||||
*/
|
||||
public class ComponentSelection extends ArrayList<IDIYComponent> implements Transferable {
|
||||
public class ComponentSelection extends ArrayList<IDIYComponent<?>> implements Transferable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -28,7 +28,7 @@ public class ComponentSelection extends ArrayList<IDIYComponent> implements Tran
|
||||
super();
|
||||
}
|
||||
|
||||
public ComponentSelection(Collection<IDIYComponent> selectedComponents) {
|
||||
public ComponentSelection(Collection<IDIYComponent<?>> selectedComponents) {
|
||||
super(selectedComponents);
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -174,7 +174,7 @@ public interface IPlugInPort {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Area getComponentArea(IDIYComponent component);
|
||||
Area getComponentArea(IDIYComponent<?> component);
|
||||
|
||||
/**
|
||||
* Notification that drag has been started from the specified point.
|
||||
@@ -217,7 +217,7 @@ public interface IPlugInPort {
|
||||
* @param components
|
||||
* @param preferredPoint
|
||||
*/
|
||||
void addComponents(List<IDIYComponent> components, Point preferredPoint);
|
||||
void addComponents(List<IDIYComponent<?>> components, Point preferredPoint);
|
||||
|
||||
/**
|
||||
* Checks if a certain layer is locked for editing.
|
||||
|
||||
+4
-4
@@ -29,10 +29,10 @@ public class Project implements Serializable {
|
||||
private String description;
|
||||
private Size width;
|
||||
private Size height;
|
||||
private List<IDIYComponent> components;
|
||||
private List<IDIYComponent<?>> components;
|
||||
|
||||
public Project() {
|
||||
components = new ArrayList<IDIYComponent>();
|
||||
components = new ArrayList<IDIYComponent<?>>();
|
||||
title = DEFAULT_TITLE;
|
||||
author = System.getProperty("user.name");
|
||||
width = DEFAULT_WIDTH;
|
||||
@@ -40,7 +40,7 @@ public class Project implements Serializable {
|
||||
}
|
||||
|
||||
public Project(String title, String author, String description, Size width, Size height,
|
||||
List<IDIYComponent> components) {
|
||||
List<IDIYComponent<?>> components) {
|
||||
super();
|
||||
this.title = title;
|
||||
this.author = author;
|
||||
@@ -95,7 +95,7 @@ public class Project implements Serializable {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public List<IDIYComponent> getComponents() {
|
||||
public List<IDIYComponent<?>> getComponents() {
|
||||
return components;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -163,7 +163,7 @@ public class ClipboardManager implements IPlugIn, ClipboardOwner {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
LOG.info("Paste triggered");
|
||||
try {
|
||||
List<IDIYComponent> components = (List<IDIYComponent>) clipboard
|
||||
List<IDIYComponent<?>> components = (List<IDIYComponent<?>>) clipboard
|
||||
.getData(ComponentSelection.listFlavor);
|
||||
plugInPort.addComponents(cloner.deepClone(components), null);
|
||||
} catch (Exception ex) {
|
||||
|
||||
+2
-2
@@ -23,9 +23,9 @@ public class BomMaker {
|
||||
private BomMaker() {
|
||||
}
|
||||
|
||||
public List<BomEntry> createBom(List<IDIYComponent> components) {
|
||||
public List<BomEntry> createBom(List<IDIYComponent<?>> components) {
|
||||
Map<String, BomEntry> entryMap = new HashMap<String, BomEntry>();
|
||||
for (IDIYComponent component : components) {
|
||||
for (IDIYComponent<?> component : components) {
|
||||
String name = component.getName();
|
||||
String value = component.getValue() == null ? "" : component.getValue().toString();
|
||||
if ((name != null) && (value != null)) {
|
||||
|
||||
+4
-4
@@ -45,7 +45,7 @@ public class StatusBar extends JPanel implements IPlugIn {
|
||||
|
||||
// State variables
|
||||
private ComponentType componentSlot;
|
||||
private List<IDIYComponent> componentsUnderCursor;
|
||||
private List<IDIYComponent<?>> componentsUnderCursor;
|
||||
|
||||
public StatusBar() {
|
||||
super();
|
||||
@@ -165,8 +165,8 @@ public class StatusBar extends JPanel implements IPlugIn {
|
||||
refreshStatusText();
|
||||
break;
|
||||
case AVAILABLE_CTRL_POINTS_CHANGED:
|
||||
componentsUnderCursor = new ArrayList<IDIYComponent>(
|
||||
((Map<IDIYComponent, ControlPointWrapper>) params[0]).keySet());
|
||||
componentsUnderCursor = new ArrayList<IDIYComponent<?>>(
|
||||
((Map<IDIYComponent<?>, ControlPointWrapper>) params[0]).keySet());
|
||||
Collections.sort(componentsUnderCursor, ComparatorFactory.getInstance()
|
||||
.getComponentNameComparator());
|
||||
refreshStatusText();
|
||||
@@ -181,7 +181,7 @@ public class StatusBar extends JPanel implements IPlugIn {
|
||||
} else {
|
||||
String formattedNames = "";
|
||||
int n = 1;
|
||||
for (IDIYComponent component : componentsUnderCursor) {
|
||||
for (IDIYComponent<?> component : componentsUnderCursor) {
|
||||
if (n > 1) {
|
||||
formattedNames += ", ";
|
||||
}
|
||||
|
||||
+5
@@ -1,5 +1,6 @@
|
||||
package org.diylc.plugins.toolbox;
|
||||
|
||||
import java.awt.Insets;
|
||||
import java.awt.dnd.DnDConstants;
|
||||
import java.awt.dnd.DragSource;
|
||||
import java.awt.event.ActionEvent;
|
||||
@@ -20,6 +21,8 @@ class ComponentButton extends JButton {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static int MARGIN = 2;
|
||||
|
||||
private IPlugInPort plugInPort;
|
||||
private ComponentType componentType;
|
||||
|
||||
@@ -28,6 +31,8 @@ class ComponentButton extends JButton {
|
||||
this.plugInPort = plugInPort;
|
||||
this.componentType = componentType;
|
||||
|
||||
setMargin(new Insets(MARGIN, MARGIN, MARGIN, MARGIN));
|
||||
|
||||
setToolTipText("<html><b>" + componentType.getName() + "</b><br>"
|
||||
+ componentType.getDescription() + "<br>Author: " + componentType.getAuthor()
|
||||
+ "</html>");
|
||||
|
||||
+4
-4
@@ -8,7 +8,7 @@ public class ComparatorFactory {
|
||||
|
||||
private static ComparatorFactory instance;
|
||||
|
||||
private Comparator<IDIYComponent> componentNameComparator;
|
||||
private Comparator<IDIYComponent<?>> componentNameComparator;
|
||||
|
||||
public static ComparatorFactory getInstance() {
|
||||
if (instance == null) {
|
||||
@@ -17,12 +17,12 @@ public class ComparatorFactory {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public Comparator<IDIYComponent> getComponentNameComparator() {
|
||||
public Comparator<IDIYComponent<?>> getComponentNameComparator() {
|
||||
if (componentNameComparator == null) {
|
||||
componentNameComparator = new Comparator<IDIYComponent>() {
|
||||
componentNameComparator = new Comparator<IDIYComponent<?>>() {
|
||||
|
||||
@Override
|
||||
public int compare(IDIYComponent o1, IDIYComponent o2) {
|
||||
public int compare(IDIYComponent<?> o1, IDIYComponent<?> o2) {
|
||||
String name1 = o1.getName();
|
||||
String name2 = o2.getName();
|
||||
if (name1 == null || name2 == null) {
|
||||
|
||||
+3
-3
@@ -133,12 +133,12 @@ public class ComponentProcessor {
|
||||
* @param selectedComponents
|
||||
* @return
|
||||
*/
|
||||
public List<PropertyWrapper> getMutualSelectionProperties(List<IDIYComponent> selectedComponents) {
|
||||
public List<PropertyWrapper> getMutualSelectionProperties(List<IDIYComponent<?>> selectedComponents) {
|
||||
if (selectedComponents.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
List<PropertyWrapper> properties = new ArrayList<PropertyWrapper>();
|
||||
IDIYComponent firstComponent = selectedComponents.get(0);
|
||||
IDIYComponent<?> firstComponent = selectedComponents.get(0);
|
||||
properties.addAll(extractProperties(firstComponent.getClass()));
|
||||
// Initialize values
|
||||
for (PropertyWrapper property : properties) {
|
||||
@@ -150,7 +150,7 @@ public class ComponentProcessor {
|
||||
}
|
||||
}
|
||||
for (int i = 1; i < selectedComponents.size(); i++) {
|
||||
IDIYComponent component = selectedComponents.get(i);
|
||||
IDIYComponent<?> component = selectedComponents.get(i);
|
||||
List<PropertyWrapper> newProperties = extractProperties(component.getClass());
|
||||
for (PropertyWrapper property : newProperties) {
|
||||
try {
|
||||
|
||||
+24
-24
@@ -71,7 +71,7 @@ public class Presenter implements IPlugInPort {
|
||||
public static boolean ENABLE_ANTIALIASING = true;
|
||||
|
||||
private double zoomLevel = 1;
|
||||
private Map<IDIYComponent, Area> componentAreaMap;
|
||||
private Map<IDIYComponent<?>, Area> componentAreaMap;
|
||||
private Project currentProject;
|
||||
private Map<String, List<ComponentType>> componentTypes;
|
||||
private List<IPlugIn> plugIns;
|
||||
@@ -79,7 +79,7 @@ public class Presenter implements IPlugInPort {
|
||||
private ComponentSelection selectedComponents;
|
||||
// List of components that have at least one of their control points
|
||||
// under the last recorded mouse position.
|
||||
private Map<IDIYComponent, ControlPointWrapper> componentControlPointMap;
|
||||
private Map<IDIYComponent<?>, ControlPointWrapper> componentControlPointMap;
|
||||
|
||||
private Cloner cloner;
|
||||
|
||||
@@ -104,7 +104,7 @@ public class Presenter implements IPlugInPort {
|
||||
public Presenter(IView view) {
|
||||
super();
|
||||
this.view = view;
|
||||
componentAreaMap = new HashMap<IDIYComponent, Area>();
|
||||
componentAreaMap = new HashMap<IDIYComponent<?>, Area>();
|
||||
plugIns = new ArrayList<IPlugIn>();
|
||||
messageDispatcher = new MessageDispatcher<EventType>();
|
||||
selectedComponents = new ComponentSelection();
|
||||
@@ -149,7 +149,7 @@ public class Presenter implements IPlugInPort {
|
||||
if (componentSlot == null) {
|
||||
// Scale point to remove zoom factor.
|
||||
Point2D scaledPoint = scalePoint(point);
|
||||
for (Map.Entry<IDIYComponent, Area> entry : componentAreaMap.entrySet()) {
|
||||
for (Map.Entry<IDIYComponent<?>, Area> entry : componentAreaMap.entrySet()) {
|
||||
if (entry.getValue().contains(scaledPoint)) {
|
||||
return Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
|
||||
}
|
||||
@@ -293,10 +293,10 @@ public class Presenter implements IPlugInPort {
|
||||
|
||||
// g2dWrapper.resetTx();
|
||||
|
||||
List<IDIYComponent> components = getCurrentProject().getComponents();
|
||||
List<IDIYComponent<?>> components = getCurrentProject().getComponents();
|
||||
componentAreaMap.clear();
|
||||
if (components != null) {
|
||||
for (IDIYComponent component : components) {
|
||||
for (IDIYComponent<?> component : components) {
|
||||
g2dWrapper.startedDrawingComponent();
|
||||
ComponentState state = ComponentState.NORMAL;
|
||||
if (drawOptions.contains(DrawOption.SELECTION)
|
||||
@@ -387,9 +387,9 @@ public class Presenter implements IPlugInPort {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private List<IDIYComponent> findComponentsAt(Point point) {
|
||||
List<IDIYComponent> components = new ArrayList<IDIYComponent>();
|
||||
for (Map.Entry<IDIYComponent, Area> entry : componentAreaMap.entrySet()) {
|
||||
private List<IDIYComponent<?>> findComponentsAt(Point point) {
|
||||
List<IDIYComponent<?>> components = new ArrayList<IDIYComponent<?>>();
|
||||
for (Map.Entry<IDIYComponent<?>, Area> entry : componentAreaMap.entrySet()) {
|
||||
if (entry.getValue().contains(point)) {
|
||||
components.add(entry.getKey());
|
||||
}
|
||||
@@ -412,12 +412,12 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
setNewComponentSlot(null);
|
||||
} else {
|
||||
List<IDIYComponent> components = findComponentsAt(scaledPoint);
|
||||
List<IDIYComponent<?>> components = findComponentsAt(scaledPoint);
|
||||
// If there's nothing under mouse cursor deselect all.
|
||||
if (components.isEmpty()) {
|
||||
selectedComponents.clear();
|
||||
} else {
|
||||
IDIYComponent component = components.get(0);
|
||||
IDIYComponent<?> component = components.get(0);
|
||||
// If ctrl is pressed just toggle the component under mouse
|
||||
// cursor.
|
||||
if (ctrlDown) {
|
||||
@@ -439,9 +439,9 @@ public class Presenter implements IPlugInPort {
|
||||
|
||||
@Override
|
||||
public void mouseMoved(Point point, boolean ctrlDown, boolean shiftDown, boolean altDown) {
|
||||
Map<IDIYComponent, ControlPointWrapper> components = new HashMap<IDIYComponent, ControlPointWrapper>();
|
||||
Map<IDIYComponent<?>, ControlPointWrapper> components = new HashMap<IDIYComponent<?>, ControlPointWrapper>();
|
||||
Point scaledPoint = scalePoint(point);
|
||||
for (IDIYComponent component : currentProject.getComponents()) {
|
||||
for (IDIYComponent<?> component : currentProject.getComponents()) {
|
||||
List<ControlPointWrapper> currentPoints = ComponentProcessor.getInstance()
|
||||
.extractControlPoints(component.getClass());
|
||||
for (ControlPointWrapper controlPoint : currentPoints) {
|
||||
@@ -475,7 +475,7 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Area getComponentArea(IDIYComponent component) {
|
||||
public Area getComponentArea(IDIYComponent<?> component) {
|
||||
return componentAreaMap.get(component);
|
||||
}
|
||||
|
||||
@@ -491,7 +491,7 @@ public class Presenter implements IPlugInPort {
|
||||
preDragProject = cloner.deepClone(currentProject);
|
||||
Point scaledPoint = scalePoint(point);
|
||||
previousDragPoint = scaledPoint;
|
||||
List<IDIYComponent> components = findComponentsAt(scaledPoint);
|
||||
List<IDIYComponent<?>> components = findComponentsAt(scaledPoint);
|
||||
if (!componentControlPointMap.isEmpty()) {
|
||||
// If we're dragging control points reset selection.
|
||||
selectedComponents.clear();
|
||||
@@ -504,7 +504,7 @@ public class Presenter implements IPlugInPort {
|
||||
messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, selectedComponents);
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
} else {
|
||||
IDIYComponent component = components.get(0);
|
||||
IDIYComponent<?> component = components.get(0);
|
||||
// If the component under the cursor is not already selected, make
|
||||
// it into the only selected component.
|
||||
if (!selectedComponents.contains(component)) {
|
||||
@@ -524,7 +524,7 @@ public class Presenter implements IPlugInPort {
|
||||
Point scaledPoint = scalePoint(point);
|
||||
if (!componentControlPointMap.isEmpty()) {
|
||||
// We're dragging control point(s).
|
||||
IDIYComponent firstComponent = componentControlPointMap.keySet().iterator().next();
|
||||
IDIYComponent<?> firstComponent = componentControlPointMap.keySet().iterator().next();
|
||||
ControlPointWrapper controlPoint = componentControlPointMap.get(firstComponent);
|
||||
if (controlPoint == null) {
|
||||
LOG.warn("Control point not found in the map!");
|
||||
@@ -543,11 +543,11 @@ public class Presenter implements IPlugInPort {
|
||||
/ Constants.GRID) * Constants.GRID);
|
||||
previousDragPoint.setLocation(x, y);
|
||||
|
||||
for (Entry<IDIYComponent, ControlPointWrapper> entry : componentControlPointMap
|
||||
for (Entry<IDIYComponent<?>, ControlPointWrapper> entry : componentControlPointMap
|
||||
.entrySet()) {
|
||||
try {
|
||||
controlPoint = entry.getValue();
|
||||
IDIYComponent component = entry.getKey();
|
||||
IDIYComponent<?> component = entry.getKey();
|
||||
controlPoint.readFrom(component);
|
||||
if (controlPoint.isEditable()) {
|
||||
controlPoint.getValue().setLocation(x, y);
|
||||
@@ -587,7 +587,7 @@ public class Presenter implements IPlugInPort {
|
||||
this.selectionRect = Utils.createRectangle(scaledPoint, previousDragPoint);
|
||||
}
|
||||
selectedComponents.clear();
|
||||
for (IDIYComponent component : currentProject.getComponents()) {
|
||||
for (IDIYComponent<?> component : currentProject.getComponents()) {
|
||||
Area area = componentAreaMap.get(component);
|
||||
if ((area != null) && area.intersects(selectionRect)) {
|
||||
selectedComponents.add(component);
|
||||
@@ -615,7 +615,7 @@ public class Presenter implements IPlugInPort {
|
||||
int dx = (int) (Math.round((toPoint.x - fromPoint.x) / zoomLevel / Constants.GRID) * Constants.GRID);
|
||||
int dy = (int) (Math.round((toPoint.y - fromPoint.y) / zoomLevel / Constants.GRID) * Constants.GRID);
|
||||
fromPoint.translate(dx, dy);
|
||||
for (IDIYComponent component : selectedComponents) {
|
||||
for (IDIYComponent<?> component : selectedComponents) {
|
||||
List<ControlPointWrapper> controlPoints = ComponentProcessor.getInstance()
|
||||
.extractControlPoints(component.getClass());
|
||||
for (ControlPointWrapper controlPoint : controlPoints) {
|
||||
@@ -639,7 +639,7 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addComponents(List<IDIYComponent> components, Point preferredPoint) {
|
||||
public void addComponents(List<IDIYComponent<?>> components, Point preferredPoint) {
|
||||
LOG.debug(String.format("addComponents(%s)", components));
|
||||
Project oldProject = cloner.deepClone(currentProject);
|
||||
currentProject.getComponents().addAll(components);
|
||||
@@ -778,7 +778,7 @@ public class Presenter implements IPlugInPort {
|
||||
LOG.debug(String.format("applyPropertiesToSelection(%s)", properties));
|
||||
Project oldProject = cloner.deepClone(currentProject);
|
||||
try {
|
||||
for (IDIYComponent component : selectedComponents) {
|
||||
for (IDIYComponent<?> component : selectedComponents) {
|
||||
for (PropertyWrapper property : properties) {
|
||||
property.writeTo(component);
|
||||
}
|
||||
@@ -814,7 +814,7 @@ public class Presenter implements IPlugInPort {
|
||||
(int) (point.y / zoomLevel));
|
||||
}
|
||||
|
||||
private boolean shouldShowControlPoint(ControlPointWrapper controlPoint, IDIYComponent component) {
|
||||
private boolean shouldShowControlPoint(ControlPointWrapper controlPoint, IDIYComponent<?> component) {
|
||||
return controlPoint.getVisibilityPolicy().equals(VisibilityPolicy.ALWAYS)
|
||||
|| ((controlPoint.getVisibilityPolicy().equals(VisibilityPolicy.WHEN_SELECTED)) && (getSelectedComponents()
|
||||
.contains(component)));
|
||||
|
||||
Reference in New Issue
Block a user