You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2010/07/23 21:01:54 UTC
svn commit: r967202 - in /pivot/trunk:
core/src/org/apache/pivot/util/CalendarDate.java
core/src/org/apache/pivot/util/Time.java
core/test/org/apache/pivot/util/test/TimeTest.java
wtk/src/org/apache/pivot/wtk/skin/ComponentSkin.java
Author: gbrown
Date: Fri Jul 23 19:01:54 2010
New Revision: 967202
URL: http://svn.apache.org/viewvc?rev=967202&view=rev
Log:
Fix minor recently-introduced focus traversal issue; revert to using regex in CalendarDate and Time classes.
Modified:
pivot/trunk/core/src/org/apache/pivot/util/CalendarDate.java
pivot/trunk/core/src/org/apache/pivot/util/Time.java
pivot/trunk/core/test/org/apache/pivot/util/test/TimeTest.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ComponentSkin.java
Modified: pivot/trunk/core/src/org/apache/pivot/util/CalendarDate.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/util/CalendarDate.java?rev=967202&r1=967201&r2=967202&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/util/CalendarDate.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/util/CalendarDate.java Fri Jul 23 19:01:54 2010
@@ -20,6 +20,8 @@ import java.io.Serializable;
import java.text.NumberFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.apache.pivot.collections.Dictionary;
import org.apache.pivot.json.JSONSerializer;
@@ -200,6 +202,7 @@ public final class CalendarDate implemen
};
private static final int GREGORIAN_CUTOVER_YEAR = 1582;
+ private static final Pattern PATTERN = Pattern.compile("^(\\d{4})-(\\d{2})-(\\d{2})$");
/**
* Creates a new <tt>CalendarDate</tt> representing the current day in the
@@ -432,15 +435,15 @@ public final class CalendarDate implemen
* A string in the form of <tt>[YYYY]-[MM]-[DD]</tt> (e.g. 2008-07-23).
*/
public static CalendarDate decode(String value) {
- String[] components = value.split("-");
+ Matcher matcher = PATTERN.matcher(value);
- if (components.length != 3) {
+ if (!matcher.matches()) {
throw new IllegalArgumentException("Invalid date format: " + value);
}
- int year = Integer.parseInt(components[0]);
- int month = Integer.parseInt(components[1]) - 1;
- int day = Integer.parseInt(components[2]) - 1;
+ int year = Integer.parseInt(matcher.group(1));
+ int month = Integer.parseInt(matcher.group(2)) - 1;
+ int day = Integer.parseInt(matcher.group(3)) - 1;
return new CalendarDate(year, month, day);
}
Modified: pivot/trunk/core/src/org/apache/pivot/util/Time.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/util/Time.java?rev=967202&r1=967201&r2=967202&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/util/Time.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/util/Time.java Fri Jul 23 19:01:54 2010
@@ -20,6 +20,8 @@ import java.io.Serializable;
import java.text.NumberFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.apache.pivot.collections.Dictionary;
import org.apache.pivot.json.JSONSerializer;
@@ -203,6 +205,8 @@ public final class Time implements Compa
public static final int MILLISECONDS_PER_HOUR = 60 * MILLISECONDS_PER_MINUTE;
public static final int MILLISECONDS_PER_DAY = 24 * MILLISECONDS_PER_HOUR;
+ private static final Pattern PATTERN = Pattern.compile("^(\\d{2}):(\\d{2}):(\\d{2})(\\.(\\d{3}))?$");
+
public Time() {
this(new GregorianCalendar());
}
@@ -380,24 +384,19 @@ public final class Time implements Compa
* <tt>[hh]:[mm]:[ss].[nnn]</tt> (e.g. 17:19:20 or 17:19:20.412).
*/
public static Time decode(String value) {
- String[] components = value.split(":");
+ Matcher matcher = PATTERN.matcher(value);
- if (components.length != 3) {
+ if (!matcher.matches()) {
throw new IllegalArgumentException("Invalid time format: " + value);
}
- int hour = Integer.parseInt(components[0]);
- int minute = Integer.parseInt(components[1]);
-
- String[] secondComponents = components[2].split("\\.");
-
- int second = Integer.parseInt(secondComponents[0]);
- int millisecond;
- if (secondComponents.length > 1) {
- millisecond = Integer.parseInt(secondComponents[1]);
- } else {
- millisecond = 0;
- }
+ int hour = Integer.parseInt(matcher.group(1));
+ int minute = Integer.parseInt(matcher.group(2));
+ int second = Integer.parseInt(matcher.group(3));
+
+ String millisecondSequence = matcher.group(4);
+ int millisecond = (millisecondSequence == null) ?
+ 0 : Integer.parseInt(millisecondSequence.substring(1));
return new Time(hour, minute, second, millisecond);
}
Modified: pivot/trunk/core/test/org/apache/pivot/util/test/TimeTest.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/test/org/apache/pivot/util/test/TimeTest.java?rev=967202&r1=967201&r2=967202&view=diff
==============================================================================
--- pivot/trunk/core/test/org/apache/pivot/util/test/TimeTest.java (original)
+++ pivot/trunk/core/test/org/apache/pivot/util/test/TimeTest.java Fri Jul 23 19:01:54 2010
@@ -43,13 +43,10 @@ public class TimeTest {
System.out.println(time.add(1000));
System.out.println(time.add(-1000));
- time = Time.decode("00:00:00.000");
- System.out.println(time);
-
- time = Time.decode("00:00:00.00");
+ time = Time.decode("00:00:00");
System.out.println(time);
- time = Time.decode("00:00:00");
+ time = Time.decode("00:00:00.000");
System.out.println(time);
try {
@@ -57,5 +54,11 @@ public class TimeTest {
} catch (IllegalArgumentException exception) {
System.out.println(exception);
}
+
+ try {
+ time = Time.decode("00:00:00.00");
+ } catch (IllegalArgumentException exception) {
+ System.out.println(exception);
+ }
}
}
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=967202&r1=967201&r2=967202&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 Jul 23 19:01:54 2010
@@ -241,9 +241,7 @@ public abstract class ComponentSkin impl
@Override
public void focusedChanged(Component component, Component obverseComponent) {
- if (component.isFocused()) {
- component.scrollAreaToVisible(0, 0, component.getWidth(), component.getHeight());
- }
+ // No-op
}
// Component mouse events
@@ -317,7 +315,14 @@ public abstract class ComponentSkin impl
FocusTraversalDirection direction = (Keyboard.isPressed(Keyboard.Modifier.SHIFT)) ?
FocusTraversalDirection.BACKWARD : FocusTraversalDirection.FORWARD;
- component.transferFocus(direction);
+ // Transfer focus to the next component
+ Component focusedComponent = component.transferFocus(direction);
+
+ // Ensure that the focused component is visible
+ if (component != focusedComponent) {
+ focusedComponent.scrollAreaToVisible(0, 0, focusedComponent.getWidth(),
+ focusedComponent.getHeight());
+ }
consumed = true;
}