本文整理汇总了Java中com.cburch.logisim.circuit.CircuitMutation.toAction方法的典型用法代码示例。如果您正苦于以下问题:Java CircuitMutation.toAction方法的具体用法?Java CircuitMutation.toAction怎么用?Java CircuitMutation.toAction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.cburch.logisim.circuit.CircuitMutation
的用法示例。
在下文中一共展示了CircuitMutation.toAction方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setValueRequested
import com.cburch.logisim.circuit.CircuitMutation; //导入方法依赖的package包/类
@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));
}
示例2: mouseReleased
import com.cburch.logisim.circuit.CircuitMutation; //导入方法依赖的package包/类
@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());
AttributeSet attrsCopy = (AttributeSet) attrs.clone();
ComponentFactory source = getFactory();
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;
} 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);
}
}
示例3: mouseReleased
import com.cburch.logisim.circuit.CircuitMutation; //导入方法依赖的package包/类
@Override
public void mouseReleased(Canvas canvas, Graphics g, MouseEvent e) {
// add the wire
if (!exists)
return;
Canvas.snapToGrid(e);
int curX = e.getX();
int curY = e.getY();
if (computeMove(curX, curY)) {
cur = Location.create(curX, curY);
}
if (hasDragged) {
exists = false;
super.mouseReleased(canvas, g, e);
ArrayList<Wire> ws = new ArrayList<Wire>(2);
if (cur.getY() == start.getY() || cur.getX() == start.getX()) {
Wire w = Wire.create(cur, start);
w = checkForRepairs(canvas, w, w.getEnd0());
w = checkForRepairs(canvas, w, w.getEnd1());
if (performShortening(canvas, start, cur)) {
return;
}
if (w.getLength() > 0)
ws.add(w);
} else {
Location m;
if (direction == HORIZONTAL) {
m = Location.create(cur.getX(), start.getY());
} else {
m = Location.create(start.getX(), cur.getY());
}
Wire w0 = Wire.create(start, m);
Wire w1 = Wire.create(m, cur);
w0 = checkForRepairs(canvas, w0, start);
w1 = checkForRepairs(canvas, w1, cur);
if (w0.getLength() > 0)
ws.add(w0);
if (w1.getLength() > 0)
ws.add(w1);
}
if (ws.size() > 0) {
CircuitMutation mutation = new CircuitMutation(canvas.getCircuit());
mutation.addAll(ws);
StringGetter desc;
if (ws.size() == 1)
desc = Strings.getter("addWireAction");
else
desc = Strings.getter("addWiresAction");
Action act = mutation.toAction(desc);
canvas.getProject().doAction(act);
lastAction = act;
}
}
}
示例4: mouseReleased
import com.cburch.logisim.circuit.CircuitMutation; //导入方法依赖的package包/类
@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);
}
}
示例5: mouseReleased
import com.cburch.logisim.circuit.CircuitMutation; //导入方法依赖的package包/类
@Override
public void mouseReleased(Canvas canvas, Graphics g, MouseEvent e) {
if (!exists)
return;
Canvas.snapToGrid(e);
int curX = e.getX();
int curY = e.getY();
if (computeMove(curX, curY)) {
cur = Location.create(curX, curY);
}
if (hasDragged) {
exists = false;
super.mouseReleased(canvas, g, e);
ArrayList<Wire> ws = new ArrayList<Wire>(2);
if (cur.getY() == start.getY() || cur.getX() == start.getX()) {
Wire w = Wire.create(cur, start);
w = checkForRepairs(canvas, w, w.getEnd0());
w = checkForRepairs(canvas, w, w.getEnd1());
if (performShortening(canvas, start, cur)) {
return;
}
if (w.getLength() > 0)
ws.add(w);
} else {
Location m;
if (direction == HORIZONTAL) {
m = Location.create(cur.getX(), start.getY());
} else {
m = Location.create(start.getX(), cur.getY());
}
Wire w0 = Wire.create(start, m);
Wire w1 = Wire.create(m, cur);
w0 = checkForRepairs(canvas, w0, start);
w1 = checkForRepairs(canvas, w1, cur);
if (w0.getLength() > 0)
ws.add(w0);
if (w1.getLength() > 0)
ws.add(w1);
}
if (ws.size() > 0) {
CircuitMutation mutation = new CircuitMutation(
canvas.getCircuit());
mutation.addAll(ws);
StringGetter desc;
if (ws.size() == 1)
desc = Strings.getter("addWireAction");
else
desc = Strings.getter("addWiresAction");
Action act = mutation.toAction(desc);
canvas.getProject().doAction(act);
lastAction = act;
}
}
}
示例6: setValueRequested
import com.cburch.logisim.circuit.CircuitMutation; //导入方法依赖的package包/类
@Override
public void setValueRequested(Attribute<Object> attr, Object value)
throws AttrTableSetException {
Selection selection = frame.getCanvas().getSelection();
Circuit circuit = frame.getCanvas().getCircuit();
if (selection.isEmpty() && circuit != null) {
AttrTableCircuitModel circuitModel = new AttrTableCircuitModel(
project, circuit);
circuitModel.setValueRequested(attr, value);
} else {
SetAttributeAction act = new SetAttributeAction(circuit,
Strings.getter("selectionAttributeAction"));
AutoLabel labler = null;
if (attr.equals(StdAttr.LABEL)) {
labler = new AutoLabel((String)value,circuit);
}
SortedSet<Component> comps = new TreeSet<Component>(new PositionComparator());
comps.addAll(selection.getComponents());
for (Component comp : comps) {
if (!(comp instanceof Wire)) {
if (comp.getFactory() instanceof SubcircuitFactory) {
SubcircuitFactory fac = (SubcircuitFactory) comp.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);
project.doAction(action);
} catch (CircuitException ex) {
JOptionPane.showMessageDialog(project.getFrame(),
ex.getMessage());
}
return;
}
}
if (attr.equals(StdAttr.LABEL)) {
if (labler.hasNext(circuit)) {
if (comps.size()>1) {
act.set(comp, attr , labler.GetNext(circuit, comp.getFactory()));
} else {
if (getAttributeSet().getValue(StdAttr.LABEL).equals((String)value))
return;
else
act.set(comp, attr, labler.GetCurrent(circuit, comp.getFactory()));
}
} else act.set(comp, attr, "");
} else
act.set(comp, attr, value);
}
}
project.doAction(act);
}
}
示例7: mouseReleased
import com.cburch.logisim.circuit.CircuitMutation; //导入方法依赖的package包/类
@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());
AttributeSet attrsCopy = (AttributeSet) attrs.clone();
ComponentFactory source = getFactory();
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 {
// aquí se modifican los circuitos agregando componentes al circuito
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;
} 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);
}
}
示例8: mouseReleased
import com.cburch.logisim.circuit.CircuitMutation; //导入方法依赖的package包/类
@Override
public void mouseReleased(Canvas canvas, Graphics g, MouseEvent e) {
if (!exists) return;
Canvas.snapToGrid(e);
int curX = e.getX();
int curY = e.getY();
if (computeMove(curX, curY)) {
cur = Location.create(curX, curY);
}
if (hasDragged) {
exists = false;
super.mouseReleased(canvas, g, e);
ArrayList<Wire> ws = new ArrayList<Wire>(2);
if (cur.getY() == start.getY() || cur.getX() == start.getX()) {
Wire w = Wire.create(cur, start);
w = checkForRepairs(canvas, w, w.getEnd0());
w = checkForRepairs(canvas, w, w.getEnd1());
if (performShortening(canvas, start, cur)) {
return;
}
if (w.getLength() > 0) ws.add(w);
} else {
Location m;
if (direction == HORIZONTAL) {
m = Location.create(cur.getX(), start.getY());
} else {
m = Location.create(start.getX(), cur.getY());
}
Wire w0 = Wire.create(start, m);
Wire w1 = Wire.create(m, cur);
w0 = checkForRepairs(canvas, w0, start);
w1 = checkForRepairs(canvas, w1, cur);
if (w0.getLength() > 0) ws.add(w0);
if (w1.getLength() > 0) ws.add(w1);
}
if (ws.size() > 0) {
CircuitMutation mutation = new CircuitMutation(canvas.getCircuit());
mutation.addAll(ws);
StringGetter desc;
if (ws.size() == 1) desc = Strings.getter("addWireAction");
else desc = Strings.getter("addWiresAction");
Action act = mutation.toAction(desc);
canvas.getProject().doAction(act);
lastAction = act;
}
}
}
示例9: actionPerformed
import com.cburch.logisim.circuit.CircuitMutation; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
Set<Wire> wires = proj.getCurrentCircuit().getWires();
CircuitState state = proj.getCircuitState();
ArrayList<Wire> wiresMutator = new ArrayList<Wire>();
Canvas canvas = proj.getFrame().getCanvas();
for (Wire wire : wires) {
Location s = wire.getE0();
Location t = wire.getE1();
if (state.getValue(s).getColor().equals(new Color(192, 0, 0))) {
Wiring w = new Wiring();
AddTool at = (AddTool) w.getTool("Pin");
AttributeSet atrSet = at.getAttributeSet();
// Revisar como alterar el numero de bits de datos
atrSet.setValue(Pin.ATTR_TRISTATE, false);
at.setAttributeSet(atrSet);
at.setState(canvas, 2);
MouseEvent mouseEvent = new MouseEvent(canvas, 0, 0, 0,
s.getX() - 100, s.getY(), 50, 50, 1, false, 1);
at.mouseReleased(canvas, canvas.getGraphics(), mouseEvent);
canvas.completeAction();
Location inicio = Location.create(s.getX() - 100, s.getY());
Location fin = Location.create(s.getX() - 50, s.getY());
Wire newWire = Wire.create(inicio, fin);
wiresMutator.add(newWire);
}
}
CircuitMutation mutation = new CircuitMutation(
canvas.getCircuit());
mutation.addAll(wiresMutator);
StringGetter desc;
if (wiresMutator.size() == 1)
desc = Strings.getter("addWireAction");
else
desc = Strings.getter("addWiresAction");
Action act = mutation.toAction(desc);
canvas.getProject().doAction(act);
canvas.completeAction();
}