modifies data bit only if necessary.

This commit is contained in:
hneemann 2017-08-29 22:17:25 +02:00
parent 67b3538ea7
commit 4dadff6e62
2 changed files with 29 additions and 1 deletions

View File

@ -1022,7 +1022,9 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
int bits = Integer.decode(num);
Vector c1 = mouseControllerSelect.corner1;
Vector c2 = mouseControllerSelect.corner2;
modify(new ModifySetBits(c1, c2, bits));
ModifySetBits modifySetBits = new ModifySetBits(c1, c2, bits);
if (modifySetBits.isSomethingToDo(circuit, library))
modify(modifySetBits);
removeHighLighted();
mouseNormal.activate();
} catch (NumberFormatException ex) {

View File

@ -54,6 +54,32 @@ public class ModifySetBits implements Modification {
circuit.modified();
}
/**
* Checks if there are relevant elements in the rectangle
*
* @param circuit the circuit
* @param library the library
* @return true if there are components with a bits attribute
*/
public boolean isSomethingToDo(Circuit circuit, ElementLibrary library) {
ArrayList<Movable> list = circuit.getElementsToMove(min, max);
for (Movable m : list)
if (m instanceof VisualElement) {
VisualElement ve = (VisualElement) m;
try {
ElementTypeDescription td = library.getElementType(ve.getElementName());
if (td != null) {
if (td.getAttributeList().contains(Keys.BITS))
if (ve.getElementAttributes().get(Keys.BITS) != bits)
return true;
}
} catch (ElementNotFoundException e) {
e.printStackTrace();
}
}
return false;
}
@Override
public String toString() {
return Lang.get("mod_set_N_BitsToSelection", bits);