fixed the problem that the new main menu could not be used on some Sony Ericsson phones (bug id 2882131)
1.1 --- a/src/de/joergjahnke/common/jme/Menu.java Mon Oct 19 07:04:36 2009 +0200
1.2 +++ b/src/de/joergjahnke/common/jme/Menu.java Tue Oct 20 07:01:34 2009 +0200
1.3 @@ -43,10 +43,18 @@
1.4 */
1.5 private MenuListener listener = null;
1.6 /**
1.7 + * Select command text
1.8 + */
1.9 + private String selectCommandText = "Select";
1.10 + /**
1.11 * Select command
1.12 */
1.13 private Command selectCommand;
1.14 /**
1.15 + * Back command text
1.16 + */
1.17 + private String backCommandText = "Back";
1.18 + /**
1.19 * Back command
1.20 */
1.21 private Command backCommand;
1.22 @@ -59,8 +67,6 @@
1.23 public Menu(final String title) {
1.24 super(title, List.IMPLICIT);
1.25 setCommandListener(this);
1.26 - setSelectCommandText("Select");
1.27 - setBackCommandText("Back");
1.28 }
1.29
1.30 /**
1.31 @@ -173,11 +179,20 @@
1.32 * @param text new text
1.33 */
1.34 public void setSelectCommandText(final String text) {
1.35 + this.selectCommandText = text;
1.36 if (this.selectCommand != null) {
1.37 removeCommand(this.selectCommand);
1.38 + setSelectCommand();
1.39 }
1.40 - this.selectCommand = new Command(text, Command.OK, 1);
1.41 + }
1.42 +
1.43 + /**
1.44 + * Create a command from the current select command text and activate this command on the screen as default select command
1.45 + */
1.46 + private void setSelectCommand() {
1.47 + this.selectCommand = new Command(this.selectCommandText, Command.OK, 1);
1.48 addCommand(this.selectCommand);
1.49 + super.setSelectCommand(this.selectCommand);
1.50 }
1.51
1.52 /**
1.53 @@ -186,11 +201,19 @@
1.54 * @param text new text, null if no Back button should be displayed
1.55 */
1.56 public void setBackCommandText(final String text) {
1.57 + this.backCommandText = text;
1.58 if (this.backCommand != null) {
1.59 removeCommand(this.backCommand);
1.60 + setBackCommand();
1.61 }
1.62 - if (text != null && !"".equals(text)) {
1.63 - this.backCommand = new Command(text, Command.BACK, 99);
1.64 + }
1.65 +
1.66 + /**
1.67 + * Create a command from the current select command text, if a text is specified, and activate this command on the screen
1.68 + */
1.69 + private void setBackCommand() {
1.70 + if (this.backCommandText != null && !"".equals(this.backCommandText)) {
1.71 + this.backCommand = new Command(this.backCommandText, Command.BACK, 99);
1.72 addCommand(this.backCommand);
1.73 }
1.74 }
1.75 @@ -213,8 +236,13 @@
1.76 append(text, icon);
1.77 }
1.78
1.79 - // assign a default command
1.80 - setSelectCommand(this.selectCommand);
1.81 + // set the select and the back command
1.82 + if (this.selectCommand == null) {
1.83 + setSelectCommand();
1.84 + }
1.85 + if (this.backCommand == null) {
1.86 + setBackCommand();
1.87 + }
1.88
1.89 // activate the menu on the display
1.90 this.previous = display.getCurrent();
1.91 @@ -228,8 +256,8 @@
1.92 * @return displayable object
1.93 */
1.94 private Displayable getPreviousRoot() {
1.95 - if(this.previous instanceof Menu && ((Menu)this.previous).previous != this.previous) {
1.96 - return ((Menu)this.previous).getPreviousRoot();
1.97 + if (this.previous instanceof Menu && ((Menu) this.previous).previous != this.previous) {
1.98 + return ((Menu) this.previous).getPreviousRoot();
1.99 } else {
1.100 return this.previous;
1.101 }
1.102 @@ -259,7 +287,7 @@
1.103 } else if (c == this.backCommand) {
1.104 // close the menu
1.105 this.currentDisplay.setCurrent(this.previous);
1.106 - if(this.listener != null) {
1.107 + if (this.listener != null) {
1.108 this.listener.menuClosed(this);
1.109 }
1.110 }