Skip to content

Commit

Permalink
Allowing to specify a screen transition style in Display.setCurrentIt…
Browse files Browse the repository at this point in the history
…em(), e.g.

//#style myForwardTransition
display.setCurrentItem(myItem);
  • Loading branch information
robert-virkus committed Oct 19, 2011
1 parent ea206c9 commit 89effdc
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ public class PolishPreprocessor extends CustomPreprocessor {
//protected static final String SET_CURRENT_ITEM_STR = "[\\w|\\.]+\\s*\\.\\s*setCurrentItem\\s*\\([\\w|\\.]+\\s*\\)";
protected static final String JAVA_VAR_STR = "[\\w|\\.|_]+";
protected static final String GET_DISPLAY_METHOD_STR = "Display\\s*\\.\\s*getDisplay\\s*\\(\\s*" + JAVA_VAR_STR + "\\s*\\)\\s*";
protected static final String SET_CURRENT_ITEM_STR = "(" + JAVA_VAR_STR + "|" + GET_DISPLAY_METHOD_STR + ")\\s*\\.\\s*setCurrentItem\\s*\\(.+\\)";
protected static final Pattern SET_CURRENT_ITEM_PATTERN = Pattern.compile( SET_CURRENT_ITEM_STR );
// protected static final String SET_CURRENT_ITEM_STR = "(" + JAVA_VAR_STR + "|" + GET_DISPLAY_METHOD_STR + ")\\s*\\.\\s*setCurrentItem\\s*\\(.+\\)";
// protected static final Pattern SET_CURRENT_ITEM_PATTERN = Pattern.compile( SET_CURRENT_ITEM_STR );

protected static final String ALERT_CONSTRUCTOR = "new\\s+Alert\\s*\\(\\s*.+\\)" ;
protected static final String SET_CURRENT_ALERT_DISPLAYABLE_STR = "[\\w|\\.]+\\s*\\.\\s*setCurrent\\s*\\(\\s*[\\w*|\\.|\\_|\\(|\\)]+\\s*,\\s*[\\w*|\\.|\\_|\\(|\\)]+\\s*\\)";
protected static final Pattern SET_CURRENT_ALERT_DISPLAYABLE_PATTERN = Pattern.compile( SET_CURRENT_ALERT_DISPLAYABLE_STR );
// protected static final String SET_CURRENT_ALERT_DISPLAYABLE_STR = "[\\w|\\.]+\\s*\\.\\s*setCurrent\\s*\\(\\s*[\\w*|\\.|\\_|\\(|\\)]+\\s*,\\s*[\\w*|\\.|\\_|\\(|\\)]+\\s*\\)";
// protected static final Pattern SET_CURRENT_ALERT_DISPLAYABLE_PATTERN = Pattern.compile( SET_CURRENT_ALERT_DISPLAYABLE_STR );

private static final Map PRIMITIVES_BY_NAME = new HashMap();
static {
Expand Down Expand Up @@ -588,61 +588,61 @@ public void processClass(StringList lines, String className) {
continue;
}

// check for display.setCurrentItem:
startPos = line.indexOf("setCurrentItem");
if ( startPos != -1) {
//System.out.println("setCurrentItem found in line " + line );
int commentPos = line.indexOf("//");
if (commentPos != -1 && commentPos < startPos) {
continue;
}
Matcher matcher = SET_CURRENT_ITEM_PATTERN.matcher( line );
if (matcher.find()) {
String group = matcher.group();
//System.out.println("group = [" + group + "]");
int parenthesisPos = group.indexOf('(', startPos );
if (parenthesisPos == -1) {
throw new BuildException( getErrorStart(className, lines) + ": setCurrentItem() method found without opening parentheses: " + line);
}
String displayVar = group.substring(0, parenthesisPos);
int dotPos = displayVar.lastIndexOf('.');
displayVar = displayVar.substring( 0, dotPos ).trim();
String itemVar = group.substring( parenthesisPos + 1, group.length() -1 ).trim();
String replacement = itemVar + ".show( " + displayVar + " )";
//System.out.println("replacement = [" + replacement + "].");
line = StringUtil.replace( line, group, replacement );
//System.out.println("line = [" + line + "]");
lines.setCurrent( line );
}
continue;
}
// // check for display.setCurrentItem:
// startPos = line.indexOf("setCurrentItem");
// if ( startPos != -1) {
// //System.out.println("setCurrentItem found in line " + line );
// int commentPos = line.indexOf("//");
// if (commentPos != -1 && commentPos < startPos) {
// continue;
// }
// Matcher matcher = SET_CURRENT_ITEM_PATTERN.matcher( line );
// if (matcher.find()) {
// String group = matcher.group();
// //System.out.println("group = [" + group + "]");
// int parenthesisPos = group.indexOf('(', startPos );
// if (parenthesisPos == -1) {
// throw new BuildException( getErrorStart(className, lines) + ": setCurrentItem() method found without opening parentheses: " + line);
// }
// String displayVar = group.substring(0, parenthesisPos);
// int dotPos = displayVar.lastIndexOf('.');
// displayVar = displayVar.substring( 0, dotPos ).trim();
// String itemVar = group.substring( parenthesisPos + 1, group.length() -1 ).trim();
// String replacement = itemVar + ".show( " + displayVar + " )";
// //System.out.println("replacement = [" + replacement + "].");
// line = StringUtil.replace( line, group, replacement );
// //System.out.println("line = [" + line + "]");
// lines.setCurrent( line );
// }
// continue;
// }

// check for display.setCurrent( Alert, Displayable ):
startPos = line.indexOf("setCurrent");
if ( startPos != -1) {
//System.out.println("setCurrent found in line " + line );
int commentPos = line.indexOf("//");
if (commentPos != -1 && commentPos < startPos) {
continue;
}
Matcher matcher = SET_CURRENT_ALERT_DISPLAYABLE_PATTERN.matcher( line );
if (matcher.find()) {
String group = matcher.group();
//System.out.println("group = [" + group + "]");
int parenthesisPos = group.indexOf('(');
String displayVar = group.substring(0, parenthesisPos);
int dotPos = displayVar.lastIndexOf('.');
displayVar = displayVar.substring( 0, dotPos ).trim();
String alertDisplayableVars = group.substring( parenthesisPos + 1, group.length() -1 ).trim();
//int commaPos = alertDisplayableVars.indexOf('.');
String replacement = "Alert.setCurrent( " + displayVar + ", " + alertDisplayableVars + " )";
//System.out.println("replacement = [" + replacement + "].");
line = StringUtil.replace( line, group, replacement );
//System.out.println("line = [" + line + "]");
lines.setCurrent( line );
}
continue;
}
// // check for display.setCurrent( Alert, Displayable ):
// startPos = line.indexOf("setCurrent");
// if ( startPos != -1) {
// //System.out.println("setCurrent found in line " + line );
// int commentPos = line.indexOf("//");
// if (commentPos != -1 && commentPos < startPos) {
// continue;
// }
// Matcher matcher = SET_CURRENT_ALERT_DISPLAYABLE_PATTERN.matcher( line );
// if (matcher.find()) {
// String group = matcher.group();
// //System.out.println("group = [" + group + "]");
// int parenthesisPos = group.indexOf('(');
// String displayVar = group.substring(0, parenthesisPos);
// int dotPos = displayVar.lastIndexOf('.');
// displayVar = displayVar.substring( 0, dotPos ).trim();
// String alertDisplayableVars = group.substring( parenthesisPos + 1, group.length() -1 ).trim();
// //int commaPos = alertDisplayableVars.indexOf('.');
// String replacement = "Alert.setCurrent( " + displayVar + ", " + alertDisplayableVars + " )";
// //System.out.println("replacement = [" + replacement + "].");
// line = StringUtil.replace( line, group, replacement );
// //System.out.println("line = [" + line + "]");
// lines.setCurrent( line );
// }
// continue;
// }


// check for Choice.POPUP:
Expand Down
6 changes: 3 additions & 3 deletions enough-polish-build/version.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Version=2.3-Preview-35
Version=2.3-Preview-36
#BetaVersion=2.2
VersionName=2.3-Preview-35
VersionMessage=Welcome to the J2ME Polish 2.3-Preview-35!
VersionName=2.3-Preview-36
VersionMessage=Welcome to the J2ME Polish 2.3-Preview-36!
31 changes: 24 additions & 7 deletions enough-polish-j2me/source/src/de/enough/polish/ui/Display.java
Original file line number Diff line number Diff line change
Expand Up @@ -1290,8 +1290,7 @@ public void setCurrent( Alert alert, Displayable nextDisplayable)


/**
* Requests that the <code>Displayable</code> that contains this
* <code>Item</code> be made current,
* Requests that the <code>Displayable</code> that contains this <code>Item</code> be made current,
* scrolls the <code>Displayable</code> so that this
* <code>Item</code> is visible, and possibly
* assigns the focus to this <code>Item</code>. The containing
Expand All @@ -1316,19 +1315,37 @@ public void setCurrent( Alert alert, Displayable nextDisplayable)
* It is also an error if the <code>Item</code> is contained
* within an <code>Alert</code>.</p>
*
* @param item - the item that should be made visible
* @throws IllegalStateException - if the item is not owned by a container
* @throws IllegalStateException - if the item is owned by an Alert
* @throws NullPointerException - if item is null
* @param item the item that should be made visible
* @throws IllegalStateException if the item is not owned by a container
* @throws IllegalStateException if the item is owned by an Alert
* @throws NullPointerException if item is null
* @since MIDP 2.0
*/
public void setCurrentItem( Item item)
{
setCurrentItem( item, null);
}

/**
* Requests that the <code>Displayable</code> that contains this <code>Item</code> be made current.
* A screen transition style specifies the used screen-change-animation.
*
* @param item the item that should be made visible
* @parem screenTransitionStyle the style that contains a screen-change-animation
* @throws IllegalStateException if the item is not owned by a container
* @throws IllegalStateException if the item is owned by an Alert
* @throws NullPointerException if item is null
* @since J2ME Polish 2.3
*/
public void setCurrentItem( Item item, Style screenTransitionStyle )
{
//#if !polish.LibraryBuild
item.show(this);
//try { throw new RuntimeException("for " + item); } catch (Exception e) { e.printStackTrace(); }
item.show(this, screenTransitionStyle);
//#endif
}


/**
* Causes the <code>Runnable</code> object <code>r</code> to have
* its <code>run()</code> method
Expand Down
17 changes: 16 additions & 1 deletion enough-polish-j2me/source/src/de/enough/polish/ui/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -5251,8 +5251,19 @@ protected void hideNotify()
* This method is the equivalent to display.setCurrentItem( item ).
*
* @param display the display of the MIDlet.
* @since J2ME Polish 2.3
*/
public void show( Display display ) {
show( display, null);
}

/**
* Shows the screen to which item belongs to and focusses this item.
* This method is the equivalent to display.setCurrentItem( item ).
*
* @param display the display of the MIDlet.
*/
public void show( Display display, Style screenTransitionStyle ) {
Screen myScreen = getScreen();
if ( myScreen == null ) {
//#debug warn
Expand All @@ -5262,7 +5273,11 @@ public void show( Display display ) {
//#if !polish.android
myScreen.focus( this );
//#endif
display.setCurrent( myScreen );
if (screenTransitionStyle != null) {
display.setCurrent(myScreen, screenTransitionStyle);
} else {
display.setCurrent( myScreen );
}
//#if polish.android
myScreen.focus( this );
//#endif
Expand Down

0 comments on commit 89effdc

Please sign in to comment.