home *** CD-ROM | disk | FTP | other *** search
/ All for Cell Phones: Sony Ericsson / Sony-Ericsson 2004.iso / Java / BounceText / BounceText.jar / com / anyEase / ScreenSaver / TextMain.class (.txt) < prev   
Encoding:
Java Class File  |  2002-09-05  |  11.4 KB  |  453 lines

  1. package com.anyEase.ScreenSaver;
  2.  
  3. import java.util.Calendar;
  4. import java.util.Date;
  5. import java.util.Random;
  6. import javax.microedition.lcdui.Canvas;
  7. import javax.microedition.lcdui.ChoiceGroup;
  8. import javax.microedition.lcdui.Command;
  9. import javax.microedition.lcdui.CommandListener;
  10. import javax.microedition.lcdui.Display;
  11. import javax.microedition.lcdui.Displayable;
  12. import javax.microedition.lcdui.Font;
  13. import javax.microedition.lcdui.Form;
  14. import javax.microedition.lcdui.Gauge;
  15. import javax.microedition.lcdui.Graphics;
  16. import javax.microedition.lcdui.Image;
  17. import javax.microedition.lcdui.TextField;
  18. import javax.microedition.rms.RecordComparator;
  19. import javax.microedition.rms.RecordEnumeration;
  20. import javax.microedition.rms.RecordFilter;
  21. import javax.microedition.rms.RecordStore;
  22. import javax.microedition.rms.RecordStoreNotFoundException;
  23.  
  24. public class TextMain extends Canvas implements CommandListener, Runnable {
  25.    final byte NOSHOW = 0;
  26.    final byte SHOWTEXT = 1;
  27.    final byte SHOWDATE = 2;
  28.    final byte SHOWTIME = 3;
  29.    BounceText text;
  30.    Command cmdExit;
  31.    Command cmdAbout;
  32.    Command cmdHelp;
  33.    Command cmdRestart;
  34.    Command cmdSpeed;
  35.    Command[] cmdEdit;
  36.    Command cmdTZone;
  37.    Command cmdBack;
  38.    int nWidth;
  39.    int nHeight;
  40.    int speed = 50;
  41.    int numBlocks = 3;
  42.    boolean bPause;
  43.    boolean bRun = true;
  44.    Thread thread;
  45.    Image imgBack;
  46.    Graphics graphBack;
  47.    int nType = 0;
  48.    Form form;
  49.    TextField textfield;
  50.    ChoiceGroup choice;
  51.    Gauge gauge;
  52.    long offset;
  53.    int num;
  54.    Block[] block;
  55.  
  56.    public TextMain(BounceText var1) {
  57.       this.text = var1;
  58.       this.cmdExit = new Command("Exit", 7, 0);
  59.       this.cmdAbout = new Command("About", 1, 1);
  60.       this.cmdHelp = new Command("Help", 1, 2);
  61.       this.cmdRestart = new Command("Restart", 1, 3);
  62.       this.cmdTZone = new Command("Time Different", 1, 4);
  63.       this.cmdSpeed = new Command("Speed", 1, 5);
  64.       this.cmdBack = new Command("Back", 2, 1);
  65.       ((Displayable)this).addCommand(this.cmdExit);
  66.       ((Displayable)this).addCommand(this.cmdAbout);
  67.       ((Displayable)this).addCommand(this.cmdHelp);
  68.       ((Displayable)this).addCommand(this.cmdRestart);
  69.       this.cmdEdit = new Command[3];
  70.  
  71.       for(int var2 = 0; var2 < this.cmdEdit.length; ++var2) {
  72.          this.cmdEdit[var2] = new Command("Edit Text " + (var2 + 1), 1, 3);
  73.          ((Displayable)this).addCommand(this.cmdEdit[var2]);
  74.       }
  75.  
  76.       ((Displayable)this).addCommand(this.cmdTZone);
  77.       ((Displayable)this).addCommand(this.cmdSpeed);
  78.       ((Displayable)this).setCommandListener(this);
  79.       this.nWidth = ((Canvas)this).getWidth();
  80.       this.nHeight = ((Canvas)this).getHeight();
  81.       this.imgBack = Image.createImage(this.nWidth, this.nHeight);
  82.       this.graphBack = this.imgBack.getGraphics();
  83.       this.block = new Block[this.numBlocks];
  84.       this.init();
  85.       this.thread = new Thread(this);
  86.       this.thread.start();
  87.       this.getTime((byte)1);
  88.    }
  89.  
  90.    public String addZeroForSmall(int var1) {
  91.       return var1 < 10 ? "0" + Integer.toString(var1) : Integer.toString(var1);
  92.    }
  93.  
  94.    public void commandAction(Command var1, Displayable var2) {
  95.       if (var2.getClass().isInstance(this.form)) {
  96.          if (var1 == this.cmdBack) {
  97.             switch (this.nType) {
  98.                case 1:
  99.                case 2:
  100.                case 3:
  101.                default:
  102.                   break;
  103.                case 4:
  104.                   this.setTimeDiff(this.textfield.getString());
  105.                   break;
  106.                case 5:
  107.                   this.speed = (11 - this.gauge.getValue()) * 10;
  108.                   if (this.speed > 100) {
  109.                      this.speed = 100;
  110.                   }
  111.  
  112.                   this.save((byte)8);
  113.                   break;
  114.                case 6:
  115.                   this.block[this.nType - 6].setType((byte)this.choice.getSelectedIndex());
  116.                   this.block[this.nType - 6].setLabel(this.textfield.getString());
  117.                   this.save((byte)1);
  118.                   this.save((byte)2);
  119.                   break;
  120.                case 7:
  121.                   this.block[this.nType - 6].setType((byte)this.choice.getSelectedIndex());
  122.                   this.block[this.nType - 6].setLabel(this.textfield.getString());
  123.                   this.save((byte)3);
  124.                   this.save((byte)4);
  125.                   break;
  126.                case 8:
  127.                   this.block[this.nType - 6].setType((byte)this.choice.getSelectedIndex());
  128.                   this.block[this.nType - 6].setLabel(this.textfield.getString());
  129.                   this.save((byte)5);
  130.                   this.save((byte)6);
  131.             }
  132.  
  133.             this.form = null;
  134.             this.textfield = null;
  135.             this.choice = null;
  136.             this.gauge = null;
  137.             Display.getDisplay(this.text).setCurrent(this);
  138.          }
  139.       } else if (var1 == this.cmdExit) {
  140.          this.bRun = false;
  141.          this.text.destroyApp(false);
  142.          this.text.notifyDestroyed();
  143.       } else {
  144.          if (var1 == this.cmdAbout) {
  145.             this.nType = 1;
  146.          } else if (var1 == this.cmdHelp) {
  147.             this.nType = 2;
  148.          } else if (var1 == this.cmdRestart) {
  149.             this.nType = 3;
  150.          } else if (var1 == this.cmdTZone) {
  151.             this.nType = 4;
  152.          } else if (var1 == this.cmdSpeed) {
  153.             this.nType = 5;
  154.          } else {
  155.             for(int var3 = 0; var3 < this.cmdEdit.length; ++var3) {
  156.                if (var1 == this.cmdEdit[var3]) {
  157.                   this.nType = 6 + var3;
  158.                }
  159.             }
  160.          }
  161.  
  162.          this.doSetup(this.nType);
  163.       }
  164.  
  165.    }
  166.  
  167.    public void doSetup(int var1) {
  168.       if (var1 >= 1 && var1 <= 8) {
  169.          if (var1 == 3) {
  170.             this.reset();
  171.          } else {
  172.             this.form = new Form("Setup");
  173.             this.form.addCommand(this.cmdBack);
  174.             this.form.setCommandListener(this);
  175.             if (var1 == 1) {
  176.                this.form.setTitle("About");
  177.                this.form.append("BounceText is a screen savers for java enabled mobile phone.\rIf you have any contents and questions,please contact support@anyease.com.\rWelcome visit www.anyease.com for more information about it and the other software.\rCopyright anyEase 2002.");
  178.             } else if (var1 == 2) {
  179.                this.form.setTitle("Help");
  180.                this.form.append("You can input different content for each text and decide which text show what content.\r You can set the speed of run and the time different when you show time.");
  181.             } else if (var1 == 4) {
  182.                this.textfield = new TextField("Time difference:", Long.toString(this.offset / 3600000L), 3, 0);
  183.                this.form.append(this.textfield);
  184.             } else if (var1 == 5) {
  185.                this.gauge = new Gauge("Speed:", true, 10, 11 - this.speed / 10);
  186.                this.form.append(this.gauge);
  187.             } else if (var1 == 6 || var1 == 7 || var1 == 8) {
  188.                this.textfield = new TextField("Private Content:", this.block[var1 - 6].getLabel(), 10, 0);
  189.                this.form.append(this.textfield);
  190.                this.choice = new ChoiceGroup("Show setting:", 1);
  191.                this.choice.append("Don't Show", (Image)null);
  192.                this.choice.append("Private Content", (Image)null);
  193.                this.choice.append("Show Date", (Image)null);
  194.                this.choice.append("Show Time", (Image)null);
  195.                this.choice.setSelectedIndex(this.block[var1 - 6].getType(), true);
  196.                this.form.append(this.choice);
  197.             }
  198.  
  199.             Display.getDisplay(this.text).setCurrent(this.form);
  200.          }
  201.       }
  202.    }
  203.  
  204.    public String getTime(byte var1) {
  205.       String var2 = "";
  206.       Calendar var3 = Calendar.getInstance();
  207.       Date var4 = new Date();
  208.       var4.setTime(this.offset + var4.getTime());
  209.       var3.setTime(var4);
  210.       if (var1 == 2) {
  211.          var2 = this.addZeroForSmall(var3.get(2)) + "/" + this.addZeroForSmall(var3.get(5)) + " " + this.getWeekString(var3.get(7));
  212.       } else if (var1 == 3) {
  213.          var2 = this.addZeroForSmall(var3.get(11)) + ":" + this.addZeroForSmall(var3.get(12)) + ":" + this.addZeroForSmall(var3.get(13));
  214.       }
  215.  
  216.       return var2;
  217.    }
  218.  
  219.    public String getWeekString(int var1) {
  220.       String var2 = "";
  221.       switch (var1) {
  222.          case 1:
  223.             var2 = "Sun";
  224.             break;
  225.          case 2:
  226.             var2 = "Mon";
  227.             break;
  228.          case 3:
  229.             var2 = "Tue";
  230.             break;
  231.          case 4:
  232.             var2 = "Wed";
  233.             break;
  234.          case 5:
  235.             var2 = "Thu";
  236.             break;
  237.          case 6:
  238.             var2 = "Fri";
  239.             break;
  240.          case 7:
  241.             var2 = "Sat";
  242.       }
  243.  
  244.       return var2;
  245.    }
  246.  
  247.    public void init() {
  248.       Random var1 = new Random();
  249.       int[] var2 = new int[4];
  250.  
  251.       for(int var3 = 0; var3 < this.numBlocks; ++var3) {
  252.          var2[0] = Math.abs(var1.nextInt() % (this.nWidth / 2));
  253.          var2[1] = Math.abs(var1.nextInt() % (this.nHeight / 2));
  254.          var2[2] = var1.nextInt();
  255.          var2[3] = var1.nextInt();
  256.          this.block[var3] = new Block("Text " + (var3 + 1), this.nWidth, this.nHeight);
  257.          this.block[var3].init(var2[0], var2[1], var2[2], var2[3]);
  258.       }
  259.  
  260.       this.read();
  261.       Object var4 = null;
  262.    }
  263.  
  264.    public void paint(Graphics var1) {
  265.       this.graphBack.setColor(0);
  266.       this.graphBack.fillRect(0, 0, this.nWidth, this.nHeight);
  267.  
  268.       for(int var2 = 0; var2 < this.numBlocks; ++var2) {
  269.          byte var3 = this.block[var2].getType();
  270.          if (var3 != 0) {
  271.             if (var3 == 2 || var3 == 3) {
  272.                this.block[var2].setLabel(this.getTime(var3));
  273.             }
  274.  
  275.             this.block[var2].move();
  276.             this.block[var2].paint(this.graphBack);
  277.          }
  278.       }
  279.  
  280.       if (this.num > 6000) {
  281.          this.graphBack.setColor(0);
  282.          this.graphBack.fillRect(0, 0, this.nWidth, this.nHeight);
  283.          this.graphBack.setColor(255, 255, 255);
  284.          this.graphBack.setFont(Font.getFont(0, 0, 8));
  285.          this.graphBack.drawString("Demo Version", 2, 2, 20);
  286.          this.graphBack.drawString("Play again!", 2, 12, 20);
  287.          this.graphBack.drawString("www.anyEase.com", 2, 22, 20);
  288.          this.graphBack.drawString("Buy it from anyEase", 2, 32, 20);
  289.          this.graphBack.drawString("or from Handango.", 2, 42, 20);
  290.       } else {
  291.          ++this.num;
  292.       }
  293.  
  294.       var1.drawImage(this.imgBack, 0, 0, 20);
  295.    }
  296.  
  297.    public void read() {
  298.       Object var1 = null;
  299.       Object var2 = null;
  300.  
  301.       try {
  302.          RecordStore var16 = RecordStore.openRecordStore("com.anyEase.ScreenSaver.Text", false);
  303.          RecordEnumeration var18 = var16.enumerateRecords((RecordFilter)null, (RecordComparator)null, false);
  304.  
  305.          for(int var29 = 8; var18.hasNextElement(); --var29) {
  306.             byte[] var6 = var18.nextRecord();
  307.             switch (var29) {
  308.                case 1:
  309.                   this.block[0].setLabel(new String(var6));
  310.                   break;
  311.                case 2:
  312.                   this.block[0].setType(Byte.parseByte(new String(var6)));
  313.                   break;
  314.                case 3:
  315.                   this.block[1].setLabel(new String(var6));
  316.                   break;
  317.                case 4:
  318.                   this.block[1].setType(Byte.parseByte(new String(var6)));
  319.                   break;
  320.                case 5:
  321.                   this.block[2].setLabel(new String(var6));
  322.                   break;
  323.                case 6:
  324.                   this.block[2].setType(Byte.parseByte(new String(var6)));
  325.                   break;
  326.                case 7:
  327.                   this.offset = Long.parseLong(new String(var6));
  328.                   break;
  329.                case 8:
  330.                   this.speed = Integer.parseInt(new String(var6));
  331.             }
  332.          }
  333.  
  334.          var18.destroy();
  335.          var16.closeRecordStore();
  336.       } catch (RecordStoreNotFoundException var12) {
  337.          try {
  338.             RecordStore var15 = RecordStore.openRecordStore("com.anyEase.ScreenSaver.Text", true);
  339.             Object var5 = null;
  340.             byte[] var20 = this.block[0].getLabel().getBytes();
  341.             var15.addRecord(var20, 0, var20.length);
  342.             var20 = Integer.toString(this.block[0].getType()).getBytes();
  343.             var15.addRecord(var20, 0, var20.length);
  344.             var20 = this.block[1].getLabel().getBytes();
  345.             var15.addRecord(var20, 0, var20.length);
  346.             var20 = Integer.toString(this.block[1].getType()).getBytes();
  347.             var15.addRecord(var20, 0, var20.length);
  348.             var20 = this.block[2].getLabel().getBytes();
  349.             var15.addRecord(var20, 0, var20.length);
  350.             var20 = Integer.toString(this.block[2].getType()).getBytes();
  351.             var15.addRecord(var20, 0, var20.length);
  352.             var20 = Long.toString(this.offset).getBytes();
  353.             var15.addRecord(var20, 0, var20.length);
  354.             var20 = Integer.toString(this.speed).getBytes();
  355.             var15.addRecord(var20, 0, var20.length);
  356.             Object var28 = null;
  357.             var15.closeRecordStore();
  358.          } catch (Exception var11) {
  359.          }
  360.       } catch (Exception var13) {
  361.          System.out.println("Other exception in read() : " + ((Throwable)var13).getMessage());
  362.       } finally {
  363.          var2 = null;
  364.          var1 = null;
  365.       }
  366.  
  367.    }
  368.  
  369.    public void reset() {
  370.       Random var1 = new Random();
  371.       int[] var2 = new int[4];
  372.  
  373.       for(int var3 = 0; var3 < this.numBlocks; ++var3) {
  374.          var2[0] = Math.abs(var1.nextInt() % (this.nWidth / 2));
  375.          var2[1] = Math.abs(var1.nextInt() % (this.nHeight / 2));
  376.          var2[2] = var1.nextInt();
  377.          var2[3] = var1.nextInt();
  378.          this.block[var3].init(var2[0], var2[1], var2[2], var2[3]);
  379.       }
  380.  
  381.       Object var4 = null;
  382.    }
  383.  
  384.    public void run() {
  385.       for(; this.bRun; ((Canvas)this).repaint()) {
  386.          try {
  387.             Thread.sleep((long)this.speed);
  388.          } catch (InterruptedException var1) {
  389.             return;
  390.          }
  391.       }
  392.  
  393.    }
  394.  
  395.    public void save(byte var1) {
  396.       Object var2 = null;
  397.  
  398.       try {
  399.          RecordStore var10 = RecordStore.openRecordStore("com.anyEase.ScreenSaver.Text", false);
  400.          Object var5 = null;
  401.          switch (var1) {
  402.             case 1:
  403.                byte[] var19 = this.block[0].getLabel().getBytes();
  404.                var10.setRecord(var1, var19, 0, var19.length);
  405.                break;
  406.             case 2:
  407.                byte[] var18 = Integer.toString(this.block[0].getType()).getBytes();
  408.                var10.setRecord(var1, var18, 0, var18.length);
  409.                break;
  410.             case 3:
  411.                byte[] var17 = this.block[1].getLabel().getBytes();
  412.                var10.setRecord(var1, var17, 0, var17.length);
  413.                break;
  414.             case 4:
  415.                byte[] var16 = Integer.toString(this.block[1].getType()).getBytes();
  416.                var10.setRecord(var1, var16, 0, var16.length);
  417.                break;
  418.             case 5:
  419.                byte[] var15 = this.block[2].getLabel().getBytes();
  420.                var10.setRecord(var1, var15, 0, var15.length);
  421.                break;
  422.             case 6:
  423.                byte[] var14 = Integer.toString(this.block[2].getType()).getBytes();
  424.                var10.setRecord(var1, var14, 0, var14.length);
  425.                break;
  426.             case 7:
  427.                byte[] var13 = Long.toString(this.offset).getBytes();
  428.                var10.setRecord(var1, var13, 0, var13.length);
  429.                break;
  430.             case 8:
  431.                byte[] var12 = Integer.toString(this.speed).getBytes();
  432.                var10.setRecord(var1, var12, 0, var12.length);
  433.          }
  434.  
  435.          var10.closeRecordStore();
  436.          var5 = null;
  437.       } catch (Exception var8) {
  438.       } finally {
  439.          var2 = null;
  440.       }
  441.  
  442.    }
  443.  
  444.    public void setTimeDiff(String var1) {
  445.       try {
  446.          this.offset = (long)(Integer.parseInt(var1) * 3600000);
  447.          this.save((byte)7);
  448.       } catch (Exception var2) {
  449.       }
  450.  
  451.    }
  452. }
  453.