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 5e7b99dc..50af82db 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 @@ -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> getSelectedComponents(); /** * Selects all components in the project. diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/DrawingManager.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/DrawingManager.java index 25232ecd..8ad3773f 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/DrawingManager.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/DrawingManager.java @@ -16,7 +16,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.diylc.common.ComponentSelection; import org.diylc.common.DrawOption; import org.diylc.common.EventType; import org.diylc.common.GridType; @@ -71,7 +70,7 @@ public class DrawingManager { } public void drawProject(Graphics2D g2d, Project project, Set drawOptions, - IComponentFiler filter, Rectangle selectionRect, ComponentSelection selectedComponents, + IComponentFiler filter, Rectangle selectionRect, List> selectedComponents, Set> lockedComponents, Set> groupedComponents, List controlPointSlot, IDIYComponent componentSlot, boolean dragInProgress) { if (project == null) { 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 541d47fd..a6812948 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 @@ -20,7 +20,6 @@ import java.util.Map; import java.util.Set; import org.apache.log4j.Logger; -import org.diylc.common.ComponentSelection; import org.diylc.common.ComponentType; import org.diylc.common.DrawOption; import org.diylc.common.EventType; @@ -54,6 +53,8 @@ public class Presenter implements IPlugInPort { public static final String DEFAULTS_KEY_PREFIX = "default."; public static final String METRIC_KEY = "metric"; + public static final List> EMPTY_SELECTION = Collections.emptyList(); + public static final int ICON_SIZE = 32; private Project currentProject; @@ -61,7 +62,7 @@ public class Presenter implements IPlugInPort { // Maps component class names to ComponentType objects. private List plugIns; - private ComponentSelection selectedComponents; + private List> selectedComponents; // Maps components that have at least one dragged point to set of indices // that designate which of their control points are being dragged. private Map, Set> controlPointMap; @@ -96,7 +97,7 @@ public class Presenter implements IPlugInPort { this.view = view; plugIns = new ArrayList(); messageDispatcher = new MessageDispatcher(true); - selectedComponents = new ComponentSelection(); + selectedComponents = new ArrayList>(); lockedComponents = new HashSet>(); currentProject = new Project(); cloner = new Cloner(); @@ -178,7 +179,7 @@ public class Presenter implements IPlugInPort { public void loadProject(Project project, boolean freshStart) { LOG.info(String.format("loadProject(%s, %s)", project.getTitle(), freshStart)); this.currentProject = project; - updateSelection(ComponentSelection.EMPTY_SELECTION); + updateSelection(EMPTY_SELECTION); messageDispatcher.dispatchMessage(EventType.PROJECT_LOADED, project, freshStart); messageDispatcher.dispatchMessage(EventType.REPAINT); messageDispatcher.dispatchMessage(EventType.LAYER_STATE_CHANGED, currentProject @@ -355,7 +356,9 @@ public class Presenter implements IPlugInPort { // messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED, // calculateSelectionDimension()); messageDispatcher.dispatchMessage(EventType.REPAINT); - updateSelection(ComponentSelection.of(component)); + List> newSelection = new ArrayList>(); + newSelection.add(component); + updateSelection(newSelection); } catch (Exception e) { LOG.error("Error instatiating component of type: " + componentTypeSlot.getInstanceClass().getName(), e); @@ -385,8 +388,11 @@ public class Presenter implements IPlugInPort { componentSlot.setControlPoint(scaledPoint, 1); addComponent(componentSlot, componentTypeSlot); // Select the new component if it's not locked. - updateSelection(isComponentLocked(componentSlot) ? ComponentSelection.EMPTY_SELECTION - : ComponentSelection.of(componentSlot)); + List> newSelection = new ArrayList>(); + if (!isComponentLocked(componentSlot)) { + newSelection.add(componentSlot); + } + updateSelection(newSelection); messageDispatcher.dispatchMessage(EventType.REPAINT); setNewComponentTypeSlot(null); } @@ -401,7 +407,8 @@ public class Presenter implements IPlugInPort { projectFileManager.notifyFileChange(); } } else { - ComponentSelection newSelection = new ComponentSelection(selectedComponents); + List> newSelection = new ArrayList>( + selectedComponents); List> components = findComponentsAt(scaledPoint); // If there's nothing under mouse cursor deselect all. if (components.isEmpty()) { @@ -445,8 +452,8 @@ public class Presenter implements IPlugInPort { refresh = instantiationManager.updatePointByPoint(scaledPoint); break; case SINGLE_CLICK: - refresh = instantiationManager.updateSingleClick(scaledPoint, snapToGrid, currentProject - .getGridSpacing()); + refresh = instantiationManager.updateSingleClick(scaledPoint, snapToGrid, + currentProject.getGridSpacing()); break; } if (refresh) { @@ -496,14 +503,14 @@ public class Presenter implements IPlugInPort { } @Override - public ComponentSelection getSelectedComponents() { - return new ComponentSelection(selectedComponents); + public List> getSelectedComponents() { + return selectedComponents; } @Override public void selectAll() { LOG.info("selectAll()"); - updateSelection(new ComponentSelection(currentProject.getComponents())); + updateSelection(new ArrayList>(currentProject.getComponents())); // messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, // selectedComponents); // messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED, @@ -531,7 +538,7 @@ public class Presenter implements IPlugInPort { List> components = findComponentsAt(scaledPoint); if (!controlPointMap.isEmpty()) { // If we're dragging control points reset selection. - updateSelection(new ComponentSelection(controlPointMap.keySet())); + updateSelection(new ArrayList>(controlPointMap.keySet())); // messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, // selectedComponents); // messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED, @@ -539,7 +546,7 @@ public class Presenter implements IPlugInPort { messageDispatcher.dispatchMessage(EventType.REPAINT); } else if (components.isEmpty()) { // If there are no components are under the cursor, reset selection. - updateSelection(ComponentSelection.EMPTY_SELECTION); + updateSelection(EMPTY_SELECTION); // messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, // selectedComponents); // messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED, @@ -551,7 +558,7 @@ public class Presenter implements IPlugInPort { // If the component under the cursor is not already selected, make // it into the only selected component. if (!selectedComponents.contains(component)) { - updateSelection(new ComponentSelection(findAllGroupedComponents(component))); + updateSelection(new ArrayList>(findAllGroupedComponents(component))); // messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, // selectedComponents); // messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED, @@ -755,7 +762,7 @@ public class Presenter implements IPlugInPort { if (scaledPoint != null) { this.selectionRect = Utils.createRectangle(scaledPoint, previousDragPoint); } - ComponentSelection newSelection = new ComponentSelection(); + List> newSelection = new ArrayList>(); for (IDIYComponent component : currentProject.getComponents()) { if (!isComponentLocked(component)) { Area area = drawingManager.getComponentArea(component); @@ -802,7 +809,7 @@ public class Presenter implements IPlugInPort { messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner .deepClone(currentProject), "Add"); projectFileManager.notifyFileChange(); - updateSelection(new ComponentSelection(components)); + updateSelection(new ArrayList>(components)); messageDispatcher.dispatchMessage(EventType.REPAINT); } @@ -824,7 +831,7 @@ public class Presenter implements IPlugInPort { messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner .deepClone(currentProject), "Delete"); projectFileManager.notifyFileChange(); - updateSelection(ComponentSelection.EMPTY_SELECTION); + updateSelection(EMPTY_SELECTION); messageDispatcher.dispatchMessage(EventType.REPAINT); } @@ -890,20 +897,20 @@ public class Presenter implements IPlugInPort { } else { currentProject.getLockedLayers().remove(layerZOrder); } - updateSelection(ComponentSelection.EMPTY_SELECTION); + updateSelection(EMPTY_SELECTION); messageDispatcher.dispatchMessage(EventType.REPAINT); messageDispatcher.dispatchMessage(EventType.LAYER_STATE_CHANGED, currentProject .getLockedLayers()); } /** - * Updates the selection with the specified {@link ComponentSelection}. + * 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(ComponentSelection newSelection) { + private void updateSelection(List> newSelection) { this.selectedComponents = newSelection; Map, Set> controlPointMap = new HashMap, Set>(); for (IDIYComponent component : selectedComponents) { @@ -1090,7 +1097,7 @@ public class Presenter implements IPlugInPort { try { instantiationManager.setComponentTypeSlot(componentType, currentProject); if (componentType != null) { - updateSelection(ComponentSelection.EMPTY_SELECTION); + updateSelection(EMPTY_SELECTION); } messageDispatcher.dispatchMessage(EventType.REPAINT); // messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/common/ComponentSelection.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/clipboard/ComponentTransferable.java similarity index 51% rename from diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/common/ComponentSelection.java rename to diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/clipboard/ComponentTransferable.java index c68e61c7..a1ea0fa2 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/common/ComponentSelection.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/clipboard/ComponentTransferable.java @@ -1,4 +1,4 @@ -package org.diylc.common; +package org.diylc.swing.plugins.clipboard; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.Transferable; @@ -10,33 +10,24 @@ 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. + * 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> implements Transferable { +public class ComponentTransferable extends ArrayList> 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 static final DataFlavor listFlavor = new DataFlavor(ComponentTransferable.class, "application/diylc"); - public ComponentSelection() { + public ComponentTransferable() { super(); } - public ComponentSelection(Collection> selectedComponents) { + public ComponentTransferable(Collection> selectedComponents) { super(selectedComponents); } diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/clipboard/EditMenuPlugin.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/clipboard/EditMenuPlugin.java index 50237d75..d5649cd7 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/clipboard/EditMenuPlugin.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/clipboard/EditMenuPlugin.java @@ -15,7 +15,6 @@ import javax.swing.AbstractAction; import javax.swing.KeyStroke; import org.apache.log4j.Logger; -import org.diylc.common.ComponentSelection; import org.diylc.common.EventType; import org.diylc.common.IPlugIn; import org.diylc.common.IPlugInPort; @@ -42,13 +41,21 @@ public class EditMenuPlugin implements IPlugIn, ClipboardOwner { private Clipboard clipboard; private Cloner cloner; -// private CutAction cutAction; + // private CutAction cutAction; private CopyAction copyAction; private PasteAction pasteAction; private UndoHandler undoHandler; public EditMenuPlugin(ISwingUI swingUI) { + SecurityManager securityManager = System.getSecurityManager(); + if (securityManager != null) { + try { + securityManager.checkSystemClipboardAccess(); + } catch (Exception e) { + e.printStackTrace(); + } + } clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); cloner = new Cloner(); undoHandler = new UndoHandler(new IUndoListener() { @@ -65,7 +72,7 @@ public class EditMenuPlugin implements IPlugIn, ClipboardOwner { refreshActions(); } }); - + swingUI.injectMenuAction(undoHandler.getUndoAction(), EDIT_TITLE); swingUI.injectMenuAction(undoHandler.getRedoAction(), EDIT_TITLE); swingUI.injectMenuAction(null, EDIT_TITLE); @@ -112,8 +119,9 @@ public class EditMenuPlugin implements IPlugIn, ClipboardOwner { boolean enabled = !plugInPort.getSelectedComponents().isEmpty(); // cutAction.setEnabled(enabled); copyAction.setEnabled(enabled); - try { - pasteAction.setEnabled(clipboard.isDataFlavorAvailable(ComponentSelection.listFlavor)); + try { + pasteAction.setEnabled(clipboard + .isDataFlavorAvailable(ComponentTransferable.listFlavor)); } catch (Exception e) { pasteAction.setEnabled(false); } @@ -152,8 +160,8 @@ public class EditMenuPlugin implements IPlugIn, ClipboardOwner { @Override public void actionPerformed(ActionEvent e) { LOG.info("Copy triggered"); - clipboard.setContents(cloner.deepClone(plugInPort.getSelectedComponents()), - EditMenuPlugin.this); + clipboard.setContents(new ComponentTransferable(cloner.deepClone(plugInPort + .getSelectedComponents())), EditMenuPlugin.this); } } @@ -175,7 +183,7 @@ public class EditMenuPlugin implements IPlugIn, ClipboardOwner { LOG.info("Paste triggered"); try { List> components = (List>) clipboard - .getData(ComponentSelection.listFlavor); + .getData(ComponentTransferable.listFlavor); plugInPort.pasteComponents(cloner.deepClone(components)); } catch (Exception ex) { LOG.error("Coule not paste.", ex); diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/statusbar/StatusBar.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/statusbar/StatusBar.java index 8f226e03..b9d15b18 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/statusbar/StatusBar.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/statusbar/StatusBar.java @@ -28,7 +28,6 @@ import javax.swing.SwingUtilities; import org.apache.log4j.Logger; import org.diylc.common.BadPositionException; -import org.diylc.common.ComponentSelection; import org.diylc.common.ComponentType; import org.diylc.common.EventType; import org.diylc.common.IPlugIn; @@ -217,7 +216,7 @@ public class StatusBar extends JPanel implements IPlugIn { } break; case SELECTION_CHANGED: - ComponentSelection selection = (ComponentSelection) params[0]; + List> selection = (List>) params[0]; Collection> stuckComponents = (Collection>) params[1]; Collection componentNames = new HashSet(); for (IDIYComponent component : selection) {