implements a new tunnel naming feature

This commit is contained in:
hneemann 2020-01-28 12:18:10 +01:00
parent 0856515b28
commit d74741e6c8
2 changed files with 24 additions and 2 deletions

View File

@ -136,6 +136,7 @@ public class CircuitComponent extends JComponent implements ChangedListener, Lib
private TutorialListener tutorialListener;
private boolean toolTipHighlighted = false;
private NetList toolTipNetList;
private String lastUsedTunnelName;
/**
* Creates a new instance
@ -791,6 +792,18 @@ public class CircuitComponent extends JComponent implements ChangedListener, Lib
* @param element the element to insert
*/
public void setPartToInsert(VisualElement element) {
if (element.equalsDescription(Tunnel.DESCRIPTION)) {
if (lastUsedTunnelName != null) {
CopiedElementLabelRenamer.LabelInstance li =
CopiedElementLabelRenamer.LabelInstance.
create(Tunnel.DESCRIPTION.getName(), lastUsedTunnelName);
if (li != null) {
lastUsedTunnelName = li.getLabel(1);
}
element.setAttribute(Keys.NETNAME, lastUsedTunnelName);
}
}
parent.ensureModelIsStopped();
mouseInsertElement.activate(element);
Point point = MouseInfo.getPointerInfo().getLocation();
@ -1168,6 +1181,10 @@ public class CircuitComponent extends JComponent implements ChangedListener, Lib
attributeDialog.disableOk();
ElementAttributes modified = attributeDialog.showDialog();
if (elementType == Tunnel.DESCRIPTION) {
if (modified.contains(Keys.NETNAME))
lastUsedTunnelName = modified.get(Keys.NETNAME);
}
if (modified != null && !locked) {
Modification<Circuit> mod = new ModifyAttributes(element, modified);
modify(checkNetRename(element, modified, mod));

View File

@ -95,7 +95,12 @@ public class CopiedElementLabelRenamer {
static final class LabelInstance {
static LabelInstance create(VisualElement ve) {
String fullLabel = ve.getElementAttributes().getLabel();
return create(ve.getElementName(), ve.getElementAttributes().getLabel());
}
static LabelInstance create(String elementName, String fullLabel) {
if (fullLabel == null)
return null;
int pos = fullLabel.length();
if (pos == 0)
@ -113,7 +118,7 @@ public class CopiedElementLabelRenamer {
}
String label = fullLabel.substring(0, pos);
LabelClass lc = new LabelClass(ve.getElementName(), label);
LabelClass lc = new LabelClass(elementName, label);
return new LabelInstance(lc, number);
}