use of com.cburch.logisim.proj.Action in project logisim-evolution by reds-heig.
the class SelectTool method keyPressed.
@Override
public void keyPressed(Canvas canvas, KeyEvent e) {
if (state == MOVING && e.getKeyCode() == KeyEvent.VK_SHIFT) {
handleMoveDrag(canvas, curDx, curDy, e.getModifiersEx());
} else {
SortedSet<Component> comps = AutoLabel.Sort(canvas.getProject().getSelection().getComponents());
int KeybEvent = e.getKeyCode();
boolean KeyTaken = false;
for (Component comp : comps) {
SetAttributeAction act = new SetAttributeAction(canvas.getCircuit(), Strings.getter("changeComponentAttributesAction"));
KeyTaken |= GateKeyboardModifier.TookKeyboardStrokes(KeybEvent, comp, comp.getAttributeSet(), canvas, act, true);
if (!act.isEmpty())
canvas.getProject().doAction(act);
}
if (!KeyTaken) {
for (Component comp : comps) {
SetAttributeAction act = new SetAttributeAction(canvas.getCircuit(), Strings.getter("changeComponentAttributesAction"));
KeyTaken |= AutoLabler.LabelKeyboardHandler(KeybEvent, comp.getAttributeSet(), comp.getFactory().getDisplayName(), comp, comp.getFactory(), canvas.getCircuit(), act, true);
if (!act.isEmpty())
canvas.getProject().doAction(act);
}
}
if (!KeyTaken)
switch(KeybEvent) {
case KeyEvent.VK_BACK_SPACE:
case KeyEvent.VK_DELETE:
if (!canvas.getSelection().isEmpty()) {
Action act = SelectionActions.clear(canvas.getSelection());
canvas.getProject().doAction(act);
e.consume();
}
break;
default:
processKeyEvent(canvas, e, KeyConfigurationEvent.KEY_PRESSED);
}
}
}
use of com.cburch.logisim.proj.Action in project logisim-evolution by reds-heig.
the class AttrTableToolModel method setValueRequested.
@Override
public void setValueRequested(Attribute<Object> attr, Object value) {
if (tool instanceof AddTool) {
AddTool mytool = (AddTool) tool;
if (mytool.getFactory() instanceof SubcircuitFactory) {
SubcircuitFactory fac = (SubcircuitFactory) mytool.getFactory();
if (attr.equals(CircuitAttributes.NAMED_CIRCUIT_BOX) || attr.equals(CircuitAttributes.NAME_ATTR)) {
try {
CircuitMutation mutation = new CircuitMutation(fac.getSubcircuit());
mutation.setForCircuit(attr, value);
Action action = mutation.toAction(null);
proj.doAction(action);
} catch (CircuitException ex) {
JOptionPane.showMessageDialog(proj.getFrame(), ex.getMessage());
}
return;
}
}
}
proj.doAction(ToolAttributeAction.create(tool, attr, value));
}
use of com.cburch.logisim.proj.Action in project logisim-evolution by reds-heig.
the class SelectTool method mousePressed.
@Override
public void mousePressed(Canvas canvas, Graphics g, MouseEvent e) {
Project proj = canvas.getProject();
Selection sel = proj.getSelection();
Circuit circuit = canvas.getCircuit();
start = Location.create(e.getX(), e.getY());
curDx = 0;
curDy = 0;
moveGesture = null;
// if the user clicks into the selection,
// selection is being modified
Collection<Component> in_sel = sel.getComponentsContaining(start, g);
if (!in_sel.isEmpty()) {
if ((e.getModifiers() & InputEvent.SHIFT_MASK) == 0) {
setState(proj, MOVING);
proj.repaintCanvas();
return;
} else {
Action act = SelectionActions.drop(sel, in_sel);
if (act != null) {
proj.doAction(act);
}
}
}
// if the user clicks into a component outside selection, user
// wants to add/reset selection
Collection<Component> clicked = circuit.getAllContaining(start, g);
if (!clicked.isEmpty()) {
if ((e.getModifiers() & InputEvent.SHIFT_MASK) == 0) {
if (sel.getComponentsContaining(start).isEmpty()) {
Action act = SelectionActions.dropAll(sel);
if (act != null) {
proj.doAction(act);
}
}
}
for (Component comp : clicked) {
if (!in_sel.contains(comp)) {
sel.add(comp);
}
}
setState(proj, MOVING);
proj.repaintCanvas();
return;
}
// selection (maybe with the shift key down).
if ((e.getModifiers() & InputEvent.SHIFT_MASK) == 0) {
Action act = SelectionActions.dropAll(sel);
if (act != null) {
proj.doAction(act);
}
}
setState(proj, RECT_SELECT);
proj.repaintCanvas();
}
use of com.cburch.logisim.proj.Action in project logisim-evolution by reds-heig.
the class SelectTool method mouseReleased.
@Override
public void mouseReleased(Canvas canvas, Graphics g, MouseEvent e) {
Project proj = canvas.getProject();
if (state == MOVING) {
setState(proj, IDLE);
computeDxDy(proj, e, g);
int dx = curDx;
int dy = curDy;
if (dx != 0 || dy != 0) {
if (!proj.getLogisimFile().contains(canvas.getCircuit())) {
canvas.setErrorMessage(Strings.getter("cannotModifyError"));
} else if (proj.getSelection().hasConflictWhenMoved(dx, dy)) {
canvas.setErrorMessage(Strings.getter("exclusiveError"));
} else {
boolean connect = shouldConnect(canvas, e.getModifiersEx());
drawConnections = false;
ReplacementMap repl;
if (connect) {
MoveGesture gesture = moveGesture;
if (gesture == null) {
gesture = new MoveGesture(new MoveRequestHandler(canvas), canvas.getCircuit(), canvas.getSelection().getAnchoredComponents());
}
canvas.setErrorMessage(new ComputingMessage(dx, dy), COLOR_COMPUTING);
MoveResult result = gesture.forceRequest(dx, dy);
clearCanvasMessage(canvas, dx, dy);
repl = result.getReplacementMap();
} else {
repl = null;
}
Selection sel = proj.getSelection();
proj.doAction(SelectionActions.translate(sel, dx, dy, repl));
}
}
moveGesture = null;
proj.repaintCanvas();
} else if (state == RECT_SELECT) {
Bounds bds = Bounds.create(start).add(start.getX() + curDx, start.getY() + curDy);
Circuit circuit = canvas.getCircuit();
Selection sel = proj.getSelection();
Collection<Component> in_sel = sel.getComponentsWithin(bds, g);
for (Component comp : circuit.getAllWithin(bds, g)) {
if (!in_sel.contains(comp))
sel.add(comp);
}
Action act = SelectionActions.drop(sel, in_sel);
if (act != null) {
proj.doAction(act);
}
setState(proj, IDLE);
proj.repaintCanvas();
}
if (e.getClickCount() >= 2) {
Set<Component> comps = canvas.getProject().getSelection().getComponents();
if (comps.size() == 1) {
for (Component comp : comps) {
if (comp.getAttributeSet().containsAttribute(StdAttr.LABEL)) {
String OldLabel = comp.getAttributeSet().getValue(StdAttr.LABEL);
SetAttributeAction act = new SetAttributeAction(canvas.getCircuit(), Strings.getter("changeComponentAttributesAction"));
AutoLabler.AskAndSetLabel(comp.getFactory().getDisplayName(), OldLabel, canvas.getCircuit(), comp, comp.getFactory(), comp.getAttributeSet(), act, true);
if (!act.isEmpty())
canvas.getProject().doAction(act);
}
}
}
}
}
use of com.cburch.logisim.proj.Action in project logisim-evolution by reds-heig.
the class AddTool method mouseReleased.
@Override
public void mouseReleased(Canvas canvas, Graphics g, MouseEvent e) {
Component added = null;
if (state == SHOW_ADD) {
Circuit circ = canvas.getCircuit();
if (!canvas.getProject().getLogisimFile().contains(circ))
return;
if (shouldSnap)
Canvas.snapToGrid(e);
moveTo(canvas, g, e.getX(), e.getY());
Location loc = Location.create(e.getX(), e.getY());
ComponentFactory source = getFactory();
AttributeSet attrsCopy = (AttributeSet) attrs.clone();
if (attrsCopy.containsAttribute(StdAttr.LABEL)) {
attrsCopy.setValue(StdAttr.LABEL, AutoLabler.GetCurrent(canvas.getCircuit(), source));
if (AutoLabler.IsActive(canvas.getCircuit())) {
if (AutoLabler.hasNext(canvas.getCircuit()))
AutoLabler.GetNext(canvas.getCircuit(), source);
else
AutoLabler.Stop(canvas.getCircuit());
} else
AutoLabler.SetLabel("", canvas.getCircuit(), source);
}
if (source == null)
return;
Component c = source.createComponent(loc, attrsCopy);
if (circ.hasConflict(c)) {
canvas.setErrorMessage(Strings.getter("exclusiveError"));
return;
}
Bounds bds = c.getBounds(g);
if (bds.getX() < 0 || bds.getY() < 0) {
canvas.setErrorMessage(Strings.getter("negativeCoordError"));
return;
}
try {
CircuitMutation mutation = new CircuitMutation(circ);
mutation.add(c);
Action action = mutation.toAction(Strings.getter("addComponentAction", factory.getDisplayGetter()));
canvas.getProject().doAction(action);
lastAddition = action;
added = c;
canvas.repaint();
} catch (CircuitException ex) {
JOptionPane.showMessageDialog(canvas.getProject().getFrame(), ex.getMessage());
}
setState(canvas, SHOW_GHOST);
} else if (state == SHOW_ADD_NO) {
setState(canvas, SHOW_NONE);
}
Project proj = canvas.getProject();
Tool next = determineNext(proj);
if (next != null) {
proj.setTool(next);
Action act = SelectionActions.dropAll(canvas.getSelection());
if (act != null) {
proj.doAction(act);
}
if (added != null)
canvas.getSelection().add(added);
}
}
Aggregations