mirror of
https://github.com/hneemann/Digital.git
synced 2025-10-01 00:40:07 -04:00
fixed some checkstyle issues
This commit is contained in:
parent
6616d03d1b
commit
27740b7584
@ -3,7 +3,6 @@ package de.neemann.digital.draw.elements;
|
|||||||
import de.neemann.digital.core.element.ElementTypeDescription;
|
import de.neemann.digital.core.element.ElementTypeDescription;
|
||||||
import de.neemann.digital.gui.components.CircuitComponent;
|
import de.neemann.digital.gui.components.CircuitComponent;
|
||||||
import de.neemann.digital.gui.components.ElementOrderer;
|
import de.neemann.digital.gui.components.ElementOrderer;
|
||||||
import de.neemann.digital.gui.components.modification.Modification;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
@ -3,10 +3,16 @@ package de.neemann.digital.gui.components.modification;
|
|||||||
import de.neemann.digital.draw.elements.Circuit;
|
import de.neemann.digital.draw.elements.Circuit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Interface to implement the events used to be reverted
|
||||||
* Created by hneemann on 25.05.17.
|
* Created by hneemann on 25.05.17.
|
||||||
*/
|
*/
|
||||||
public interface Modification {
|
public interface Modification {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performes a modification on the given circuit
|
||||||
|
*
|
||||||
|
* @param circuit the circuit to modify
|
||||||
|
*/
|
||||||
void modify(Circuit circuit);
|
void modify(Circuit circuit);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,8 @@ import de.neemann.digital.draw.elements.VisualElement;
|
|||||||
import de.neemann.digital.draw.graphics.Vector;
|
import de.neemann.digital.draw.graphics.Vector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* A modification on a visual element.
|
||||||
|
* The element is identified by its position and name.
|
||||||
* Created by hneemann on 25.05.17.
|
* Created by hneemann on 25.05.17.
|
||||||
*/
|
*/
|
||||||
public abstract class ModificationOfVisualElement implements Modification {
|
public abstract class ModificationOfVisualElement implements Modification {
|
||||||
@ -12,15 +14,32 @@ public abstract class ModificationOfVisualElement implements Modification {
|
|||||||
private final Vector pos;
|
private final Vector pos;
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance
|
||||||
|
*
|
||||||
|
* @param ve the element to modify
|
||||||
|
*/
|
||||||
public ModificationOfVisualElement(VisualElement ve) {
|
public ModificationOfVisualElement(VisualElement ve) {
|
||||||
this(ve, ve.getPos());
|
this(ve, ve.getPos());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance
|
||||||
|
*
|
||||||
|
* @param ve the element to modify
|
||||||
|
* @param initialPos the initial position of the element
|
||||||
|
*/
|
||||||
public ModificationOfVisualElement(VisualElement ve, Vector initialPos) {
|
public ModificationOfVisualElement(VisualElement ve, Vector initialPos) {
|
||||||
name = ve.getElementName();
|
name = ve.getElementName();
|
||||||
pos = initialPos;
|
pos = initialPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the element which is to modify
|
||||||
|
*
|
||||||
|
* @param circuit the circuit
|
||||||
|
* @return the element to modify
|
||||||
|
*/
|
||||||
public VisualElement getVisualElement(Circuit circuit) {
|
public VisualElement getVisualElement(Circuit circuit) {
|
||||||
for (VisualElement ve : circuit.getElements()) {
|
for (VisualElement ve : circuit.getElements()) {
|
||||||
if (ve.getPos().equals(pos) && ve.getElementName().equals(name))
|
if (ve.getPos().equals(pos) && ve.getElementName().equals(name))
|
||||||
|
@ -5,6 +5,8 @@ import de.neemann.digital.draw.elements.Wire;
|
|||||||
import de.neemann.digital.draw.graphics.Vector;
|
import de.neemann.digital.draw.graphics.Vector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* A modification on a wire
|
||||||
|
* The wire is identified by its position.
|
||||||
* Created by hneemann on 25.05.17.
|
* Created by hneemann on 25.05.17.
|
||||||
*/
|
*/
|
||||||
public abstract class ModificationOfWire implements Modification {
|
public abstract class ModificationOfWire implements Modification {
|
||||||
@ -12,15 +14,32 @@ public abstract class ModificationOfWire implements Modification {
|
|||||||
private final Vector p1;
|
private final Vector p1;
|
||||||
private final Vector p2;
|
private final Vector p2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance
|
||||||
|
*
|
||||||
|
* @param wire the wire to modify
|
||||||
|
*/
|
||||||
public ModificationOfWire(Wire wire) {
|
public ModificationOfWire(Wire wire) {
|
||||||
this(wire, wire.p1);
|
this(wire, wire.p1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance
|
||||||
|
*
|
||||||
|
* @param wire the wire to modify
|
||||||
|
* @param initialPos the initial position of the wire
|
||||||
|
*/
|
||||||
public ModificationOfWire(Wire wire, Vector initialPos) {
|
public ModificationOfWire(Wire wire, Vector initialPos) {
|
||||||
p1 = initialPos;
|
p1 = initialPos;
|
||||||
p2 = initialPos.add(wire.p2.sub(wire.p1));
|
p2 = initialPos.add(wire.p2.sub(wire.p1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the wire to modify
|
||||||
|
*
|
||||||
|
* @param circuit the circuit to modify
|
||||||
|
* @return the wire to modify
|
||||||
|
*/
|
||||||
public Wire getWire(Circuit circuit) {
|
public Wire getWire(Circuit circuit) {
|
||||||
for (Wire w : circuit.getWires()) {
|
for (Wire w : circuit.getWires()) {
|
||||||
if (w.p1.equals(p1) && w.p2.equals(p2))
|
if (w.p1.equals(p1) && w.p2.equals(p2))
|
||||||
|
@ -5,6 +5,7 @@ import de.neemann.digital.draw.elements.Circuit;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* A single modification which is build from a set of other modifications.
|
||||||
* Created by hneemann on 25.05.17.
|
* Created by hneemann on 25.05.17.
|
||||||
*/
|
*/
|
||||||
public final class Modifications implements Modification {
|
public final class Modifications implements Modification {
|
||||||
@ -20,18 +21,35 @@ public final class Modifications implements Modification {
|
|||||||
m.modify(circuit);
|
m.modify(circuit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The builder to construct an instance
|
||||||
|
*/
|
||||||
public static final class Builder {
|
public static final class Builder {
|
||||||
private final ArrayList<Modification> list;
|
private final ArrayList<Modification> list;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance
|
||||||
|
*/
|
||||||
public Builder() {
|
public Builder() {
|
||||||
list = new ArrayList<>();
|
list = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a modification to this set
|
||||||
|
*
|
||||||
|
* @param m the modification to add
|
||||||
|
* @return this for chained calls
|
||||||
|
*/
|
||||||
public Builder add(Modification m) {
|
public Builder add(Modification m) {
|
||||||
list.add(m);
|
list.add(m);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the unified of modification
|
||||||
|
*
|
||||||
|
* @return the unified modification
|
||||||
|
*/
|
||||||
public Modification build() {
|
public Modification build() {
|
||||||
return new Modifications(list);
|
return new Modifications(list);
|
||||||
}
|
}
|
||||||
|
@ -5,13 +5,23 @@ import de.neemann.digital.draw.elements.Circuit;
|
|||||||
import de.neemann.digital.draw.elements.VisualElement;
|
import de.neemann.digital.draw.elements.VisualElement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Modifies an attribute.
|
||||||
* Created by hneemann on 25.05.17.
|
* Created by hneemann on 25.05.17.
|
||||||
|
*
|
||||||
|
* @param <VALUE> the used value type
|
||||||
*/
|
*/
|
||||||
public class ModifyAttribute<VALUE> extends ModificationOfVisualElement {
|
public class ModifyAttribute<VALUE> extends ModificationOfVisualElement {
|
||||||
|
|
||||||
private final Key<VALUE> key;
|
private final Key<VALUE> key;
|
||||||
private final VALUE value;
|
private final VALUE value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance
|
||||||
|
*
|
||||||
|
* @param ve the visual element to modify
|
||||||
|
* @param key the key to modify
|
||||||
|
* @param value the new value
|
||||||
|
*/
|
||||||
public ModifyAttribute(VisualElement ve, Key<VALUE> key, VALUE value) {
|
public ModifyAttribute(VisualElement ve, Key<VALUE> key, VALUE value) {
|
||||||
super(ve);
|
super(ve);
|
||||||
this.key = key;
|
this.key = key;
|
||||||
|
@ -5,12 +5,18 @@ import de.neemann.digital.draw.elements.Circuit;
|
|||||||
import de.neemann.digital.draw.elements.VisualElement;
|
import de.neemann.digital.draw.elements.VisualElement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Sets all attributes of an element
|
||||||
* Created by hneemann on 25.05.17.
|
* Created by hneemann on 25.05.17.
|
||||||
*/
|
*/
|
||||||
public class ModifyAttributes extends ModificationOfVisualElement {
|
public class ModifyAttributes extends ModificationOfVisualElement {
|
||||||
|
|
||||||
private final ElementAttributes attributes;
|
private final ElementAttributes attributes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance
|
||||||
|
*
|
||||||
|
* @param ve the already modified element
|
||||||
|
*/
|
||||||
public ModifyAttributes(VisualElement ve) {
|
public ModifyAttributes(VisualElement ve) {
|
||||||
super(ve);
|
super(ve);
|
||||||
attributes = new ElementAttributes(ve.getElementAttributes());
|
attributes = new ElementAttributes(ve.getElementAttributes());
|
||||||
|
@ -5,9 +5,17 @@ import de.neemann.digital.draw.elements.VisualElement;
|
|||||||
import de.neemann.digital.draw.graphics.Vector;
|
import de.neemann.digital.draw.graphics.Vector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Modifier which deletes an element
|
||||||
* Created by hneemann on 26.05.17.
|
* Created by hneemann on 26.05.17.
|
||||||
*/
|
*/
|
||||||
public class ModifyDeleteElement extends ModificationOfVisualElement {
|
public class ModifyDeleteElement extends ModificationOfVisualElement {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The element to delete
|
||||||
|
*
|
||||||
|
* @param ve the visual element
|
||||||
|
* @param initialPos its initial position
|
||||||
|
*/
|
||||||
public ModifyDeleteElement(VisualElement ve, Vector initialPos) {
|
public ModifyDeleteElement(VisualElement ve, Vector initialPos) {
|
||||||
super(ve, initialPos);
|
super(ve, initialPos);
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,19 @@ import de.neemann.digital.draw.elements.Circuit;
|
|||||||
import de.neemann.digital.draw.graphics.Vector;
|
import de.neemann.digital.draw.graphics.Vector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Modifier to delete all elements in a given rectangle
|
||||||
* Created by hneemann on 26.05.17.
|
* Created by hneemann on 26.05.17.
|
||||||
*/
|
*/
|
||||||
public class ModifyDeleteRect implements Modification {
|
public class ModifyDeleteRect implements Modification {
|
||||||
private final Vector min;
|
private final Vector min;
|
||||||
private final Vector max;
|
private final Vector max;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance
|
||||||
|
*
|
||||||
|
* @param min the upper left corner
|
||||||
|
* @param max the lower right corner
|
||||||
|
*/
|
||||||
public ModifyDeleteRect(Vector min, Vector max) {
|
public ModifyDeleteRect(Vector min, Vector max) {
|
||||||
this.min = min;
|
this.min = min;
|
||||||
this.max = max;
|
this.max = max;
|
||||||
|
@ -5,10 +5,17 @@ import de.neemann.digital.draw.elements.Wire;
|
|||||||
import de.neemann.digital.draw.graphics.Vector;
|
import de.neemann.digital.draw.graphics.Vector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Modifier to delete a wire
|
||||||
* Created by hneemann on 26.05.17.
|
* Created by hneemann on 26.05.17.
|
||||||
*/
|
*/
|
||||||
public class ModifyDeleteWire extends ModificationOfWire {
|
public class ModifyDeleteWire extends ModificationOfWire {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance
|
||||||
|
*
|
||||||
|
* @param wire the wire to delete
|
||||||
|
* @param initialPos its initial position
|
||||||
|
*/
|
||||||
public ModifyDeleteWire(Wire wire, Vector initialPos) {
|
public ModifyDeleteWire(Wire wire, Vector initialPos) {
|
||||||
super(wire, initialPos);
|
super(wire, initialPos);
|
||||||
}
|
}
|
||||||
|
@ -4,11 +4,17 @@ import de.neemann.digital.draw.elements.Circuit;
|
|||||||
import de.neemann.digital.draw.elements.VisualElement;
|
import de.neemann.digital.draw.elements.VisualElement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Modifier to insert an element
|
||||||
* Created by hneemann on 26.05.17.
|
* Created by hneemann on 26.05.17.
|
||||||
*/
|
*/
|
||||||
public class ModifyInsertElement implements Modification {
|
public class ModifyInsertElement implements Modification {
|
||||||
private final VisualElement element;
|
private final VisualElement element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance
|
||||||
|
*
|
||||||
|
* @param element the element to insert
|
||||||
|
*/
|
||||||
public ModifyInsertElement(VisualElement element) {
|
public ModifyInsertElement(VisualElement element) {
|
||||||
this.element = new VisualElement(element);
|
this.element = new VisualElement(element);
|
||||||
}
|
}
|
||||||
|
@ -5,12 +5,18 @@ import de.neemann.digital.draw.elements.Wire;
|
|||||||
import de.neemann.digital.draw.graphics.Vector;
|
import de.neemann.digital.draw.graphics.Vector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Modifier to insert a wire.
|
||||||
* Created by hneemann on 26.05.17.
|
* Created by hneemann on 26.05.17.
|
||||||
*/
|
*/
|
||||||
public class ModifyInsertWire implements Modification {
|
public class ModifyInsertWire implements Modification {
|
||||||
private final Vector p1;
|
private final Vector p1;
|
||||||
private final Vector p2;
|
private final Vector p2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance
|
||||||
|
*
|
||||||
|
* @param w the wire to insert
|
||||||
|
*/
|
||||||
public ModifyInsertWire(Wire w) {
|
public ModifyInsertWire(Wire w) {
|
||||||
p1 = w.p1;
|
p1 = w.p1;
|
||||||
p2 = w.p2;
|
p2 = w.p2;
|
||||||
|
@ -5,12 +5,19 @@ import de.neemann.digital.draw.elements.VisualElement;
|
|||||||
import de.neemann.digital.draw.graphics.Vector;
|
import de.neemann.digital.draw.graphics.Vector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Modifier to move and rotate a single visual element
|
||||||
* Created by hneemann on 26.05.17.
|
* Created by hneemann on 26.05.17.
|
||||||
*/
|
*/
|
||||||
public class ModifyMoveAndRotElement extends ModificationOfVisualElement {
|
public class ModifyMoveAndRotElement extends ModificationOfVisualElement {
|
||||||
private final Vector pos;
|
private final Vector pos;
|
||||||
private final int rotation;
|
private final int rotation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance
|
||||||
|
*
|
||||||
|
* @param ve the visual Element
|
||||||
|
* @param initialPos its initial position
|
||||||
|
*/
|
||||||
public ModifyMoveAndRotElement(VisualElement ve, Vector initialPos) {
|
public ModifyMoveAndRotElement(VisualElement ve, Vector initialPos) {
|
||||||
super(ve, initialPos);
|
super(ve, initialPos);
|
||||||
pos = ve.getPos();
|
pos = ve.getPos();
|
||||||
|
@ -11,6 +11,7 @@ import de.neemann.digital.draw.graphics.Vector;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Modifier to move a selection
|
||||||
* Created by hneemann on 26.05.17.
|
* Created by hneemann on 26.05.17.
|
||||||
*/
|
*/
|
||||||
public class ModifyMoveSelected implements Modification {
|
public class ModifyMoveSelected implements Modification {
|
||||||
@ -20,6 +21,15 @@ public class ModifyMoveSelected implements Modification {
|
|||||||
private final int accumulatedRotate;
|
private final int accumulatedRotate;
|
||||||
private final Vector center;
|
private final Vector center;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance
|
||||||
|
*
|
||||||
|
* @param min the upper left corner
|
||||||
|
* @param max the lower right corner
|
||||||
|
* @param accumulatedDelta the translation
|
||||||
|
* @param accumulatedRotate the rotation
|
||||||
|
* @param center the center of the selection rectangle
|
||||||
|
*/
|
||||||
public ModifyMoveSelected(Vector min, Vector max, Vector accumulatedDelta, int accumulatedRotate, Vector center) {
|
public ModifyMoveSelected(Vector min, Vector max, Vector accumulatedDelta, int accumulatedRotate, Vector center) {
|
||||||
this.min = min;
|
this.min = min;
|
||||||
this.max = max;
|
this.max = max;
|
||||||
@ -40,6 +50,12 @@ public class ModifyMoveSelected implements Modification {
|
|||||||
circuit.elementsMoved();
|
circuit.elementsMoved();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rotates the given elements
|
||||||
|
*
|
||||||
|
* @param elements the elements to rotate
|
||||||
|
* @param center the center position
|
||||||
|
*/
|
||||||
public static void rotateElements(ArrayList<Movable> elements, Vector center) {
|
public static void rotateElements(ArrayList<Movable> elements, Vector center) {
|
||||||
Transform transform = new TransformRotate(center, 1) {
|
Transform transform = new TransformRotate(center, 1) {
|
||||||
@Override
|
@Override
|
||||||
|
@ -5,11 +5,18 @@ import de.neemann.digital.draw.elements.Wire;
|
|||||||
import de.neemann.digital.draw.graphics.Vector;
|
import de.neemann.digital.draw.graphics.Vector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Modifier to move a wire
|
||||||
* Created by hneemann on 26.05.17.
|
* Created by hneemann on 26.05.17.
|
||||||
*/
|
*/
|
||||||
public class ModifyMoveWire extends ModificationOfWire {
|
public class ModifyMoveWire extends ModificationOfWire {
|
||||||
private final Vector delta;
|
private final Vector delta;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance
|
||||||
|
*
|
||||||
|
* @param wire the wire to modify
|
||||||
|
* @param initialPos its initial position
|
||||||
|
*/
|
||||||
public ModifyMoveWire(Wire wire, Vector initialPos) {
|
public ModifyMoveWire(Wire wire, Vector initialPos) {
|
||||||
super(wire, initialPos);
|
super(wire, initialPos);
|
||||||
delta = wire.getPos().sub(initialPos);
|
delta = wire.getPos().sub(initialPos);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user