Author: rwhitcomb Date: Wed Nov 1 02:16:53 2023 New Revision: 1913476 URL: http://svn.apache.org/viewvc?rev=1913476&view=rev Log: PIVOT-1032: Last set of changes to reduce "checkstyle" violations, plus some code enhancements.
Modified: pivot/trunk/core/src/org/apache/pivot/collections/HashSet.java pivot/trunk/core/src/org/apache/pivot/util/StringUtils.java pivot/trunk/core/src/org/apache/pivot/util/Utils.java pivot/trunk/core/src/org/apache/pivot/util/concurrent/Task.java pivot/trunk/core/src/org/apache/pivot/util/concurrent/TimeoutException.java pivot/trunk/core/test/org/apache/pivot/util/test/StringUtilsTest.java pivot/trunk/tests/src/org/apache/pivot/tests/console_test.bxml pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraGaugeSkin.java pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java pivot/trunk/wtk/src/org/apache/pivot/wtk/Button.java pivot/trunk/wtk/src/org/apache/pivot/wtk/Keyboard.java pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInputListener.java pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/DisplaySkin.java pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkin.java pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinListItemView.java pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinNumberedListView.java Modified: pivot/trunk/core/src/org/apache/pivot/collections/HashSet.java URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/collections/HashSet.java?rev=1913476&r1=1913475&r2=1913476&view=diff ============================================================================== --- pivot/trunk/core/src/org/apache/pivot/collections/HashSet.java (original) +++ pivot/trunk/core/src/org/apache/pivot/collections/HashSet.java Wed Nov 1 02:16:53 2023 @@ -35,7 +35,7 @@ public class HashSet<E> implements Set<E private E element = null; - public ElementIterator(Iterator<E> iterator) { + public ElementIterator(final Iterator<E> iterator) { Utils.checkNull(iterator, "iterator"); this.iterator = iterator; @@ -79,25 +79,25 @@ public class HashSet<E> implements Set<E public HashSet() { } - public HashSet(Set<E> set) { + public HashSet(final Set<E> set) { for (E element : set) { add(element); } } @SafeVarargs - public HashSet(E... elements) { + public HashSet(final E... elements) { for (E element : elements) { add(element); } } - public HashSet(Comparator<E> comparator) { + public HashSet(final Comparator<E> comparator) { setComparator(comparator); } @Override - public boolean add(E element) { + public boolean add(final E element) { boolean added = false; if (!hashMap.containsKey(element)) { @@ -113,7 +113,7 @@ public class HashSet<E> implements Set<E } @Override - public boolean remove(E element) { + public boolean remove(final E element) { boolean removed = false; if (hashMap.containsKey(element)) { @@ -140,7 +140,7 @@ public class HashSet<E> implements Set<E } @Override - public boolean contains(E element) { + public boolean contains(final E element) { return hashMap.containsKey(element); } @@ -160,7 +160,7 @@ public class HashSet<E> implements Set<E } @Override - public void setComparator(Comparator<E> comparator) { + public void setComparator(final Comparator<E> comparator) { Comparator<E> previousComparator = getComparator(); hashMap.setComparator(comparator); @@ -186,7 +186,7 @@ public class HashSet<E> implements Set<E @Override @SuppressWarnings("unchecked") - public boolean equals(Object o) { + public boolean equals(final Object o) { boolean equals = false; if (this == o) { @@ -224,7 +224,7 @@ public class HashSet<E> implements Set<E public String toString() { StringBuilder sb = new StringBuilder(); - sb.append(getClass().getName()); + sb.append(getClass().getSimpleName()); sb.append(" ("); int i = 0; Modified: pivot/trunk/core/src/org/apache/pivot/util/StringUtils.java URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/util/StringUtils.java?rev=1913476&r1=1913475&r2=1913476&view=diff ============================================================================== --- pivot/trunk/core/src/org/apache/pivot/util/StringUtils.java (original) +++ pivot/trunk/core/src/org/apache/pivot/util/StringUtils.java Wed Nov 1 02:16:53 2023 @@ -18,6 +18,7 @@ package org.apache.pivot.util; import java.math.BigDecimal; import java.math.BigInteger; +import java.util.Arrays; /** @@ -50,16 +51,10 @@ public final class StringUtils { throw new IllegalArgumentException("Requested string size " + n + " is out of range."); } - // Nothing fancy here, but allocate the space and set length upfront - // because we know how big the result should be. - StringBuilder builder = new StringBuilder(n); - builder.setLength(n); - if (ch != '\0') { - for (int i = 0; i < n; i++) { - builder.setCharAt(i, ch); - } - } - return builder.toString(); + char[] chars = new char[n]; + Arrays.fill(chars, ch); + + return new String(chars); } /** Modified: pivot/trunk/core/src/org/apache/pivot/util/Utils.java URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/util/Utils.java?rev=1913476&r1=1913475&r2=1913476&view=diff ============================================================================== --- pivot/trunk/core/src/org/apache/pivot/util/Utils.java (original) +++ pivot/trunk/core/src/org/apache/pivot/util/Utils.java Wed Nov 1 02:16:53 2023 @@ -450,5 +450,19 @@ public final class Utils { } } + /** + * Check and throw an exception if the given object is not of the given class. + * + * @param nm A suitable object name for the object. + * @param obj The object whose class must be checked. + * @param cls The required class of the object. + * @throws IllegalArgumentException if the object is NOT the required class. + */ + public static void notInstanceOf(final String nm, final Object obj, final Class<?> cls) { + if (!cls.isInstance(obj)) { + throw new IllegalArgumentException(nm + " (" + obj.getClass().getSimpleName() + ") " + + "must be an instance of " + cls.getSimpleName() + "."); + } + } } Modified: pivot/trunk/core/src/org/apache/pivot/util/concurrent/Task.java URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/util/concurrent/Task.java?rev=1913476&r1=1913475&r2=1913476&view=diff ============================================================================== --- pivot/trunk/core/src/org/apache/pivot/util/concurrent/Task.java (original) +++ pivot/trunk/core/src/org/apache/pivot/util/concurrent/Task.java Wed Nov 1 02:16:53 2023 @@ -31,63 +31,110 @@ import org.apache.pivot.util.Utils; */ public abstract class Task<V> { /** - * Task execution callback that is posted to the executor service. + * Task execution callback that is posted to the executor service; responsible + * for running the background task from the {@link #run} method, where it + * invokes the {@link Task#execute} method (abstract here, so it must be + * implemented in the subclass). */ private class ExecuteCallback implements Runnable { @Override public void run() { - V resultLocal = null; - Throwable faultLocal = null; + V taskResult = null; + Throwable taskFault = null; synchronized (Task.this) { Task.this.taskThread = new WeakReference<Thread>(Thread.currentThread()); } try { - resultLocal = execute(); + taskResult = execute(); } catch (Throwable throwable) { - faultLocal = throwable; + taskFault = throwable; } - TaskListener<V> taskListenerLocal; + TaskListener<V> localListener; synchronized (Task.this) { - Task.this.result = resultLocal; - Task.this.fault = faultLocal; + Task.this.result = taskResult; + Task.this.fault = taskFault; abort = false; - taskListenerLocal = Task.this.taskListener; + localListener = Task.this.taskListener; Task.this.taskListener = null; } - if (faultLocal == null) { - taskListenerLocal.taskExecuted(Task.this); + if (taskFault == null) { + localListener.taskExecuted(Task.this); } else { - taskListenerLocal.executeFailed(Task.this); + localListener.executeFailed(Task.this); } } } + /** + * The executor service used to launch this background task. + */ private ExecutorService executorService; + /** + * The result of this task's execution. Not valid until and unless the task + * finishes successfully. + */ private V result = null; + /** + * The reason for the task's failure, if any. Not valid until and unless the + * task's {@link #execute} method throws an exception. + */ private Throwable fault = null; + /** + * Listener attached to this task which is notified when the task finishes + * either successfully, or with an exception. + */ private TaskListener<V> taskListener = null; + /** + * Weak reference to the thread actually executing the task. Provided as a + * convenience if needed. Not valid until the task's {@link #execute} method + * is called. "Weak" so that garbage collection can recover all this task's + * resources once this thread finishes. + */ private WeakReference<Thread> taskThread = null; + /** + * Timeout value, which can be used to ensure the task finishes even if something + * untoward happens. Must be implemented and respected by the subclass. + */ protected volatile long timeout = Long.MAX_VALUE; + /** + * Flag used to signal that the task should be / has been aborted. Implemented and + * respected by the subclass. + */ protected volatile boolean abort = false; + /** + * Default executor service used to launch tasks if no other is provided. The default is a + * cached thread pool. + */ public static final ExecutorService DEFAULT_EXECUTOR_SERVICE = Executors.newCachedThreadPool(); + + /** + * Construct this task using the default executor service to launch it. + */ public Task() { this(DEFAULT_EXECUTOR_SERVICE); } - public Task(ExecutorService executorService) { - Utils.checkNull(executorService, "executorService"); + /** + * Construct this task using the given executor service to launch it. + * + * @param execService The service to use to execute this background task (must not + * be <code>null</code>). + * @throws IllegalArgumentException if the executor service is {@code null}. + */ + public Task(final ExecutorService execService) { + Utils.checkNull(execService, "executorService"); - this.executorService = executorService; + executorService = execService; } /** @@ -100,39 +147,42 @@ public abstract class Task<V> { public abstract V execute() throws TaskExecutionException; /** - * Asynchronously executes the task. The caller is notified of the task's - * completion via the listener argument. Note that the listener will be - * notified on the task's worker thread, not on the thread that executed the - * task. - * - * @param taskListenerArgument The listener to be notified when the task - * completes. + * Asynchronously executes the task using the executor service specified + * at construction time.. The caller is notified of the task's completion + * via the listener argument. Note that the listener will be notified on + * the task's worker thread, not on the thread that requested the task + * execution. + * + * @param taskListenerValue The listener to be notified when the task + * completes or throws an exception. + * @throws IllegalThreadStateException if this task is already scheduled / running. */ - public synchronized void execute(TaskListener<V> taskListenerArgument) { - execute(taskListenerArgument, executorService); + public synchronized void execute(final TaskListener<V> taskListenerValue) { + execute(taskListenerValue, executorService); } /** * Asynchronously executes the task. The caller is notified of the task's * completion via the listener argument. Note that the listener will be - * notified on the task's worker thread, not on the thread that executed the - * task. + * notified on the task's background worker thread, not on the thread that + * requested the task execution. * - * @param taskListenerArgument The listener to be notified when the task - * completes. - * @param executorServiceArgument The service to submit the task to, - * overriding the Task's own ExecutorService. - */ - public synchronized void execute(TaskListener<V> taskListenerArgument, - ExecutorService executorServiceArgument) { - Utils.checkNull(taskListenerArgument, "taskListener"); - Utils.checkNull(executorServiceArgument, "executorService"); + * @param taskListenerValue The listener to be notified when the task + * completes or throws an exception. + * @param execServiceOverride The service to submit the task to (which may be + * an override of the Task's own <code>ExecutorService</code>). + * @throws IllegalThreadStateException if this task is already scheduled / running. + */ + public synchronized void execute(final TaskListener<V> taskListenerValue, + final ExecutorService execServiceOverride) { + Utils.checkNull(taskListenerValue, "taskListener"); + Utils.checkNull(execServiceOverride, "executorService"); - if (this.taskListener != null) { + if (taskListener != null) { throw new IllegalThreadStateException("Task is already pending."); } - this.taskListener = taskListenerArgument; + taskListener = taskListenerValue; result = null; fault = null; @@ -140,8 +190,7 @@ public abstract class Task<V> { abort = false; // Create a new execute callback and post it to the executor service - ExecuteCallback executeCallback = new ExecuteCallback(); - executorServiceArgument.submit(executeCallback); + execServiceOverride.submit(new ExecuteCallback()); } /** @@ -155,9 +204,10 @@ public abstract class Task<V> { * Returns the result of executing the task. * * @return The task result, or {@code null} if the task is still executing - * or has failed. The result itself may also be {@code null}; callers - * should call {@link #isPending()} and {@link #getFault()} to distinguish - * between these cases. + * or has failed. The result itself may also be {@code null}, especially + * for a {@code Task<Void>}, or just if the task execution resulted in that. + * Callers should call {@link #isPending()} and {@link #getFault()} to + * distinguish between these cases. */ public synchronized V getResult() { return result; @@ -208,11 +258,12 @@ public abstract class Task<V> { * Sets the timeout value for this task. It is the responsibility of the * implementing class to respect this value. * - * @param timeout The time by which the task must complete execution. If the - * timeout is exceeded, a {@link TimeoutException} will be thrown. + * @param timeoutValue The time by which the task must complete execution. If the + * timeout is exceeded, a {@link TimeoutException} must be thrown (again, the + * responsibility of the implementing class). */ - public synchronized void setTimeout(long timeout) { - this.timeout = timeout; + public synchronized void setTimeout(final long timeoutValue) { + timeout = timeoutValue; } /** Modified: pivot/trunk/core/src/org/apache/pivot/util/concurrent/TimeoutException.java URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/util/concurrent/TimeoutException.java?rev=1913476&r1=1913475&r2=1913476&view=diff ============================================================================== --- pivot/trunk/core/src/org/apache/pivot/util/concurrent/TimeoutException.java (original) +++ pivot/trunk/core/src/org/apache/pivot/util/concurrent/TimeoutException.java Wed Nov 1 02:16:53 2023 @@ -22,11 +22,19 @@ package org.apache.pivot.util.concurrent public class TimeoutException extends RuntimeException { private static final long serialVersionUID = 7512511291820426011L; + /** + * Construct the exception with no message. + */ public TimeoutException() { super(); } - public TimeoutException(String message) { + /** + * Construct the exception with the given message. + * + * @param message Message associated with this exception. + */ + public TimeoutException(final String message) { super(message); } } Modified: pivot/trunk/core/test/org/apache/pivot/util/test/StringUtilsTest.java URL: http://svn.apache.org/viewvc/pivot/trunk/core/test/org/apache/pivot/util/test/StringUtilsTest.java?rev=1913476&r1=1913475&r2=1913476&view=diff ============================================================================== --- pivot/trunk/core/test/org/apache/pivot/util/test/StringUtilsTest.java (original) +++ pivot/trunk/core/test/org/apache/pivot/util/test/StringUtilsTest.java Wed Nov 1 02:16:53 2023 @@ -54,5 +54,23 @@ public class StringUtilsTest { assertEquals("[a, b, c, d, e, f, g]", output); } + /** + * Run tests of {@link StringUtils#fromNChars}. + */ + @Test + public void test2() { + String actual1 = StringUtils.fromNChars(' ', 0); + assertEquals("", actual1); + + String actual2 = StringUtils.fromNChars('\0', 10); + assertEquals("\0\0\0\0\0\0\0\0\0\0", actual2); + + String actual3 = StringUtils.fromNChars(' ', 8); + assertEquals(" ", actual3); + + String actual4 = StringUtils.fromNChars('\u2022', 6); + assertEquals("â¢â¢â¢â¢â¢â¢", actual4); + } + } Modified: pivot/trunk/tests/src/org/apache/pivot/tests/console_test.bxml URL: http://svn.apache.org/viewvc/pivot/trunk/tests/src/org/apache/pivot/tests/console_test.bxml?rev=1913476&r1=1913475&r2=1913476&view=diff ============================================================================== --- pivot/trunk/tests/src/org/apache/pivot/tests/console_test.bxml (original) +++ pivot/trunk/tests/src/org/apache/pivot/tests/console_test.bxml Wed Nov 1 02:16:53 2023 @@ -26,12 +26,12 @@ limitations under the License. <TablePane.Column width="1*"/> </columns> <rows> - <TablePane.Row height="3*"> + <TablePane.Row height="1*"> <FlowPane> <PushButton bxml:id="logMessageButton" buttonData="Log Message"/> </FlowPane> </TablePane.Row> - <TablePane.Row height="1*"> + <TablePane.Row height="3*"> <Border title="Console"> <ScrollPane horizontalScrollBarPolicy="fill" verticalScrollBarPolicy="auto"> <TextArea bxml:id="consoleArea" editable="false" styles="{wrapText:true}"/> Modified: pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraGaugeSkin.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraGaugeSkin.java?rev=1913476&r1=1913475&r2=1913476&view=diff ============================================================================== --- pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraGaugeSkin.java (original) +++ pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraGaugeSkin.java Wed Nov 1 02:16:53 2023 @@ -147,7 +147,7 @@ public class TerraGaugeSkin<T extends Nu public void paint(final Graphics2D graphics) { @SuppressWarnings("unchecked") Gauge<T> gauge = (Gauge<T>) getComponent(); - // NOTE: sanity check: warning level > min && < max, warning < critical if both set + // NOTE: warning level > min && < max, warning < critical if both set // also critical > main && < max, critical > warning if both set String text = gauge.getText(); Modified: pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java?rev=1913476&r1=1913475&r2=1913476&view=diff ============================================================================== --- pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java (original) +++ pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java Wed Nov 1 02:16:53 2023 @@ -1178,23 +1178,22 @@ public class TerraTextInputSkin extends return consumed; } - private boolean handleLeftRightKeys(final TextInput textInput, final int keyCode, final boolean isShiftPressed, - final int selStart, final int selLength) { + private boolean handleLeftRightKeys(final TextInput textInput, final int keyCode, + final Keyboard.Modifiers mods, final int selStart, final int selLength) { boolean consumed = false; int start = selStart, length = selLength; - Modifier wordNavigationModifier = Platform.getWordNavigationModifier(); // Sometimes while selecting we need to make the opposite end visible if (keyCode == KeyCode.LEFT) { SelectDirection visiblePosition = SelectDirection.LEFT; - if (Keyboard.isPressed(wordNavigationModifier)) { + if (mods.wordNavPressed) { int wordStart = (selectDirection == SelectDirection.RIGHT) ? start + length : start; // Find the start of the next word to the left if (wordStart > 0) { wordStart = CharUtils.findPriorWord(textInput.getCharacters(), wordStart); - if (isShiftPressed) { + if (mods.shiftPressed) { if (wordStart >= start) { // We've just reduced the previous right selection, so leave the anchor alone length = wordStart - start; @@ -1217,7 +1216,7 @@ public class TerraTextInputSkin extends start = wordStart; } - } else if (isShiftPressed) { + } else if (mods.shiftPressed) { // If the previous direction was LEFT, then increase the selection // else decrease the selection back to the anchor. if (selectDirection != null) { @@ -1287,13 +1286,13 @@ public class TerraTextInputSkin extends } else if (keyCode == KeyCode.RIGHT) { SelectDirection visiblePosition = SelectDirection.RIGHT; - if (Keyboard.isPressed(wordNavigationModifier)) { + if (mods.wordNavPressed) { int wordStart = (selectDirection == SelectDirection.LEFT) ? start : start + length; // Find the start of the next word to the right if (wordStart < textInput.getCharacterCount()) { wordStart = CharUtils.findNextWord(textInput.getCharacters(), wordStart); - if (isShiftPressed) { + if (mods.shiftPressed) { if (wordStart <= start + length) { // We've just reduced the previous left selection, so leave the anchor alone length -= wordStart - start; @@ -1316,7 +1315,7 @@ public class TerraTextInputSkin extends selectDirection = null; } } - } else if (isShiftPressed) { + } else if (mods.shiftPressed) { // If the previous direction was RIGHT, then increase the selection // else decrease the selection back to the anchor. if (selectDirection != null) { @@ -1439,8 +1438,7 @@ public class TerraTextInputSkin extends int start = textInput.getSelectionStart(); int length = textInput.getSelectionLength(); - boolean isMetaPressed = Keyboard.isPressed(Modifier.META); - boolean isShiftPressed = Keyboard.isPressed(Modifier.SHIFT); + Keyboard.Modifiers mods = Keyboard.pressed(); if (keyCode == KeyCode.DELETE && isEditable) { if (start < textInput.getCharacterCount()) { @@ -1457,8 +1455,8 @@ public class TerraTextInputSkin extends textInput.removeText(start, length); consumed = true; } - } else if (keyCode == KeyCode.HOME || (keyCode == KeyCode.LEFT && isMetaPressed)) { - if (isShiftPressed) { + } else if (keyCode == KeyCode.HOME || (keyCode == KeyCode.LEFT && mods.metaPressed)) { + if (mods.shiftPressed) { // Select from the beginning of the text to the current pivot position if (selectDirection == SelectDirection.LEFT) { textInput.setSelection(0, start + length); @@ -1475,10 +1473,10 @@ public class TerraTextInputSkin extends scrollCharacterToVisible(0); consumed = true; - } else if (keyCode == KeyCode.END || (keyCode == KeyCode.RIGHT && isMetaPressed)) { + } else if (keyCode == KeyCode.END || (keyCode == KeyCode.RIGHT && mods.metaPressed)) { int n = textInput.getCharacterCount(); - if (isShiftPressed) { + if (mods.shiftPressed) { // Select from current pivot position to the end of the text if (selectDirection == SelectDirection.LEFT) { start += length; @@ -1495,10 +1493,10 @@ public class TerraTextInputSkin extends consumed = true; } else if (keyCode == KeyCode.LEFT) { - consumed = handleLeftRightKeys(textInput, keyCode, isShiftPressed, start, length); + consumed = handleLeftRightKeys(textInput, keyCode, mods, start, length); } else if (keyCode == KeyCode.RIGHT) { - consumed = handleLeftRightKeys(textInput, keyCode, isShiftPressed, start, length); - } else if (Keyboard.isPressed(Platform.getCommandModifier())) { + consumed = handleLeftRightKeys(textInput, keyCode, mods, start, length); + } else if (mods.cmdPressed) { if (keyCode == KeyCode.A) { textInput.setSelection(0, textInput.getCharacterCount()); consumed = true; @@ -1522,14 +1520,14 @@ public class TerraTextInputSkin extends textInput.paste(); consumed = true; } else if (keyCode == KeyCode.Z && isEditable) { - if (!isShiftPressed) { + if (!mods.shiftPressed) { textInput.undo(); } consumed = true; } } else if (keyCode == KeyCode.INSERT) { - if (isShiftPressed && isEditable) { + if (mods.shiftPressed && isEditable) { textInput.paste(); consumed = true; } Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Button.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Button.java?rev=1913476&r1=1913475&r2=1913476&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/Button.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Button.java Wed Nov 1 02:16:53 2023 @@ -145,11 +145,8 @@ public abstract class Button extends Com private DataRenderer dataRenderer = null; private Action action = null; - private ActionListener actionListener = new ActionListener() { - @Override - public void enabledChanged(Action actionArgument) { - setEnabled(actionArgument.isEnabled()); - } + private ActionListener actionListener = (buttonAction) -> { + setEnabled(buttonAction.isEnabled()); }; private State state = State.UNSELECTED; 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=1913476&r1=1913475&r2=1913476&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/Keyboard.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Keyboard.java Wed Nov 1 02:16:53 2023 @@ -16,9 +16,12 @@ */ package org.apache.pivot.wtk; -import static java.awt.event.InputEvent.*; -import java.awt.event.KeyEvent; +import static java.awt.event.InputEvent.ALT_DOWN_MASK; +import static java.awt.event.InputEvent.CTRL_DOWN_MASK; +import static java.awt.event.InputEvent.META_DOWN_MASK; +import static java.awt.event.InputEvent.SHIFT_DOWN_MASK; import static java.awt.event.KeyEvent.*; +import java.awt.event.KeyEvent; import java.lang.reflect.Field; import java.util.Locale; import java.util.regex.Matcher; @@ -182,6 +185,24 @@ public final class Keyboard { } /** + * A tuple class to return in one swoop the current set of modifiers being pressed. + */ + public static class Modifiers { + /** Is the platform-specified {@code Cmd} key pressed? */ + public boolean cmdPressed; + /** Is the platform-specific word navigation key pressed? */ + public boolean wordNavPressed; + /** Is the {@link Modifier#SHIFT} key pressed? */ + public boolean shiftPressed; + /** Is the {@link Modifier#CTRL} key pressed? */ + public boolean ctrlPressed; + /** Is the {@link Modifier#ALT} key pressed? */ + public boolean altPressed; + /** Is the {@link Modifier#META} key prssed? */ + public boolean metaPressed; + } + + /** * Enumeration representing key locations. */ public enum KeyLocation { @@ -595,6 +616,38 @@ public final class Keyboard { } /** + * Shortcut method to test if the {@link Platform#getWordNavigationModifier} is pressed. + * + * @return The result of {@code isPressed(Platform.getWordNavigationModifier())}. + */ + public static boolean isWordNavPressed() { + return isPressed(Platform.getWordNavigationModifier()); + } + + /** + * Return a standardized set of flags to say which modifiers are currently pressed. + * <p> This is for convenience in keypress handlers that typically need to know all + * these states, and have to deal with the platform differences as well. So, + * consolidate that logic here for "one-stop shopping". + * + * @return The platform-specific set of flags as to which modifiers are currently + * pressed by the user. + */ + public static Modifiers pressed() { + Modifiers mods = new Modifiers(); + + mods.cmdPressed = isCmdPressed(); + mods.wordNavPressed = isWordNavPressed(); + + mods.shiftPressed = isPressed(Modifier.SHIFT); + mods.ctrlPressed = isPressed(Modifier.CTRL); + mods.altPressed = isPressed(Modifier.ALT); + mods.metaPressed = isPressed(Modifier.META); + + return mods; + } + + /** * Returns the current drop action. * * @return The drop action corresponding to the currently pressed modifier keys. Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java?rev=1913476&r1=1913475&r2=1913476&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java Wed Nov 1 02:16:53 2023 @@ -41,14 +41,14 @@ public class TextInput extends Component * * @param x The X-position (of the mouse probably). */ - public int getInsertionPoint(int x); + int getInsertionPoint(int x); /** * @return The bounds of the character at a given index. * * @param index The location to check. */ - public Bounds getCharacterBounds(int index); + Bounds getCharacterBounds(int index); } /** @@ -62,7 +62,7 @@ public class TextInput extends Component * @param value The value retrieved from the bound object. * @return A text representation of this value for display. */ - public String toString(Object value); + String toString(Object value); /** * Converts a text string to a value to be stored in the bind context @@ -71,14 +71,14 @@ public class TextInput extends Component * @param text The current text from the control. * @return A value suitable for storage in the bound object. */ - public Object valueOf(String text); + Object valueOf(String text); } /** * Interface for a text operation that can be undone. */ private interface Edit { - public void undo(); + void undo(); } /** @@ -88,8 +88,8 @@ public class TextInput extends Component private final int index; private final int count; - public InsertTextEdit(final CharSequence text, final int index) { - this.index = index; + InsertTextEdit(final CharSequence text, final int insertIndex) { + this.index = insertIndex; count = text.length(); } @@ -106,9 +106,9 @@ public class TextInput extends Component private final int index; private final String text; - public RemoveTextEdit(final int index, final int count) { - this.index = index; - text = getText(index, index + count); + RemoveTextEdit(final int removeIndex, final int count) { + this.index = removeIndex; + text = getText(removeIndex, removeIndex + count); } @Override @@ -181,17 +181,17 @@ public class TextInput extends Component } public void setText(final String text) { - setText(text); + setText((CharSequence) text); } - public void setText(final CharSequence text) { - Utils.checkNull(text, "text"); + public void setText(final CharSequence newText) { + CharSequence text = newText; - if (text.length() > maximumLength) { - throw new IllegalArgumentException("Text length is greater than maximum length."); - } + Utils.checkNull(text, "text"); + Utils.checkTextMaximumLength(-1, text.length(), maximumLength); - characters = new StringBuilder(text); + characters.setLength(0); + characters.append(text); // Update selection int previousSelectionStart = selectionStart; @@ -222,12 +222,11 @@ public class TextInput extends Component insertText(text, index, true); } - private void insertText(final CharSequence text, final int index, final boolean addToEditHistory) { - Utils.checkNull(text, "text"); + private void insertText(final CharSequence newText, final int index, final boolean addToEditHistory) { + Utils.checkNull(newText, "text"); + Utils.checkTextMaximumLength(characters.length(), newText.length(), maximumLength); - if (characters.length() + text.length() > maximumLength) { - throw new IllegalArgumentException("Insertion of text would exceed maximum length."); - } + CharSequence text = newText; if (text.length() > 0) { Vote vote = textInputContentListeners.previewInsertText(this, text, index); @@ -335,11 +334,11 @@ public class TextInput extends Component * composed text (that is, the text currently being composed into something * meaningful). * - * @param composedText The current composed text (which can be {@code null} + * @param currentComposedText The current composed text (which can be {@code null} * for many different reasons). */ - public void setComposedText(final AttributedStringCharacterIterator composedText) { - this.composedText = composedText; + public void setComposedText(final AttributedStringCharacterIterator currentComposedText) { + this.composedText = currentComposedText; } /** @@ -468,23 +467,24 @@ public class TextInput extends Component * Sets the selection. The sum of the selection start and length must be * less than the length of the text input's content. * - * @param selectionStart The starting index of the selection. - * @param selectionLength The length of the selection. + * @param newStart The starting index of the selection. + * @param newLength The length of the selection. */ - public final void setSelection(final int selectionStart, final int selectionLength) { - Utils.checkNonNegative(selectionLength, "selectionLength"); + public final void setSelection(final int newStart, final int newLength) { + int start = newStart; + int length = newLength; + + Utils.checkNonNegative(length, "selectionLength"); int composedTextLength = composedText != null ? (composedText.getEndIndex() - composedText.getBeginIndex()) : 0; - if (selectionStart < 0 || selectionStart + selectionLength > characters.length() + composedTextLength) { - throw new IndexOutOfBoundsException("Selection value is out of bounds."); - } + Utils.checkIndexBounds(start, length, 0, characters.length() + composedTextLength); - int previousSelectionStart = this.selectionStart; - int previousSelectionLength = this.selectionLength; + int previousSelectionStart = selectionStart; + int previousSelectionLength = selectionLength; - if (previousSelectionStart != selectionStart || previousSelectionLength != selectionLength) { - this.selectionStart = selectionStart; - this.selectionLength = selectionLength; + if (previousSelectionStart != start || previousSelectionLength != length) { + selectionStart = start; + selectionLength = length; textInputSelectionListeners.selectionChanged(this, previousSelectionStart, previousSelectionLength); @@ -552,16 +552,16 @@ public class TextInput extends Component /** * Sets the text size. * - * @param textSize The number of characters to display in the text input. + * @param textSizeValue The number of characters to display in the text input. * @throws IllegalArgumentException if the size value is negative. */ - public final void setTextSize(final int textSize) { - Utils.checkNonNegative(textSize, "textSize"); + public final void setTextSize(final int textSizeValue) { + Utils.checkNonNegative(textSizeValue, "textSize"); - int previousTextSize = this.textSize; + int previousTextSize = textSize; - if (previousTextSize != textSize) { - this.textSize = textSize; + if (previousTextSize != textSizeValue) { + textSize = textSizeValue; textInputListeners.textSizeChanged(this, previousTextSize); } } @@ -578,16 +578,16 @@ public class TextInput extends Component /** * Sets the maximum length of the text input's text content. * - * @param maximumLength The maximum length of the text input's text content. + * @param newMaximumLength The maximum length of the text input's text content. * @throws IllegalArgumentException if the length value is negative. */ - public final void setMaximumLength(final int maximumLength) { - Utils.checkNonNegative(maximumLength, "maximumLength"); + public final void setMaximumLength(final int newMaximumLength) { + Utils.checkNonNegative(newMaximumLength, "maximumLength"); - int previousMaximumLength = this.maximumLength; + int previousMaximumLength = maximumLength; - if (previousMaximumLength != maximumLength) { - this.maximumLength = maximumLength; + if (previousMaximumLength != newMaximumLength) { + maximumLength = newMaximumLength; // Truncate the text, if necessary (do not allow listeners to vote on this change) int length = characters.length(); @@ -617,12 +617,12 @@ public class TextInput extends Component * Sets or clears the password flag. If the password flag is set, the text * input will visually mask its contents. * - * @param password {@code true} if this is a password text input; + * @param passwordValue {@code true} if this is a password text input; * {@code false}, otherwise. */ - public final void setPassword(final boolean password) { - if (this.password != password) { - this.password = password; + public final void setPassword(final boolean passwordValue) { + if (password != passwordValue) { + password = passwordValue; textInputListeners.passwordChanged(this); } } @@ -637,13 +637,13 @@ public class TextInput extends Component /** * Sets the text input's prompt. * - * @param prompt The prompt text, or {@code null} for no prompt. + * @param promptText The prompt text, or {@code null} for no prompt. */ - public final void setPrompt(final String prompt) { - String previousPrompt = this.prompt; + public final void setPrompt(final String promptText) { + String previousPrompt = prompt; - if (previousPrompt != prompt) { - this.prompt = prompt; + if (previousPrompt != promptText) { + prompt = promptText; textInputListeners.promptChanged(this, previousPrompt); } } @@ -660,13 +660,13 @@ public class TextInput extends Component /** * Sets the text input's text key. * - * @param textKey The text key, or {@code null} to clear the binding. + * @param newTextKey The text key, or {@code null} to clear the binding. */ - public final void setTextKey(final String textKey) { - String previousTextKey = this.textKey; + public final void setTextKey(final String newTextKey) { + String previousTextKey = textKey; - if (previousTextKey != textKey) { - this.textKey = textKey; + if (previousTextKey != newTextKey) { + textKey = newTextKey; textInputBindingListeners.textKeyChanged(this, previousTextKey); } } @@ -675,13 +675,13 @@ public class TextInput extends Component return textBindType; } - public final void setTextBindType(final BindType textBindType) { - Utils.checkNull(textBindType, "textBindType"); + public final void setTextBindType(final BindType newTextBindType) { + Utils.checkNull(newTextBindType, "textBindType"); - BindType previousTextBindType = this.textBindType; + BindType previousTextBindType = textBindType; - if (previousTextBindType != textBindType) { - this.textBindType = textBindType; + if (previousTextBindType != newTextBindType) { + textBindType = newTextBindType; textInputBindingListeners.textBindTypeChanged(this, previousTextBindType); } } @@ -690,11 +690,11 @@ public class TextInput extends Component return textBindMapping; } - public final void setTextBindMapping(final TextBindMapping textBindMapping) { - TextBindMapping previousTextBindMapping = this.textBindMapping; + public final void setTextBindMapping(final TextBindMapping newTextBindMapping) { + TextBindMapping previousTextBindMapping = textBindMapping; - if (previousTextBindMapping != textBindMapping) { - this.textBindMapping = textBindMapping; + if (previousTextBindMapping != newTextBindMapping) { + textBindMapping = newTextBindMapping; textInputBindingListeners.textBindMappingChanged(this, previousTextBindMapping); } } @@ -750,14 +750,14 @@ public class TextInput extends Component /** * Sets the validator associated with this text input. * - * @param validator The validator to use, or {@code null} to use no + * @param newValidator The validator to use, or {@code null} to use no * validator. */ - public final void setValidator(final Validator validator) { + public final void setValidator(final Validator newValidator) { Validator previousValidator = this.validator; - if (validator != previousValidator) { - this.validator = validator; + if (newValidator != previousValidator) { + this.validator = newValidator; // Store previous text valid flag boolean previousTextValid = textValid; @@ -785,11 +785,11 @@ public class TextInput extends Component * Sets the text input's strict validation flag. When enabled, only valid * text will be accepted by the text input. * - * @param strictValidation The new flag setting. + * @param strictValidationValue The new flag setting. */ - public final void setStrictValidation(final boolean strictValidation) { - if (this.strictValidation != strictValidation) { - this.strictValidation = strictValidation; + public final void setStrictValidation(final boolean strictValidationValue) { + if (strictValidation != strictValidationValue) { + strictValidation = strictValidationValue; textInputListeners.strictValidationChanged(this); } } @@ -815,17 +815,17 @@ public class TextInput extends Component /** * Sets the text area's editable flag. * - * @param editable The new flag setting. + * @param editableValue The new flag setting. */ - public final void setEditable(final boolean editable) { - if (this.editable != editable) { - if (!editable) { + public final void setEditable(final boolean editableValue) { + if (editable != editableValue) { + if (!editableValue) { if (isFocused()) { clearFocus(); } } - this.editable = editable; + editable = editableValue; textInputListeners.editableChanged(this); } Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInputListener.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInputListener.java?rev=1913476&r1=1913475&r2=1913476&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInputListener.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInputListener.java Wed Nov 1 02:16:53 2023 @@ -28,44 +28,44 @@ public interface TextInputListener { * @deprecated Since 2.1 and Java 8 the interface itself has default implementations. */ @Deprecated - public static class Adapter implements TextInputListener { + class Adapter implements TextInputListener { @Override - public void textSizeChanged(TextInput textInput, int previousTextSize) { + public void textSizeChanged(final TextInput textInput, final int previousTextSize) { // empty block } @Override - public void maximumLengthChanged(TextInput textInput, int previousMaximumLength) { + public void maximumLengthChanged(final TextInput textInput, final int previousMaximumLength) { // empty block } @Override - public void passwordChanged(TextInput textInput) { + public void passwordChanged(final TextInput textInput) { // empty block } @Override - public void promptChanged(TextInput textInput, String previousPrompt) { + public void promptChanged(final TextInput textInput, final String previousPrompt) { // empty block } @Override - public void textValidatorChanged(TextInput textInput, Validator previousValidator) { + public void textValidatorChanged(final TextInput textInput, final Validator previousValidator) { // empty block } @Override - public void strictValidationChanged(TextInput textInput) { + public void strictValidationChanged(final TextInput textInput) { // empty block } @Override - public void textValidChanged(TextInput textInput) { + public void textValidChanged(final TextInput textInput) { // empty block } @Override - public void editableChanged(TextInput textInput) { + public void editableChanged(final TextInput textInput) { // empty block } } @@ -73,44 +73,44 @@ public interface TextInputListener { /** * Text input listener listeners list. */ - public static class Listeners extends ListenerList<TextInputListener> implements TextInputListener { + class Listeners extends ListenerList<TextInputListener> implements TextInputListener { @Override - public void textSizeChanged(TextInput textInput, int previousTextSize) { + public void textSizeChanged(final TextInput textInput, final int previousTextSize) { forEach(listener -> listener.textSizeChanged(textInput, previousTextSize)); } @Override - public void maximumLengthChanged(TextInput textInput, int previousMaximumLength) { + public void maximumLengthChanged(final TextInput textInput, final int previousMaximumLength) { forEach(listener -> listener.maximumLengthChanged(textInput, previousMaximumLength)); } @Override - public void passwordChanged(TextInput textInput) { + public void passwordChanged(final TextInput textInput) { forEach(listener -> listener.passwordChanged(textInput)); } @Override - public void promptChanged(TextInput textInput, String previousPrompt) { + public void promptChanged(final TextInput textInput, final String previousPrompt) { forEach(listener -> listener.promptChanged(textInput, previousPrompt)); } @Override - public void textValidatorChanged(TextInput textInput, Validator previousValidator) { + public void textValidatorChanged(final TextInput textInput, final Validator previousValidator) { forEach(listener -> listener.textValidatorChanged(textInput, previousValidator)); } @Override - public void strictValidationChanged(TextInput textInput) { + public void strictValidationChanged(final TextInput textInput) { forEach(listener -> listener.strictValidationChanged(textInput)); } @Override - public void textValidChanged(TextInput textInput) { + public void textValidChanged(final TextInput textInput) { forEach(listener -> listener.textValidChanged(textInput)); } @Override - public void editableChanged(TextInput textInput) { + public void editableChanged(final TextInput textInput) { forEach(listener -> listener.editableChanged(textInput)); } } @@ -121,7 +121,7 @@ public interface TextInputListener { * @param textInput The source of this event. * @param previousTextSize The previous text size for the control */ - default void textSizeChanged(TextInput textInput, int previousTextSize) { + default void textSizeChanged(final TextInput textInput, final int previousTextSize) { } /** @@ -130,7 +130,7 @@ public interface TextInputListener { * @param textInput The source of this event. * @param previousMaximumLength The previous maximum text length. */ - default void maximumLengthChanged(TextInput textInput, int previousMaximumLength) { + default void maximumLengthChanged(final TextInput textInput, final int previousMaximumLength) { } /** @@ -138,7 +138,7 @@ public interface TextInputListener { * * @param textInput The source of this event. */ - default void passwordChanged(TextInput textInput) { + default void passwordChanged(final TextInput textInput) { } /** @@ -147,7 +147,7 @@ public interface TextInputListener { * @param textInput The source of this event. * @param previousPrompt The previous prompt string. */ - default void promptChanged(TextInput textInput, String previousPrompt) { + default void promptChanged(final TextInput textInput, final String previousPrompt) { } /** @@ -156,7 +156,7 @@ public interface TextInputListener { * @param textInput The source of this event. * @param previousValidator The previous validator for the text. */ - default void textValidatorChanged(TextInput textInput, Validator previousValidator) { + default void textValidatorChanged(final TextInput textInput, final Validator previousValidator) { } /** @@ -164,7 +164,7 @@ public interface TextInputListener { * * @param textInput The text input that has changed. */ - default void strictValidationChanged(TextInput textInput) { + default void strictValidationChanged(final TextInput textInput) { } /** @@ -172,7 +172,7 @@ public interface TextInputListener { * * @param textInput The text input that has been changed. */ - default void textValidChanged(TextInput textInput) { + default void textValidChanged(final TextInput textInput) { } /** @@ -180,7 +180,7 @@ public interface TextInputListener { * * @param textInput The text input whose state has changed. */ - default void editableChanged(TextInput textInput) { + default void editableChanged(final TextInput textInput) { } } Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/DisplaySkin.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/DisplaySkin.java?rev=1913476&r1=1913475&r2=1913476&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/DisplaySkin.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/DisplaySkin.java Wed Nov 1 02:16:53 2023 @@ -35,6 +35,9 @@ public class DisplaySkin extends Contain setBackgroundColor(Color.LIGHT_GRAY); } + /** + * {@inheritDoc} + */ @Override public void install(final Component component) { if (!(component instanceof Display)) { @@ -45,6 +48,9 @@ public class DisplaySkin extends Contain super.install(component); } + /** + * {@inheritDoc} + */ @Override public void layout() { Display display = (Display) getComponent(); Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkin.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkin.java?rev=1913476&r1=1913475&r2=1913476&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkin.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkin.java Wed Nov 1 02:16:53 2023 @@ -1071,6 +1071,73 @@ org.apache.pivot.util.Console.getDefault return consumed; } + private boolean navigateHome(final TextPane textPane, final Document document, + final boolean commandPressed, final boolean shiftPressed) { + int selectionStart = textPane.getSelectionStart(); + int selectionLength = textPane.getSelectionLength(); + + int start; + if (commandPressed) { + // Move the caret to the beginning of the text + start = 0; + } else { + // Move the caret to the beginning of the line + start = getRowOffset(document, selectionStart); + } + + if (shiftPressed) { + // TODO: if last direction was left, then extend further left + // but if right, then reverse selection from the pivot point + selectionLength += selectionStart - start; + } else { + selectionLength = 0; + } + + if (start >= 0) { + textPane.setSelection(start, selectionLength); + scrollCharacterToVisible(start); + return true; + } + + return false; + } + + private boolean navigateEnd(final TextPane textPane, final Document document, + final boolean commandPressed, final boolean shiftPressed) { + int selectionStart = textPane.getSelectionStart(); + int selectionLength = textPane.getSelectionLength(); + + int end; + int index = selectionStart + selectionLength; + + if (commandPressed) { + // Move the caret to end of the text + end = textPane.getCharacterCount() - 1; + } else { + // Move the caret to the end of the line + int rowOffset = getRowOffset(document, index); + int rowLength = getRowLength(document, index); + end = rowOffset + rowLength; + } + + if (shiftPressed) { + // TODO: if last direction was right, then extend further right + // but if left, then reverse selection from the pivot point + selectionLength += end - index; + } else { + selectionStart = end; + selectionLength = 0; + } + + if (selectionStart + selectionLength <= textPane.getCharacterCount()) { + textPane.setSelection(selectionStart, selectionLength); + scrollCharacterToVisible(selectionStart + selectionLength); + return true; + } + + return false; + } + @Override public boolean keyPressed(final Component component, final int keyCode, final Keyboard.KeyLocation keyLocation) { @@ -1097,57 +1164,10 @@ org.apache.pivot.util.Console.getDefault consumed = commandKey(textPane, document, keyCode, isEditable, shiftPressed); } else if (keyCode == Keyboard.KeyCode.HOME || (keyCode == Keyboard.KeyCode.LEFT && metaPressed)) { - int start; - if (commandPressed) { - // Move the caret to the beginning of the text - start = 0; - } else { - // Move the caret to the beginning of the line - start = getRowOffset(document, selectionStart); - } - - if (shiftPressed) { - // TODO: if last direction was left, then extend further left - // but if right, then reverse selection from the pivot point - selectionLength += selectionStart - start; - } else { - selectionLength = 0; - } - - if (start >= 0) { - textPane.setSelection(start, selectionLength); - scrollCharacterToVisible(start); - consumed = true; - } + consumed = navigateHome(textPane, document, commandPressed, shiftPressed); } else if (keyCode == Keyboard.KeyCode.END || (keyCode == Keyboard.KeyCode.RIGHT && metaPressed)) { - int end; - int index = selectionStart + selectionLength; - - if (commandPressed) { - // Move the caret to end of the text - end = textPane.getCharacterCount() - 1; - } else { - // Move the caret to the end of the line - int rowOffset = getRowOffset(document, index); - int rowLength = getRowLength(document, index); - end = rowOffset + rowLength; - } - - if (shiftPressed) { - // TODO: if last direction was right, then extend further right - // but if left, then reverse selection from the pivot point - selectionLength += end - index; - } else { - selectionStart = end; - selectionLength = 0; - } - - if (selectionStart + selectionLength <= textPane.getCharacterCount()) { - textPane.setSelection(selectionStart, selectionLength); - scrollCharacterToVisible(selectionStart + selectionLength); - consumed = true; - } + consumed = navigateEnd(textPane, document, commandPressed, shiftPressed); } else if (keyCode == Keyboard.KeyCode.LEFT) { if (wordNavPressed) { // Move the caret to the start of the next word to our left Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinListItemView.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinListItemView.java?rev=1913476&r1=1913475&r2=1913476&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinListItemView.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinListItemView.java Wed Nov 1 02:16:53 2023 @@ -21,15 +21,26 @@ import java.util.Iterator; import org.apache.pivot.wtk.text.List; import org.apache.pivot.wtk.text.TextNode; +/** + * View (which includes layout) for list items inside a <code>TextPane</code>. + */ class TextPaneSkinListItemView extends TextPaneSkinVerticalElementView { + /** The included text node for the index for this list item. */ private TextNode indexTextNode; + /** The view for the index text node. */ private TextPaneSkinTextNodeView indexTextNodeView; - public TextPaneSkinListItemView(TextPaneSkin textPaneSkin, List.Item listItem) { + /** + * Construct one of these from the model references. + * + * @param textPaneSkin Skin of the entire <code>TextPane</code> component. + * @param listItem The list item we represent, which has the data to layout and display. + */ + TextPaneSkinListItemView(final TextPaneSkin textPaneSkin, final List.Item listItem) { super(textPaneSkin, listItem); - this.indexTextNode = new TextNode(""); + indexTextNode = new TextNode(""); } @Override @@ -42,13 +53,18 @@ class TextPaneSkinListItemView extends T insert(indexTextNodeView, 0); } - public void setIndexText(String indexText) { + /** + * Set the text for this item's index. + * + * @param indexText The new text for this item's index. + */ + public void setIndexText(final String indexText) { indexTextNode.setText(indexText); indexTextNodeView.invalidateUpTree(); } @Override - protected void childLayout(int breakWidth) { + protected void childLayout(final int breakWidth) { int bw = breakWidth; indexTextNodeView.layout(bw); @@ -76,6 +92,11 @@ class TextPaneSkinListItemView extends T setSize(width, height); } + /** + * Calculate and return the width of our index text. + * + * @return Width of our index text. + */ public int getIndexTextWidth() { return indexTextNodeView.getWidth(); } Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinNumberedListView.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinNumberedListView.java?rev=1913476&r1=1913475&r2=1913476&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinNumberedListView.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinNumberedListView.java Wed Nov 1 02:16:53 2023 @@ -22,15 +22,18 @@ import org.apache.pivot.wtk.text.Numbere import org.apache.pivot.wtk.text.NumberedList.Style; import org.apache.pivot.wtk.text.NumberedListListener; +/** + * Skin implementation of the {@link NumberedList} elements. + */ class TextPaneSkinNumberedListView extends TextPaneSkinListView implements NumberedListListener { private static class RomanValue { public final int integerVal; public final String romanNumeral; - public RomanValue(int integerVal, String romanNumeral) { - this.integerVal = integerVal; - this.romanNumeral = romanNumeral; + public RomanValue(final int intVal, final String roman) { + integerVal = intVal; + romanNumeral = roman; } } @@ -50,7 +53,7 @@ class TextPaneSkinNumberedListView exten new RomanValue(1, "I") }; - private static String int2roman(int n) { + private static String int2roman(final int n) { int num = n; StringBuffer result = new StringBuffer(10); @@ -65,8 +68,8 @@ class TextPaneSkinNumberedListView exten return result.toString(); } - private static String int2alpha(int n) { - return (char) ('A' + n - 1) + ""; + private static String int2alpha(final int n) { + return Character.toString((char) (n - 1 + 'A')); } public TextPaneSkinNumberedListView(TextPaneSkin textPaneSkin, NumberedList numberedList) {