本文整理汇总了Java中com.cburch.logisim.circuit.CircuitMutation.add方法的典型用法代码示例。如果您正苦于以下问题:Java CircuitMutation.add方法的具体用法?Java CircuitMutation.add怎么用?Java CircuitMutation.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.cburch.logisim.circuit.CircuitMutation
的用法示例。
在下文中一共展示了CircuitMutation.add方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: remove
import com.cburch.logisim.circuit.CircuitMutation; //导入方法依赖的package包/类
void remove(CircuitMutation xn, Component comp) {
boolean removed = selected.remove(comp);
if (lifted.contains(comp)) {
if (xn == null) {
throw new IllegalStateException("cannot remove");
} else {
lifted.remove(comp);
removed = true;
xn.add(comp);
}
}
if (removed) {
if (shouldSnapComponent(comp))
computeShouldSnap();
fireSelectionChanged();
}
}
示例2: remove
import com.cburch.logisim.circuit.CircuitMutation; //导入方法依赖的package包/类
void remove(CircuitMutation xn, Component comp) {
boolean removed = selected.remove(comp);
if (lifted.contains(comp)) {
if (xn == null) {
throw new IllegalStateException("cannot remove");
} else {
lifted.remove(comp);
removed = true;
xn.add(comp);
}
}
if (removed) {
if (shouldSnapComponent(comp)) computeShouldSnap();
fireSelectionChanged();
}
}
示例3: placeOutput
import com.cburch.logisim.circuit.CircuitMutation; //导入方法依赖的package包/类
private static void placeOutput(CircuitMutation result, Location loc, String name) {
ComponentFactory factory = Pin.FACTORY;
AttributeSet attrs = factory.createAttributeSet();
attrs.setValue(StdAttr.FACING, Direction.WEST);
attrs.setValue(Pin.ATTR_TYPE, Boolean.TRUE);
attrs.setValue(StdAttr.LABEL, name);
attrs.setValue(Pin.ATTR_LABEL_LOC, Direction.NORTH);
result.add(factory.createComponent(loc, attrs));
}
示例4: placeOutput
import com.cburch.logisim.circuit.CircuitMutation; //导入方法依赖的package包/类
private static void placeOutput(CircuitMutation result, Location loc,
String name) {
ComponentFactory factory = Pin.FACTORY;
AttributeSet attrs = factory.createAttributeSet();
attrs.setValue(StdAttr.FACING, Direction.WEST);
attrs.setValue(Pin.ATTR_TYPE, Boolean.TRUE);
attrs.setValue(StdAttr.LABEL, name);
attrs.setValue(Pin.ATTR_LABEL_LOC, Direction.NORTH);
result.add(factory.createComponent(loc, attrs));
}
示例5: placeInputs
import com.cburch.logisim.circuit.CircuitMutation; //导入方法依赖的package包/类
private static void placeInputs(CircuitMutation result, InputData inputData) {
ArrayList<Location> forbiddenYs = new ArrayList<Location>();
Comparator<Location> compareYs = new CompareYs();
int curX = 40;
int curY = 30;
for (int i = 0; i < inputData.names.length; i++) {
String name = inputData.names[i];
SingleInput singleInput = inputData.inputs.get(name);
// determine point where we can intersect with spine
int spineX = singleInput.spineX;
Location spineLoc = Location.create(spineX, curY);
if (singleInput.ys.size() > 0) {
// search for a Y that won't intersect with others
// (we needn't bother if the pin doesn't connect
// with anything anyway.)
Collections.sort(forbiddenYs, compareYs);
while (Collections.binarySearch(forbiddenYs, spineLoc, compareYs) >= 0) {
curY += 10;
spineLoc = Location.create(spineX, curY);
}
singleInput.ys.add(spineLoc);
}
Location loc = Location.create(curX, curY);
// now create the pin
ComponentFactory factory = Pin.FACTORY;
AttributeSet attrs = factory.createAttributeSet();
attrs.setValue(StdAttr.FACING, Direction.EAST);
attrs.setValue(Pin.ATTR_TYPE, Boolean.FALSE);
attrs.setValue(Pin.ATTR_TRISTATE, Boolean.FALSE);
attrs.setValue(StdAttr.LABEL, name);
attrs.setValue(Pin.ATTR_LABEL_LOC, Direction.NORTH);
result.add(factory.createComponent(loc, attrs));
ArrayList<Location> spine = singleInput.ys;
if (spine.size() > 0) {
// create wire connecting pin to spine
/*
* This should no longer matter - the wires will be repaired anyway by the
* circuit's WireRepair class. if (spine.size() == 2 &&
* spine.get(0).equals(spine.get(1))) { // a freak accident where the input is
* used just once, // and it happens that the pin is placed where no // spine is
* necessary Iterator<Wire> it = circuit.getWires(spineLoc).iterator(); Wire
* existing = it.next(); Wire replace = Wire.create(loc, existing.getEnd1());
* result.replace(existing, replace); } else {
*/
result.add(Wire.create(loc, spineLoc));
// }
// create spine
Collections.sort(spine, compareYs);
Location prev = spine.get(0);
for (int k = 1, n = spine.size(); k < n; k++) {
Location cur = spine.get(k);
if (!cur.equals(prev)) {
result.add(Wire.create(prev, cur));
prev = cur;
}
}
}
// advance y and forbid spine intersections for next pin
forbiddenYs.addAll(singleInput.ys);
curY += 50;
}
}
示例6: 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);
}
}
示例7: placeInputs
import com.cburch.logisim.circuit.CircuitMutation; //导入方法依赖的package包/类
private static void placeInputs(CircuitMutation result, InputData inputData) {
ArrayList<Location> forbiddenYs = new ArrayList<Location>();
Comparator<Location> compareYs = new CompareYs();
int curX = 40;
int curY = 30;
for (int i = 0; i < inputData.names.length; i++) {
String name = inputData.names[i];
SingleInput singleInput = inputData.inputs.get(name);
// determine point where we can intersect with spine
int spineX = singleInput.spineX;
Location spineLoc = Location.create(spineX, curY);
if (singleInput.ys.size() > 0) {
// search for a Y that won't intersect with others
// (we needn't bother if the pin doesn't connect
// with anything anyway.)
Collections.sort(forbiddenYs, compareYs);
while (Collections.binarySearch(forbiddenYs, spineLoc,
compareYs) >= 0) {
curY += 10;
spineLoc = Location.create(spineX, curY);
}
singleInput.ys.add(spineLoc);
}
Location loc = Location.create(curX, curY);
// now create the pin
ComponentFactory factory = Pin.FACTORY;
AttributeSet attrs = factory.createAttributeSet();
attrs.setValue(StdAttr.FACING, Direction.EAST);
attrs.setValue(Pin.ATTR_TYPE, Boolean.FALSE);
attrs.setValue(Pin.ATTR_TRISTATE, Boolean.FALSE);
attrs.setValue(StdAttr.LABEL, name);
attrs.setValue(Pin.ATTR_LABEL_LOC, Direction.NORTH);
result.add(factory.createComponent(loc, attrs));
ArrayList<Location> spine = singleInput.ys;
if (spine.size() > 0) {
// create wire connecting pin to spine
/*
* This should no longer matter - the wires will be repaired
* anyway by the circuit's WireRepair class. if (spine.size() ==
* 2 && spine.get(0).equals(spine.get(1))) { // a freak accident
* where the input is used just once, // and it happens that the
* pin is placed where no // spine is necessary Iterator<Wire>
* it = circuit.getWires(spineLoc).iterator(); Wire existing =
* it.next(); Wire replace = Wire.create(loc,
* existing.getEnd1()); result.replace(existing, replace); }
* else {
*/
result.add(Wire.create(loc, spineLoc));
// }
// create spine
Collections.sort(spine, compareYs);
Location prev = spine.get(0);
for (int k = 1, n = spine.size(); k < n; k++) {
Location cur = spine.get(k);
if (!cur.equals(prev)) {
result.add(Wire.create(prev, cur));
prev = cur;
}
}
}
// advance y and forbid spine intersections for next pin
forbiddenYs.addAll(singleInput.ys);
curY += 50;
}
}
示例8: 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);
}
}
示例9: placeInputs
import com.cburch.logisim.circuit.CircuitMutation; //导入方法依赖的package包/类
private static void placeInputs(CircuitMutation result, InputData inputData) {
ArrayList<Location> forbiddenYs = new ArrayList<Location>();
Comparator<Location> compareYs = new CompareYs();
int curX = 40;
int curY = 30;
for (int i = 0; i < inputData.names.length; i++) {
String name = inputData.names[i];
SingleInput singleInput = inputData.inputs.get(name);
// determine point where we can intersect with spine
int spineX = singleInput.spineX;
Location spineLoc = Location.create(spineX, curY);
if (singleInput.ys.size() > 0) {
// search for a Y that won't intersect with others
// (we needn't bother if the pin doesn't connect
// with anything anyway.)
Collections.sort(forbiddenYs, compareYs);
while (Collections.binarySearch(forbiddenYs, spineLoc, compareYs) >= 0) {
curY += 10;
spineLoc = Location.create(spineX, curY);
}
singleInput.ys.add(spineLoc);
}
Location loc = Location.create(curX, curY);
// now create the pin
ComponentFactory factory = Pin.FACTORY;
AttributeSet attrs = factory.createAttributeSet();
attrs.setValue(StdAttr.FACING, Direction.EAST);
attrs.setValue(Pin.ATTR_TYPE, Boolean.FALSE);
attrs.setValue(Pin.ATTR_TRISTATE, Boolean.FALSE);
attrs.setValue(StdAttr.LABEL, name);
attrs.setValue(Pin.ATTR_LABEL_LOC, Direction.NORTH);
result.add(factory.createComponent(loc, attrs));
ArrayList<Location> spine = singleInput.ys;
if (spine.size() > 0) {
// create wire connecting pin to spine
/* This should no longer matter - the wires will be repaired
* anyway by the circuit's WireRepair class.
if (spine.size() == 2 && spine.get(0).equals(spine.get(1))) {
// a freak accident where the input is used just once,
// and it happens that the pin is placed where no
// spine is necessary
Iterator<Wire> it = circuit.getWires(spineLoc).iterator();
Wire existing = it.next();
Wire replace = Wire.create(loc, existing.getEnd1());
result.replace(existing, replace);
} else {
*/
result.add(Wire.create(loc, spineLoc));
// }
// create spine
Collections.sort(spine, compareYs);
Location prev = spine.get(0);
for (int k = 1, n = spine.size(); k < n; k++) {
Location cur = spine.get(k);
if (!cur.equals(prev)) {
result.add(Wire.create(prev, cur));
prev = cur;
}
}
}
// advance y and forbid spine intersections for next pin
forbiddenYs.addAll(singleInput.ys);
curY += 50;
}
}
示例10: 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);
}
}