Search in sources :

Example 1 with KeyConfigurationEvent

use of com.cburch.logisim.tools.key.KeyConfigurationEvent in project logisim-evolution by reds-heig.

the class ToolAttributeAction method create.

public static Action create(Tool tool, Attribute<?> attr, Object value) {
    AttributeSet attrs = tool.getAttributeSet();
    KeyConfigurationEvent e = new KeyConfigurationEvent(0, attrs, null, null);
    KeyConfigurationResult r = new KeyConfigurationResult(e, attr, value);
    return new ToolAttributeAction(r);
}
Also used : KeyConfigurationResult(com.cburch.logisim.tools.key.KeyConfigurationResult) AttributeSet(com.cburch.logisim.data.AttributeSet) KeyConfigurationEvent(com.cburch.logisim.tools.key.KeyConfigurationEvent)

Example 2 with KeyConfigurationEvent

use of com.cburch.logisim.tools.key.KeyConfigurationEvent 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);
            }
        }
    }
}
Also used : KeyConfigurationResult(com.cburch.logisim.tools.key.KeyConfigurationResult) Attribute(com.cburch.logisim.data.Attribute) Selection(com.cburch.logisim.gui.main.Selection) ComponentFactory(com.cburch.logisim.comp.ComponentFactory) AttributeSet(com.cburch.logisim.data.AttributeSet) KeyConfigurationEvent(com.cburch.logisim.tools.key.KeyConfigurationEvent) Component(com.cburch.logisim.comp.Component) KeyConfigurator(com.cburch.logisim.tools.key.KeyConfigurator) HashMap(java.util.HashMap) Map(java.util.Map) ReplacementMap(com.cburch.logisim.circuit.ReplacementMap)

Example 3 with KeyConfigurationEvent

use of com.cburch.logisim.tools.key.KeyConfigurationEvent 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);
        }
    }
}
Also used : KeyConfigurationResult(com.cburch.logisim.tools.key.KeyConfigurationResult) Action(com.cburch.logisim.proj.Action) ToolAttributeAction(com.cburch.logisim.gui.main.ToolAttributeAction) AttributeSet(com.cburch.logisim.data.AttributeSet) KeyConfigurationEvent(com.cburch.logisim.tools.key.KeyConfigurationEvent) ComponentFactory(com.cburch.logisim.comp.ComponentFactory) KeyConfigurator(com.cburch.logisim.tools.key.KeyConfigurator)

Aggregations

AttributeSet (com.cburch.logisim.data.AttributeSet)3 KeyConfigurationEvent (com.cburch.logisim.tools.key.KeyConfigurationEvent)3 KeyConfigurationResult (com.cburch.logisim.tools.key.KeyConfigurationResult)3 ComponentFactory (com.cburch.logisim.comp.ComponentFactory)2 KeyConfigurator (com.cburch.logisim.tools.key.KeyConfigurator)2 ReplacementMap (com.cburch.logisim.circuit.ReplacementMap)1 Component (com.cburch.logisim.comp.Component)1 Attribute (com.cburch.logisim.data.Attribute)1 Selection (com.cburch.logisim.gui.main.Selection)1 ToolAttributeAction (com.cburch.logisim.gui.main.ToolAttributeAction)1 Action (com.cburch.logisim.proj.Action)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1