package rms.view.util;

import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JPanel;

/**
 * Panel showing a loading gif and blocking all input to the underlying
 * components
 *
 * @author Timothy
 */
public final class LoadingPanel extends JPanel implements FocusListener, MouseListener {

    public LoadingPanel() {
        initComponents();
        initComponentsMore();
    }

    private void initComponentsMore() {
        this.addFocusListener(this);
        this.addMouseListener(this);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();

        setOpaque(false);
        setLayout(new java.awt.BorderLayout());

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/rms/view/util/loading.gif"))); // NOI18N
        add(jLabel1, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    // End of variables declaration//GEN-END:variables

    @Override
    public void setVisible(boolean aFlag) {
        if (aFlag) {
            // Grab the focus to capture all key events
            requestFocus();
        }
        super.setVisible(aFlag);
    }

    @Override
    public void focusGained(FocusEvent e) {
        // Do nothing
    }

    @Override
    public void focusLost(FocusEvent e) {
        // Make sure focus is not lost while visible
        if (isVisible()) {
            requestFocus();
        }
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        // Capture but ignore all mouse events
    }

    @Override
    public void mousePressed(MouseEvent e) {
        // Capture but ignore all mouse events
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        // Capture but ignore all mouse events
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        // Capture but ignore all mouse events
    }

    @Override
    public void mouseExited(MouseEvent e) {
        // Capture but ignore all mouse events
    }
}

@@ -218,19 +218,19 @@
 loading 
-gif
+GIF
  and blo
@@ -276,16 +276,17 @@
 mponents
+.
 %0A *%0A * @
@@ -1608,32 +1608,65 @@
 oolean aFlag) %7B%0A
+        super.setVisible(aFlag);%0A
         if (aFla
@@ -1719,22 +1719,33 @@
 all key 
+and mouse 
 events
+.
 %0A       
@@ -1753,66 +1753,114 @@
     
-requestFocus();%0A        %7D%0A        super.setVisible(aFlag);
+//NOTE: Component must first be visible for this to succeed.%0A            requestFocusInWindow();%0A        %7D
 %0A   
@@ -2058,16 +2058,17 @@
  visible
+.
 %0A       
@@ -2111,16 +2111,24 @@
 estFocus
+InWindow
 ();%0A    

Fix LoadingPanel focus request