refactored awt.transferable out of the presenter

fixed copy/paste between instances
This commit is contained in:
bancika
2011-01-26 18:44:40 +00:00
parent f28dda37a6
commit 126d629cdc
6 changed files with 58 additions and 54 deletions
@@ -1,60 +0,0 @@
package org.diylc.common;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.diylc.core.IDIYComponent;
/**
* Represents component selection as a {@link List} of
* {@link IDIYComponent} objects. Implements {@link Transferable}, so it is
* suitable for clipboard usage.
*
* @author Branislav Stojkovic
*/
public class ComponentSelection extends ArrayList<IDIYComponent<?>> implements Transferable {
private static final long serialVersionUID = 1L;
public static final DataFlavor listFlavor = new DataFlavor(List.class, "Java List");
public static final ComponentSelection EMPTY_SELECTION = new ComponentSelection();
public static ComponentSelection of(IDIYComponent<?> component) {
ComponentSelection selection = new ComponentSelection();
selection.add(component);
return selection;
}
public ComponentSelection() {
super();
}
public ComponentSelection(Collection<IDIYComponent<?>> selectedComponents) {
super(selectedComponents);
}
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
if (flavor.equals(listFlavor)) {
return this;
}
throw new UnsupportedFlavorException(flavor);
}
@Override
public DataFlavor[] getTransferDataFlavors() {
return new DataFlavor[] { listFlavor };
}
@Override
public boolean isDataFlavorSupported(DataFlavor flavor) {
return flavor.equals(listFlavor);
}
}
@@ -170,11 +170,11 @@ public interface IPlugInPort {
void mouseMoved(Point point, boolean ctrlDown, boolean shiftDown, boolean altDown);
/**
* Returns the current {@link ComponentSelection}.
* Returns the current {@link ComponentTransferable}.
*
* @return
*/
ComponentSelection getSelectedComponents();
List<IDIYComponent<?>> getSelectedComponents();
/**
* Selects all components in the project.