improve drag&drop

This commit is contained in:
Branislav Stojkovic
2019-02-03 19:37:38 +01:00
parent 3027753225
commit 81b299865c
5 changed files with 45 additions and 19 deletions
@@ -1156,7 +1156,7 @@ public class Presenter implements IPlugInPort {
return true;
previousDragPoint.translate(actualD.x, actualD.y);
} else if (selectedComponents.isEmpty() && instantiationManager.getComponentTypeSlot() == null) {
} else if (selectedComponents.isEmpty() && instantiationManager.getComponentTypeSlot() == null && previousDragPoint != null) {
// If there's no selection, the only thing to do is update the
// selection rectangle and refresh.
Rectangle oldSelectionRect = selectionRect == null ? null : new Rectangle(selectionRect);
@@ -2135,10 +2135,10 @@ public class Presenter implements IPlugInPort {
return;
}
if (componentType == null) {
controlPointMap.clear();
updateSelection(EMPTY_SELECTION);
}
// if (componentType == null) {
// controlPointMap.clear();
// updateSelection(EMPTY_SELECTION);
// }
// try to find a default template if none is provided
if (componentType != null && template == null) {
Binary file not shown.
Binary file not shown.
@@ -25,6 +25,7 @@ import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;
import org.diylc.common.ComponentType;
import org.diylc.common.IPlugInPort;
import org.diylc.swing.plugins.canvas.EmptyTransferable;
import org.diylc.swing.plugins.tree.TreePanel.Payload;
@@ -45,20 +46,37 @@ class TreeGestureListener implements DragGestureListener {
@Override
public void dragGestureRecognized(DragGestureEvent dge) {
JTree tree = (JTree) dge.getComponent();
Point p = dge.getDragOrigin();
TreePath path = tree.getClosestPathForLocation(p.x, p.y);
if (path != null && path.getLastPathComponent() instanceof DefaultMutableTreeNode) {
DefaultMutableTreeNode leaf = (DefaultMutableTreeNode)path.getLastPathComponent();
Payload payload = (Payload) leaf.getUserObject();
if (payload != null && (payload.getComponentType() != null || payload.getClickListener() != null)) {
if (payload.getComponentType() != null)
presenter.setNewComponentTypeSlot(payload.getComponentType(), null, true);
else
payload.getClickListener().mouseClicked(null);
dge.startDrag(presenter.getCursorAt(dge.getDragOrigin()), new EmptyTransferable(), new TreeSourceListener(
presenter));
ComponentType type = null;
Payload payload = null;
if (presenter.getNewComponentTypeSlot() == null) {
JTree tree = (JTree) dge.getComponent();
Point p = dge.getDragOrigin();
TreePath path = tree.getClosestPathForLocation(p.x, p.y);
if (path != null && path.getLastPathComponent() instanceof DefaultMutableTreeNode) {
DefaultMutableTreeNode leaf = (DefaultMutableTreeNode) path.getLastPathComponent();
payload = (Payload) leaf.getUserObject();
if (payload != null && (payload.getComponentType() != null || payload.getClickListener() != null))
type = payload.getComponentType();
}
} else {
type = presenter.getNewComponentTypeSlot();
}
boolean start = false;
if (type == null)
{
if (payload != null && payload.getClickListener() != null) {
payload.getClickListener().mouseClicked(null);
start = true;
}
}
else {
presenter.setNewComponentTypeSlot(type, null, true);
start = true;
}
if (start)
dge.startDrag(presenter.getCursorAt(dge.getDragOrigin()), new EmptyTransferable(),
new TreeSourceListener(presenter));
}
}
+9 -1
View File
@@ -2397,7 +2397,15 @@
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>Create a backup of config file when there is an issue with loading (cross-version)</description>
</org.diylc.appframework.update.Change>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>Automatically select dropped components from the component tree after they get placed</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>BUG_FIX</changeType>
<description>Drag&amp;Drop from the tree sometimes picks up a wrong component type</description>
</org.diylc.appframework.update.Change>
</changes>
<url>https://github.com/bancika/diy-layout-creator/releases</url>
</org.diylc.appframework.update.Version>