mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-28 15:32:40 -04:00
more robust groupEdit
This commit is contained in:
parent
fc062f33c3
commit
a950dff866
@ -981,35 +981,45 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
|||||||
if (!isLocked())
|
if (!isLocked())
|
||||||
try {
|
try {
|
||||||
ArrayList<Key> keyList = new ArrayList<>();
|
ArrayList<Key> keyList = new ArrayList<>();
|
||||||
ElementAttributes attr = new ElementAttributes();
|
|
||||||
ArrayList<VisualElement> elementList = new ArrayList<>();
|
ArrayList<VisualElement> elementList = new ArrayList<>();
|
||||||
for (VisualElement ve : circuit.getElements())
|
for (VisualElement ve : circuit.getElements())
|
||||||
if (ve.matches(min, max)) {
|
if (ve.matches(min, max)) {
|
||||||
elementList.add(ve);
|
elementList.add(ve);
|
||||||
for (Key k : library.getElementType(ve.getElementName()).getAttributeList()) {
|
for (Key k : library.getElementType(ve.getElementName()).getAttributeList()) {
|
||||||
if (k.isGroupEditAllowed() && !keyList.contains(k)) {
|
if (k.isGroupEditAllowed() && !keyList.contains(k))
|
||||||
keyList.add(k);
|
keyList.add(k);
|
||||||
attr.set(k, ve.getElementAttributes().get(k));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AttributeDialog attributeDialog = new AttributeDialog(this, keyList, attr);
|
if (keyList.size() > 0) {
|
||||||
ElementAttributes mod = attributeDialog.showDialog();
|
Key key = null;
|
||||||
if (attributeDialog.isOkPressed()) {
|
if (keyList.size() == 1)
|
||||||
if (mod == null) mod = attr;
|
key = keyList.get(0);
|
||||||
|
else {
|
||||||
|
ItemPicker<Key> ip = new ItemPicker<Key>(this, keyList);
|
||||||
|
if (ip.showDialog())
|
||||||
|
key = ip.getSelected();
|
||||||
|
}
|
||||||
|
if (key != null) {
|
||||||
|
keyList.clear();
|
||||||
|
keyList.add(key);
|
||||||
|
ElementAttributes attr = new ElementAttributes();
|
||||||
|
AttributeDialog attributeDialog = new AttributeDialog(this, keyList, attr);
|
||||||
|
ElementAttributes mod = attributeDialog.showDialog();
|
||||||
|
if (attributeDialog.isOkPressed()) {
|
||||||
|
if (mod == null) mod = attr;
|
||||||
|
|
||||||
Modifications.Builder modBuilder = new Modifications.Builder(Lang.get("mod_groupEdit"));
|
Modifications.Builder modBuilder = new Modifications.Builder(Lang.get("mod_groupEdit"));
|
||||||
for (Key k : keyList) {
|
Object newVal = mod.get(key);
|
||||||
Object newVal = mod.get(k);
|
for (VisualElement ve : elementList) {
|
||||||
for (VisualElement ve : elementList) {
|
if (library.getElementType(ve.getElementName()).getAttributeList().contains(key)) {
|
||||||
if (library.getElementType(ve.getElementName()).getAttributeList().contains(k)) {
|
if (!ve.getElementAttributes().get(key).equals(newVal))
|
||||||
if (!ve.getElementAttributes().get(k).equals(newVal))
|
modBuilder.add(new ModifyAttribute<>(ve, key, newVal));
|
||||||
modBuilder.add(new ModifyAttribute<>(ve, k, newVal));
|
}
|
||||||
}
|
}
|
||||||
|
modify(modBuilder.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
modify(modBuilder.build());
|
|
||||||
}
|
}
|
||||||
} catch (ElementNotFoundException e) {
|
} catch (ElementNotFoundException e) {
|
||||||
// Do nothing if an element is not in library
|
// Do nothing if an element is not in library
|
||||||
|
Loading…
x
Reference in New Issue
Block a user