mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
ctrl to unstuck components
This commit is contained in:
+6
-3
@@ -172,7 +172,7 @@ public interface IPlugInPort {
|
||||
* @param parentMenuName
|
||||
*/
|
||||
void injectSubmenu(String name, Icon icon, String parentMenuName);
|
||||
|
||||
|
||||
Double[] getAvailableZoomLevels();
|
||||
|
||||
/**
|
||||
@@ -233,8 +233,11 @@ public interface IPlugInPort {
|
||||
* Note: point coordinates are scaled for zoom factor.
|
||||
*
|
||||
* @param point
|
||||
* @param ctrlDown
|
||||
* @param shiftDown
|
||||
* @param altDown
|
||||
*/
|
||||
void dragStarted(Point point);
|
||||
void dragStarted(Point point, boolean ctrlDown, boolean shiftDown, boolean altDown);
|
||||
|
||||
/**
|
||||
* Checks if it's possible to drop over the specified point.
|
||||
@@ -284,7 +287,7 @@ public interface IPlugInPort {
|
||||
* new default value, must not be null
|
||||
*/
|
||||
void setSelectionDefaultPropertyValue(String propertyName, Object value);
|
||||
|
||||
|
||||
/**
|
||||
* Sets default value for the specified property name for projects.
|
||||
*
|
||||
|
||||
+2
-2
@@ -5,7 +5,6 @@ import java.awt.dnd.DragGestureListener;
|
||||
|
||||
import org.diylc.common.IPlugInPort;
|
||||
|
||||
|
||||
/**
|
||||
* {@link DragGestureListener} for {@link CanvasPanel}.
|
||||
*
|
||||
@@ -22,7 +21,8 @@ class CanvasGestureListener implements DragGestureListener {
|
||||
|
||||
@Override
|
||||
public void dragGestureRecognized(DragGestureEvent dge) {
|
||||
presenter.dragStarted(dge.getDragOrigin());
|
||||
presenter.dragStarted(dge.getDragOrigin(), dge.getTriggerEvent().isControlDown(), dge
|
||||
.getTriggerEvent().isShiftDown(), dge.getTriggerEvent().isAltDown());
|
||||
dge.startDrag(presenter.getCursorAt(dge.getDragOrigin()), new EmptyTransferable(),
|
||||
new CanvasSourceListener(presenter));
|
||||
}
|
||||
|
||||
+1
-1
@@ -76,7 +76,7 @@ class CanvasPanel extends JComponent implements Autoscroll {
|
||||
private void initializeDnD() {
|
||||
// Initialize drag source recognizer.
|
||||
DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer(this,
|
||||
DnDConstants.ACTION_MOVE, new CanvasGestureListener(plugInPort));
|
||||
DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK, new CanvasGestureListener(plugInPort));
|
||||
// Initialize drop target.
|
||||
new DropTarget(this, DnDConstants.ACTION_COPY_OR_MOVE,
|
||||
new CanvasTargetListener(plugInPort), true);
|
||||
|
||||
+21
-13
@@ -202,13 +202,14 @@ public class StatusBar extends JPanel implements IPlugIn {
|
||||
Collection<IDIYComponent<?>> stuckComponents = (Collection<IDIYComponent<?>>) params[1];
|
||||
Collection<String> componentNames = new HashSet<String>();
|
||||
for (IDIYComponent<?> component : selection) {
|
||||
componentNames.add(component.getName());
|
||||
componentNames.add("<font color='blue'>" + component.getName() + "</font>");
|
||||
}
|
||||
this.selectedComponentNames = new ArrayList<String>(componentNames);
|
||||
Collections.sort(this.selectedComponentNames);
|
||||
this.stuckComponentNames = new ArrayList<String>();
|
||||
for (IDIYComponent<?> component : stuckComponents) {
|
||||
this.stuckComponentNames.add(component.getName());
|
||||
this.stuckComponentNames.add("<font color='blue'>" + component.getName()
|
||||
+ "</font>");
|
||||
}
|
||||
this.stuckComponentNames.removeAll(this.selectedComponentNames);
|
||||
Collections.sort(this.stuckComponentNames);
|
||||
@@ -242,21 +243,22 @@ public class StatusBar extends JPanel implements IPlugIn {
|
||||
}
|
||||
|
||||
private void refreshStatusText() {
|
||||
String statusText = "";
|
||||
if (componentSlot == null) {
|
||||
if (componentsUnderCursor != null && !componentsUnderCursor.isEmpty()) {
|
||||
String formattedNames = Utils.toCommaString(componentsUnderCursor);
|
||||
getStatusLabel().setText("Drag control point(s) of " + formattedNames);
|
||||
statusText = "Drag control point(s) of " + formattedNames;
|
||||
} else if (selectedComponentNames != null && !selectedComponentNames.isEmpty()) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(Utils.toCommaString(selectedComponentNames));
|
||||
if (!stuckComponentNames.isEmpty()) {
|
||||
builder.append(" (");
|
||||
builder.append(" (hold <b>Ctrl</b> to unstuck from ");
|
||||
builder.append(Utils.toCommaString(stuckComponentNames));
|
||||
builder.append(" would be affected by dragging as well)");
|
||||
builder.append(")");
|
||||
}
|
||||
getStatusLabel().setText("Selection: " + builder.toString());
|
||||
statusText = "<html>Selection: " + builder.toString() + "</html>";
|
||||
} else {
|
||||
getStatusLabel().setText("");
|
||||
statusText = "";
|
||||
}
|
||||
} else {
|
||||
switch (componentSlot.getCreationMethod()) {
|
||||
@@ -267,16 +269,22 @@ public class StatusBar extends JPanel implements IPlugIn {
|
||||
} else {
|
||||
count = "second";
|
||||
}
|
||||
getStatusLabel().setText(
|
||||
"Click on the canvas to set the " + count + " control point of a new "
|
||||
+ componentSlot.getName() + " or press Esc to cancel");
|
||||
statusText = "Click on the canvas to set the " + count + " control point of a new "
|
||||
+ componentSlot.getName() + " or press Esc to cancel";
|
||||
break;
|
||||
case SINGLE_CLICK:
|
||||
getStatusLabel().setText(
|
||||
"Click on the canvas to create a new " + componentSlot.getName()
|
||||
+ " or press Esc to cancel");
|
||||
statusText = "Click on the canvas to create a new " + componentSlot.getName()
|
||||
+ " or press Esc to cancel";
|
||||
break;
|
||||
}
|
||||
}
|
||||
final String finalStatus = statusText;
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
getStatusLabel().setText(finalStatus);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ class ToolboxGestureListener implements DragGestureListener {
|
||||
|
||||
@Override
|
||||
public void dragGestureRecognized(DragGestureEvent dge) {
|
||||
presenter.dragStarted(dge.getDragOrigin());
|
||||
// presenter.dragStarted(dge.getDragOrigin());
|
||||
dge.startDrag(Cursor.getDefaultCursor(), new StringSelection(className),
|
||||
new ToolboxSourceListener(presenter));
|
||||
}
|
||||
|
||||
+29
-4
@@ -20,6 +20,7 @@ import java.util.Set;
|
||||
|
||||
import org.diylc.common.ComponentSelection;
|
||||
import org.diylc.common.DrawOption;
|
||||
import org.diylc.common.EventType;
|
||||
import org.diylc.common.GridType;
|
||||
import org.diylc.common.IComponentFiler;
|
||||
import org.diylc.core.ComponentState;
|
||||
@@ -29,6 +30,7 @@ import org.diylc.core.VisibilityPolicy;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
import com.diyfever.gui.miscutils.ConfigurationManager;
|
||||
import com.diyfever.gui.simplemq.MessageDispatcher;
|
||||
|
||||
/**
|
||||
* Utility that deals with painting {@link Project} on the {@link Graphics2D}
|
||||
@@ -36,10 +38,12 @@ import com.diyfever.gui.miscutils.ConfigurationManager;
|
||||
*
|
||||
* @author Branislav Stojkovic
|
||||
*/
|
||||
public class ProjectPainter {
|
||||
public class DrawingManager {
|
||||
|
||||
public static int CONTROL_POINT_SIZE = 7;
|
||||
|
||||
public static final int CONTROL_POINT_SIZE = 7;
|
||||
public static final String ANTIALIASING_KEY = "anti-aliasing";
|
||||
public static final String ZOOM_KEY = "zoom";
|
||||
public static boolean DEBUG_COMPONENT_AREAS = false;
|
||||
|
||||
public static Color GRID_COLOR = new Color(240, 240, 240);
|
||||
@@ -54,8 +58,14 @@ public class ProjectPainter {
|
||||
|
||||
private Composite slotComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f);
|
||||
|
||||
public ProjectPainter() {
|
||||
private double zoomLevel = 1d;// ConfigurationManager.getInstance().readDouble(ZOOM_KEY,
|
||||
// 1d);
|
||||
|
||||
private MessageDispatcher<EventType> messageDispatcher;
|
||||
|
||||
public DrawingManager(MessageDispatcher<EventType> messageDispatcher) {
|
||||
super();
|
||||
this.messageDispatcher = messageDispatcher;
|
||||
componentAreaMap = new HashMap<IDIYComponent<?>, Area>();
|
||||
lastDrawnStateMap = new HashMap<IDIYComponent<?>, ComponentState>();
|
||||
}
|
||||
@@ -63,7 +73,7 @@ public class ProjectPainter {
|
||||
public void drawProject(Graphics2D g2d, Project project, Set<DrawOption> drawOptions,
|
||||
IComponentFiler filter, Rectangle selectionRect, ComponentSelection selectedComponents,
|
||||
Set<IDIYComponent<?>> groupedComponents, List<Point> controlPointSlot,
|
||||
IDIYComponent<?> componentSlot, boolean dragInProgress, double zoomLevel) {
|
||||
IDIYComponent<?> componentSlot, boolean dragInProgress) {
|
||||
if (project == null) {
|
||||
return;
|
||||
}
|
||||
@@ -247,6 +257,16 @@ public class ProjectPainter {
|
||||
}
|
||||
}
|
||||
|
||||
public double getZoomLevel() {
|
||||
return zoomLevel;
|
||||
}
|
||||
|
||||
public void setZoomLevel(double zoomLevel) {
|
||||
this.zoomLevel = zoomLevel;
|
||||
fireZoomChanged();
|
||||
// ConfigurationManager.getInstance().writeValue(ZOOM_KEY, zoomLevel);
|
||||
}
|
||||
|
||||
public void invalidateComponent(IDIYComponent<?> component) {
|
||||
componentAreaMap.remove(component);
|
||||
lastDrawnStateMap.remove(component);
|
||||
@@ -290,4 +310,9 @@ public class ProjectPainter {
|
||||
}
|
||||
return new Dimension((int) width, (int) height);
|
||||
}
|
||||
|
||||
public void fireZoomChanged() {
|
||||
messageDispatcher.dispatchMessage(EventType.ZOOM_CHANGED, zoomLevel);
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
}
|
||||
}
|
||||
+25
-28
@@ -60,11 +60,9 @@ public class Presenter implements IPlugInPort {
|
||||
public static final VersionNumber CURRENT_VERSION = new VersionNumber(3, 0, 1);
|
||||
public static final String DEFAULTS_KEY_PREFIX = "default.";
|
||||
public static final String METRIC_KEY = "metric";
|
||||
public static final String ZOOM_KEY = "zoom";
|
||||
|
||||
public static final int ICON_SIZE = 32;
|
||||
|
||||
private double zoomLevel = ConfigurationManager.getInstance().readDouble(ZOOM_KEY, 1d);
|
||||
private Project currentProject;
|
||||
private Map<String, List<ComponentType>> componentTypes;
|
||||
// Maps component class names to ComponentType objects.
|
||||
@@ -78,7 +76,7 @@ public class Presenter implements IPlugInPort {
|
||||
|
||||
// Utilities
|
||||
private Cloner cloner;
|
||||
private ProjectPainter projectPainter;
|
||||
private DrawingManager drawingManager;
|
||||
private ProjectFileManager projectFileManager;
|
||||
|
||||
private Rectangle selectionRect;
|
||||
@@ -113,7 +111,7 @@ public class Presenter implements IPlugInPort {
|
||||
selectedComponents = new ComponentSelection();
|
||||
currentProject = new Project();
|
||||
cloner = new Cloner();
|
||||
projectPainter = new ProjectPainter();
|
||||
drawingManager = new DrawingManager(messageDispatcher);
|
||||
projectFileManager = new ProjectFileManager(messageDispatcher);
|
||||
|
||||
// lockedLayers = EnumSet.noneOf(ComponentLayer.class);
|
||||
@@ -142,19 +140,16 @@ public class Presenter implements IPlugInPort {
|
||||
|
||||
@Override
|
||||
public double getZoomLevel() {
|
||||
return zoomLevel;
|
||||
return drawingManager.getZoomLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setZoomLevel(double zoomLevel) {
|
||||
LOG.info(String.format("setZoomLevel(%s)", zoomLevel));
|
||||
if (this.zoomLevel == zoomLevel) {
|
||||
if (drawingManager.getZoomLevel() == zoomLevel) {
|
||||
return;
|
||||
}
|
||||
this.zoomLevel = zoomLevel;
|
||||
ConfigurationManager.getInstance().writeValue(ZOOM_KEY, zoomLevel);
|
||||
messageDispatcher.dispatchMessage(EventType.ZOOM_CHANGED, zoomLevel);
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
drawingManager.setZoomLevel(zoomLevel);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -163,7 +158,7 @@ public class Presenter implements IPlugInPort {
|
||||
if (componentTypeSlot == null) {
|
||||
// Scale point to remove zoom factor.
|
||||
Point2D scaledPoint = scalePoint(point);
|
||||
if (projectPainter.isCursorOverArea(scaledPoint)) {
|
||||
if (drawingManager.isCursorOverArea(scaledPoint)) {
|
||||
return Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
|
||||
}
|
||||
if (controlPointMap != null && !controlPointMap.isEmpty()) {
|
||||
@@ -175,7 +170,8 @@ public class Presenter implements IPlugInPort {
|
||||
|
||||
@Override
|
||||
public Dimension getCanvasDimensions(boolean useZoom) {
|
||||
return projectPainter.getCanvasDimensions(currentProject, zoomLevel, useZoom);
|
||||
return drawingManager.getCanvasDimensions(currentProject, drawingManager.getZoomLevel(),
|
||||
useZoom);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -302,9 +298,9 @@ public class Presenter implements IPlugInPort {
|
||||
} else {
|
||||
componentSlotToDraw = componentSlot;
|
||||
}
|
||||
projectPainter.drawProject(g2d, currentProject, drawOptions, filter, selectionRect,
|
||||
drawingManager.drawProject(g2d, currentProject, drawOptions, filter, selectionRect,
|
||||
selectedComponents, groupedComponents, Arrays.asList(controlPointSlot,
|
||||
potentialControlPoint), componentSlotToDraw, dragInProgress, zoomLevel);
|
||||
potentialControlPoint), componentSlotToDraw, dragInProgress);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -334,7 +330,7 @@ public class Presenter implements IPlugInPort {
|
||||
* @return
|
||||
*/
|
||||
private List<IDIYComponent<?>> findComponentsAt(Point point) {
|
||||
return projectPainter.findComponentsAt(point, currentProject);
|
||||
return drawingManager.findComponentsAt(point, currentProject);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -495,7 +491,7 @@ public class Presenter implements IPlugInPort {
|
||||
if (selectedComponents.contains(component) && componentType.isStretchable()
|
||||
&& findAllGroupedComponents(component).size() == 1) {
|
||||
try {
|
||||
if (scaledPoint.distance(controlPoint) < ProjectPainter.CONTROL_POINT_SIZE) {
|
||||
if (scaledPoint.distance(controlPoint) < DrawingManager.CONTROL_POINT_SIZE) {
|
||||
Set<Integer> indices = new HashSet<Integer>();
|
||||
if (componentType.isStretchable()) {
|
||||
indices.add(pointIndex);
|
||||
@@ -553,7 +549,7 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dragStarted(Point point) {
|
||||
public void dragStarted(Point point, boolean ctrlDown, boolean shiftDown, boolean altDown) {
|
||||
LOG.debug(String.format("dragStarted(%s)", point));
|
||||
dragInProgress = true;
|
||||
preDragProject = cloner.deepClone(currentProject);
|
||||
@@ -607,7 +603,9 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
}
|
||||
// Expand control points to include all stuck components.
|
||||
includeStuckComponents(controlPointMap);
|
||||
if (!ctrlDown) {
|
||||
includeStuckComponents(controlPointMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -643,7 +641,7 @@ public class Presenter implements IPlugInPort {
|
||||
Point secondPoint = entry.getKey().getControlPoint(j);
|
||||
// If they are close enough we can consider them
|
||||
// matched.
|
||||
if (firstPoint.distance(secondPoint) < ProjectPainter.CONTROL_POINT_SIZE) {
|
||||
if (firstPoint.distance(secondPoint) < DrawingManager.CONTROL_POINT_SIZE) {
|
||||
componentMatches = true;
|
||||
break;
|
||||
}
|
||||
@@ -724,7 +722,7 @@ public class Presenter implements IPlugInPort {
|
||||
// Update all points.
|
||||
for (Map.Entry<IDIYComponent<?>, Set<Integer>> entry : controlPointMap.entrySet()) {
|
||||
IDIYComponent<?> c = entry.getKey();
|
||||
projectPainter.invalidateComponent(c);
|
||||
drawingManager.invalidateComponent(c);
|
||||
for (Integer index : entry.getValue()) {
|
||||
Point p = new Point(c.getControlPoint(index));
|
||||
p.translate(dx, dy);
|
||||
@@ -786,7 +784,7 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
selectedComponents.clear();
|
||||
for (IDIYComponent<?> component : currentProject.getComponents()) {
|
||||
Area area = projectPainter.getComponentArea(component);
|
||||
Area area = drawingManager.getComponentArea(component);
|
||||
if ((area != null) && (selectionRect != null) && area.intersects(selectionRect)) {
|
||||
selectedComponents.addAll(findAllGroupedComponents(component));
|
||||
}
|
||||
@@ -844,7 +842,7 @@ public class Presenter implements IPlugInPort {
|
||||
ungroupComponents(selectedComponents);
|
||||
// Remove from area map.
|
||||
for (IDIYComponent<?> component : selectedComponents) {
|
||||
projectPainter.invalidateComponent(component);
|
||||
drawingManager.invalidateComponent(component);
|
||||
}
|
||||
currentProject.getComponents().removeAll(selectedComponents);
|
||||
this.selectedComponents.clear();
|
||||
@@ -978,7 +976,7 @@ public class Presenter implements IPlugInPort {
|
||||
boolean metric = ConfigurationManager.getInstance().readBoolean(METRIC_KEY, true);
|
||||
Area area = new Area();
|
||||
for (IDIYComponent<?> component : selectedComponents) {
|
||||
Area componentArea = projectPainter.getComponentArea(component);
|
||||
Area componentArea = drawingManager.getComponentArea(component);
|
||||
if (componentArea != null) {
|
||||
area.add(componentArea);
|
||||
}
|
||||
@@ -1097,7 +1095,7 @@ public class Presenter implements IPlugInPort {
|
||||
Project oldProject = cloner.deepClone(currentProject);
|
||||
try {
|
||||
for (IDIYComponent<?> component : selectedComponents) {
|
||||
projectPainter.invalidateComponent(component);
|
||||
drawingManager.invalidateComponent(component);
|
||||
for (PropertyWrapper property : properties) {
|
||||
property.writeTo(component);
|
||||
}
|
||||
@@ -1155,8 +1153,7 @@ public class Presenter implements IPlugInPort {
|
||||
.deepClone(currentProject), "Edit Project");
|
||||
projectFileManager.notifyFileChange();
|
||||
}
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
messageDispatcher.dispatchMessage(EventType.ZOOM_CHANGED, zoomLevel);
|
||||
drawingManager.fireZoomChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1202,7 +1199,7 @@ public class Presenter implements IPlugInPort {
|
||||
* @return
|
||||
*/
|
||||
private Point scalePoint(Point point) {
|
||||
return point == null ? null : new Point((int) (point.x / zoomLevel),
|
||||
(int) (point.y / zoomLevel));
|
||||
return point == null ? null : new Point((int) (point.x / drawingManager.getZoomLevel()),
|
||||
(int) (point.y / drawingManager.getZoomLevel()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user