double click on a component button to select all of that type

This commit is contained in:
bancika
2011-08-26 17:56:33 +00:00
parent 15ac8ff2e9
commit f137a398dc
5 changed files with 53 additions and 20 deletions
@@ -191,6 +191,15 @@ public interface IPlugInPort {
* @return
*/
List<IDIYComponent<?>> 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<IDIYComponent<?>> newSelection);
/**
* Selects all components in the project.
@@ -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
@@ -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<IDIYComponent<?>> newSelection) {
public void updateSelection(List<IDIYComponent<?>> newSelection) {
this.selectedComponents = newSelection;
Map<IDIYComponent<?>, Set<Integer>> controlPointMap = new HashMap<IDIYComponent<?>, Set<Integer>>();
for (IDIYComponent<?> component : selectedComponents) {
@@ -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("<html><b>" + componentType.getName() + "</b><br>"
+ componentType.getDescription() + "<br>Author: " + componentType.getAuthor()
+ "<br><br>Double click to select all components of this type"
+ "</html>");
// 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<IDIYComponent<?>> components = plugInPort.getCurrentProject().getComponents();
List<IDIYComponent<?>> newSelection = new ArrayList<IDIYComponent<?>>();
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