/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mobirent.gui;

import com.mobirent.abstracttags.Epitomize;
import gr.bluevibe.fire.components.Component;
import gr.bluevibe.fire.components.Panel;
import gr.bluevibe.fire.components.Row;
import gr.bluevibe.fire.displayables.FireScreen;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.TextField;

/**
 *
 * @author Budai Attila
 */
public class AllSetupPanel extends Epitomize {

    private static AllSetupPanel INSTANCE = null;
    private static Panel panel;
    private static Command back = new Command("Mégse", Command.EXIT, 0);
    private static Command ok = new Command("Mentes", Command.BACK, 0);
    private Row row = new Row(), row1 = new Row();

    private AllSetupPanel() {
        panel = getSetupPanel();
    }

    public void idSetup() {
        row.setText("");
        row1.setText("");
        row.setIs(true);
        row1.setIs(true);

        if (panel.getId().equals("Adatok")) {
            screen.closePopup();
            screen.setCurrent(AllSetupPanel.panel);
            row.setId("felhasználónév");
            row.setLabel("Név: ", FireScreen.defaultLabelFont, new Integer(screen.getWidth() / 2), FireScreen.RIGHT);
            row1.setId("jelszó");
            row1.setLabel("Jelszó: ", FireScreen.defaultLabelFont, new Integer(screen.getWidth() / 2), FireScreen.RIGHT);
            row.setText(userName);
            panel.add(row);
            panel.add(row1);

        } else if (panel.getId().equals("URL")) {
            screen.closePopup();
            screen.setCurrent(AllSetupPanel.panel);
            row.setId("URL");
            row.setLabel("URL: ", FireScreen.defaultLabelFont, new Integer(screen.getWidth() / 2), FireScreen.RIGHT);
            row.setText(URL);
            panel.add(row);

        } else {
            screen.closePopup();
            screen.setCurrent(AllSetupPanel.panel);
            row.setId("PhoneID");
            row.setLabel("Azonosító: ", FireScreen.defaultLabelFont, new Integer(screen.getWidth() / 2), FireScreen.RIGHT);
            row.setText(phoneId);
            panel.add(row);
        }
        panel.setPointerPos(0);
        System.gc();
    }

    private Panel getSetupPanel() {
        Panel pan = new Panel();

        row.setEditable(true);
        row1.setEditable(true);
        row.setTextBoxConstrains(TextField.INITIAL_CAPS_WORD);
        row.setTextBoxConstrains(1);
        row.setTextBoxSize(50);
        row1.setTextBoxConstrains(TextField.INITIAL_CAPS_WORD);
        row1.setTextBoxSize(50);

        pan.addCommand(back);
        pan.addCommand(ok);
        pan.setCommandListener(this);
        return pan;
    }

    public static AllSetupPanel getInstance() {

        if (INSTANCE == null) {
            INSTANCE = new AllSetupPanel();
        }
        System.gc();
        return INSTANCE;
    }

    public static void delPanelTags() {
        panel.removeAll();
    }

    public Panel getPanel() {
        return panel;
    }

    public void commandAction(Command cmd, Component c) {
        System.gc();
        if (cmd == back) {
            screen.closePopup();
            screen.setCurrent(SetupPanel.getInstance().getPanel(), FireScreen.RIGHT);
            return;
        }
        if (cmd == ok) {
            if (panel.getId().equals("Adatok") && (row.getText().length() == 0 || row1.getText().length() == 0)) {
                screen.closePopup();
                screen.getCurrentPanel().showAlert("Üres adatot nem mentünk!", null);
                return;
            }
            if (panel.getId().equals("Adatok")) {
                userName = row.getText();
                passwd = row1.getText();
            } else if (panel.getId().equals("URL")) {
                URL = row.getText();

            }
        }
        screen.closePopup();
        screen.setCurrent(SetupPanel.getInstance().getPanel(), FireScreen.RIGHT);

        recordStoreWriter("Adatok", userName + " " + passwd + " " + URL + " " + sessionId + " " + orderID + " " + OId + " ");
        return;
    }
}
