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 2021/04/30 21:53:25 UTC
svn commit: r1889343 - in /pivot/trunk:
charts/src/org/apache/pivot/charts/content/
core/src/org/apache/pivot/collections/
core/src/org/apache/pivot/collections/concurrent/
core/src/org/apache/pivot/functional/monad/ core/src/org/apache/pivot/util/
cor...
Author: rwhitcomb
Date: Fri Apr 30 21:53:24 2021
New Revision: 1889343
URL: http://svn.apache.org/viewvc?rev=1889343&view=rev
Log:
PIVOT-1032: Fix as many of the "checkstyle" problems in these files as possible.
Modified:
pivot/trunk/charts/src/org/apache/pivot/charts/content/Interval.java
pivot/trunk/charts/src/org/apache/pivot/charts/content/Point.java
pivot/trunk/core/src/org/apache/pivot/collections/EnumList.java
pivot/trunk/core/src/org/apache/pivot/collections/concurrent/SynchronizedSet.java
pivot/trunk/core/src/org/apache/pivot/functional/monad/TryCompanion.java
pivot/trunk/core/src/org/apache/pivot/util/StringUtils.java
pivot/trunk/core/test/org/apache/pivot/util/test/ImmutableIteratorTest.java
pivot/trunk/core/test/org/apache/pivot/util/test/MIMETypeTest.java
pivot/trunk/core/test/org/apache/pivot/util/test/StringUtilsTest.java
pivot/trunk/core/test/org/apache/pivot/util/test/VoteResultTest.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/effects/Transition.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ComponentSkin.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/DisplaySkin.java
Modified: pivot/trunk/charts/src/org/apache/pivot/charts/content/Interval.java
URL: http://svn.apache.org/viewvc/pivot/trunk/charts/src/org/apache/pivot/charts/content/Interval.java?rev=1889343&r1=1889342&r2=1889343&view=diff
==============================================================================
--- pivot/trunk/charts/src/org/apache/pivot/charts/content/Interval.java (original)
+++ pivot/trunk/charts/src/org/apache/pivot/charts/content/Interval.java Fri Apr 30 21:53:24 2021
@@ -20,13 +20,23 @@ package org.apache.pivot.charts.content;
* Represents value data for interval chart views.
*/
public class Interval extends Point {
+ /**
+ * The interval data.
+ */
private float width = 0;
+ /**
+ * @return The data value.
+ */
public float getWidth() {
return width;
}
- public void setWidth(float width) {
- this.width = width;
+ /**
+ * Set the data value.
+ * @param newWidth The new data value.
+ */
+ public void setWidth(final float newWidth) {
+ width = newWidth;
}
}
Modified: pivot/trunk/charts/src/org/apache/pivot/charts/content/Point.java
URL: http://svn.apache.org/viewvc/pivot/trunk/charts/src/org/apache/pivot/charts/content/Point.java?rev=1889343&r1=1889342&r2=1889343&view=diff
==============================================================================
--- pivot/trunk/charts/src/org/apache/pivot/charts/content/Point.java (original)
+++ pivot/trunk/charts/src/org/apache/pivot/charts/content/Point.java Fri Apr 30 21:53:24 2021
@@ -17,25 +17,45 @@
package org.apache.pivot.charts.content;
/**
- * Represents value data for x/y chart views.
+ * Represents value data for X/Y chart views.
*/
public class Point {
+ /**
+ * The X-position data.
+ */
private float x = 0;
+ /**
+ * The Y-position data.
+ */
private float y = 0;
+ /**
+ * @return The X-position data.
+ */
public float getX() {
return x;
}
- public void setX(float x) {
- this.x = x;
+ /**
+ * Set the X-position data.
+ * @param xValue The X-position value.
+ */
+ public void setX(final float xValue) {
+ x = xValue;
}
+ /**
+ * @return The Y-position data.
+ */
public float getY() {
return y;
}
- public void setY(float y) {
- this.y = y;
+ /**
+ * Set the Y-position data.
+ * @param yValue The Y-position value.
+ */
+ public void setY(final float yValue) {
+ y = yValue;
}
}
Modified: pivot/trunk/core/src/org/apache/pivot/collections/EnumList.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/collections/EnumList.java?rev=1889343&r1=1889342&r2=1889343&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/collections/EnumList.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/collections/EnumList.java Fri Apr 30 21:53:24 2021
@@ -24,6 +24,7 @@ import java.util.NoSuchElementException;
import org.apache.pivot.annotations.UnsupportedOperation;
import org.apache.pivot.util.ListenerList;
+import org.apache.pivot.util.StringUtils;
import org.apache.pivot.util.Utils;
/**
@@ -41,7 +42,11 @@ import org.apache.pivot.util.Utils;
public class EnumList<E extends Enum<E>> extends ReadOnlySequence<E> implements List<E>, Serializable {
private static final long serialVersionUID = 5104856822133576300L;
+ /**
+ * Iterator over the list items.
+ */
private class ItemIterator implements Iterator<E> {
+ /** Index into the array of elements. */
private int i = 0;
@Override
@@ -65,21 +70,36 @@ public class EnumList<E extends Enum<E>>
}
}
+
+ /**
+ * The enum class of the elements.
+ */
private Class<E> enumClass;
+ /**
+ * The set items.
+ */
private E[] items;
+ /**
+ * The listeners for changes in this set (which will never actually get called,
+ * since the set never changes).
+ */
private transient ListListenerList<E> listListeners = new ListListenerList<>();
+
/**
* Construct the full list populated by the enum constants of the given class.
*
- * @param enumClass The enum class whose constant values are used to fully populate the list.
+ * @param enumClassValue The enum class whose constant values are used to fully populate the list.
*/
- public EnumList(final Class<E> enumClass) {
- this.enumClass = enumClass;
+ public EnumList(final Class<E> enumClassValue) {
+ enumClass = enumClassValue;
items = enumClass.getEnumConstants();
}
+ /**
+ * @return The class of the elements in this set.
+ */
public Class<E> getEnumClass() {
return enumClass;
}
@@ -112,6 +132,9 @@ public class EnumList<E extends Enum<E>>
return items.length;
}
+ /**
+ * @return An array of the elements in this set.
+ */
public E[] toArray() {
return Arrays.copyOf(items, items.length);
}
@@ -149,22 +172,8 @@ public class EnumList<E extends Enum<E>>
@Override
public String toString() {
- StringBuilder sb = new StringBuilder();
-
- sb.append(getClass().getName());
- sb.append(" [");
-
- for (int i = 0; i < items.length; i++) {
- if (i > 0) {
- sb.append(", ");
- }
-
- sb.append(items[i]);
- }
-
- sb.append("]");
-
- return sb.toString();
+ StringBuilder sb = new StringBuilder(getClass().getName());
+ return StringUtils.append(sb, items).toString();
}
@Override
Modified: pivot/trunk/core/src/org/apache/pivot/collections/concurrent/SynchronizedSet.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/collections/concurrent/SynchronizedSet.java?rev=1889343&r1=1889342&r2=1889343&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/collections/concurrent/SynchronizedSet.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/collections/concurrent/SynchronizedSet.java Fri Apr 30 21:53:24 2021
@@ -27,51 +27,70 @@ import org.apache.pivot.util.Utils;
/**
* Synchronized implementation of the {@link Set} interface.
+ *
+ * @param <E> Type of element contained in this set.
*/
public class SynchronizedSet<E> implements Set<E> {
+ /**
+ * A synchronized wrapper around {@link SetListener.Listeners}.
+ *
+ * @param <E> The type of element stored in the set.
+ */
private static class SynchronizedSetListenerList<E> extends SetListener.Listeners<E> {
@Override
- public synchronized void add(SetListener<E> listener) {
+ public synchronized void add(final SetListener<E> listener) {
super.add(listener);
}
@Override
- public synchronized void remove(SetListener<E> listener) {
+ public synchronized void remove(final SetListener<E> listener) {
super.remove(listener);
}
@Override
- public synchronized void elementAdded(Set<E> set, E element) {
+ public synchronized void elementAdded(final Set<E> set, final E element) {
super.elementAdded(set, element);
}
@Override
- public synchronized void elementRemoved(Set<E> set, E element) {
+ public synchronized void elementRemoved(final Set<E> set, final E element) {
super.elementRemoved(set, element);
}
@Override
- public synchronized void setCleared(Set<E> set) {
+ public synchronized void setCleared(final Set<E> set) {
super.setCleared(set);
}
@Override
- public synchronized void comparatorChanged(Set<E> set, Comparator<E> previousComparator) {
+ public synchronized void comparatorChanged(final Set<E> set, final Comparator<E> previousComparator) {
super.comparatorChanged(set, previousComparator);
}
}
+ /**
+ * The underlying set we are wrapping.
+ */
private Set<E> set;
+ /**
+ * The synchronized listeners on this set.
+ */
private SynchronizedSetListenerList<E> setListeners = new SynchronizedSetListenerList<>();
- public SynchronizedSet(Set<E> set) {
- Utils.checkNull(set, "set");
+ /**
+ * Wrap the given set with this synchronized version.
+ *
+ * @param wrappedSet The unsynchronized set to be wrapped by this one.
+ * @throws IllegalArgumentException if the given set is {@code null}.
+ */
+ public SynchronizedSet(final Set<E> wrappedSet) {
+ Utils.checkNull(wrappedSet, "set");
- this.set = set;
+ set = wrappedSet;
}
@Override
- public synchronized boolean add(E element) {
+ public synchronized boolean add(final E element) {
boolean added = false;
if (!contains(element)) {
@@ -85,7 +104,7 @@ public class SynchronizedSet<E> implemen
}
@Override
- public synchronized boolean remove(E element) {
+ public synchronized boolean remove(final E element) {
boolean removed = false;
if (contains(element)) {
@@ -99,7 +118,7 @@ public class SynchronizedSet<E> implemen
}
@Override
- public synchronized boolean contains(E element) {
+ public synchronized boolean contains(final E element) {
return set.contains(element);
}
@@ -127,7 +146,7 @@ public class SynchronizedSet<E> implemen
}
@Override
- public synchronized void setComparator(Comparator<E> comparator) {
+ public synchronized void setComparator(final Comparator<E> comparator) {
Comparator<E> previousComparator = getComparator();
set.setComparator(comparator);
setListeners.comparatorChanged(this, previousComparator);
Modified: pivot/trunk/core/src/org/apache/pivot/functional/monad/TryCompanion.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/functional/monad/TryCompanion.java?rev=1889343&r1=1889342&r2=1889343&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/functional/monad/TryCompanion.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/functional/monad/TryCompanion.java Fri Apr 30 21:53:24 2021
@@ -25,6 +25,9 @@ import java.util.Objects;
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public final class TryCompanion<T> {
+ /**
+ * The singleton (static) instance.
+ */
private static final TryCompanion INSTANCE = new TryCompanion<>();
/**
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=1889343&r1=1889342&r2=1889343&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/util/StringUtils.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/util/StringUtils.java Fri Apr 30 21:53:24 2021
@@ -21,17 +21,22 @@ import java.math.BigInteger;
/**
- * A set of static methods that perform various string manipulation
- * functions.
+ * A set of static methods that perform various string manipulation functions.
*/
public final class StringUtils {
+ /**
+ * Maximum length of string constructed by {@link #fromNChars} (arbitrary).
+ */
+ private static final int MAX_STRING_SIZE = Integer.MAX_VALUE >> 2;
+
+
/** Private constructor since this is a utility class. */
private StringUtils() {
}
/**
* Make a string the consists of "n" copies of the given character.
- * <p> Note: "n" must be positive and less than 512K (arbitrary).
+ * <p> Note: "n" must be positive and less than {@link #MAX_STRING_SIZE}.
*
* @param ch The character to copy.
* @param n The number of times to copy this character.
@@ -41,7 +46,7 @@ public final class StringUtils {
if (n == 0) {
return "";
}
- if (n < 0 || n > Integer.MAX_VALUE / 4) {
+ if (n < 0 || n > MAX_STRING_SIZE) {
throw new IllegalArgumentException("Requested string size " + n + " is out of range.");
}
@@ -217,6 +222,39 @@ public final class StringUtils {
}
sb.append(']');
+
+ return sb;
+ }
+
+ /**
+ * Given an array of items, construct a string representation of the array
+ * that looks like:
+ * <p><code>[<i>item1</i>, <i>item2</i>, ...]</code></p>
+ * appending the results to the given string builder for further use.
+ * <p> If the {@link StringBuilder} has any preceding text (that is, {@code length > 0})
+ * then append a blank before the list representation.
+ *
+ * @param <T> The type of items in the array.
+ * @param sb The {@link StringBuilder} already in progress.
+ * @param arr The array of items.
+ * @return The input {@code StringBuilder} for further use.
+ */
+ public static <T> StringBuilder append(final StringBuilder sb, final T[] arr) {
+ // Separate this text from any preceding text
+ if (sb.length() > 0) {
+ sb.append(' ');
+ }
+ sb.append('[');
+
+ for (int i = 0; i < arr.length; i++) {
+ if (i > 0) {
+ sb.append(", ");
+ }
+
+ sb.append(arr[i]);
+ }
+
+ sb.append(']');
return sb;
}
Modified: pivot/trunk/core/test/org/apache/pivot/util/test/ImmutableIteratorTest.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/test/org/apache/pivot/util/test/ImmutableIteratorTest.java?rev=1889343&r1=1889342&r2=1889343&view=diff
==============================================================================
--- pivot/trunk/core/test/org/apache/pivot/util/test/ImmutableIteratorTest.java (original)
+++ pivot/trunk/core/test/org/apache/pivot/util/test/ImmutableIteratorTest.java Fri Apr 30 21:53:24 2021
@@ -26,7 +26,15 @@ import org.apache.pivot.collections.Arra
import org.apache.pivot.util.ImmutableIterator;
+/**
+ * Tests of the {@link ImmutableIterator} class, which is used
+ * for iteration over many things, when we don't need/want to
+ * modify the object we're iterating over.
+ */
public class ImmutableIteratorTest {
+ /**
+ * Run the basic tests.
+ */
@Test
public void test() {
ArrayList<String> strings = new ArrayList<>();
Modified: pivot/trunk/core/test/org/apache/pivot/util/test/MIMETypeTest.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/test/org/apache/pivot/util/test/MIMETypeTest.java?rev=1889343&r1=1889342&r2=1889343&view=diff
==============================================================================
--- pivot/trunk/core/test/org/apache/pivot/util/test/MIMETypeTest.java (original)
+++ pivot/trunk/core/test/org/apache/pivot/util/test/MIMETypeTest.java Fri Apr 30 21:53:24 2021
@@ -25,6 +25,9 @@ import org.junit.Test;
* Testing the {@link MIMEType} decoding method.
*/
public class MIMETypeTest {
+ /**
+ * Basic tests.
+ */
@Test
public void testMIMEType() {
MIMEType mimeType = MIMEType.decode("foo; a=123; b=456; c=789");
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=1889343&r1=1889342&r2=1889343&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 Fri Apr 30 21:53:24 2021
@@ -28,15 +28,28 @@ import org.apache.pivot.util.StringUtils
* Test the methods in {@link StringUtils}.
*/
public class StringUtilsTest {
+ /**
+ * Our (tiny) test case.
+ */
private static String[] values = {
- "a", "b", "c", "d", "e", "f", "g"
+ "b", "c", "d", "e", "f", "g"
};
+ /**
+ * Run some basic tests.
+ */
@Test
public void test1() {
List<String> list = new ArrayList<>();
- list.addAll(values);
String output = StringUtils.toString(list);
+ assertEquals("[]", output);
+
+ list.add("a");
+ output = StringUtils.toString(list);
+ assertEquals("[a]", output);
+
+ list.addAll(values);
+ output = StringUtils.toString(list);
System.out.println("list " + output);
assertEquals("[a, b, c, d, e, f, g]", output);
}
Modified: pivot/trunk/core/test/org/apache/pivot/util/test/VoteResultTest.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/test/org/apache/pivot/util/test/VoteResultTest.java?rev=1889343&r1=1889342&r2=1889343&view=diff
==============================================================================
--- pivot/trunk/core/test/org/apache/pivot/util/test/VoteResultTest.java (original)
+++ pivot/trunk/core/test/org/apache/pivot/util/test/VoteResultTest.java Fri Apr 30 21:53:24 2021
@@ -26,7 +26,14 @@ import org.apache.pivot.util.Vote;
import org.apache.pivot.util.VoteResult;
+/**
+ * Tests of the {@link VoteResult} class; used for tabulating votes
+ * inside of lambda functions.
+ */
public class VoteResultTest {
+ /**
+ * Run the basic tests.
+ */
@Test
public void test1() {
ArrayList<Vote> votes = new ArrayList<>();
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/effects/Transition.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/effects/Transition.java?rev=1889343&r1=1889342&r2=1889343&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/effects/Transition.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/effects/Transition.java Fri Apr 30 21:53:24 2021
@@ -16,6 +16,8 @@
*/
package org.apache.pivot.wtk.effects;
+import java.util.Optional;
+
import org.apache.pivot.util.Utils;
import org.apache.pivot.wtk.ApplicationContext;
import org.apache.pivot.wtk.Theme;
@@ -25,90 +27,123 @@ import org.apache.pivot.wtk.Theme;
* effects.
*/
public abstract class Transition {
+ /**
+ * Number of milliseconds per second.
+ */
+ private static final int MILLIS_PER_SECOND = 1000;
+
+ /**
+ * The duration of the transition (milliseconds).
+ */
private int duration;
+
+ /**
+ * Rate of the transition in frames per second.
+ */
private int rate;
+
+ /**
+ * Whether the transition repeats once it is finished.
+ */
private boolean repeating;
+ /**
+ * Whether the transition is to be run in reverse.
+ */
private boolean reversed = false;
- private TransitionListener transitionListener;
+ /**
+ * Optional {@code TransitionListener} for transition events.
+ */
+ private Optional<TransitionListener> optionalListener = Optional.empty();
+ /**
+ * The transition start time (in milliseconds).
+ */
private long startTime = 0;
+ /**
+ * The current millisecond timestamp, set on every callback.
+ */
private long currentTime = 0;
+ /**
+ * Set during transition operation to be the current callback for updates,
+ * then cleared once the transition is over.
+ */
private ApplicationContext.ScheduledCallback transitionCallback = null;
- private final Runnable updateCallback = new Runnable() {
- @Override
- public void run() {
- currentTime = System.currentTimeMillis();
-
- long endTime = startTime + duration;
- if (currentTime >= endTime) {
- if (repeating) {
- startTime = endTime;
- } else {
- currentTime = endTime;
- stop();
-
- if (transitionListener != null) {
- transitionListener.transitionCompleted(Transition.this);
- }
- }
- }
+ /**
+ * Callback for every interval to call {@link #update} and then {@link #stop}
+ * once the transition interval is over.
+ */
+ private final Runnable updateCallback = () -> {
+ currentTime = System.currentTimeMillis();
- update();
+ long endTime = startTime + duration;
+ if (currentTime >= endTime) {
+ if (repeating) {
+ startTime = endTime;
+ } else {
+ currentTime = endTime;
+ stop();
+
+ optionalListener.ifPresent(listener -> listener.transitionCompleted(Transition.this));
+ }
}
+
+ update();
};
+
/**
- * Creates a new non-repeating transition with the given duration, rate.
+ * Creates a new non-repeating transition with the given duration, and rate.
*
- * @param duration Transition duration, in milliseconds.
- * @param rate Transition rate, in frames per second.
+ * @param durationValue Transition duration, in milliseconds.
+ * @param rateValue Transition rate, in frames per second.
*/
- public Transition(int duration, int rate) {
- this(duration, rate, false);
+ public Transition(final int durationValue, final int rateValue) {
+ this(durationValue, rateValue, false);
}
/**
* Creates a new transition with the given duration, rate, and repeat.
*
- * @param duration Transition duration, in milliseconds.
- * @param rate Transition rate, in frames per second.
- * @param repeating {@code true} if the transition should repeat;
+ * @param durationValue Transition duration, in milliseconds.
+ * @param rateValue Transition rate, in frames per second.
+ * @param repeat {@code true} if the transition should repeat;
* {@code false}, otherwise.
*/
- public Transition(int duration, int rate, boolean repeating) {
- this(duration, rate, repeating, false);
+ public Transition(final int durationValue, final int rateValue, final boolean repeat) {
+ this(durationValue, rateValue, repeat, false);
}
/**
* Creates a new transition with the given duration, rate, and repeat.
*
* Note that if the current Theme has transitions not enabled,
- * will be set default values instead of given arguments.
+ * the duration and rate will both be set to zero, so that the final
+ * update is called once, in a minimum amount of time after the start.
*
- * @param duration Transition duration, in milliseconds.
- * @param rate Transition rate, in frames per second.
- * @param repeating {@code true} if the transition should repeat;
+ * @param durationValue Transition duration, in milliseconds.
+ * @param rateValue Transition rate, in frames per second.
+ * @param repeat {@code true} if the transition should repeat;
* {@code false}, otherwise.
- * @param reversed {@code true} if the transition should run in reverse;
+ * @param reverse {@code true} if the transition should run in reverse;
* {@code false} otherwise.
*/
- public Transition(int duration, int rate, boolean repeating, boolean reversed) {
- Utils.checkNonNegative(duration, "duration");
+ public Transition(final int durationValue, final int rateValue, final boolean repeat, final boolean reverse) {
+ Utils.checkNonNegative(durationValue, "duration");
if (!themeHasTransitionEnabled()) {
// System.out.println("transitions not enabled, overriding transition values");
- this.duration = 0;
- this.rate = 0;
+ duration = 0;
+ rate = 0;
} else {
- this.duration = duration;
- this.rate = rate;
+ duration = durationValue;
+ rate = rateValue;
}
- this.repeating = repeating;
- this.reversed = reversed;
+ repeating = repeat;
+ reversed = reverse;
}
/**
@@ -125,16 +160,16 @@ public abstract class Transition {
* Sets the transition duration, the length of time the transition is
* scheduled to run.
*
- * @param duration The duration of the transition, in milliseconds.
+ * @param durationValue The duration of the transition, in milliseconds.
*/
- public void setDuration(int duration) {
- Utils.checkNonNegative(duration, "duration");
+ public void setDuration(final int durationValue) {
+ Utils.checkNonNegative(durationValue, "duration");
- if (transitionCallback != null) {
+ if (isRunning()) {
throw new IllegalStateException("Transition is currently running.");
}
- this.duration = duration;
+ duration = durationValue;
}
/**
@@ -151,16 +186,16 @@ public abstract class Transition {
* Sets the transition rate, the number of times the transition will be
* updated within the span of one second.
*
- * @param rate The transition rate, in frames per second.
+ * @param rateValue The transition rate, in frames per second.
*/
- public void setRate(int rate) {
- Utils.checkNonNegative(rate, "rate");
+ public void setRate(final int rateValue) {
+ Utils.checkNonNegative(rateValue, "rate");
- if (transitionCallback != null) {
+ if (isRunning()) {
throw new IllegalStateException("Transition is currently running.");
}
- this.rate = rate;
+ rate = rateValue;
}
/**
@@ -172,8 +207,9 @@ public abstract class Transition {
*/
public int getInterval() {
int interval;
+
if (rate != 0) {
- interval = (int) ((1f / rate) * 1000);
+ interval = (int) ((1.0f / rate) * MILLIS_PER_SECOND);
} else {
interval = 1;
}
@@ -207,8 +243,8 @@ public abstract class Transition {
*/
public int getElapsedTime() {
long endTime = startTime + duration;
-
int elapsedTime;
+
if (reversed) {
elapsedTime = (int) (endTime - currentTime);
} else {
@@ -227,8 +263,9 @@ public abstract class Transition {
*/
public float getPercentComplete() {
float percentComplete;
+
if (duration != 0) {
- percentComplete = (float) (currentTime - startTime) / (float) (duration);
+ percentComplete = (float) (currentTime - startTime) / (float) duration;
} else {
percentComplete = 1.0f;
}
@@ -246,12 +283,14 @@ public abstract class Transition {
* @return {@code true} if the transition is currently running;
* {@code false} if it is not
*/
- public boolean isRunning() {
+ public final boolean isRunning() {
return (transitionCallback != null);
}
/**
- * Starts the transition with no listener.
+ * Starts the transition. Calls {@link #update()} to establish the initial
+ * state and starts a time that will repeatedly call {@link #update()} at
+ * the current rate. No {@code TransitionListener} will be notified.
*
* @see #start(TransitionListener)
*/
@@ -265,15 +304,15 @@ public abstract class Transition {
* the current rate. The specified {@code TransitionListener} will be
* notified when the transition completes.
*
- * @param transitionListenerArgument The listener to get notified when the
- * transition completes, or {@code null} if no notification is necessary
+ * @param listener The listener to get notified when the transition completes,
+ * or {@code null} if no notification is necessary.
*/
- public void start(TransitionListener transitionListenerArgument) {
- if (transitionCallback != null) {
+ public void start(final TransitionListener listener) {
+ if (isRunning()) {
throw new IllegalStateException("Transition is currently running.");
}
- this.transitionListener = transitionListenerArgument;
+ optionalListener = Optional.ofNullable(listener);
startTime = System.currentTimeMillis();
currentTime = startTime;
@@ -285,11 +324,11 @@ public abstract class Transition {
}
/**
- * Stops the transition. Does not fire a
+ * Stops the transition running with no final update, and does not fire a
* {@link TransitionListener#transitionCompleted(Transition)} event.
*/
public void stop() {
- if (transitionCallback != null) {
+ if (isRunning()) {
transitionCallback.cancel();
}
@@ -297,15 +336,16 @@ public abstract class Transition {
}
/**
- * "Fast-forwards" to the end of the transition and fires a
+ * "Fast-forward" to the end of the transition, run {@link #update}
+ * the last time, and fire a
* {@link TransitionListener#transitionCompleted(Transition)} event.
*/
public void end() {
- if (transitionCallback != null) {
+ if (isRunning()) {
currentTime = startTime + duration;
stop();
update();
- transitionListener.transitionCompleted(this);
+ optionalListener.ifPresent(listener -> listener.transitionCompleted(this));
}
}
@@ -315,6 +355,11 @@ public abstract class Transition {
*/
protected abstract void update();
+ /**
+ * Is the transition a repeating one?
+ *
+ * @return {@code true} if the transition should repeat; {@code false} if not.
+ */
public boolean isRepeating() {
return repeating;
}
@@ -322,8 +367,7 @@ public abstract class Transition {
/**
* Tests whether the transition is reversed.
*
- * @return {@code true} if the transition is reversed; {@code false},
- * otherwise.
+ * @return {@code true} if the transition is reversed; {@code false} otherwise.
*/
public boolean isReversed() {
return reversed;
@@ -332,10 +376,10 @@ public abstract class Transition {
/**
* Sets the transition's reversed flag.
*
- * @param reversed Whether the transition should be reversed.
+ * @param reverse Whether the transition should be reversed.
*/
- public void setReversed(boolean reversed) {
- this.reversed = reversed;
+ public void setReversed(final boolean reverse) {
+ reversed = reverse;
}
/**
@@ -356,7 +400,8 @@ public abstract class Transition {
* Tell if the theme has transitions enabled.<br> Usually this means that (if false) any
* effect/transition will not be drawn.
*
- * @return true if enabled (default), false otherwise
+ * @return {@code true} if enabled (default), {@code false} otherwise.
+ * @see Theme#isTransitionEnabled
*/
protected boolean themeHasTransitionEnabled() {
return Theme.getTheme().isTransitionEnabled();
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=1889343&r1=1889342&r2=1889343&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 Fri Apr 30 21:53:24 2021
@@ -19,6 +19,7 @@ package org.apache.pivot.wtk.skin;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
+import java.util.Optional;
import org.apache.pivot.collections.EnumSet;
import org.apache.pivot.util.Utils;
@@ -64,7 +65,7 @@ public abstract class ComponentSkin impl
ComponentKeyListener, ComponentTooltipListener {
/** The component to which this skin is attached. */
- private Component installedComponent = null;
+ private Optional<Component> installedComponent = Optional.empty();
/** This component's current full width (usually calculated during layout). */
private int width = 0;
@@ -137,7 +138,7 @@ public abstract class ComponentSkin impl
*/
@Override
public void install(final Component component) {
- assert (this.installedComponent == null)
+ assert (!installedComponent.isPresent())
: "This " + getClass().getSimpleName() + " is already installed on a component.";
component.getComponentListeners().add(this);
@@ -148,7 +149,7 @@ public abstract class ComponentSkin impl
component.getComponentKeyListeners().add(this);
component.getComponentTooltipListeners().add(this);
- this.installedComponent = component;
+ installedComponent = Optional.ofNullable(component);
}
/**
@@ -157,7 +158,7 @@ public abstract class ComponentSkin impl
*/
@Override
public final Component getComponent() {
- return installedComponent;
+ return installedComponent.orElse(null);
}
/**
@@ -399,16 +400,15 @@ public abstract class ComponentSkin impl
}
}
- // Utility methods
/**
* Mark the component's entire size as invalid, to be repainted when
* the event queue is empty.
*/
protected void invalidateComponent() {
- if (installedComponent != null) {
- installedComponent.invalidate();
- installedComponent.repaint();
- }
+ installedComponent.ifPresent(component -> {
+ component.invalidate();
+ component.repaint();
+ });
}
/**
@@ -424,9 +424,7 @@ public abstract class ComponentSkin impl
* @param immediate {@code true} to repaint the entire component now.
*/
protected void repaintComponent(final boolean immediate) {
- if (installedComponent != null) {
- installedComponent.repaint(immediate);
- }
+ installedComponent.ifPresent(component -> component.repaint(immediate));
}
/**
@@ -436,9 +434,7 @@ public abstract class ComponentSkin impl
protected void repaintComponent(final Bounds area) {
assert (area != null) : "area is null.";
- if (installedComponent != null) {
- installedComponent.repaint(area.x, area.y, area.width, area.height);
- }
+ installedComponent.ifPresent(component -> component.repaint(area.x, area.y, area.width, area.height));
}
/**
@@ -450,9 +446,7 @@ public abstract class ComponentSkin impl
* @param areaHeight The height of the area to repaint.
*/
protected void repaintComponent(final int x, final int y, final int areaWidth, final int areaHeight) {
- if (installedComponent != null) {
- installedComponent.repaint(x, y, areaWidth, areaHeight);
- }
+ installedComponent.ifPresent(component -> component.repaint(x, y, areaWidth, areaHeight));
}
/**
@@ -466,9 +460,7 @@ public abstract class ComponentSkin impl
*/
protected void repaintComponent(final int x, final int y, final int areaWidth, final int areaHeight,
final boolean immediate) {
- if (installedComponent != null) {
- installedComponent.repaint(x, y, areaWidth, areaHeight, immediate);
- }
+ installedComponent.ifPresent(component -> component.repaint(x, y, areaWidth, areaHeight, immediate));
}
/**
@@ -680,8 +672,7 @@ public abstract class ComponentSkin impl
* <p> Should be overridden by any component's skin that wants
* to handle Input Method events (such as {@code TextInput}).
*
- * @return The input method listener (if any) for this
- * component.
+ * @return The input method listener (if any) for this component.
*/
public TextInputMethodListener getTextInputMethodListener() {
return null;
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=1889343&r1=1889342&r2=1889343&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 Fri Apr 30 21:53:24 2021
@@ -24,16 +24,19 @@ import org.apache.pivot.wtk.Display;
import org.apache.pivot.wtk.Window;
/**
- * Display skin.
+ * Skin for the {@link Display} component.
*/
public class DisplaySkin extends ContainerSkin {
+ /**
+ * Default constructor; sets default background color.
+ */
public DisplaySkin() {
super();
setBackgroundColor(Color.LIGHT_GRAY);
}
@Override
- public void install(Component component) {
+ public void install(final Component component) {
if (!(component instanceof Display)) {
throw new IllegalArgumentException(
"DisplaySkin can only be installed on instances of Display.");
@@ -56,6 +59,8 @@ public class DisplaySkin extends Contain
} else {
Dimensions preferredSize = window.getPreferredSize();
+ // Don't use "window.getSize()" so that we can optimize by only
+ // calculating the window height if the width differs.
if (window.getWidth() != preferredSize.width
|| window.getHeight() != preferredSize.height) {
window.setSize(preferredSize.width, preferredSize.height);