1

I'm trying to make a waiting screen using Form Glass Pane in LWUIT, the following is the code that I'm using

    public class LoadingGlassPane implements Painter {
    public static boolean isShown = false;
    public static IForm form;

    public void paint(Graphics g, Rectangle rect) {
        System.out.println("paint LoadingGlassPane");
        Font font = g.getFont();
        int color = g.getColor();
        g.setColor(0);
        g.setFont(Font.getDefaultFont());
        g.drawString("Loading...", 20, 120);
        g.setColor(color);
        g.setFont(font);
    }

    public void installPane(IForm f) {
        f.setGlassPane(this);
    }

    public void uninstallPane(IForm f) {
        f.setGlassPane(null);
    }

    public static IForm getForm() {
        return form;
    }

    public static void setForm(IForm form) {
        LoadingGlassPane.form = form;
    }

    public static boolean isIsShown() {
        return isShown;
    }

    public static void setIsShown(boolean isShown) {
        LoadingGlassPane.isShown = isShown;
    }
}

and

public class ProgressGlassPane extends LoadingGlassPane implements Animation, Runnable {

        int spacing = 20;
        int fontSpacing = 10;
        String loadMsg = "Loading...";
        //HTMLComponent htmlC;
    //    Dialog loading;

    //    public ProgressGlassPane(Dialog loading) {
    //        this.loading = loading;
    //    }
        public ProgressGlassPane() {
        }

        public void paint(Graphics g, Rectangle rect) {
            //while (isShown == true) {
                System.out.println("paint ProgressGlassPane");
                int color = g.getColor();
                Font font = g.getFont();

                int pos = (int) ((System.currentTimeMillis() % 2700) / 300);
                Font f = Font.getDefaultFont();
                //int startX = loading.getAbsoluteX() + (loading.getWidth() / 2) - spacing;
                int startX = (LGB.width / 2) - spacing;
                //int fontStartX = loading.getAbsoluteX() + (loading.getWidth() - f.stringWidth(loadMsg)) / 2;
                int fontStartX = (LGB.width - f.stringWidth(loadMsg)) / 2;
                //int startY = loading.getAbsoluteY() + (loading.getHeight() / 2) - spacing - (f.getHeight() + fontSpacing) / 2;
                int startY = (LGB.height / 2) - spacing - (f.getHeight() + fontSpacing) / 2;
                int i = 0;
                g.setColor(0xffffff);
                g.fillRect(Math.min(startX - 3, fontStartX), startY - 3, Math.max(spacing * 2 + 7, f.stringWidth(loadMsg)) + 1, spacing * 2 + 7 + f.getHeight() + fontSpacing);
                g.setColor(0);
                g.setFont(f);
                g.drawString(loadMsg, fontStartX, startY);
                startY += f.getHeight() + fontSpacing;
                for (int y = 0; y < 3; y++) {
                    for (int x = 0; x < 3; x++) {
                        int thickness = 3;
                        if (i == pos) {
                            thickness = 7;
                        } else if (i == pos - 1) {
                            thickness = 5;
                        }
                        g.fillRect(startX + x * spacing - (thickness / 2), startY + y * spacing - (thickness / 2), thickness, thickness);
                        i++;
                    }
                }
                g.setColor(color);
                g.setFont(font);
           // }
        }

        public boolean animate() {
            return true;
        }

        public void paint(Graphics g) {
            paint(g, null);
        }

        //void installPane(Form f) {
        public void installPane(IForm f) {
            super.installPane(f);
            //f.setGlassPane(this);
            f.registerAnimated(this);

        }

        //void uninstallPane(Form f) {
        public void uninstallPane(IForm f) {
            super.uninstallPane(f);
            //f.setGlassPane(this);
            f.deregisterAnimated(this);
        }

        public void run() {
            System.out.println("I'm running");
            if (isShown == true && form != null) {
                installPane(form);
            }
            else
            {
                uninstallPane(form);
            }
        }
    }

and from within my form

public static ProgressGlassPane progressPane;
progressPane = new ProgressGlassPane();

progressPane.setForm(this);
progressPane.setIsShown(true);
progressPane.run();

//Some Webservice code I want to run 
progressPane.setIsShown(false);

What I want to do exactly is to open the glass pan while I'm loading my data and hide it when I finish, but what Happen it send the request and after get the response show the glass pane , I have tried to put my glass pane in different thread to run independently from the main thread, and it is also not working.

tshepang
  • 12,111
  • 21
  • 91
  • 136
Amira Elsayed Ismail
  • 9,216
  • 30
  • 92
  • 175

1 Answers1

1

Is the webservice code blocking?

If you are on the EDT then that just wouldn't work. You need to uninstall from the completion.

Shai Almog
  • 51,749
  • 5
  • 35
  • 65