Don't focus slider + traversal policy
This commit is contained in:
parent
641dafa3c1
commit
9b5c0251d6
@ -0,0 +1,48 @@
|
|||||||
|
package net.sf.openrocket.gui.adaptors;
|
||||||
|
|
||||||
|
import java.awt.Component;
|
||||||
|
import java.awt.Container;
|
||||||
|
import java.awt.FocusTraversalPolicy;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom adapter class for focus traversal, based on a given order of GUI components
|
||||||
|
*
|
||||||
|
* @author Sibo Van Gool <sibo.vangool@hotmail.com>
|
||||||
|
*/
|
||||||
|
public class CustomFocusTraversalPolicy extends FocusTraversalPolicy {
|
||||||
|
List<Component> order;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param order the order of components to traverse
|
||||||
|
*/
|
||||||
|
public CustomFocusTraversalPolicy(List<Component> order) {
|
||||||
|
this.order = new LinkedList<Component>(order);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Component getComponentAfter(Container focusCycleRoot, Component aComponent) {
|
||||||
|
int idx = (order.indexOf(aComponent) + 1) % order.size();
|
||||||
|
return order.get(idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Component getComponentBefore(Container focusCycleRoot, Component aComponent) {
|
||||||
|
int idx = order.indexOf(aComponent) - 1;
|
||||||
|
if (idx < 0) {
|
||||||
|
idx = order.size() - 1;
|
||||||
|
}
|
||||||
|
return order.get(idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Component getDefaultComponent(Container focusCycleRoot) {
|
||||||
|
return order.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Component getLastComponent(Container focusCycleRoot) {
|
||||||
|
return order.get(order.size() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Component getFirstComponent(Container focusCycleRoot) {
|
||||||
|
return order.get(0);
|
||||||
|
}
|
||||||
|
}
|
@ -26,6 +26,7 @@ public class BasicSlider extends JSlider {
|
|||||||
super(brm);
|
super(brm);
|
||||||
setOrientation(orientation);
|
setOrientation(orientation);
|
||||||
setInverted(inverted);
|
setInverted(inverted);
|
||||||
|
setFocusable(false);
|
||||||
setUI(new BasicSliderUI(this));
|
setUI(new BasicSliderUI(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user