mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
Ability to drag components directly from the tree to the canvas for
faster process
This commit is contained in:
@@ -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) {}
|
||||
}
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user