home *** CD-ROM | disk | FTP | other *** search
- import javax.microedition.lcdui.Command;
- import javax.microedition.lcdui.CommandListener;
- import javax.microedition.lcdui.Display;
- import javax.microedition.lcdui.Displayable;
- import javax.microedition.lcdui.Image;
- import javax.microedition.lcdui.List;
-
- public class CommandsForm implements CommandListener, ChessDisplayable, ServletResponseReceiver {
- private boolean responsereceived = false;
- private String response = null;
- private ChessLogic chesslogic = null;
- private ChessDisplayable chessreturn = null;
- private List myScreen;
- private Command OKCommand;
- private Command backCommand;
-
- public CommandsForm(ChessLogic var1, ChessDisplayable var2) {
- this.chesslogic = var1;
- this.chessreturn = var2;
- this.initialize();
- }
-
- private void alert(String var1) {
- MessageForm var2 = new MessageForm("Alert", var1, this.chessreturn);
- var2.makeCurrent(CU.getDisplay());
- }
-
- private boolean checkPostActive() {
- ChessGame var1 = this.chesslogic.getChessGame();
- if (var1 == null) {
- return false;
- } else if (var1.postActive()) {
- this.alert("Unable to send command, still postthread active. \nStatus: " + var1.getStatus());
- return true;
- } else {
- return false;
- }
- }
-
- public void commandAction(Command var1, Displayable var2) {
- if (var1 != this.OKCommand && var1 != List.SELECT_COMMAND) {
- if (var1 == this.backCommand) {
- if (this.chesslogic.getChessGame() != null) {
- this.chesslogic.getChessGame().setServletRedirection(this.chesslogic);
- }
-
- this.chessreturn.makeCurrent(CU.getDisplay());
- }
-
- } else {
- this.executeCommand(this.myScreen.getString(this.myScreen.getSelectedIndex()));
- }
- }
-
- private void executeCommand(String var1) {
- ChessGame var2 = this.chesslogic.getChessGame();
- if (var2 != null) {
- var2.setServletRedirection(this);
- }
-
- if (var1.equals("Logon")) {
- if (this.checkPostActive()) {
- return;
- }
-
- LogonForm var3 = new LogonForm(this.chesslogic, this);
- var3.makeCurrent(CU.getDisplay());
- } else if (var1.equals("Match player")) {
- if (this.checkPostActive()) {
- return;
- }
-
- var2.doPost("who a", false);
- } else if (var1.equals("Resign from game")) {
- if (this.checkPostActive()) {
- return;
- }
-
- var2.doPost("resign", true);
- } else if (var1.equals("Offer draw")) {
- if (this.checkPostActive()) {
- return;
- }
-
- var2.doPost("draw", true);
- } else if (var1.equals("Abort from game")) {
- if (this.checkPostActive()) {
- return;
- }
-
- var2.doPost("abort", true);
- } else if (var1.equals("Refresh board")) {
- if (this.checkPostActive()) {
- return;
- }
-
- var2.doPost("refresh", false);
- } else if (var1.equals("Nextstate")) {
- if (this.checkPostActive()) {
- return;
- }
-
- var2.doPost("nextstate", false);
- } else if (var1.equals("Accept draw-offer")) {
- if (this.checkPostActive()) {
- return;
- }
-
- var2.doPost("accept", true);
- } else if (var1.equals("Decline draw-offer")) {
- if (this.checkPostActive()) {
- return;
- }
-
- var2.doPost("decline", true);
- } else if (var1.equals("Review match-offer")) {
- MessageForm var4 = new MessageForm("Match offered", var2.viewMatchIssue(), this);
- var4.makeCurrent(CU.getDisplay());
- } else if (var1.equals("Accept challenge")) {
- if (this.checkPostActive()) {
- return;
- }
-
- var2.doPost("accept", true);
- } else if (var1.equals("Decline challenge")) {
- if (this.checkPostActive()) {
- return;
- }
-
- var2.doPost("decline", true);
- } else if (var1.equals("Review challenge")) {
- MessageForm var5 = new MessageForm("Challenged by", var2.viewChallenge(), this);
- var5.makeCurrent(CU.getDisplay());
- } else if (var1.equals("Poll")) {
- if (this.checkPostActive()) {
- return;
- }
-
- var2.doPost("poll", false);
- } else if (var1.equals("Logoff")) {
- if (this.checkPostActive()) {
- return;
- }
-
- var2.doPost("logoff", true);
- this.chesslogic.reset();
- this.chesslogic.setChessGame((ChessGame)null);
- } else if (var1.equals("Exit")) {
- CU.exitMIDlet();
- } else if (var1.equals("About")) {
- CU.displayChessMIDlet();
- } else if (var1.equals("Setup Servlet URL")) {
- SetupServlet var6 = new SetupServlet(this.chesslogic, this);
- var6.makeCurrent(CU.getDisplay());
- } else if (var1.equals("Setup Chess Engine")) {
- SetupChess var7 = new SetupChess(this.chesslogic, this);
- var7.makeCurrent(CU.getDisplay());
- } else if (var1.equals("Post History")) {
- MessageForm var8 = new MessageForm("Post History", PostThread.getPostHistory(), this);
- var8.makeCurrent(CU.getDisplay());
- }
-
- if (var2 != null) {
- this.myScreen.setTitle(var2.getStatus());
- }
-
- }
-
- public void initialize() {
- this.myScreen = new List("Choose Command", 3);
- this.OKCommand = new Command("OK", 4, 1);
- this.backCommand = new Command("Chess", 2, 1);
- if (this.chesslogic.getChessGame() == null) {
- this.myScreen.append("Logon", (Image)null);
- } else {
- ChessGame var1 = this.chesslogic.getChessGame();
- if (!var1.isPlaying()) {
- this.myScreen.append("Match player", (Image)null);
- } else {
- this.myScreen.append("Resign from game", (Image)null);
- this.myScreen.append("Offer draw", (Image)null);
- this.myScreen.append("Abort from game", (Image)null);
- this.myScreen.append("Refresh board", (Image)null);
- this.myScreen.append("Nextstate", (Image)null);
- if (var1.drawOffered()) {
- this.myScreen.append("Accept draw-offer", (Image)null);
- this.myScreen.append("Decline draw-offer", (Image)null);
- }
- }
-
- if (var1.matchIssued()) {
- this.myScreen.append("Review match-offer", (Image)null);
- }
-
- if (var1.isChallenged()) {
- this.myScreen.append("Accept challenge", (Image)null);
- this.myScreen.append("Decline challenge", (Image)null);
- this.myScreen.append("Review challenge", (Image)null);
- }
-
- this.myScreen.append("Poll", (Image)null);
- this.myScreen.append("Logoff", (Image)null);
- }
-
- this.myScreen.append("Exit", (Image)null);
- this.myScreen.append("About", (Image)null);
- this.myScreen.append("Setup Servlet URL", (Image)null);
- this.myScreen.append("Setup Chess Engine", (Image)null);
- this.myScreen.append("Post History", (Image)null);
- this.myScreen.addCommand(this.OKCommand);
- this.myScreen.addCommand(this.backCommand);
- ChessGame var2 = this.chesslogic.getChessGame();
- if (var2 != null && var2.postActive()) {
- this.myScreen.setTitle(var2.getStatus());
- }
-
- }
-
- public boolean isActive() {
- return CU.getDisplay().getCurrent() == this.myScreen;
- }
-
- public void makeCurrent(Display var1) {
- this.initialize();
- var1.setCurrent(this.myScreen);
- this.myScreen.setCommandListener(this);
- }
-
- public void receiveServletResponse(String var1) {
- this.response = var1;
- if (CU.firstToken(var1).equals("who")) {
- MatchForm var2 = new MatchForm(CU.removeFirstTokens(var1, 1), this.chesslogic, this);
- var2.makeCurrent(CU.getDisplay());
- } else if (CU.firstToken(var1).equals("nextstate")) {
- if (this.chesslogic.getChessGame() != null) {
- this.chesslogic.getChessGame().setServletRedirection(this.chesslogic);
- }
-
- this.chessreturn.makeCurrent(CU.getDisplay());
- } else if (CU.firstToken(var1).equals("refresh")) {
- if (this.chesslogic.getChessGame() != null) {
- this.chesslogic.getChessGame().setServletRedirection(this.chesslogic);
- }
-
- this.chessreturn.makeCurrent(CU.getDisplay());
- }
-
- this.responsereceived = true;
- }
- }
-