added export trace

improved status message on selection
This commit is contained in:
bancika
2011-01-14 10:00:04 +00:00
parent e5c0b01aca
commit ef443925c2
10 changed files with 217 additions and 57 deletions
@@ -6,14 +6,14 @@
<unit class="org.diylc.core.measures.ResistanceUnit">K</unit> <unit class="org.diylc.core.measures.ResistanceUnit">K</unit>
</org.diylc.core.measures.Resistance> </org.diylc.core.measures.Resistance>
</entry> </entry>
<entry>
<string>lastPath</string>
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop</string>
</entry>
<entry> <entry>
<string>metric</string> <string>metric</string>
<boolean>true</boolean> <boolean>true</boolean>
</entry> </entry>
<entry>
<string>lastPath</string>
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop</string>
</entry>
<entry> <entry>
<string>default.org.diylc.components.semiconductors.DIL_IC:Value</string> <string>default.org.diylc.components.semiconductors.DIL_IC:Value</string>
<string>LM366</string> <string>LM366</string>
@@ -10,6 +10,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.swing.Action; import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.SwingConstants; import javax.swing.SwingConstants;
import javax.swing.JPopupMenu.Separator; import javax.swing.JPopupMenu.Separator;
@@ -123,7 +124,18 @@ public interface IPlugInPort {
* @param menuName * @param menuName
* name of the menu to insert into * name of the menu to insert into
*/ */
public void injectMenuAction(Action action, String menuName); void injectMenuAction(Action action, String menuName);
/**
* Injects a custom submenu into application's main menu. If
* <code>action</code> is set to null {@link Separator} will be added. If
* the specified menu does not exist it will be automatically created.
*
* @param name
* @param icon
* @param parentMenuName
*/
void injectSubmenu(String name, Icon icon, String parentMenuName);
/** /**
* Returns current zoom level where <code>zoomLevel = 1.0d</code> means * Returns current zoom level where <code>zoomLevel = 1.0d</code> means
@@ -1,12 +1,12 @@
package org.diylc.gui; package org.diylc.gui;
import javax.swing.Action; import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.JComponent; import javax.swing.JComponent;
import org.diylc.common.BadPositionException; import org.diylc.common.BadPositionException;
import org.diylc.common.IPlugInPort; import org.diylc.common.IPlugInPort;
/** /**
* Base interface for the main GUI component. * Base interface for the main GUI component.
* *
@@ -38,4 +38,13 @@ public interface IView {
* @see IPlugInPort#injectMenuAction * @see IPlugInPort#injectMenuAction
*/ */
void addMenuAction(Action action, String menuName); void addMenuAction(Action action, String menuName);
/**
* Adds a submenu to an existing menu.
*
* @param name
* @param icon
* @param parentMenuName
*/
void addSubmenu(String name, Icon icon, String parentMenuName);
} }
@@ -12,6 +12,7 @@ import java.util.Map;
import javax.swing.Action; import javax.swing.Action;
import javax.swing.BoxLayout; import javax.swing.BoxLayout;
import javax.swing.Icon;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JMenu; import javax.swing.JMenu;
@@ -177,6 +178,23 @@ public class MainFrame extends JFrame implements IView {
@Override @Override
public void addMenuAction(Action action, String menuName) { public void addMenuAction(Action action, String menuName) {
JMenu menu = findOrCreateMenu(menuName);
if (action == null) {
menu.addSeparator();
} else {
menu.add(action);
}
}
@Override
public void addSubmenu(String name, Icon icon, String parentMenuName) {
JMenu menu = findOrCreateMenu(parentMenuName);
JMenu submenu = new JMenu(name);
menu.add(submenu);
menuMap.put(name, submenu);
}
private JMenu findOrCreateMenu(String menuName) {
JMenu menu; JMenu menu;
if (menuMap.containsKey(menuName)) { if (menuMap.containsKey(menuName)) {
menu = menuMap.get(menuName); menu = menuMap.get(menuName);
@@ -185,10 +203,6 @@ public class MainFrame extends JFrame implements IView {
menuMap.put(menuName, menu); menuMap.put(menuName, menu);
getMainMenuBar().add(menu); getMainMenuBar().add(menu);
} }
if (action == null) { return menu;
menu.addSeparator();
} else {
menu.add(action);
}
} }
} }
@@ -19,6 +19,7 @@ import org.diylc.core.Project;
import org.diylc.gui.DialogFactory; import org.diylc.gui.DialogFactory;
import org.diylc.images.IconLoader; import org.diylc.images.IconLoader;
import com.diyfever.gui.IDrawingProvider;
import com.diyfever.gui.export.DrawingExporter; import com.diyfever.gui.export.DrawingExporter;
import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver; import com.thoughtworks.xstream.io.xml.DomDriver;
@@ -33,8 +34,11 @@ public class FileManager implements IPlugIn {
private static final Logger LOG = Logger.getLogger(FileManager.class); private static final Logger LOG = Logger.getLogger(FileManager.class);
private static final String FILE_TITLE = "File"; private static final String FILE_TITLE = "File";
private static final String TRACE_MASK_TITLE = "Trace Mask";
private IPlugInPort plugInPort; private IPlugInPort plugInPort;
private ProjectDrawingProvider drawingProvider; private ProjectDrawingProvider drawingProvider;
private TraceMaskDrawingProvider traceMaskDrawingProvider;
private XStream xStream = new XStream(new DomDriver()); private XStream xStream = new XStream(new DomDriver());
@@ -42,18 +46,24 @@ public class FileManager implements IPlugIn {
public void connect(IPlugInPort plugInPort) { public void connect(IPlugInPort plugInPort) {
this.plugInPort = plugInPort; this.plugInPort = plugInPort;
this.drawingProvider = new ProjectDrawingProvider(plugInPort); this.drawingProvider = new ProjectDrawingProvider(plugInPort);
this.traceMaskDrawingProvider = new TraceMaskDrawingProvider(plugInPort);
plugInPort.injectMenuAction(new NewAction(), FILE_TITLE); plugInPort.injectMenuAction(new NewAction(), FILE_TITLE);
plugInPort.injectMenuAction(new OpenAction(), FILE_TITLE); plugInPort.injectMenuAction(new OpenAction(), FILE_TITLE);
plugInPort.injectMenuAction(new SaveAction(), FILE_TITLE); plugInPort.injectMenuAction(new SaveAction(), FILE_TITLE);
plugInPort.injectMenuAction(new SaveAsAction(), FILE_TITLE); plugInPort.injectMenuAction(new SaveAsAction(), FILE_TITLE);
plugInPort.injectMenuAction(null, FILE_TITLE); plugInPort.injectMenuAction(null, FILE_TITLE);
plugInPort.injectMenuAction(new ExportPDFAction(drawingProvider), FILE_TITLE);
plugInPort.injectMenuAction(new ExportPNGAction(drawingProvider), FILE_TITLE);
plugInPort.injectMenuAction(new PrintAction(drawingProvider), FILE_TITLE);
plugInPort.injectSubmenu(TRACE_MASK_TITLE, null, FILE_TITLE);
plugInPort
.injectMenuAction(new ExportPDFAction(traceMaskDrawingProvider), TRACE_MASK_TITLE);
plugInPort
.injectMenuAction(new ExportPNGAction(traceMaskDrawingProvider), TRACE_MASK_TITLE);
plugInPort.injectMenuAction(new PrintAction(traceMaskDrawingProvider), TRACE_MASK_TITLE);
plugInPort.injectMenuAction(new CreateBomAction(), FILE_TITLE); plugInPort.injectMenuAction(new CreateBomAction(), FILE_TITLE);
plugInPort.injectMenuAction(null, FILE_TITLE); plugInPort.injectMenuAction(null, FILE_TITLE);
plugInPort.injectMenuAction(new ExportPDFAction(), FILE_TITLE);
plugInPort.injectMenuAction(new ExportPNGAction(), FILE_TITLE);
plugInPort.injectMenuAction(new PrintAction(), FILE_TITLE);
plugInPort.injectMenuAction(null, FILE_TITLE);
plugInPort.injectMenuAction(new ExitAction(), FILE_TITLE); plugInPort.injectMenuAction(new ExitAction(), FILE_TITLE);
} }
@@ -194,8 +204,11 @@ public class FileManager implements IPlugIn {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public ExportPDFAction() { private IDrawingProvider drawingProvider;
public ExportPDFAction(IDrawingProvider drawingProvider) {
super(); super();
this.drawingProvider = drawingProvider;
putValue(AbstractAction.NAME, "Export to PDF"); putValue(AbstractAction.NAME, "Export to PDF");
putValue(AbstractAction.SMALL_ICON, IconLoader.PDF.getIcon()); putValue(AbstractAction.SMALL_ICON, IconLoader.PDF.getIcon());
} }
@@ -205,7 +218,7 @@ public class FileManager implements IPlugIn {
File file = DialogFactory.getInstance().showSaveDialog(FileFilterEnum.PDF.getFilter(), File file = DialogFactory.getInstance().showSaveDialog(FileFilterEnum.PDF.getFilter(),
null, FileFilterEnum.PDF.getExtensions()[0], null); null, FileFilterEnum.PDF.getExtensions()[0], null);
if (file != null) { if (file != null) {
DrawingExporter.getInstance().exportPDF(drawingProvider, file); DrawingExporter.getInstance().exportPDF(this.drawingProvider, file);
} }
} }
} }
@@ -214,8 +227,11 @@ public class FileManager implements IPlugIn {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public ExportPNGAction() { private IDrawingProvider drawingProvider;
public ExportPNGAction(IDrawingProvider drawingProvider) {
super(); super();
this.drawingProvider = drawingProvider;
putValue(AbstractAction.NAME, "Export to PNG"); putValue(AbstractAction.NAME, "Export to PNG");
putValue(AbstractAction.SMALL_ICON, IconLoader.Image.getIcon()); putValue(AbstractAction.SMALL_ICON, IconLoader.Image.getIcon());
} }
@@ -225,7 +241,7 @@ public class FileManager implements IPlugIn {
File file = DialogFactory.getInstance().showSaveDialog(FileFilterEnum.PNG.getFilter(), File file = DialogFactory.getInstance().showSaveDialog(FileFilterEnum.PNG.getFilter(),
null, FileFilterEnum.PNG.getExtensions()[0], null); null, FileFilterEnum.PNG.getExtensions()[0], null);
if (file != null) { if (file != null) {
DrawingExporter.getInstance().exportPNG(drawingProvider, file); DrawingExporter.getInstance().exportPNG(this.drawingProvider, file);
} }
} }
} }
@@ -234,15 +250,18 @@ public class FileManager implements IPlugIn {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public PrintAction() { private IDrawingProvider drawingProvider;
public PrintAction(IDrawingProvider drawingProvider) {
super(); super();
this.drawingProvider = drawingProvider;
putValue(AbstractAction.NAME, "Print..."); putValue(AbstractAction.NAME, "Print...");
putValue(AbstractAction.SMALL_ICON, IconLoader.Print.getIcon()); putValue(AbstractAction.SMALL_ICON, IconLoader.Print.getIcon());
} }
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
DrawingExporter.getInstance().print(drawingProvider); DrawingExporter.getInstance().print(this.drawingProvider);
} }
} }
@@ -6,7 +6,6 @@ import java.awt.Graphics2D;
import java.util.EnumSet; import java.util.EnumSet;
import org.diylc.common.DrawOption; import org.diylc.common.DrawOption;
import org.diylc.common.IComponentFiler;
import org.diylc.common.IPlugInPort; import org.diylc.common.IPlugInPort;
import com.diyfever.gui.IDrawingProvider; import com.diyfever.gui.IDrawingProvider;
@@ -31,11 +30,6 @@ public class ProjectDrawingProvider implements IDrawingProvider {
plugInPort.draw((Graphics2D) g, EnumSet.of(DrawOption.ZOOM, DrawOption.ANTIALIASING), null); plugInPort.draw((Graphics2D) g, EnumSet.of(DrawOption.ZOOM, DrawOption.ANTIALIASING), null);
} }
public void draw(Graphics g, IComponentFiler filter) {
plugInPort.draw((Graphics2D) g, EnumSet.of(DrawOption.ZOOM, DrawOption.ANTIALIASING),
filter);
}
@Override @Override
public Dimension getSize() { public Dimension getSize() {
return plugInPort.getCanvasDimensions(true); return plugInPort.getCanvasDimensions(true);
@@ -12,6 +12,7 @@ import java.io.FileInputStream;
import java.util.EnumSet; import java.util.EnumSet;
import javax.swing.Action; import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JFileChooser; import javax.swing.JFileChooser;
import javax.swing.JLabel; import javax.swing.JLabel;
@@ -59,6 +60,10 @@ public class ProjectPreview extends JPanel implements PropertyChangeListener, IF
@Override @Override
public void addMenuAction(Action action, String menuName) { public void addMenuAction(Action action, String menuName) {
} }
@Override
public void addSubmenu(String name, Icon icon, String parentMenuName) {
}
}); });
xStream = new XStream(new DomDriver()); xStream = new XStream(new DomDriver());
@@ -0,0 +1,43 @@
package org.diylc.plugins.file;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.EnumSet;
import org.diylc.common.DrawOption;
import org.diylc.common.IComponentFiler;
import org.diylc.common.IPlugInPort;
import org.diylc.core.IDIYComponent;
import org.diylc.presenter.ComponentZOrderFiler;
import com.diyfever.gui.IDrawingProvider;
/**
* {@link IDrawingProvider} implementation that uses {@link IPlugInPort} to draw
* a project onto the canvas.
*
* @author Branislav Stojkovic
*/
public class TraceMaskDrawingProvider implements IDrawingProvider {
private IPlugInPort plugInPort;
private IComponentFiler filter;
public TraceMaskDrawingProvider(IPlugInPort plugInPort) {
super();
this.plugInPort = plugInPort;
this.filter = new ComponentZOrderFiler(IDIYComponent.ABOVE_BOARD);
}
@Override
public void draw(Graphics g) {
plugInPort.draw((Graphics2D) g, EnumSet.of(DrawOption.ZOOM, DrawOption.ANTIALIASING),
this.filter);
}
@Override
public Dimension getSize() {
return plugInPort.getCanvasDimensions(true);
}
}
@@ -57,6 +57,7 @@ public class StatusBar extends JPanel implements IPlugIn {
private ComponentType componentSlot; private ComponentType componentSlot;
private List<IDIYComponent<?>> componentsUnderCursor; private List<IDIYComponent<?>> componentsUnderCursor;
private List<String> selectedComponentNames; private List<String> selectedComponentNames;
private List<String> stuckComponentNames;
public StatusBar() { public StatusBar() {
super(); super();
@@ -189,12 +190,19 @@ public class StatusBar extends JPanel implements IPlugIn {
break; break;
case SELECTION_CHANGED: case SELECTION_CHANGED:
ComponentSelection selection = (ComponentSelection) params[0]; ComponentSelection selection = (ComponentSelection) params[0];
Collection<IDIYComponent<?>> stuckComponents = (Collection<IDIYComponent<?>>) params[1];
Collection<String> componentNames = new HashSet<String>(); Collection<String> componentNames = new HashSet<String>();
for (IDIYComponent<?> component : selection) { for (IDIYComponent<?> component : selection) {
componentNames.add(component.getName()); componentNames.add(component.getName());
} }
this.selectedComponentNames = new ArrayList<String>(componentNames); this.selectedComponentNames = new ArrayList<String>(componentNames);
Collections.sort(this.selectedComponentNames); Collections.sort(this.selectedComponentNames);
this.stuckComponentNames = new ArrayList<String>();
for (IDIYComponent<?> component : stuckComponents) {
this.stuckComponentNames.add(component.getName());
}
this.stuckComponentNames.removeAll(this.selectedComponentNames);
Collections.sort(this.stuckComponentNames);
refreshStatusText(); refreshStatusText();
break; break;
case SELECTION_SIZE_CHANGED: case SELECTION_SIZE_CHANGED:
@@ -245,18 +253,32 @@ public class StatusBar extends JPanel implements IPlugIn {
} }
getStatusLabel().setText("Drag " + formattedNames); getStatusLabel().setText("Drag " + formattedNames);
} else if (selectedComponentNames != null && !selectedComponentNames.isEmpty()) { } else if (selectedComponentNames != null && !selectedComponentNames.isEmpty()) {
String formattedNames = ""; StringBuilder builder = new StringBuilder();
for (int i = 0; i < selectedComponentNames.size(); i++) { for (int i = 0; i < selectedComponentNames.size(); i++) {
if (i > 0) { if (i > 0) {
if (i == selectedComponentNames.size() - 1) { if (i == selectedComponentNames.size() - 1) {
formattedNames += " and "; builder.append(" and ");
} else { } else {
formattedNames += ", "; builder.append(", ");
} }
} }
formattedNames += selectedComponentNames.get(i); builder.append(selectedComponentNames.get(i));
} }
getStatusLabel().setText("Selection: " + formattedNames); if (!stuckComponentNames.isEmpty()) {
builder.append(" (");
for (int i = 0; i < stuckComponentNames.size(); i++) {
if (i > 0) {
if (i == stuckComponentNames.size() - 1) {
builder.append(" and ");
} else {
builder.append(", ");
}
}
builder.append(stuckComponentNames.get(i));
}
builder.append(" would be affected by dragging as well)");
}
getStatusLabel().setText("Selection: " + builder.toString());
} else { } else {
getStatusLabel().setText(""); getStatusLabel().setText("");
} }
@@ -22,6 +22,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.swing.Action; import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.JComponent; import javax.swing.JComponent;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@@ -341,6 +342,12 @@ public class Presenter implements IPlugInPort {
view.addMenuAction(action, menuName); view.addMenuAction(action, menuName);
} }
@Override
public void injectSubmenu(String name, Icon icon, String parentMenuName) {
LOG.info(String.format("injectSubmenu(%s, icon, %s)", name, parentMenuName));
view.addSubmenu(name, icon, parentMenuName);
}
/** /**
* Finds all components whose areas include the specified {@link Point}. * Finds all components whose areas include the specified {@link Point}.
* Point is <b>not</b> scaled by the zoom factor. * Point is <b>not</b> scaled by the zoom factor.
@@ -394,9 +401,11 @@ public class Presenter implements IPlugInPort {
selectedComponents.addAll(findAllGroupedComponents(component)); selectedComponents.addAll(findAllGroupedComponents(component));
} }
} }
messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, selectedComponents); fireSelectionChanged();
messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED, // messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED,
calculateSelectionDimension()); // selectedComponents);
// messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED,
// calculateSelectionDimension());
messageDispatcher.dispatchMessage(EventType.REPAINT); messageDispatcher.dispatchMessage(EventType.REPAINT);
} }
} }
@@ -458,9 +467,11 @@ public class Presenter implements IPlugInPort {
public void selectAll() { public void selectAll() {
LOG.info("selectAll()"); LOG.info("selectAll()");
this.selectedComponents = new ComponentSelection(currentProject.getComponents()); this.selectedComponents = new ComponentSelection(currentProject.getComponents());
messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, selectedComponents); fireSelectionChanged();
messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED, // messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED,
calculateSelectionDimension()); // selectedComponents);
// messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED,
// calculateSelectionDimension());
messageDispatcher.dispatchMessage(EventType.REPAINT); messageDispatcher.dispatchMessage(EventType.REPAINT);
} }
@@ -486,16 +497,20 @@ public class Presenter implements IPlugInPort {
// If we're dragging control points reset selection. // If we're dragging control points reset selection.
selectedComponents.clear(); selectedComponents.clear();
selectedComponents.addAll(controlPointMap.keySet()); selectedComponents.addAll(controlPointMap.keySet());
messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, selectedComponents); fireSelectionChanged();
messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED, // messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED,
calculateSelectionDimension()); // selectedComponents);
// messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED,
// calculateSelectionDimension());
messageDispatcher.dispatchMessage(EventType.REPAINT); messageDispatcher.dispatchMessage(EventType.REPAINT);
} else if (components.isEmpty()) { } else if (components.isEmpty()) {
// If there are no components are under the cursor, reset selection. // If there are no components are under the cursor, reset selection.
selectedComponents.clear(); selectedComponents.clear();
messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, selectedComponents); fireSelectionChanged();
messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED, // messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED,
calculateSelectionDimension()); // selectedComponents);
// messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED,
// calculateSelectionDimension());
messageDispatcher.dispatchMessage(EventType.REPAINT); messageDispatcher.dispatchMessage(EventType.REPAINT);
} else { } else {
// Take the last component, i.e. the top order component. // Take the last component, i.e. the top order component.
@@ -505,9 +520,11 @@ public class Presenter implements IPlugInPort {
if (!selectedComponents.contains(component)) { if (!selectedComponents.contains(component)) {
selectedComponents.clear(); selectedComponents.clear();
selectedComponents.addAll(findAllGroupedComponents(component)); selectedComponents.addAll(findAllGroupedComponents(component));
messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, selectedComponents); fireSelectionChanged();
messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED, // messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED,
calculateSelectionDimension()); // selectedComponents);
// messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED,
// calculateSelectionDimension());
messageDispatcher.dispatchMessage(EventType.REPAINT); messageDispatcher.dispatchMessage(EventType.REPAINT);
} }
// If there aren't any control points, try to add all the selected // If there aren't any control points, try to add all the selected
@@ -659,9 +676,10 @@ public class Presenter implements IPlugInPort {
} }
} }
selectionRect = null; selectionRect = null;
messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, selectedComponents); // messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED,
messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED, // selectedComponents);
calculateSelectionDimension()); // messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED,
// calculateSelectionDimension());
} }
// There is selection, so we need to finalize the drag&drop // There is selection, so we need to finalize the drag&drop
// operation. // operation.
@@ -670,6 +688,7 @@ public class Presenter implements IPlugInPort {
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, preDragProject, cloner messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, preDragProject, cloner
.deepClone(currentProject), "Move"); .deepClone(currentProject), "Move");
} }
fireSelectionChanged();
messageDispatcher.dispatchMessage(EventType.REPAINT); messageDispatcher.dispatchMessage(EventType.REPAINT);
dragInProgress = false; dragInProgress = false;
} }
@@ -749,9 +768,10 @@ public class Presenter implements IPlugInPort {
Project oldProject = cloner.deepClone(currentProject); Project oldProject = cloner.deepClone(currentProject);
// First remove the selected components from other groups. // First remove the selected components from other groups.
ungroupComponents(selectedComponents); ungroupComponents(selectedComponents);
// Then group them together // Then group them together.
currentProject.getGroups().add(new HashSet<IDIYComponent<?>>(selectedComponents)); currentProject.getGroups().add(new HashSet<IDIYComponent<?>>(selectedComponents));
// Notify the listeners. // Notify the listeners.
messageDispatcher.dispatchMessage(EventType.REPAINT);
if (!oldProject.equals(currentProject)) { if (!oldProject.equals(currentProject)) {
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner
.deepClone(currentProject), "Group"); .deepClone(currentProject), "Group");
@@ -764,12 +784,29 @@ public class Presenter implements IPlugInPort {
Project oldProject = cloner.deepClone(currentProject); Project oldProject = cloner.deepClone(currentProject);
ungroupComponents(selectedComponents); ungroupComponents(selectedComponents);
// Notify the listeners. // Notify the listeners.
messageDispatcher.dispatchMessage(EventType.REPAINT);
if (!oldProject.equals(currentProject)) { if (!oldProject.equals(currentProject)) {
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner
.deepClone(currentProject), "Group"); .deepClone(currentProject), "Group");
} }
} }
private void fireSelectionChanged() {
Map<IDIYComponent<?>, Set<Integer>> controlPointMap = new HashMap<IDIYComponent<?>, Set<Integer>>();
for (IDIYComponent<?> component : selectedComponents) {
Set<Integer> indices = new HashSet<Integer>();
for (int i = 0; i < component.getControlPointCount(); i++) {
indices.add(i);
}
controlPointMap.put(component, indices);
}
includeStuckComponents(controlPointMap);
messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, selectedComponents,
controlPointMap.keySet());
messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED,
calculateSelectionDimension());
}
/** /**
* Removes all the groups that contain at least one of the specified * Removes all the groups that contain at least one of the specified
* components. * components.
@@ -926,9 +963,12 @@ public class Presenter implements IPlugInPort {
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner
.deepClone(currentProject), "Add " + componentType.getName()); .deepClone(currentProject), "Add " + componentType.getName());
} }
messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, selectedComponents);
messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED, fireSelectionChanged();
calculateSelectionDimension()); // messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED,
// selectedComponents);
// messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED,
// calculateSelectionDimension());
messageDispatcher.dispatchMessage(EventType.REPAINT); messageDispatcher.dispatchMessage(EventType.REPAINT);
} }
@@ -965,9 +1005,11 @@ public class Presenter implements IPlugInPort {
: componentType.getName())); : componentType.getName()));
this.componentSlot = componentType; this.componentSlot = componentType;
selectedComponents.clear(); selectedComponents.clear();
messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, selectedComponents); fireSelectionChanged();
messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED, // messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED,
calculateSelectionDimension()); // selectedComponents);
// messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED,
// calculateSelectionDimension());
messageDispatcher.dispatchMessage(EventType.SLOT_CHANGED, componentSlot); messageDispatcher.dispatchMessage(EventType.SLOT_CHANGED, componentSlot);
} }