use of com.cburch.logisim.gui.main.Selection in project logisim-evolution by reds-heig.
the class EditTool method mousePressed.
@Override
public void mousePressed(Canvas canvas, Graphics g, MouseEvent e) {
boolean wire = updateLocation(canvas, e);
Location oldWireLoc = wireLoc;
wireLoc = NULL_LOCATION;
lastX = Integer.MIN_VALUE;
if (wire) {
current = wiring;
Selection sel = canvas.getSelection();
Circuit circ = canvas.getCircuit();
Collection<Component> selected = sel.getAnchoredComponents();
ArrayList<Component> suppress = null;
for (Wire w : circ.getWires()) {
if (selected.contains(w)) {
if (w.contains(oldWireLoc)) {
if (suppress == null)
suppress = new ArrayList<Component>();
suppress.add(w);
}
}
}
sel.setSuppressHandles(suppress);
} else {
current = select;
}
pressX = e.getX();
pressY = e.getY();
current.mousePressed(canvas, g, e);
}
use of com.cburch.logisim.gui.main.Selection in project logisim-evolution by reds-heig.
the class EditTool method attemptReface.
private void attemptReface(Canvas canvas, final Direction facing, KeyEvent e) {
if (e.getModifiersEx() == 0) {
final Circuit circuit = canvas.getCircuit();
final Selection sel = canvas.getSelection();
SetAttributeAction act = new SetAttributeAction(circuit, Strings.getter("selectionRefaceAction"));
for (Component comp : sel.getComponents()) {
if (!(comp instanceof Wire)) {
Attribute<Direction> attr = getFacingAttribute(comp);
if (attr != null) {
act.set(comp, attr, facing);
}
}
}
if (!act.isEmpty()) {
canvas.getProject().doAction(act);
e.consume();
}
}
}
use of com.cburch.logisim.gui.main.Selection in project logisim-evolution by reds-heig.
the class SelectTool method computeDxDy.
private void computeDxDy(Project proj, MouseEvent e, Graphics g) {
Bounds bds = proj.getSelection().getBounds(g);
int dx;
int dy;
if (bds == Bounds.EMPTY_BOUNDS) {
dx = e.getX() - start.getX();
dy = e.getY() - start.getY();
} else {
dx = Math.max(e.getX() - start.getX(), -bds.getX());
dy = Math.max(e.getY() - start.getY(), -bds.getY());
}
Selection sel = proj.getSelection();
if (sel.shouldSnap()) {
dx = Canvas.snapXToGrid(dx);
dy = Canvas.snapYToGrid(dy);
}
curDx = dx;
curDy = dy;
}
use of com.cburch.logisim.gui.main.Selection in project logisim-evolution by reds-heig.
the class Project method setCircuitState.
public void setCircuitState(CircuitState value) {
if (value == null || circuitState == value)
return;
CircuitState old = circuitState;
Circuit oldCircuit = old == null ? null : old.getCircuit();
Circuit newCircuit = value.getCircuit();
boolean circuitChanged = old == null || oldCircuit != newCircuit;
if (circuitChanged) {
Canvas canvas = frame == null ? null : frame.getCanvas();
if (canvas != null) {
if (tool != null)
tool.deselect(canvas);
Selection selection = canvas.getSelection();
if (selection != null) {
Action act = SelectionActions.dropAll(selection);
if (act != null) {
doAction(act);
}
}
if (tool != null)
tool.select(canvas);
}
if (oldCircuit != null) {
for (CircuitListener l : circuitListeners) {
oldCircuit.removeCircuitListener(l);
}
}
}
circuitState = value;
stateMap.put(circuitState.getCircuit(), circuitState);
simulator.setCircuitState(circuitState);
if (circuitChanged) {
fireEvent(ProjectEvent.ACTION_SET_CURRENT, oldCircuit, newCircuit);
if (newCircuit != null) {
for (CircuitListener l : circuitListeners) {
newCircuit.addCircuitListener(l);
}
}
}
fireEvent(ProjectEvent.ACTION_SET_STATE, old, circuitState);
}
use of com.cburch.logisim.gui.main.Selection in project logisim-evolution by reds-heig.
the class Project method setTool.
public void setTool(Tool value) {
if (tool == value)
return;
Tool old = tool;
Canvas canvas = frame.getCanvas();
if (old != null)
old.deselect(canvas);
Selection selection = canvas.getSelection();
if (selection != null && !selection.isEmpty()) {
if (value == null || !getOptions().getMouseMappings().containsSelectTool()) {
Action act = SelectionActions.anchorAll(selection);
/*
* Circuit circuit = canvas.getCircuit(); CircuitMutation xn =
* new CircuitMutation(circuit); if (value == null) { Action act
* = SelectionActions.dropAll(selection); if (act != null) {
* doAction(act); } } else if
* (!getOptions().getMouseMappings().containsSelectTool()) {
* Action act = SelectionActions.dropAll(selection);
*/
if (act != null) {
doAction(act);
}
}
/*
* if (!xn.isEmpty()) doAction(xn.toAction(null));
*/
}
startupScreen = false;
tool = value;
if (tool != null)
tool.select(frame.getCanvas());
fireEvent(ProjectEvent.ACTION_SET_TOOL, old, tool);
}
Aggregations