From f137a398dce8b3a3d4fc5f8e01848054a7c54034 Mon Sep 17 00:00:00 2001 From: bancika Date: Fri, 26 Aug 2011 17:56:33 +0000 Subject: [PATCH] double click on a component button to select all of that type --- .../src/org/diylc/common/IPlugInPort.java | 9 ++++ .../diylc/presenter/ComponentProcessor.java | 3 +- .../src/org/diylc/presenter/Presenter.java | 9 +--- .../plugins/toolbox/ComponentButton.java | 48 ++++++++++++++----- .../DIYLC/update.xml | 4 ++ 5 files changed, 53 insertions(+), 20 deletions(-) diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/common/IPlugInPort.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/common/IPlugInPort.java index 144e0f1e..0249f4e1 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/common/IPlugInPort.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/common/IPlugInPort.java @@ -191,6 +191,15 @@ public interface IPlugInPort { * @return */ List> getSelectedComponents(); + + /** + * Updates the selection with the specified list of component. Also, updates + * control point map with all components that are stuck to the newly + * selected components. + * + * @param newSelection + */ + void updateSelection(List> newSelection); /** * Selects all components in the project. diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/ComponentProcessor.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/ComponentProcessor.java index 32f1c365..8f1c9d49 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/ComponentProcessor.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/ComponentProcessor.java @@ -157,7 +157,8 @@ public class ComponentProcessor { } /** - * Returns properties mutual for all the selected components. + * Returns properties that have the same value for all the selected + * components. * * @param selectedComponents * @return diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/Presenter.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/Presenter.java index b6a58aef..33ef4097 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/Presenter.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/Presenter.java @@ -1062,14 +1062,7 @@ public class Presenter implements IPlugInPort { drawingManager.setTheme(theme); } - /** - * Updates the selection with the specified {@link ComponentTransferable}. - * Also, updates control point map with all components that are stuck to the - * newly selected components. - * - * @param newSelection - */ - private void updateSelection(List> newSelection) { + public void updateSelection(List> newSelection) { this.selectedComponents = newSelection; Map, Set> controlPointMap = new HashMap, Set>(); for (IDIYComponent component : selectedComponents) { diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/toolbox/ComponentButton.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/toolbox/ComponentButton.java index 84b4b73f..e913051d 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/toolbox/ComponentButton.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/toolbox/ComponentButton.java @@ -7,11 +7,16 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.ArrayList; +import java.util.List; import javax.swing.JButton; import org.diylc.common.ComponentType; import org.diylc.common.IPlugInPort; +import org.diylc.core.IDIYComponent; /** * {@link JButton} that displays component type icon and instantiates the @@ -37,22 +42,43 @@ class ComponentButton extends JButton { setToolTipText("" + componentType.getName() + "
" + componentType.getDescription() + "
Author: " + componentType.getAuthor() + + "

Double click to select all components of this type" + ""); // initializeDnD(); - addActionListener(new ActionListener() { - + addMouseListener(new MouseAdapter() { + @Override - public void actionPerformed(ActionEvent e) { - // plugInPort.setCursorIcon(componentType.getIcon()); - plugInPort.setNewComponentTypeSlot(componentType); - // try { - // plugInPort.instantiateComponent(componentType - // .getComponentInstanceClass(), null); - // } catch (Exception e1) { - // e1.printStackTrace(); - // } + public void mouseClicked(MouseEvent e) { + if (e.getClickCount() == 1) { + plugInPort.setNewComponentTypeSlot(componentType); + } else { + List> components = plugInPort.getCurrentProject().getComponents(); + List> newSelection = new ArrayList>(); + for (IDIYComponent component : components) { + if (componentType.getInstanceClass().equals(component.getClass())) { + newSelection.add(component); + } + } + plugInPort.updateSelection(newSelection); + plugInPort.setNewComponentTypeSlot(null); + plugInPort.refresh(); + } } }); +// addActionListener(new ActionListener() { +// +// @Override +// public void actionPerformed(ActionEvent e) { +// // plugInPort.setCursorIcon(componentType.getIcon()); +// plugInPort.setNewComponentTypeSlot(componentType); +// // try { +// // plugInPort.instantiateComponent(componentType +// // .getComponentInstanceClass(), null); +// // } catch (Exception e1) { +// // e1.printStackTrace(); +// // } +// } +// }); addKeyListener(new KeyAdapter() { @Override diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/update.xml b/ diy-layout-creator --username bancika@gmail.com/DIYLC/update.xml index db56a6b3..e9a3838f 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/update.xml +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/update.xml @@ -334,6 +334,10 @@ NEW_FEATURE Outline mode that resembles PCB silkscreen + + NEW_FEATURE + Double click on a component button in the toolbar selects all components of that type + http://code.google.com/p/diy-layout-creator/downloads/list