Package telefono

Source Code of telefono.Item

/*
* MicroPocha.java
*
* Created on 3 de junio de 2005, 15:31
*/

package telefono;

import java.io.IOException;
import java.util.Calendar;
import java.util.NoSuchElementException;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;

/**
*
* @author Enrique Vicent Ramis
*/
public class MicroPocha extends MIDlet implements javax.microedition.lcdui.CommandListener
{
    private Partida partida=null;
    private static Almacen almacen=null;
   
    /** Creates a new instance of MicroPocha */
    public MicroPocha()
    {
        almacen = new telefono.almacen.AlmacenMicropocha(this);
    }
   
    public static Almacen getAlmacen()
    {
        return almacen;
    }
   
    private Form crearPartida;//GEN-BEGIN:MVDFields
    private List menuEntrada;
    private Alert about;
    private ChoiceGroup tipoJuego;
    private TextField textField1;
    private TextField textField2;
    private TextField textField3;
    private TextField textField4;
    private TextField textField5;
    private Command cancelCommand1;
    private Command irATablero;
    private Alert noImplementado;
    private Form salida;
    private Command exitCommand1;
    private Command cancelCommand2;
    private Command exitCommand3;
    private telefono.Tablero tablero;
    private Command pantallaGrafico;
    private Command SalirDeTablero;
    private telefono.Grafico grafico;
    private Command backCommand1;
    private Image image1;
    private Image image2;
    private ImageItem imageItem2;
    private StringItem stringItem1;
    private StringItem stringItem2;
    private Command itemCommand1;
    private List cargarPartida;
    private Command screenCommand1;
    private Command borrarRms1;
    private Command okCommand1;
    private Command borrarRms;
    private Command GuardarComoCommand;
    private Form guardarComo;
    private StringItem stringItem3;
    private TextField guardaComoTextField;
    private Command okCommand2;
    private Command cancelCommand4;
    private Image image3;
    private ImageItem imageItem3;
    private Command backCommand2;
    private Command backCommand3;
    private Command cancelCarga;
    private Command reset;
    private Command screenCommand3;//GEN-END:MVDFields
   
//GEN-LINE:MVDMethods
   
    /** This method initializes UI of the application.//GEN-BEGIN:MVDInitBegin
     */
    private void initialize() {//GEN-END:MVDInitBegin
        // Insert pre-init code here
        getDisplay().setCurrent(get_menuEntrada());//GEN-LINE:MVDInitInit
        // Insert post-init code here
    }//GEN-LINE:MVDInitEnd
   
    /**
     * This method should return an instance of the display.
     */
    public Display getDisplay () {//GEN-FIRST:MVDGetDisplay
        return Display.getDisplay(this);
    }//GEN-LAST:MVDGetDisplay
   
    /**
     * This method should exit the midlet.
     */
    public void exitMIDlet () {//GEN-FIRST:MVDExitMidlet
        getDisplay().setCurrent(null);
        destroyApp(true);
        notifyDestroyed();
    }//GEN-LAST:MVDExitMidlet
   
    /** Called by the system to indicate that a command has been invoked on a particular displayable.//GEN-BEGIN:MVDCABegin
     * @param command the Command that ws invoked
     * @param displayable the Displayable on which the command was invoked
     */
    public void commandAction(Command command, Displayable displayable) {//GEN-END:MVDCABegin
        // Insert global pre-action code here
        if (displayable == menuEntrada) {//GEN-BEGIN:MVDCABody
            if (command == menuEntrada.SELECT_COMMAND) {
                switch (get_menuEntrada().getSelectedIndex()) {
                    case 0://GEN-END:MVDCABody
                        // Insert pre-action code here
                        getDisplay().setCurrent(get_crearPartida());//GEN-LINE:MVDCAAction6
                        // Insert post-action code here
                        break;//GEN-BEGIN:MVDCACase6
                    case 2://GEN-END:MVDCACase6
                        // Insert pre-action code here
                        getDisplay().setCurrent(get_about(), get_menuEntrada());//GEN-LINE:MVDCAAction8
                        // Insert post-action code here
                        break;//GEN-BEGIN:MVDCACase8
                    case 3://GEN-END:MVDCACase8
                        // Insert pre-action code here
                        exitMIDlet();//GEN-LINE:MVDCAAction25
                        // Insert post-action code here
                        break;//GEN-BEGIN:MVDCACase25
                    case 1://GEN-END:MVDCACase25
                        // Insert pre-action code here
                        //reinicializamos, siempre
                        cargarPartida=null;
                        getDisplay().setCurrent(get_cargarPartida());//GEN-LINE:MVDCAAction72
                        // Insert post-action code here
                        break;//GEN-BEGIN:MVDCACase72
                }
            }
        } else if (displayable == grafico) {
            if (command == backCommand1) {//GEN-END:MVDCACase72
                // Insert pre-action code here
                getDisplay().setCurrent(get_tablero());//GEN-LINE:MVDCAAction39
                // Insert post-action code here
            }//GEN-BEGIN:MVDCACase39
        } else if (displayable == crearPartida) {
            if (command == cancelCommand1) {//GEN-END:MVDCACase39
                // Insert pre-action code here
                getDisplay().setCurrent(get_menuEntrada());//GEN-LINE:MVDCAAction20
                // Insert post-action code here
            } else if (command == irATablero) {//GEN-LINE:MVDCACase20
                creaPartida();
                getDisplay().setCurrent(get_tablero());//GEN-LINE:MVDCAAction22
                // Insert post-action code here
            }//GEN-BEGIN:MVDCACase22
        } else if (displayable == salida) {
            if (command == cancelCommand2) {//GEN-END:MVDCACase22
                // Insert pre-action code here
                getDisplay().setCurrent(get_tablero());//GEN-LINE:MVDCAAction30
                // Insert post-action code here
            } else if (command == exitCommand1) {//GEN-LINE:MVDCACase30
                // Insert pre-action code here
                exitMIDlet();//GEN-LINE:MVDCAAction28
                // Insert post-action code here
            } else if (command == itemCommand1) {//GEN-LINE:MVDCACase28
                partida.reiniciar();
                get_tablero().reiniciar();
                getDisplay().setCurrent(get_tablero());//GEN-LINE:MVDCAAction47
                // Insert post-action code here
            } else if (command == reset) {//GEN-LINE:MVDCACase47
                // Insert pre-action code here
                getDisplay().setCurrent(get_menuEntrada());//GEN-LINE:MVDCAAction80
                // Insert post-action code here
            }//GEN-BEGIN:MVDCACase80
        } else if (displayable == cargarPartida) {
            if (command == okCommand1) {//GEN-END:MVDCACase80
                int seleccionado=cargarPartida.getSelectedIndex();
                if(seleccionado!=-1)
                {
                    String objetivo=cargarPartida.getString(seleccionado);
                    try
                    {
                        String xml=almacen.cargar(objetivo);
                        this.fromXml(xml);
                        getDisplay().setCurrent(get_tablero());//GEN-LINE:MVDCAAction55
                    }
                    catch (NoSuchElementException ex)
                    {
                        ex.printStackTrace();
                    }
                    catch (IOException ex)
                    {
                        ex.printStackTrace();
                    }
                    catch (XmlPullParserException ex)
                    {
                        ex.printStackTrace();
                    }
                }//si seleccionado
            } else if (command == borrarRms) {//GEN-LINE:MVDCACase55
                int seleccionado=cargarPartida.getSelectedIndex();
                if(seleccionado!=-1)
                {
                    String objetivo=cargarPartida.getString(seleccionado);
                    try
                    {
                        almacen.borrar(objetivo);
                        cargarPartida.delete(seleccionado);
                    }
                    catch (NoSuchElementException ex)
                    {
                        ex.printStackTrace();
                    }
                    catch (IOException ex)
                    {
                        ex.printStackTrace();
                    }
                }
                // Do nothing//GEN-LINE:MVDCAAction53
                // Insert post-action code here
            } else if (command == cancelCarga) {//GEN-LINE:MVDCACase53
                // Insert pre-action code here
                getDisplay().setCurrent(get_menuEntrada());//GEN-LINE:MVDCAAction78
                // Insert post-action code here
            }//GEN-BEGIN:MVDCACase78
        } else if (displayable == guardarComo) {
            if (command == cancelCommand4) {//GEN-END:MVDCACase78
                // Insert pre-action code here
                getDisplay().setCurrent(get_tablero());//GEN-LINE:MVDCAAction68
                // Insert post-action code here
            } else if (command == okCommand2) {//GEN-LINE:MVDCACase68
                String nombre=guardaComoTextField.getString();
                try
                {
                    almacen.guardar(nombre);
                }
                catch (IOException ex)
                {
                    ex.printStackTrace();
                }
                getDisplay().setCurrent(get_tablero());//GEN-LINE:MVDCAAction66
                // Insert post-action code here
            }//GEN-BEGIN:MVDCACase66
        } else if (displayable == tablero) {
            if (command == pantallaGrafico) {//GEN-END:MVDCACase66
                // Insert pre-action code here
                getDisplay().setCurrent(get_grafico());//GEN-LINE:MVDCAAction34
                // Insert post-action code here
            } else if (command == GuardarComoCommand) {//GEN-LINE:MVDCACase34
                // Insert pre-action code here
                getDisplay().setCurrent(get_guardarComo());//GEN-LINE:MVDCAAction61
                // Insert post-action code here
            } else if (command == SalirDeTablero) {//GEN-LINE:MVDCACase61
                // Insert pre-action code here
                getDisplay().setCurrent(get_salida());//GEN-LINE:MVDCAAction36
                // Insert post-action code here
            }//GEN-BEGIN:MVDCACase36
        }//GEN-END:MVDCACase36
        // Insert global post-action code here
}//GEN-LINE:MVDCAEnd
   
    /** This method returns instance for crearPartida component and should be called instead of accessing crearPartida field directly.//GEN-BEGIN:MVDGetBegin2
     * @return Instance for crearPartida component
     */
    public Form get_crearPartida() {
        if (crearPartida == null) {//GEN-END:MVDGetBegin2
            // Insert pre-init code here
            crearPartida = new Form(null, new Item[] {//GEN-BEGIN:MVDGetInit2
                get_tipoJuego(),
                get_textField1(),
                get_textField2(),
                get_textField3(),
                get_textField4(),
                get_textField5()
            });
            crearPartida.addCommand(get_cancelCommand1());
            crearPartida.addCommand(get_irATablero());
            crearPartida.setCommandListener(this);//GEN-END:MVDGetInit2
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd2
        return crearPartida;
    }//GEN-END:MVDGetEnd2
   
    /** This method returns instance for menuEntrada component and should be called instead of accessing menuEntrada field directly.//GEN-BEGIN:MVDGetBegin3
     * @return Instance for menuEntrada component
     */
    public List get_menuEntrada() {
        if (menuEntrada == null) {//GEN-END:MVDGetBegin3
            // Insert pre-init code here
            menuEntrada = new List(null, Choice.IMPLICIT, new String[] {//GEN-BEGIN:MVDGetInit3
                "Nueva Partida",
                "Cargar Partida",
                "Acerca",
                "Salir"
            }, new Image[] {
                null,
                null,
                null,
                null
            });
            menuEntrada.setCommandListener(this);
            menuEntrada.setSelectedFlags(new boolean[] {
                false,
                false,
                false,
                false
            });//GEN-END:MVDGetInit3
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd3
        return menuEntrada;
    }//GEN-END:MVDGetEnd3
   
    /** This method returns instance for about component and should be called instead of accessing about field directly.//GEN-BEGIN:MVDGetBegin9
     * @return Instance for about component
     */
    public Alert get_about() {
        if (about == null) {//GEN-END:MVDGetBegin9
            // Insert pre-init code here
            about = new Alert("Acerca de esta aplicaci\u00F3n", "Micro Pocha:\n\nprograma para apuntar los resultados de cada mano en la pocha (juego de cartas). Tanto en su versi\u00F3n normal como pocheada (extendida)\n\ntambien puede apuntar otros juegos de cartas\n\nAutor: Enrique Vicent Ramis (eccnil@gmail.com)\n\nversion 1.4.2\n\nnovedades 1.4.2\n-marcado del jugador que es mano en la proxima partida\n\nnovedades 1.4\n-ahora el guardado se realiza en 2\u00BA plano.\n-corregidos varios men\u00FAs introducidos en la 1.3.x\n\nnovedades 1.3.1\n-compatible con telefonos mas antiguos (cldc 1.0 / midp 1.0)\n\nnovedades 1.3\n-guarda y carga partidas\n-la partida por defecto tiene como ultimo jugador a \"yo\"\n-guardado automatico\n-enlace con la pantalla incial desde la final\n\nnovedades 1.2.3\n-corregido bug en la leyenda del gr\u00E1fico\n-corregido bug el \u00FAltimo jugador no puede empezar siendo mano\n\nnovedades 1.2.2\n-ahora el gr\u00E1fico tiene leyenda.\n\nnovedades 1.2\n-colores en los nombres de los usuarios que indican el color que tienen en el gr\u00E1fico\n-puntos marcadores de quien da (se activa con la tecla #).\n-opcion de reiniciar la partida en el men\u00FA de salir.\n\nbugs corregidos 1.1\n-fucn\u00F3n salir con resultados incompletos\n-modificar un resultado que no sea de la \u00FAltima ronda\n-a\u00F1adida la posibilidad de desempatar\n-esta pantalla", null, AlertType.INFO);//GEN-BEGIN:MVDGetInit9
            about.setTimeout(-2);//GEN-END:MVDGetInit9
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd9
        return about;
    }//GEN-END:MVDGetEnd9
   
    /** This method returns instance for tipoJuego component and should be called instead of accessing tipoJuego field directly.//GEN-BEGIN:MVDGetBegin10
     * @return Instance for tipoJuego component
     */
    public ChoiceGroup get_tipoJuego() {
        if (tipoJuego == null) {//GEN-END:MVDGetBegin10
            // Insert pre-init code here
            tipoJuego = new ChoiceGroup("Tipo de juego:", Choice.EXCLUSIVE, new String[] {//GEN-BEGIN:MVDGetInit10
                "Pocha",
                "Pocheada",
                "Otro"
            }, new Image[] {
                null,
                null,
                null
            });
            tipoJuego.setSelectedFlags(new boolean[] {
                true,
                false,
                false
            });//GEN-END:MVDGetInit10
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd10
        return tipoJuego;
    }//GEN-END:MVDGetEnd10
   
    /** This method returns instance for textField1 component and should be called instead of accessing textField1 field directly.//GEN-BEGIN:MVDGetBegin14
     * @return Instance for textField1 component
     */
    public TextField get_textField1() {
        if (textField1 == null) {//GEN-END:MVDGetBegin14
            // Insert pre-init code here
            textField1 = new TextField("Jugador 1", "", 120, TextField.ANY);//GEN-LINE:MVDGetInit14
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd14
        return textField1;
    }//GEN-END:MVDGetEnd14
   
    /** This method returns instance for textField2 component and should be called instead of accessing textField2 field directly.//GEN-BEGIN:MVDGetBegin15
     * @return Instance for textField2 component
     */
    public TextField get_textField2() {
        if (textField2 == null) {//GEN-END:MVDGetBegin15
            // Insert pre-init code here
            textField2 = new TextField("Jugador 2 (en blanco para ninguno)", null, 120, TextField.ANY);//GEN-LINE:MVDGetInit15
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd15
        return textField2;
    }//GEN-END:MVDGetEnd15
   
    /** This method returns instance for textField3 component and should be called instead of accessing textField3 field directly.//GEN-BEGIN:MVDGetBegin16
     * @return Instance for textField3 component
     */
    public TextField get_textField3() {
        if (textField3 == null) {//GEN-END:MVDGetBegin16
            // Insert pre-init code here
            textField3 = new TextField("Jugador 3 (en blanco para ninguno)", null, 120, TextField.ANY);//GEN-LINE:MVDGetInit16
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd16
        return textField3;
    }//GEN-END:MVDGetEnd16
   
    /** This method returns instance for textField4 component and should be called instead of accessing textField4 field directly.//GEN-BEGIN:MVDGetBegin17
     * @return Instance for textField4 component
     */
    public TextField get_textField4() {
        if (textField4 == null) {//GEN-END:MVDGetBegin17
            // Insert pre-init code here
            textField4 = new TextField("Jugador 4 (en blanco para ninguno)", null, 120, TextField.ANY);//GEN-LINE:MVDGetInit17
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd17
        return textField4;
    }//GEN-END:MVDGetEnd17
   
    /** This method returns instance for textField5 component and should be called instead of accessing textField5 field directly.//GEN-BEGIN:MVDGetBegin18
     * @return Instance for textField5 component
     */
    public TextField get_textField5() {
        if (textField5 == null) {//GEN-END:MVDGetBegin18
            // Insert pre-init code here
            textField5 = new TextField("Jugador 5 (en blanco para ninguno)", "Yo", 120, TextField.ANY);//GEN-LINE:MVDGetInit18
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd18
        return textField5;
    }//GEN-END:MVDGetEnd18
   
    /** This method returns instance for cancelCommand1 component and should be called instead of accessing cancelCommand1 field directly.//GEN-BEGIN:MVDGetBegin19
     * @return Instance for cancelCommand1 component
     */
    public Command get_cancelCommand1() {
        if (cancelCommand1 == null) {//GEN-END:MVDGetBegin19
            // Insert pre-init code here
            cancelCommand1 = new Command("Cancel", Command.CANCEL, 2);//GEN-LINE:MVDGetInit19
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd19
        return cancelCommand1;
    }//GEN-END:MVDGetEnd19
   
    /** This method returns instance for irATablero component and should be called instead of accessing irATablero field directly.//GEN-BEGIN:MVDGetBegin21
     * @return Instance for irATablero component
     */
    public Command get_irATablero() {
        if (irATablero == null) {//GEN-END:MVDGetBegin21
            // Insert pre-init code here
            irATablero = new Command("Ok", Command.OK, 1);//GEN-LINE:MVDGetInit21
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd21
        return irATablero;
    }//GEN-END:MVDGetEnd21
   
    /** This method returns instance for noImplementado component and should be called instead of accessing noImplementado field directly.//GEN-BEGIN:MVDGetBegin23
     * @return Instance for noImplementado component
     */
    public Alert get_noImplementado() {
        if (noImplementado == null) {//GEN-END:MVDGetBegin23
            // Insert pre-init code here
            noImplementado = new Alert("No Implementado Aun", "Esta opcion todav\u00EDa no ha sido implementada", null, AlertType.INFO);//GEN-BEGIN:MVDGetInit23
            noImplementado.setTimeout(-2);//GEN-END:MVDGetInit23
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd23
        return noImplementado;
    }//GEN-END:MVDGetEnd23
   
    /** This method returns instance for salida component and should be called instead of accessing salida field directly.//GEN-BEGIN:MVDGetBegin26
     * @return Instance for salida component
     */
    public Form get_salida() {
        if (salida == null) {//GEN-END:MVDGetBegin26
            // Insert pre-init code here
            salida = new Form("Resultdos", new Item[] {//GEN-BEGIN:MVDGetInit26
                get_imageItem3(),
                get_stringItem1(),
                get_imageItem2(),
                get_stringItem2()
            });
            salida.addCommand(get_exitCommand1());
            salida.addCommand(get_cancelCommand2());
            salida.addCommand(get_itemCommand1());
            salida.addCommand(get_reset());
            salida.setCommandListener(this);//GEN-END:MVDGetInit26
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd26
        return salida;
    }//GEN-END:MVDGetEnd26
   
    /** This method returns instance for exitCommand1 component and should be called instead of accessing exitCommand1 field directly.//GEN-BEGIN:MVDGetBegin27
     * @return Instance for exitCommand1 component
     */
    public Command get_exitCommand1() {
        if (exitCommand1 == null) {//GEN-END:MVDGetBegin27
            // Insert pre-init code here
            exitCommand1 = new Command("Terminar", Command.EXIT, 1);//GEN-LINE:MVDGetInit27
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd27
        return exitCommand1;
    }//GEN-END:MVDGetEnd27
   
    /** This method returns instance for cancelCommand2 component and should be called instead of accessing cancelCommand2 field directly.//GEN-BEGIN:MVDGetBegin29
     * @return Instance for cancelCommand2 component
     */
    public Command get_cancelCommand2() {
        if (cancelCommand2 == null) {//GEN-END:MVDGetBegin29
            // Insert pre-init code here
            cancelCommand2 = new Command("Volver", Command.CANCEL, 1);//GEN-LINE:MVDGetInit29
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd29
        return cancelCommand2;
    }//GEN-END:MVDGetEnd29
   
    /** This method returns instance for exitCommand3 component and should be called instead of accessing exitCommand3 field directly.//GEN-BEGIN:MVDGetBegin31
     * @return Instance for exitCommand3 component
     */
    public Command get_exitCommand3() {
        if (exitCommand3 == null) {//GEN-END:MVDGetBegin31
            // Insert pre-init code here
            exitCommand3 = new Command("Exit", Command.EXIT, 1);//GEN-LINE:MVDGetInit31
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd31
        return exitCommand3;
    }//GEN-END:MVDGetEnd31
   
    /** This method returns instance for tablero component and should be called instead of accessing tablero field directly.//GEN-BEGIN:MVDGetBegin32
     * @return Instance for tablero component
     */
    public telefono.Tablero get_tablero() {
        if (tablero == null) {//GEN-END:MVDGetBegin32
            // Insert pre-init code here
            tablero = new telefono.Tablero(null, this);//GEN-BEGIN:MVDGetInit32
            tablero.addCommand(get_pantallaGrafico());
            tablero.addCommand(get_SalirDeTablero());
            tablero.addCommand(get_GuardarComoCommand());
            tablero.setCommandListener(this);//GEN-END:MVDGetInit32
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd32
        return tablero;
    }//GEN-END:MVDGetEnd32
   
    /** This method returns instance for pantallaGrafico component and should be called instead of accessing pantallaGrafico field directly.//GEN-BEGIN:MVDGetBegin33
     * @return Instance for pantallaGrafico component
     */
    public Command get_pantallaGrafico() {
        if (pantallaGrafico == null) {//GEN-END:MVDGetBegin33
            // Insert pre-init code here
            pantallaGrafico = new Command("Grafico", Command.SCREEN, 1);//GEN-LINE:MVDGetInit33
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd33
        return pantallaGrafico;
    }//GEN-END:MVDGetEnd33
   
    /** This method returns instance for SalirDeTablero component and should be called instead of accessing SalirDeTablero field directly.//GEN-BEGIN:MVDGetBegin35
     * @return Instance for SalirDeTablero component
     */
    public Command get_SalirDeTablero() {
        if (SalirDeTablero == null) {//GEN-END:MVDGetBegin35
            // Insert pre-init code here
            SalirDeTablero = new Command("Terminar", Command.EXIT, 3);//GEN-LINE:MVDGetInit35
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd35
        return SalirDeTablero;
    }//GEN-END:MVDGetEnd35
   
    /** This method returns instance for grafico component and should be called instead of accessing grafico field directly.//GEN-BEGIN:MVDGetBegin37
     * @return Instance for grafico component
     */
    public telefono.Grafico get_grafico() {
        if (grafico == null) {//GEN-END:MVDGetBegin37
            // Insert pre-init code here
            grafico = new telefono.Grafico(partida, this);//GEN-BEGIN:MVDGetInit37
            grafico.addCommand(get_backCommand1());
            grafico.setCommandListener(this);//GEN-END:MVDGetInit37
            grafico.addCommand(get_backCommand1());
        }//GEN-BEGIN:MVDGetEnd37
        return grafico;
    }//GEN-END:MVDGetEnd37
   
    /** This method returns instance for backCommand1 component and should be called instead of accessing backCommand1 field directly.//GEN-BEGIN:MVDGetBegin38
     * @return Instance for backCommand1 component
     */
    public Command get_backCommand1() {
        if (backCommand1 == null) {//GEN-END:MVDGetBegin38
            // Insert pre-init code here
            backCommand1 = new Command("Volver", Command.BACK, 1);//GEN-LINE:MVDGetInit38
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd38
        return backCommand1;
    }//GEN-END:MVDGetEnd38
   
    /** This method returns instance for image1 component and should be called instead of accessing image1 field directly.//GEN-BEGIN:MVDGetBegin40
     * @return Instance for image1 component
     */
    public Image get_image1() {
        if (image1 == null) {//GEN-END:MVDGetBegin40
            // Insert pre-init code here
            try {//GEN-BEGIN:MVDGetInit40
                image1 = Image.createImage("/res/champ.png");
            } catch (java.io.IOException exception) {
                exception.printStackTrace();
            }//GEN-END:MVDGetInit40
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd40
        return image1;
    }//GEN-END:MVDGetEnd40
    /** This method returns instance for image2 component and should be called instead of accessing image2 field directly.//GEN-BEGIN:MVDGetBegin42
     * @return Instance for image2 component
     */
    public Image get_image2() {
        if (image2 == null) {//GEN-END:MVDGetBegin42
            // Insert pre-init code here
            try {//GEN-BEGIN:MVDGetInit42
                image2 = Image.createImage("/res/crybaby.png");
            } catch (java.io.IOException exception) {
                exception.printStackTrace();
            }//GEN-END:MVDGetInit42
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd42
        return image2;
    }//GEN-END:MVDGetEnd42
   
    /** This method returns instance for imageItem2 component and should be called instead of accessing imageItem2 field directly.//GEN-BEGIN:MVDGetBegin43
     * @return Instance for imageItem2 component
     */
    public ImageItem get_imageItem2() {
        if (imageItem2 == null) {//GEN-END:MVDGetBegin43
            class Item /* para compatibilidad con midp1.0 */
            {
                static final public int LAYOUT_LEFT=1;
                static final public int LAYOUT_NEWLINE_AFTER=0x200;
                static final public int LAYOUT_NEWLINE_BEFORE=0x100;
                static final public int LAYOUT_RIGHT=2;
            };           
            imageItem2 = new ImageItem("Perdedor", get_image2(), ImageItem.LAYOUT_LEFT | ImageItem.LAYOUT_NEWLINE_BEFORE | ImageItem.LAYOUT_NEWLINE_AFTER, "PERDEDOR");//GEN-LINE:MVDGetInit43

        }//GEN-BEGIN:MVDGetEnd43
        return imageItem2;
    }//GEN-END:MVDGetEnd43
   
    /** This method returns instance for stringItem1 component and should be called instead of accessing stringItem1 field directly.//GEN-BEGIN:MVDGetBegin44
     * @return Instance for stringItem1 component
     */
    public StringItem get_stringItem1() {
        if (stringItem1 == null) {//GEN-END:MVDGetBegin44
            // Insert pre-init code here
            stringItem1 = new StringItem(partida.getGanadorNombre(), ""+partida.getGanadorPuntos()+" puntos");//GEN-LINE:MVDGetInit44
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd44
        return stringItem1;
    }//GEN-END:MVDGetEnd44
   
    /** This method returns instance for stringItem2 component and should be called instead of accessing stringItem2 field directly.//GEN-BEGIN:MVDGetBegin45
     * @return Instance for stringItem2 component
     */
    public StringItem get_stringItem2() {
        if (stringItem2 == null) {//GEN-END:MVDGetBegin45
            // Insert pre-init code here
            stringItem2 = new StringItem(partida.getPerdedorNombre(), ""+partida.getPerdedorPuntos()+" puntos");//GEN-LINE:MVDGetInit45
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd45
        return stringItem2;
    }//GEN-END:MVDGetEnd45
   
    /** This method returns instance for itemCommand1 component and should be called instead of accessing itemCommand1 field directly.//GEN-BEGIN:MVDGetBegin46
     * @return Instance for itemCommand1 component
     */
    public Command get_itemCommand1() {
        if (itemCommand1 == null) {//GEN-END:MVDGetBegin46
            // Insert pre-init code here
            itemCommand1 = new Command("Reiniciar", Command.ITEM, 1);//GEN-LINE:MVDGetInit46
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd46
        return itemCommand1;
    }//GEN-END:MVDGetEnd46
   
    /** This method returns instance for cargarPartida component and should be called instead of accessing cargarPartida field directly.//GEN-BEGIN:MVDGetBegin48
     * @return Instance for cargarPartida component
     */
    public List get_cargarPartida() {
        if (cargarPartida == null) {//GEN-END:MVDGetBegin48

            cargarPartida = new List("Cargar partida", Choice.IMPLICIT, new String[0], new Image[0]);//GEN-BEGIN:MVDGetInit48
            cargarPartida.addCommand(get_borrarRms());
            cargarPartida.addCommand(get_okCommand1());
            cargarPartida.addCommand(get_cancelCarga());
            cargarPartida.setCommandListener(this);
            cargarPartida.setSelectedFlags(new boolean[0]);//GEN-END:MVDGetInit48
            //cargarPartida.deleteAll();
            String[] slots=this.almacen.getExistentes();
            for(int i=0;i<slots.length;i++)
            {
                cargarPartida.append(slots[i],null);
            }
        }//GEN-BEGIN:MVDGetEnd48
        return cargarPartida;
    }//GEN-END:MVDGetEnd48
   
    /** This method returns instance for screenCommand1 component and should be called instead of accessing screenCommand1 field directly.//GEN-BEGIN:MVDGetBegin50
     * @return Instance for screenCommand1 component
     */
    public Command get_screenCommand1() {
        if (screenCommand1 == null) {//GEN-END:MVDGetBegin50
            // Insert pre-init code here
            screenCommand1 = new Command("Cargar", Command.SCREEN, 1);//GEN-LINE:MVDGetInit50
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd50
        return screenCommand1;
    }//GEN-END:MVDGetEnd50
   
    /** This method returns instance for borrarRms1 component and should be called instead of accessing borrarRms1 field directly.//GEN-BEGIN:MVDGetBegin52
     * @return Instance for borrarRms1 component
     */
    public Command get_borrarRms1() {
        if (borrarRms1 == null) {//GEN-END:MVDGetBegin52
            // Insert pre-init code here
            borrarRms1 = new Command("Cancelar", Command.CANCEL, 1);//GEN-LINE:MVDGetInit52
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd52
        return borrarRms1;
    }//GEN-END:MVDGetEnd52
   
    /** This method returns instance for okCommand1 component and should be called instead of accessing okCommand1 field directly.//GEN-BEGIN:MVDGetBegin54
     * @return Instance for okCommand1 component
     */
    public Command get_okCommand1() {
        if (okCommand1 == null) {//GEN-END:MVDGetBegin54
            // Insert pre-init code here
            /** carga , ok de carga*/
            okCommand1 = new Command("Ok", Command.OK, 1);//GEN-LINE:MVDGetInit54
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd54
        return okCommand1;
    }//GEN-END:MVDGetEnd54
   
    /** This method returns instance for borrarRms component and should be called instead of accessing borrarRms field directly.//GEN-BEGIN:MVDGetBegin58
     * @return Instance for borrarRms component
     */
    public Command get_borrarRms() {
        if (borrarRms == null) {//GEN-END:MVDGetBegin58
            // Insert pre-init code here
            borrarRms = new Command("Borrar", Command.ITEM, 2);//GEN-LINE:MVDGetInit58
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd58
        return borrarRms;
    }//GEN-END:MVDGetEnd58
   
    /** This method returns instance for GuardarComoCommand component and should be called instead of accessing GuardarComoCommand field directly.//GEN-BEGIN:MVDGetBegin60
     * @return Instance for GuardarComoCommand component
     */
    public Command get_GuardarComoCommand() {
        if (GuardarComoCommand == null) {//GEN-END:MVDGetBegin60
            // Insert pre-init code here
            GuardarComoCommand = new Command("Guardar Como", Command.CANCEL, 2);//GEN-LINE:MVDGetInit60
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd60
        return GuardarComoCommand;
    }//GEN-END:MVDGetEnd60
   
    /** This method returns instance for guardarComo component and should be called instead of accessing guardarComo field directly.//GEN-BEGIN:MVDGetBegin62
     * @return Instance for guardarComo component
     */
    public Form get_guardarComo() {
        if (guardarComo == null) {//GEN-END:MVDGetBegin62
            // Insert pre-init code here
            guardarComo = new Form("Cuardar como", new Item[] {//GEN-BEGIN:MVDGetInit62
                get_guardaComoTextField(),
                get_stringItem3()
            });
            guardarComo.addCommand(get_okCommand2());
            guardarComo.addCommand(get_cancelCommand4());
            guardarComo.setCommandListener(this);//GEN-END:MVDGetInit62
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd62
        return guardarComo;
    }//GEN-END:MVDGetEnd62
   
    /** This method returns instance for stringItem3 component and should be called instead of accessing stringItem3 field directly.//GEN-BEGIN:MVDGetBegin63
     * @return Instance for stringItem3 component
     */
    public StringItem get_stringItem3() {
        if (stringItem3 == null) {//GEN-END:MVDGetBegin63
            // Insert pre-init code here
            stringItem3 = new StringItem("Nota:", "Se sobreescribe sin confirmaci\u00F3n, los nombres de archivos en may\u00FAsculas son diferentes a los nombres en min\u00FAsculas.");//GEN-LINE:MVDGetInit63
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd63
        return stringItem3;
    }//GEN-END:MVDGetEnd63
   
    /** This method returns instance for guardaComoTextField component and should be called instead of accessing guardaComoTextField field directly.//GEN-BEGIN:MVDGetBegin64
     * @return Instance for guardaComoTextField component
     */
    public TextField get_guardaComoTextField() {
        if (guardaComoTextField == null) {//GEN-END:MVDGetBegin64
            // Insert pre-init code here
            guardaComoTextField = new TextField("Introduzca el nombre de archivo", "nuevo", 120, TextField.ANY);//GEN-LINE:MVDGetInit64
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd64
        return guardaComoTextField;
    }//GEN-END:MVDGetEnd64
   
    /** This method returns instance for okCommand2 component and should be called instead of accessing okCommand2 field directly.//GEN-BEGIN:MVDGetBegin65
     * @return Instance for okCommand2 component
     */
    public Command get_okCommand2() {
        if (okCommand2 == null) {//GEN-END:MVDGetBegin65
            // Insert pre-init code here
            okCommand2 = new Command("Ok", Command.OK, 1);//GEN-LINE:MVDGetInit65
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd65
        return okCommand2;
    }//GEN-END:MVDGetEnd65
   
    /** This method returns instance for cancelCommand4 component and should be called instead of accessing cancelCommand4 field directly.//GEN-BEGIN:MVDGetBegin67
     * @return Instance for cancelCommand4 component
     */
    public Command get_cancelCommand4() {
        if (cancelCommand4 == null) {//GEN-END:MVDGetBegin67
            // Insert pre-init code here
            cancelCommand4 = new Command("Cancel", Command.CANCEL, 1);//GEN-LINE:MVDGetInit67
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd67
        return cancelCommand4;
    }//GEN-END:MVDGetEnd67
   
    /** This method returns instance for image3 component and should be called instead of accessing image3 field directly.//GEN-BEGIN:MVDGetBegin69
     * @return Instance for image3 component
     */
    public Image get_image3() {
        if (image3 == null) {//GEN-END:MVDGetBegin69
            // Insert pre-init code here
            try {//GEN-BEGIN:MVDGetInit69
                image3 = Image.createImage((String) null);
            } catch (java.io.IOException exception) {
                exception.printStackTrace();
            }//GEN-END:MVDGetInit69
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd69
        return image3;
    }//GEN-END:MVDGetEnd69
   
    /** This method returns instance for imageItem3 component and should be called instead of accessing imageItem3 field directly.//GEN-BEGIN:MVDGetBegin70
     * @return Instance for imageItem3 component
     */
    public ImageItem get_imageItem3() {
        if (imageItem3 == null) {//GEN-END:MVDGetBegin70
            class Item /* para compatibilidad con midp1.0 */
            {
                static final public int LAYOUT_LEFT=1;
                static final public int LAYOUT_NEWLINE_AFTER=0x200;
                static final public int LAYOUT_NEWLINE_BEFORE=0x100;
                static final public int LAYOUT_RIGHT=2;
            };
            imageItem3 = new ImageItem("Ganador", get_image1(), ImageItem.LAYOUT_LEFT | ImageItem.LAYOUT_NEWLINE_AFTER, "CAMPEON");//GEN-LINE:MVDGetInit70
           
        }//GEN-BEGIN:MVDGetEnd70
        return imageItem3;
    }//GEN-END:MVDGetEnd70
   
    /** This method returns instance for backCommand2 component and should be called instead of accessing backCommand2 field directly.//GEN-BEGIN:MVDGetBegin74
     * @return Instance for backCommand2 component
     */
    public Command get_backCommand2() {
        if (backCommand2 == null) {//GEN-END:MVDGetBegin74
            // Insert pre-init code here
            backCommand2 = new Command("Back", Command.BACK, 1);//GEN-LINE:MVDGetInit74
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd74
        return backCommand2;
    }//GEN-END:MVDGetEnd74
   
    /** This method returns instance for backCommand3 component and should be called instead of accessing backCommand3 field directly.//GEN-BEGIN:MVDGetBegin75
     * @return Instance for backCommand3 component
     */
    public Command get_backCommand3() {
        if (backCommand3 == null) {//GEN-END:MVDGetBegin75
            // Insert pre-init code here
            backCommand3 = new Command("Back", Command.BACK, 1);//GEN-LINE:MVDGetInit75
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd75
        return backCommand3;
    }//GEN-END:MVDGetEnd75
   
    /** This method returns instance for cancelCarga component and should be called instead of accessing cancelCarga field directly.//GEN-BEGIN:MVDGetBegin77
     * @return Instance for cancelCarga component
     */
    public Command get_cancelCarga() {
        if (cancelCarga == null) {//GEN-END:MVDGetBegin77
            // Insert pre-init code here
            cancelCarga = new Command("Cancelar", Command.CANCEL, 1);//GEN-LINE:MVDGetInit77
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd77
        return cancelCarga;
    }//GEN-END:MVDGetEnd77
   
    /** This method returns instance for reset component and should be called instead of accessing reset field directly.//GEN-BEGIN:MVDGetBegin79
     * @return Instance for reset component
     */
    public Command get_reset() {
        if (reset == null) {//GEN-END:MVDGetBegin79
            // Insert pre-init code here
            reset = new Command("Menu de Inicio", Command.SCREEN, 1);//GEN-LINE:MVDGetInit79
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd79
        return reset;
    }//GEN-END:MVDGetEnd79
   
    /** This method returns instance for screenCommand3 component and should be called instead of accessing screenCommand3 field directly.//GEN-BEGIN:MVDGetBegin81
     * @return Instance for screenCommand3 component
     */
    public Command get_screenCommand3() {
        if (screenCommand3 == null) {//GEN-END:MVDGetBegin81
            // Insert pre-init code here
            screenCommand3 = new Command("Screen", Command.SCREEN, 1);//GEN-LINE:MVDGetInit81
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd81
        return screenCommand3;
    }//GEN-END:MVDGetEnd81
   
    /** crea la pantalla de juego*/
    private void creaPartida()
    {
        //crear partida
        java.util.Vector nombres=new java.util.Vector();
        nombres.addElement(this.textField1.getString());
        if(this.textField2.getString().trim().length()>0)
            nombres.addElement(this.textField2.getString());
        if(this.textField3.getString().trim().length()>0)
            nombres.addElement(this.textField3.getString());
        if(this.textField4.getString().trim().length()>0)
            nombres.addElement(this.textField4.getString());
        if(this.textField5.getString().trim().length()>0)
            nombres.addElement(this.textField5.getString());
        int reglas;
        switch(this.tipoJuego.getSelectedIndex())
        {
            case 0:
                reglas=Partida.POCHA;
                break;
            case 1:
                reglas=Partida.POCHEADA;
                break;
            case 2:
            default:
                reglas=Partida.OTRO;
                break;
        }
        String[] nombresA=new String[nombres.size()];
        nombres.copyInto(nombresA);
        partida=new Partida(nombresA, reglas);
        //mostrar tablero
        Display display=Display.getDisplay(this);
        Command exitCommand = new Command("Salir",Command.SCREEN,2);
        tablero=new Tablero(partida, this);
        tablero.addCommand(get_pantallaGrafico());
        tablero.addCommand(get_SalirDeTablero());
        tablero.addCommand(get_GuardarComoCommand());
    }
   
    public void startApp()
    {
        initialize();
    }
   
    public void pauseApp()
    {
        try
        {
            this.almacen.guardar();
        }
        catch (IOException ex)
        {
            ex.printStackTrace();
        }
    }
   
    public void destroyApp(boolean unconditional)
    {
        try
        {
            this.almacen.guardar();
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }
   
    /**
     * Serializa los datos de la partida en formato xml
     * @param destino buffer donde escribe el resultado.
     */
    public void toXml(StringBuffer destino)
    {
        destino.append("<?xml version='1.0' encoding='UTF-8'?>");
        destino.append('\n');
        destino.append("<app version='3.0'>");
        destino.append('\n');
        this.partida.toXml(destino);
        destino.append('\n');
        this.tablero.toXml(destino);
        destino.append('\n');
        destino.append("</app>");
        destino.append('\n');
       
       
    }
   
    /** metodo no funcioal para probar c?digo
     */
    private void sandbox()
    {
       
    }
   
    /**
     * Construye un juego de Micropocha partiendo de una
     * cadena xml que se gener? con el m?todo {@link #toXml}
     * @param xml cadena xml generada en {@link #toXml}
     * @throws org.xmlpull.v1.XmlPullParserException xml no parseable
     * @throws java.io.IOException error rms
     */
    public void fromXml(String xml) throws XmlPullParserException, IOException
    {
        XmlPullParserFactory fabrica=XmlPullParserFactory.newInstance();
        XmlPullParser analiazador=fabrica.newPullParser();
        fromXml(xml,analiazador);
    }
   
    /**
     * Construye un juego de Micropocha partiendo de una
     * cadena xml que se gener? con el m?todo {@link #toXml}
     * @param xml cadena xml{@link #toXml}
     * @param analizador analizador xml de tipo pull
     * @throws org.xmlpull.v1.XmlPullParserException error de parseado
     * @throws java.io.IOException error rms
     */
    public void fromXml(String xml,XmlPullParser analizador) throws XmlPullParserException, IOException
    {
        java.io.ByteArrayInputStream bai=new java.io.ByteArrayInputStream(xml.getBytes());
        java.io.InputStreamReader isr=new java.io.InputStreamReader(bai);
        analizador.setInput(isr);
        while(true)
        {
            int evt=analizador.next();
            if(evt==XmlPullParser.START_TAG)
            {
                if(analizador.getName().equals(Partida.xmlTag))
                {
                    this.partida=null;
                    this.partida=new Partida(isr,analizador);
                }
                if(analizador.getName().equals(Tablero.xmlTag))
                {
                    this.tablero=null;
                    Command exitCommand = new Command("Salir",Command.SCREEN,2);
                    this.tablero=new Tablero(this.partida,this,isr,analizador);
                    tablero.addCommand(get_pantallaGrafico());
                    tablero.addCommand(get_SalirDeTablero());
                    tablero.addCommand(get_GuardarComoCommand());
                }
            }
            else if(evt==XmlPullParser.END_TAG)
            {
                return;
            }
        }
    }
   
}
TOP

Related Classes of telefono.Item

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.