You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by rw...@apache.org on 2017/10/02 22:22:42 UTC
svn commit: r1810613 - in /pivot/trunk:
core/src/org/apache/pivot/collections/EnumSet.java
wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTabPaneSkin.java
wtk/src/org/apache/pivot/wtk/Keyboard.java
wtk/src/org/apache/pivot/wtk/skin/ComponentSkin.java
Author: rwhitcomb
Date: Mon Oct 2 22:22:41 2017
New Revision: 1810613
URL: http://svn.apache.org/viewvc?rev=1810613&view=rev
Log:
PIVOT-1007: Several changes to get Ctrl-Tab and Ctrl-Shift-Tab to cycle
among the current tabs in a TabPane container.
1. Implement the logic in TerraTabPaneSkin.java.
2. Add methods to EnumSet to create enum sets ("of", "addAll", "noneOf")
that are similar to the methods in Java's EnumSet.
3. Add an "areAnyPressed" method to Keyboard to check a set of modifiers.
4. Change ComponentSkin to only do the "Tab" logic there is none of the
modifiers except SHIFT are pressed. This allows Tab to cycle through
components in a container while Ctrl-Tab moves around the tabs (each
of which is a container).
5. These other changes use the new EnumSet methods for convenience.
Modified:
pivot/trunk/core/src/org/apache/pivot/collections/EnumSet.java
pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTabPaneSkin.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/Keyboard.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ComponentSkin.java
Modified: pivot/trunk/core/src/org/apache/pivot/collections/EnumSet.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/collections/EnumSet.java?rev=1810613&r1=1810612&r2=1810613&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/collections/EnumSet.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/collections/EnumSet.java Mon Oct 2 22:22:41 2017
@@ -163,4 +163,97 @@ public class EnumSet<E extends Enum<E>>
public ListenerList<SetListener<E>> getSetListeners() {
return setListeners;
}
+
+ /**
+ * Creates an empty enum set.
+ *
+ * @param <E> The enum type of the set.
+ * @param elementClass The class of the individual elements to be used
+ * in this set.
+ * @return The new empty set.
+ */
+ public static <E extends Enum<E>> EnumSet<E> noneOf(Class<E> elementClass) {
+ return new EnumSet<E>(elementClass);
+ }
+
+ /**
+ * Creates an enum set containing the given element.
+ *
+ * @param <E> The enum type of the set.
+ * @param e The only element to assign to the new set.
+ * @return The new set containing the single element.
+ */
+ public static <E extends Enum<E>> EnumSet<E> of(E e) {
+ EnumSet<E> set = new EnumSet<>(e.getDeclaringClass());
+ set.add(e);
+ return set;
+ }
+
+ /**
+ * Creates an enum set containing the given elements.
+ *
+ * @param <E> The enum type of the set.
+ * @param e1 The first element to add to the new set.
+ * @param e2 The second element to add.
+ * @return The new set containing only these two elements.
+ */
+ public static <E extends Enum<E>> EnumSet<E> of (E e1, E e2) {
+ EnumSet<E> set = new EnumSet<>(e1.getDeclaringClass());
+ set.add(e1);
+ set.add(e2);
+ return set;
+ }
+
+ /**
+ * Creates an enum set containing the given elements.
+ *
+ * @param <E> The enum type of the set.
+ * @param e1 The first element to add to the new set.
+ * @param e2 The second element to add.
+ * @param e3 The third element to add.
+ * @return The new set containing only these three elements.
+ */
+ public static <E extends Enum<E>> EnumSet<E> of (E e1, E e2, E e3) {
+ EnumSet<E> set = new EnumSet<>(e1.getDeclaringClass());
+ set.add(e1);
+ set.add(e2);
+ set.add(e3);
+ return set;
+ }
+
+ /**
+ * Creates an enum set containing the given elements.
+ *
+ * @param <E> The enum type of the set.
+ * @param e1 The first element to add to the new set.
+ * @param e2 The second element to add.
+ * @param e3 The third element to add.
+ * @param e4 The fourth element to add.
+ * @return The new set containing only these four elements.
+ */
+ public static <E extends Enum<E>> EnumSet<E> of(E e1, E e2, E e3, E e4) {
+ EnumSet<E> set = new EnumSet<>(e1.getDeclaringClass());
+ set.add(e1);
+ set.add(e2);
+ set.add(e3);
+ set.add(e4);
+ return set;
+ }
+
+ /**
+ * Adds all the elements of the given collection of this enum
+ * to this set.
+ *
+ * @param c The other collection to add to this set.
+ * @return Whether or not the enum set changed as a result.
+ */
+ public boolean addAll(Collection<E> c) {
+ boolean changed = false;
+ for (E elem : c) {
+ if (add(elem)) {
+ changed = true;
+ }
+ }
+ return changed;
+ }
}
Modified: pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTabPaneSkin.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTabPaneSkin.java?rev=1810613&r1=1810612&r2=1810613&view=diff
==============================================================================
--- pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTabPaneSkin.java (original)
+++ pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTabPaneSkin.java Mon Oct 2 22:22:41 2017
@@ -1411,6 +1411,8 @@ public class TerraTabPaneSkin extends Ta
* {@link KeyCode#KEYPAD_9 KEYPAD_9}<br>or CommandModifier +
* {@link KeyCode#N1 1} to {@link KeyCode#N9 9} Select the (enabled) tab at
* index 0 to 8 respectively.
+ * <p> CommandModifier + Tab to cycle forward through the tabs,
+ * CommandModifier + Shift + Tab to cycle backward.
*
* @see Platform#getCommandModifier()
*/
@@ -1480,6 +1482,21 @@ public class TerraTabPaneSkin extends Ta
break;
}
+ case Keyboard.KeyCode.TAB:
+ selectedIndex = tabPane.getSelectedIndex();
+ if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)) {
+ if (selectedIndex <= 0)
+ selectedIndex = tabs.getLength() - 1;
+ else
+ selectedIndex--;
+ } else {
+ if (selectedIndex >= tabs.getLength() - 1)
+ selectedIndex = 0;
+ else
+ selectedIndex++;
+ }
+ break;
+
default: {
break;
}
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Keyboard.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Keyboard.java?rev=1810613&r1=1810612&r2=1810613&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Keyboard.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Keyboard.java Mon Oct 2 22:22:41 2017
@@ -20,6 +20,9 @@ import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.lang.reflect.Field;
import java.util.Locale;
+
+import org.apache.pivot.collections.EnumSet;
+import org.apache.pivot.collections.Set;
import org.apache.pivot.util.Utils;
/**
@@ -35,6 +38,13 @@ public final class Keyboard {
public int getMask() {
return 1 << ordinal();
}
+
+ /**
+ * The set of all possible keyboard modifiers (for use with {@link #isPressed}
+ * or {@link #areAnyPressed}).
+ */
+ public static final Set<Modifier> allModifiers =
+ EnumSet.of(Modifier.SHIFT, Modifier.CTRL, Modifier.ALT, Modifier.META);
}
/**
@@ -283,6 +293,24 @@ public final class Keyboard {
}
/**
+ * Are any of the given set of {@link Modifier}s pressed?
+ *
+ * @param modifiers The set of modifiers to test.
+ * @return <tt>true</tt> if any of them are pressed, <tt>false</tt>
+ * if none are pressed.
+ */
+ public static boolean areAnyPressed(Set<Modifier> modifiers) {
+ boolean result = false;
+ for (Modifier modifier : modifiers) {
+ if (isPressed(modifier)) {
+ result = true;
+ break;
+ }
+ }
+ return result;
+ }
+
+ /**
* Returns the current drop action.
*
* @return The drop action corresponding to the currently pressed modifier
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ComponentSkin.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ComponentSkin.java?rev=1810613&r1=1810612&r2=1810613&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ComponentSkin.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ComponentSkin.java Mon Oct 2 22:22:41 2017
@@ -19,6 +19,7 @@ package org.apache.pivot.wtk.skin;
import java.awt.Color;
import java.awt.Font;
+import org.apache.pivot.collections.EnumSet;
import org.apache.pivot.json.JSONSerializer;
import org.apache.pivot.serialization.SerializationException;
import org.apache.pivot.util.Utils;
@@ -268,7 +269,13 @@ public abstract class ComponentSkin impl
Keyboard.KeyLocation keyLocation) {
boolean consumed = false;
- if (keyCode == Keyboard.KeyCode.TAB && getComponent().isFocused()) {
+ EnumSet<Keyboard.Modifier> otherModifiers = EnumSet.noneOf(Keyboard.Modifier.class);
+ otherModifiers.addAll(Keyboard.Modifier.allModifiers);
+ otherModifiers.remove(Keyboard.Modifier.SHIFT);
+
+ if (keyCode == Keyboard.KeyCode.TAB &&
+ !Keyboard.areAnyPressed(otherModifiers) &&
+ getComponent().isFocused()) {
FocusTraversalDirection direction = (Keyboard.isPressed(Keyboard.Modifier.SHIFT)) ? FocusTraversalDirection.BACKWARD
: FocusTraversalDirection.FORWARD;