Derive the z-order of a building blocks placed as a single component based on its child components

This commit is contained in:
Bane Stojkovic
2026-11-01 22:56:48 +01:00
parent 79d230ff07
commit b15a6e3f64
9 changed files with 455 additions and 55 deletions
@@ -37,11 +37,11 @@ import javax.swing.SwingUtilities;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import org.diylc.common.ComponentType;
import org.diylc.common.IPlugInPort;
import org.diylc.core.ComponentGroup;
import org.diylc.core.IDIYComponent;
import org.diylc.lang.LangUtil;
import org.diylc.presenter.ComponentProcessor;
import org.diylc.swing.ISwingUI;
import org.diylc.swing.gui.ComponentPopupMenu;
import org.diylc.swing.gui.DragDropList;
@@ -257,7 +257,7 @@ public class ExplorerPane extends JPanel {
0, false, false)
.getPreferredSize().height);
componentList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
componentList.setCellRenderer(new ComponentListCellRenderer(plugInPort.getComponentTypes()));
componentList.setCellRenderer(new ComponentListCellRenderer());
selectionListener = new ListSelectionListener() {
@Override
@@ -586,13 +586,6 @@ public class ExplorerPane extends JPanel {
protected DefaultListCellRenderer defaultRenderer = new DefaultListCellRenderer();
private Map<String, ComponentType> componentTypes;
public ComponentListCellRenderer(Map<String, List<ComponentType>> componentTypeMap) {
this.componentTypes = componentTypeMap.values().stream().flatMap(x -> x.stream())
.collect(Collectors.toMap(x -> x.getInstanceClass().getCanonicalName(), x -> x));
}
@Override
public Component getListCellRendererComponent(JList<? extends ComponentGroupItem> list,
ComponentGroupItem value, int index, boolean isSelected, boolean cellHasFocus) {
@@ -605,14 +598,15 @@ public class ExplorerPane extends JPanel {
if (groupItem.getComponentCount() == 1) {
// Render as individual component (ungrouped)
IDIYComponent<?> component = groupItem.getGroup().iterator().next();
ComponentType componentType = componentTypes.get(component.getClass().getCanonicalName());
if (componentType == null) {
double zOrder = ComponentProcessor.getInstance().getZOrder(component);
// internal types without a descriptor have no layer
if (zOrder == Double.MAX_VALUE) {
renderer.setText(component.toString());
return renderer;
}
int layerId = (int) Math.round(componentType.getZOrder());
int layerId = (int) Math.round(zOrder);
String valueForDisplay = component.getValueForDisplay();
if (isSelected) {
@@ -637,9 +631,9 @@ public class ExplorerPane extends JPanel {
// Calculate maximum layer from components in the group
int maxLayerId = 0;
for (IDIYComponent<?> component : groupItem.getGroup()) {
ComponentType componentType = componentTypes.get(component.getClass().getCanonicalName());
if (componentType != null) {
int layerId = (int) Math.round(componentType.getZOrder());
double zOrder = ComponentProcessor.getInstance().getZOrder(component);
if (zOrder != Double.MAX_VALUE) {
int layerId = (int) Math.round(zOrder);
if (layerId > maxLayerId) {
maxLayerId = layerId;
}
@@ -1,6 +1,7 @@
package org.diylc;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.geom.Point2D;
import java.io.IOException;
import java.util.ArrayList;
@@ -14,10 +15,13 @@ import org.junit.Test;
import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.appframework.miscutils.InMemoryConfigurationManager;
import org.diylc.clipboard.ComponentTransferable;
import org.diylc.common.ComponentType;
import org.diylc.common.EventType;
import org.diylc.common.IPlugIn;
import org.diylc.common.IPlugInPort;
import org.diylc.components.chassis.ChassisPanel;
import org.diylc.components.composite.CompositeComponent;
import org.diylc.core.IDIYComponent;
import org.diylc.core.Template;
import org.diylc.presenter.Presenter;
@@ -45,6 +49,24 @@ public class PresenterTests extends TestBase {
Assert.assertEquals(1, presenter.getCurrentProject().getComponents().size());
}
@Test
public void testChassisCompositeIsPlacedUnderExistingComponents() {
instantiateTwoClick("Passive", "Resistor", new Point(1000, 1000), new Point(1200, 1000));
CompositeComponent chassis = new CompositeComponent();
chassis.initBlockName("Chassis");
chassis.getChildComponents().add(new ChassisPanel());
chassis.getChildComponents().add(new ChassisPanel());
List<IDIYComponent<?>> clipboard = new ArrayList<IDIYComponent<?>>();
clipboard.add(chassis);
presenter.pasteComponents(new ComponentTransferable(clipboard, "Chassis"), false, true);
presenter.mouseClicked(new Point(500, 500), MouseEvent.BUTTON1, false, false, false, 1);
List<IDIYComponent<?>> components = presenter.getCurrentProject().getComponents();
Assert.assertEquals(2, components.size());
Assert.assertTrue(components.get(0) instanceof CompositeComponent);
}
@Test
public void testNodeNameHover() {
final String[] receivedTooltip = new String[1];