use of com.cburch.logisim.comp.Component in project logisim-evolution by reds-heig.
the class ComponentSelector method getSelectedItems.
public List<SelectionItem> getSelectedItems() {
TreePath[] sel = getSelectionPaths();
if (sel == null || sel.length == 0)
return Collections.emptyList();
ArrayList<SelectionItem> ret = new ArrayList<SelectionItem>();
for (int i = 0; i < sel.length; i++) {
TreePath path = sel[i];
Object last = path.getLastPathComponent();
ComponentNode n = null;
Object opt = null;
if (last instanceof OptionNode) {
OptionNode o = (OptionNode) last;
n = o.parent;
opt = o.option;
} else if (last instanceof ComponentNode) {
n = (ComponentNode) last;
if (n.opts != null)
n = null;
}
if (n != null) {
int count = 0;
for (CircuitNode cur = n.parent; cur != null; cur = cur.parent) {
count++;
}
Component[] nPath = new Component[count - 1];
CircuitNode cur = n.parent;
for (int j = nPath.length - 1; j >= 0; j--) {
nPath[j] = cur.subcircComp;
cur = cur.parent;
}
ret.add(new SelectionItem(logModel, nPath, n.comp, opt));
}
}
return ret.size() == 0 ? null : ret;
}
use of com.cburch.logisim.comp.Component 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.comp.Component 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.comp.Component 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.comp.Component in project logisim-evolution by reds-heig.
the class TextTool method mousePressed.
@Override
public void mousePressed(Canvas canvas, Graphics g, MouseEvent e) {
Project proj = canvas.getProject();
Circuit circ = canvas.getCircuit();
if (!proj.getLogisimFile().contains(circ)) {
if (caret != null)
caret.cancelEditing();
canvas.setErrorMessage(Strings.getter("cannotModifyError"));
return;
}
// Maybe user is clicking within the current caret.
if (caret != null) {
if (caret.getBounds(g).contains(e.getX(), e.getY())) {
// Yes
caret.mousePressed(e);
proj.repaintCanvas();
return;
} else {
// No. End the current caret.
caret.stopEditing();
}
}
// caret will be null at this point
// Otherwise search for a new caret.
int x = e.getX();
int y = e.getY();
Location loc = Location.create(x, y);
ComponentUserEvent event = new ComponentUserEvent(canvas, x, y);
// First search in selection.
for (Component comp : proj.getSelection().getComponentsContaining(loc, g)) {
TextEditable editable = (TextEditable) comp.getFeature(TextEditable.class);
if (editable != null) {
caret = editable.getTextCaret(event);
if (caret != null) {
proj.getFrame().viewComponentAttributes(circ, comp);
caretComponent = comp;
caretCreatingText = false;
break;
}
}
}
// Then search in circuit
if (caret == null) {
for (Component comp : circ.getAllContaining(loc, g)) {
TextEditable editable = (TextEditable) comp.getFeature(TextEditable.class);
if (editable != null) {
caret = editable.getTextCaret(event);
if (caret != null) {
proj.getFrame().viewComponentAttributes(circ, comp);
caretComponent = comp;
caretCreatingText = false;
break;
}
}
}
}
// if nothing found, create a new label
if (caret == null) {
if (loc.getX() < 0 || loc.getY() < 0)
return;
AttributeSet copy = (AttributeSet) attrs.clone();
caretComponent = Text.FACTORY.createComponent(loc, copy);
caretCreatingText = true;
TextEditable editable = (TextEditable) caretComponent.getFeature(TextEditable.class);
if (editable != null) {
caret = editable.getTextCaret(event);
proj.getFrame().viewComponentAttributes(circ, caretComponent);
}
}
if (caret != null) {
caretCanvas = canvas;
caretCircuit = canvas.getCircuit();
caret.addCaretListener(listener);
caretCircuit.addCircuitListener(listener);
}
proj.repaintCanvas();
}
Aggregations