use of com.cburch.logisim.tools.key.KeyConfigurator 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.tools.key.KeyConfigurator in project logisim-evolution by reds-heig.
the class AddTool method processKeyEvent.
private void processKeyEvent(Canvas canvas, KeyEvent event, int type) {
KeyConfigurator handler = keyHandler;
if (!keyHandlerTried) {
ComponentFactory source = getFactory();
AttributeSet baseAttrs = getBaseAttributes();
handler = (KeyConfigurator) source.getFeature(KeyConfigurator.class, baseAttrs);
keyHandler = handler;
keyHandlerTried = true;
}
if (handler != null) {
AttributeSet baseAttrs = getBaseAttributes();
KeyConfigurationEvent e = new KeyConfigurationEvent(type, baseAttrs, event, this);
KeyConfigurationResult r = handler.keyEventReceived(e);
if (r != null) {
Action act = ToolAttributeAction.create(r);
canvas.getProject().doAction(act);
}
}
}
Aggregations