Ability to drag components directly from the tree to the canvas for

faster process
This commit is contained in:
Branislav Stojkovic
2019-02-02 12:18:37 +01:00
parent 08a0e451e7
commit 34ea20eedd
11 changed files with 261 additions and 99 deletions
@@ -278,9 +278,10 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
* component.
*
* @param componentType
* @param template
* @param template
* @param forceInstatiate
*/
void setNewComponentTypeSlot(ComponentType componentType, Template template);
void setNewComponentTypeSlot(ComponentType componentType, Template template, boolean forceInstatiate);
/**
* Changes default size notation, true for metric, false for imperial.
@@ -94,7 +94,7 @@ public class InstantiationManager {
this.potentialControlPoint = potentialControlPoint;
}
public void setComponentTypeSlot(ComponentType componentTypeSlot, Template template, Project currentProject)
public void setComponentTypeSlot(ComponentType componentTypeSlot, Template template, Project currentProject, boolean forceInstatiate)
throws Exception {
this.componentTypeSlot = componentTypeSlot;
this.template = template;
@@ -103,7 +103,7 @@ public class InstantiationManager {
} else {
switch (componentTypeSlot.getCreationMethod()) {
case POINT_BY_POINT:
this.componentSlot = null;
this.componentSlot = forceInstatiate ? instantiateComponent(componentTypeSlot, template, new Point(0, 0), currentProject) : null;
break;
case SINGLE_CLICK:
this.componentSlot = instantiateComponent(componentTypeSlot, template, new Point(0, 0), currentProject);
@@ -97,7 +97,7 @@ public class Presenter implements IPlugInPort {
List<Version> allVersions = (List<Version>) xStream.fromXML(in);
CURRENT_VERSION = allVersions.get(allVersions.size() - 1).getVersionNumber();
LOG.info("Current DIYLC version: " + CURRENT_VERSION);
RECENT_VERSIONS = allVersions.subList(allVersions.size() - 3, allVersions.size());
RECENT_VERSIONS = allVersions.subList(allVersions.size() - 10, allVersions.size());
Collections.sort(RECENT_VERSIONS, new Comparator<Version>() {
@Override
@@ -571,9 +571,9 @@ public class Presenter implements IPlugInPort {
editSelection();
}
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.CONTINUOUS_CREATION_KEY, false)) {
setNewComponentTypeSlot(componentTypeSlot, template);
setNewComponentTypeSlot(componentTypeSlot, template, false);
} else {
setNewComponentTypeSlot(null, null);
setNewComponentTypeSlot(null, null, false);
}
break;
case POINT_BY_POINT:
@@ -595,33 +595,7 @@ public class Presenter implements IPlugInPort {
} else {
// On the second click, add the component to the
// project.
List<IDIYComponent<?>> componentSlot = instantiationManager.getComponentSlot();
Point firstPoint = componentSlot.get(0).getControlPoint(0);
// don't allow to create component with the same points
if (scaledPoint.equals(firstPoint))
return;
componentSlot.get(0).setControlPoint(scaledPoint, 1);
List<IDIYComponent<?>> newSelection = new ArrayList<IDIYComponent<?>>();
for (IDIYComponent<?> component : componentSlot) {
addComponent(component, true);
// Select the new component if it's not locked and invisible.
if (!isComponentLocked(component) && isComponentVisible(component)) {
newSelection.add(component);
}
}
updateSelection(newSelection);
messageDispatcher.dispatchMessage(EventType.REPAINT);
if (componentTypeSlot.isAutoEdit()
&& ConfigurationManager.getInstance().readBoolean(IPlugInPort.AUTO_EDIT_KEY, false)) {
editSelection();
}
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.CONTINUOUS_CREATION_KEY, false)) {
setNewComponentTypeSlot(componentTypeSlot, template);
} else {
setNewComponentTypeSlot(null, null);
}
addPendingComponentsToProject(scaledPoint, componentTypeSlot, template);
}
break;
default:
@@ -675,6 +649,36 @@ public class Presenter implements IPlugInPort {
}
}
private void addPendingComponentsToProject(Point scaledPoint, ComponentType componentTypeSlot, Template template) {
List<IDIYComponent<?>> componentSlot = instantiationManager.getComponentSlot();
Point firstPoint = componentSlot.get(0).getControlPoint(0);
// don't allow to create component with the same points
if (scaledPoint == null || scaledPoint.equals(firstPoint))
return;
// componentSlot.get(0).setControlPoint(scaledPoint, 1);
List<IDIYComponent<?>> newSelection = new ArrayList<IDIYComponent<?>>();
for (IDIYComponent<?> component : componentSlot) {
addComponent(component, true);
// Select the new component if it's not locked and invisible.
if (!isComponentLocked(component) && isComponentVisible(component)) {
newSelection.add(component);
}
}
updateSelection(newSelection);
messageDispatcher.dispatchMessage(EventType.REPAINT);
if (componentTypeSlot.isAutoEdit()
&& ConfigurationManager.getInstance().readBoolean(IPlugInPort.AUTO_EDIT_KEY, false)) {
editSelection();
}
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.CONTINUOUS_CREATION_KEY, false)) {
setNewComponentTypeSlot(componentTypeSlot, template, false);
} else {
setNewComponentTypeSlot(null, null, false);
}
}
@Override
public boolean keyPressed(int key, boolean ctrlDown, boolean shiftDown, boolean altDown) {
if (key != VK_DOWN && key != VK_LEFT && key != VK_UP && key != VK_RIGHT && key != IKeyProcessor.VK_H
@@ -1162,6 +1166,10 @@ public class Presenter implements IPlugInPort {
}
// messageDispatcher.dispatchMessage(EventType.SELECTION_RECT_CHANGED,
// selectionRect);
} else if (instantiationManager.getComponentSlot() != null) {
this.previousScaledPoint = scalePoint(point);
instantiationManager.updateSingleClick(previousScaledPoint, isSnapToGrid(),
currentProject.getGridSpacing());
}
messageDispatcher.dispatchMessage(EventType.REPAINT);
return true;
@@ -1448,10 +1456,15 @@ public class Presenter implements IPlugInPort {
@Override
public void dragEnded(Point point) {
LOG.debug(String.format("dragEnded(%s)", point));
if (!dragInProgress) {
return;
}
Point scaledPoint = scalePoint(point);
if (!dragInProgress) {
if (instantiationManager.getComponentSlot() != null)
addPendingComponentsToProject(scaledPoint, instantiationManager.getComponentTypeSlot(), null);
return;
}
if (selectedComponents.isEmpty()) {
// If there's no selection finalize selectionRect and see which
// components intersect with it.
@@ -2113,11 +2126,11 @@ public class Presenter implements IPlugInPort {
}
@Override
public void setNewComponentTypeSlot(ComponentType componentType, Template template) {
public void setNewComponentTypeSlot(ComponentType componentType, Template template, boolean forceInstatiate) {
LOG.info(String.format("setNewComponentSlot(%s)", componentType == null ? null : componentType.getName()));
if (componentType != null && componentType.getInstanceClass() == null) {
LOG.info("Cannot set new component type slot for type " + componentType.getName());
setNewComponentTypeSlot(null, null);
setNewComponentTypeSlot(null, null, false);
return;
}
@@ -2135,10 +2148,13 @@ public class Presenter implements IPlugInPort {
}
try {
instantiationManager.setComponentTypeSlot(componentType, template, currentProject);
if (componentType != null) {
instantiationManager.setComponentTypeSlot(componentType, template, currentProject, forceInstatiate);
if (forceInstatiate)
updateSelection(instantiationManager.getComponentSlot());
else if (componentType != null)
updateSelection(EMPTY_SELECTION);
}
messageDispatcher.dispatchMessage(EventType.REPAINT);
// messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED,
// selectedComponents);
@@ -148,7 +148,7 @@ public class CanvasPanel extends JComponent implements Autoscroll {
@Override
public void actionPerformed(ActionEvent e) {
CanvasPanel.this.plugInPort.setNewComponentTypeSlot(null, null);
CanvasPanel.this.plugInPort.setNewComponentTypeSlot(null, null, false);
}
});
@@ -167,7 +167,7 @@ public class CanvasPanel extends JComponent implements Autoscroll {
for (Map.Entry<String, List<ComponentType>> entry : componentTypes.entrySet()) {
for (ComponentType type : entry.getValue()) {
if (type.getInstanceClass().getCanonicalName().equals(clazz)) {
CanvasPanel.this.plugInPort.setNewComponentTypeSlot(type, null);
CanvasPanel.this.plugInPort.setNewComponentTypeSlot(type, null, false);
// hack: fake mouse movement to repaint
CanvasPanel.this.plugInPort.mouseMoved(getMousePosition(), false, false, false);
return;
@@ -201,7 +201,7 @@ public class CanvasPanel extends JComponent implements Autoscroll {
LOG.error("Could not find type: " + typeName);
return;
}
this.plugInPort.setNewComponentTypeSlot(type, null);
this.plugInPort.setNewComponentTypeSlot(type, null, false);
}
// hack: fake mouse movement to repaint
@@ -21,58 +21,57 @@
*/
package org.diylc.swing.plugins.statusbar;
import java.awt.BorderLayout;
import java.awt.Cursor;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.geom.Point2D;
import java.text.DecimalFormat;
import java.text.Format;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.awt.BorderLayout;
import java.awt.Cursor;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.geom.Point2D;
import java.text.DecimalFormat;
import java.text.Format;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import javax.swing.BorderFactory;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.BorderFactory;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import net.java.balloontip.BalloonTip;
import net.java.balloontip.styles.EdgedBalloonStyle;
import net.java.balloontip.BalloonTip;
import net.java.balloontip.styles.EdgedBalloonStyle;
import org.apache.log4j.Logger;
import org.diylc.announcements.AnnouncementProvider;
import org.diylc.appframework.miscutils.Utils;
import org.apache.log4j.Logger;
import org.diylc.announcements.AnnouncementProvider;
import org.diylc.appframework.miscutils.Utils;
import org.diylc.appframework.update.UpdateChecker;
import org.diylc.appframework.update.Version;
import org.diylc.common.BadPositionException;
import org.diylc.common.ComponentType;
import org.diylc.common.EventType;
import org.diylc.common.IPlugIn;
import org.diylc.common.IPlugInPort;
import org.diylc.common.ITask;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IView;
import org.diylc.images.IconLoader;
import org.diylc.swing.ISwingUI;
import org.diylc.swingframework.MemoryBar;
import org.diylc.swingframework.miscutils.PercentageListCellRenderer;
import org.diylc.common.BadPositionException;
import org.diylc.common.ComponentType;
import org.diylc.common.EventType;
import org.diylc.common.IPlugIn;
import org.diylc.common.IPlugInPort;
import org.diylc.common.ITask;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IView;
import org.diylc.images.IconLoader;
import org.diylc.swing.ISwingUI;
import org.diylc.swingframework.MemoryBar;
import org.diylc.swingframework.miscutils.PercentageListCellRenderer;
import org.diylc.swingframework.update.UpdateDialog;
import org.diylc.swingframework.update.UpdateLabel;
import org.diylc.swingframework.update.UpdateLabel;
public class StatusBar extends JPanel implements IPlugIn {
@@ -69,7 +69,7 @@ public class ComponentButtonFactory {
@Override
public void actionPerformed(ActionEvent e) {
plugInPort.setNewComponentTypeSlot(componentType, null);
plugInPort.setNewComponentTypeSlot(componentType, null, false);
}
});
@@ -90,7 +90,7 @@ public class ComponentButtonFactory {
newSelection.addAll(plugInPort.getSelectedComponents());
}
plugInPort.updateSelection(newSelection);
plugInPort.setNewComponentTypeSlot(null, null);
plugInPort.setNewComponentTypeSlot(null, null, false);
plugInPort.refresh();
}
}
@@ -122,7 +122,7 @@ public class ComponentButtonFactory {
@Override
public void actionPerformed(ActionEvent e) {
plugInPort.setNewComponentTypeSlot(componentType, variant);
plugInPort.setNewComponentTypeSlot(componentType, variant, false);
}
});
@@ -84,7 +84,7 @@ class ComponentTabbedPane extends JTabbedPane {
@Override
public void stateChanged(ChangeEvent e) {
ComponentTabbedPane.this.plugInPort.setNewComponentTypeSlot(null, null);
ComponentTabbedPane.this.plugInPort.setNewComponentTypeSlot(null, null, false);
// Refresh recent components if needed
if (pendingRecentComponents != null) {
refreshRecentComponentsToolbar(getRecentToolbar(), pendingRecentComponents);
@@ -0,0 +1,64 @@
/*
*
* DIY Layout Creator (DIYLC). Copyright (c) 2009-2018 held jointly by the individual authors.
*
* This file is part of DIYLC.
*
* DIYLC is free software: you can redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* DIYLC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with DIYLC. If not, see
* <http://www.gnu.org/licenses/>.
*/
package org.diylc.swing.plugins.tree;
import java.awt.Point;
import java.awt.dnd.DragGestureEvent;
import java.awt.dnd.DragGestureListener;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;
import org.diylc.common.IPlugInPort;
import org.diylc.swing.plugins.canvas.EmptyTransferable;
import org.diylc.swing.plugins.tree.TreePanel.Payload;
/**
* {@link DragGestureListener} for {@link TreePanel}.
*
* @author Branislav Stojkovic
*/
class TreeGestureListener implements DragGestureListener {
private IPlugInPort presenter;
public TreeGestureListener(IPlugInPort presenter) {
super();
this.presenter = presenter;
}
@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) {
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));
}
}
}
}
@@ -25,6 +25,8 @@ import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DragSource;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
@@ -167,6 +169,14 @@ public class TreePanel extends JPanel {
});
getTree().expandRow(0);
initializeDnD();
}
private void initializeDnD() {
// Initialize drag source recognizer.
DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer(getTree(),
DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK, new TreeGestureListener(plugInPort));
}
public JScrollPane getTreeScroll() {
@@ -226,7 +236,7 @@ public class TreePanel extends JPanel {
@Override
public void mouseClicked(MouseEvent e) {
if (plugInPort.getNewComponentTypeSlot() != componentType)
plugInPort.setNewComponentTypeSlot(componentType, null);
plugInPort.setNewComponentTypeSlot(componentType, null, false);
}
});
final DefaultMutableTreeNode componentNode = new DefaultMutableTreeNode(payload, false);
@@ -289,7 +299,7 @@ public class TreePanel extends JPanel {
@Override
public void mouseClicked(MouseEvent e) {
plugInPort.setNewComponentTypeSlot(type, null);
plugInPort.setNewComponentTypeSlot(type, null, false);
}
}), false);
categoryNode.add(componentNode);
@@ -710,7 +720,7 @@ public class TreePanel extends JPanel {
}
plugInPort.updateSelection(newSelection);
plugInPort.setNewComponentTypeSlot(null, null);
plugInPort.setNewComponentTypeSlot(null, null, false);
plugInPort.refresh();
}
}
@@ -0,0 +1,68 @@
/*
DIY Layout Creator (DIYLC).
Copyright (c) 2009-2018 held jointly by the individual authors.
This file is part of DIYLC.
DIYLC is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
DIYLC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
*/
package org.diylc.swing.plugins.tree;
import java.awt.Point;
import java.awt.dnd.DragSourceDragEvent;
import java.awt.dnd.DragSourceDropEvent;
import java.awt.dnd.DragSourceEvent;
import java.awt.dnd.DragSourceListener;
import org.diylc.common.IPlugInPort;
/**
* {@link DragSourceListener} for {@link TreePanel}.
*
* @author Branislav Stojkovic
*/
class TreeSourceListener implements DragSourceListener {
private IPlugInPort presenter;
public TreeSourceListener(IPlugInPort presenter) {
super();
this.presenter = presenter;
}
@Override
public void dragDropEnd(DragSourceDropEvent dsde) {
presenter.dragEnded(null);
}
@Override
public void dragEnter(DragSourceDragEvent dsde) {}
@Override
public void dragExit(DragSourceEvent dse) {}
@Override
public void dragOver(DragSourceDragEvent dsde) {
Point p = dsde.getDragSourceContext().getComponent().getMousePosition();
if (p != null) {
dsde.getDragSourceContext().getComponent().firePropertyChange("dragPoint", p.x, p.y);
}
}
@Override
public void dropActionChanged(DragSourceDragEvent dsde) {}
}
+5 -1
View File
@@ -2357,7 +2357,11 @@
</versionNumber>
<releaseDate>2019-01-28 00:00:00.000 CET</releaseDate>
<name></name>
<changes>
<changes>
<org.diylc.appframework.update.Change>
<changeType>NEW_FEATURE</changeType>
<description>Ability to drag components directly from the tree to the canvas for faster process</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>NEW_FEATURE</changeType>
<description>"Fuse Symbol" added</description>