com.objogate.wl.swing.gesture.MappedKeyStrokeProbe Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of windowlicker-swing Show documentation
Show all versions of windowlicker-swing Show documentation
This is the Windowlicker Swing library.
The newest version!
package com.objogate.wl.swing.gesture;
import javax.swing.InputMap;
import javax.swing.JComponent;
import javax.swing.KeyStroke;
import java.util.Comparator;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import org.hamcrest.Description;
import com.objogate.wl.Probe;
import com.objogate.wl.swing.ComponentSelector;
public class MappedKeyStrokeProbe implements Probe {
private final ComponentSelector extends JComponent> componentSelector;
private final int inputMapId;
private final Object actionName;
public KeyStroke mappedKeyStroke = null;
public MappedKeyStrokeProbe(ComponentSelector extends JComponent> componentSelector, int inputMapId, Object actionName) {
this.actionName = actionName;
this.componentSelector = componentSelector;
this.inputMapId = inputMapId;
}
public void probe() {
componentSelector.probe();
if (componentSelector.isSatisfied()) {
JComponent component = componentSelector.component();
mappedKeyStroke = preferredKeyStrokeBoundToAction(component);
}
}
// Pick key strokes with lower valued key codes because higher key codes seem to be used for obscure keyboards
// like the cut/copy/paste keys that only exist on old Sun keyboards.
private KeyStroke preferredKeyStrokeBoundToAction(JComponent component) {
TreeMap