use of com.cburch.logisim.comp.Component in project logisim-evolution by reds-heig.
the class SelectTool method processKeyEvent.
private void processKeyEvent(Canvas canvas, KeyEvent e, int type) {
HashMap<Component, KeyConfigurator> handlers = keyHandlers;
if (handlers == null) {
handlers = new HashMap<Component, KeyConfigurator>();
Selection sel = canvas.getSelection();
for (Component comp : sel.getComponents()) {
ComponentFactory factory = comp.getFactory();
AttributeSet attrs = comp.getAttributeSet();
Object handler = factory.getFeature(KeyConfigurator.class, attrs);
if (handler != null) {
KeyConfigurator base = (KeyConfigurator) handler;
handlers.put(comp, base.clone());
}
}
keyHandlers = handlers;
}
if (!handlers.isEmpty()) {
boolean consume = false;
ArrayList<KeyConfigurationResult> results;
results = new ArrayList<KeyConfigurationResult>();
for (Map.Entry<Component, KeyConfigurator> entry : handlers.entrySet()) {
Component comp = entry.getKey();
KeyConfigurator handler = entry.getValue();
KeyConfigurationEvent event = new KeyConfigurationEvent(type, comp.getAttributeSet(), e, comp);
KeyConfigurationResult result = handler.keyEventReceived(event);
consume |= event.isConsumed();
if (result != null) {
results.add(result);
}
}
if (consume) {
e.consume();
}
if (!results.isEmpty()) {
SetAttributeAction act = new SetAttributeAction(canvas.getCircuit(), Strings.getter("changeComponentAttributesAction"));
for (KeyConfigurationResult result : results) {
Component comp = (Component) result.getEvent().getData();
Map<Attribute<?>, Object> newValues = result.getAttributeValues();
for (Map.Entry<Attribute<?>, Object> entry : newValues.entrySet()) {
act.set(comp, entry.getKey(), entry.getValue());
}
}
if (!act.isEmpty()) {
canvas.getProject().doAction(act);
}
}
}
}
use of com.cburch.logisim.comp.Component 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.comp.Component in project logisim-evolution by reds-heig.
the class SelectTool method getHiddenComponents.
@Override
public Set<Component> getHiddenComponents(Canvas canvas) {
if (state == MOVING) {
int dx = curDx;
int dy = curDy;
if (dx == 0 && dy == 0) {
return null;
}
Set<Component> sel = canvas.getSelection().getComponents();
MoveGesture gesture = moveGesture;
if (gesture != null && drawConnections) {
MoveResult result = gesture.findResult(dx, dy);
if (result != null) {
HashSet<Component> ret = new HashSet<Component>(sel);
ret.addAll(result.getReplacementMap().getRemovals());
return ret;
}
}
return sel;
} else {
return null;
}
}
use of com.cburch.logisim.comp.Component in project logisim-evolution by reds-heig.
the class SetAttributeAction method doIt.
@Override
public void doIt(Project proj) {
CircuitMutation xn = new CircuitMutation(circuit);
int len = values.size();
oldValues.clear();
for (int i = 0; i < len; i++) {
Component comp = comps.get(i);
Attribute<Object> attr = attrs.get(i);
Object value = values.get(i);
if (circuit.contains(comp)) {
oldValues.add(null);
xn.set(comp, attr, value);
} else {
AttributeSet compAttrs = comp.getAttributeSet();
oldValues.add(compAttrs.getValue(attr));
compAttrs.setValue(attr, value);
}
}
if (!xn.isEmpty()) {
CircuitTransactionResult result = xn.execute();
xnReverse = result.getReverseTransaction();
}
}
use of com.cburch.logisim.comp.Component in project logisim-evolution by reds-heig.
the class SetAttributeAction method undo.
@Override
public void undo(Project proj) {
if (xnReverse != null)
xnReverse.execute();
for (int i = oldValues.size() - 1; i >= 0; i--) {
Component comp = comps.get(i);
Attribute<Object> attr = attrs.get(i);
Object value = oldValues.get(i);
if (value != null) {
comp.getAttributeSet().setValue(attr, value);
}
}
}
Aggregations