move section handling to base component interface

do analysis in background thread
This commit is contained in:
Branislav Stojkovic
2019-03-09 18:01:42 +01:00
parent 1c1ec2fcf5
commit 7af919b303
8 changed files with 98 additions and 59 deletions
@@ -291,5 +291,11 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
@Override @Override
public String getInternalLinkName(int index1, int index2) { public String getInternalLinkName(int index1, int index2) {
return null; return null;
} }
@Override
public String getSectionName(int pointIndex) {
return null;
}
} }
@@ -24,7 +24,7 @@ package org.diylc.core;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Point; import java.awt.Point;
import java.io.Serializable; import java.io.Serializable;
import org.diylc.core.annotations.ComponentDescriptor; import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty; import org.diylc.core.annotations.EditableProperty;
@@ -128,7 +128,13 @@ public interface IDIYComponent<T> extends Serializable {
* @param index2 * @param index2
* @return name of the internal linked formed by the two control points, null if they do not form an internal link * @return name of the internal linked formed by the two control points, null if they do not form an internal link
*/ */
String getInternalLinkName(int index1, int index2); String getInternalLinkName(int index1, int index2);
/**
* @param pointIndex name of the internal section containing the specified point, or null if the component does not have internal sections.
* @return
*/
String getSectionName(int pointIndex);
/** /**
* Draws the component onto the {@link Graphics2D}. * Draws the component onto the {@link Graphics2D}.
@@ -48,7 +48,8 @@ public class Node implements Comparable<Node> {
} }
public String getDisplayName() { public String getDisplayName() {
return component.getControlPointNodeName(pointIndex); String section = component.getSectionName(pointIndex);
return (section == null ? "" : section + ".") + component.getControlPointNodeName(pointIndex);
} }
@Override @Override
Binary file not shown.
@@ -2,5 +2,7 @@ package org.diylc.netlist;
public interface ISpiceMapper { public interface ISpiceMapper {
int mapToSpiceNode(int index); int mapToSpiceNode(int Index);
String getSectionName(int pointIndex);
} }
Binary file not shown.
Binary file not shown.
@@ -1657,28 +1657,44 @@ public class ActionFactory {
super(); super();
this.plugInPort = plugInPort; this.plugInPort = plugInPort;
this.swingUI = swingUI; this.swingUI = swingUI;
putValue(AbstractAction.NAME, "Create DIYLC Netlist"); putValue(AbstractAction.NAME, "Generate DIYLC Netlist");
putValue(AbstractAction.SMALL_ICON, IconLoader.Web.getIcon()); putValue(AbstractAction.SMALL_ICON, IconLoader.Web.getIcon());
} }
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
List<Netlist> res = plugInPort.extractNetlists(); swingUI.executeBackgroundTask(new ITask<List<Netlist>>() {
if (res == null) {
swingUI.showMessage("The generated netlist is empty, nothing to show.", "DIYLC Netlist", ISwingUI.INFORMATION_MESSAGE); @Override
return; public List<Netlist> doInBackground() throws Exception {
} return plugInPort.extractNetlists();
StringBuilder sb = new StringBuilder("<html>");
for (Netlist netlist : res) {
sb.append("<p style=\"font-family: " + new JLabel().getFont().getName() + "; font-size: 9px\"><b>Switch configuration: ").append(netlist.getSwitchSetup()).append("</b><br><br>Connected node groups:<br>");
for (Group v : netlist.getSortedGroups()) {
sb.append("&nbsp;&nbsp;").append(v.getSortedNodes()).append("<br>");
} }
sb.append("</p><br><hr>");
} @Override
sb.append("</html>"); public void failed(Exception e) {
new TextDialog(swingUI.getOwnerFrame().getRootPane(), sb.toString(), "DIYLC Netlist", new Dimension(600, 480)).setVisible(true); swingUI.showMessage("Failed to generate the netlist: " + e.getMessage(), "DIYLC Netlist", ISwingUI.INFORMATION_MESSAGE);
}
@Override
public void complete(List<Netlist> res) {
if (res == null) {
swingUI.showMessage("The generated netlist is empty, nothing to show.", "DIYLC Netlist", ISwingUI.INFORMATION_MESSAGE);
return;
}
StringBuilder sb = new StringBuilder("<html>");
for (Netlist netlist : res) {
sb.append("<p style=\"font-family: " + new JLabel().getFont().getName() + "; font-size: 9px\"><b>Switch configuration: ").
append(netlist.getSwitchSetup()).append("</b><br><br>Connected node groups:<br>");
for (Group v : netlist.getSortedGroups()) {
sb.append("&nbsp;&nbsp;").append(v.getSortedNodes()).append("<br>");
}
sb.append("</p><br><hr>");
}
sb.append("</html>");
new TextDialog(swingUI.getOwnerFrame().getRootPane(), sb.toString(), "DIYLC Netlist", new Dimension(600, 480)).setVisible(true);
}
}, true);
} }
} }
@@ -1701,45 +1717,53 @@ public class ActionFactory {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
List<Netlist> netlists = plugInPort.extractNetlists();
if (netlists == null || netlists.isEmpty()) {
swingUI.showMessage("The generated netlist is empty, nothing to show.", summarizer.getName(), ISwingUI.INFORMATION_MESSAGE);
return;
}
List<Summary> res = null; swingUI.executeBackgroundTask(new ITask<List<Summary>>() {
try {
res = summarizer.summarize(netlists, null); @Override
} catch (Exception ex) { public List<Summary> doInBackground() throws Exception {
swingUI.showMessage(ex.getMessage(), summarizer.getName(), ISwingUI.ERROR_MESSAGE); List<Netlist> netlists = plugInPort.extractNetlists();
return; if (netlists == null || netlists.isEmpty()) {
} throw new Exception("The generated netlist is empty, nothing to show.");
}
if (res == null) {
swingUI.showMessage("The generated summary is empty, nothing to show.", summarizer.getName(), ISwingUI.INFORMATION_MESSAGE); return summarizer.summarize(netlists, null);
return; }
}
StringBuilder sb = new StringBuilder("<html>"); @Override
public void failed(Exception e) {
for (Summary summary : res) { swingUI.showMessage(e.getMessage(), summarizer.getName(), ISwingUI.INFORMATION_MESSAGE);
sb.append("<p style=\"font-family: "). }
append(summarizer.getFontName()).
append("; font-size: 9px\">"); @Override
public void complete(List<Summary> res) {
if (res.size() > 1) if (res == null) {
sb.append("<b>Switch configuration: "). swingUI.showMessage("The generated summary is empty, nothing to show.", summarizer.getName(), ISwingUI.INFORMATION_MESSAGE);
append(summary.getNetlist().getSwitchSetup()). return;
append("</b><br><br>"); }
StringBuilder sb = new StringBuilder("<html>");
sb.append(summary.getSummary());
for (Summary summary : res) {
sb.append("</p><br>"); sb.append("<p style=\"font-family: ").
append(summarizer.getFontName()).
if (res.size() > 1) append("; font-size: 9px\">");
sb.append("<hr>");
} if (res.size() > 1)
sb.append("</html>"); sb.append("<b>Switch configuration: ").
new TextDialog(swingUI.getOwnerFrame().getRootPane(), sb.toString(), summarizer.getName(), new Dimension(600, 480)).setVisible(true); append(summary.getNetlist().getSwitchSetup()).
append("</b><br><br>");
sb.append(summary.getSummary());
sb.append("</p><br>");
if (res.size() > 1)
sb.append("<hr>");
}
sb.append("</html>");
new TextDialog(swingUI.getOwnerFrame().getRootPane(), sb.toString(), summarizer.getName(), new Dimension(600, 480)).setVisible(true);
}
}, true);
} }
} }
} }