/*
 * Image/J Plugins
 * Copyright (C) 2002-2008 Jarek Sacha
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Latest release available at http://sourceforge.net/projects/ij-plugins/
 *
 */
package net.sf.ij_plugins.ui;

import javax.swing.*;
import java.awt.event.InputEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;

/**
 * Demo of using {@link GlassPane}.
 * Based on example by Alexander Potochkin
 * http://weblogs.java.net/blog/alexfromsun/archive/2007/06/_enablingdisabl_1.html
 *
 * @author Jarek Sacha
 * @since Nov 15, 2008 8:09:11 AM
 */
public final class GlassPaneDemo extends JFrame {
    //    private JComponent initialGlassPane = new InitialGlassPane();
    private JComponent betterGlassPane = new GlassPane();

    public GlassPaneDemo() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JMenuBar bar = new JMenuBar();
        JMenu menu = new JMenu("Options");
        final JCheckBoxMenuItem showItem = new JCheckBoxMenuItem("Show GlassPane");
        showItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_MASK));
        showItem.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    getGlassPane().setVisible(true);
                } else {
                    getGlassPane().setVisible(false);
                }

                // Request focus to the better GlassPane
                if (betterGlassPane.isShowing()) {
                    betterGlassPane.requestFocusInWindow();
                }
            }
        });

        menu.add(showItem);
        menu.addSeparator();

        ButtonGroup group = new ButtonGroup();

        final JMenuItem item1 = new JRadioButtonMenuItem("Initial GlassPane");
        item1.setSelected(true);
        group.add(item1);
        menu.add(item1);

        final JMenuItem item2 = new JRadioButtonMenuItem("Better GlassPane");
        group.add(item2);
        menu.add(item2);

        ItemListener menuListener = new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                if (item1.isSelected()) {
                    setGlassPane(betterGlassPane);
                } else {
                    setGlassPane(betterGlassPane);
                }
            }
        };
        item1.addItemListener(menuListener);
        item2.addItemListener(menuListener);

        bar.add(menu);
        setJMenuBar(bar);

        setGlassPane(betterGlassPane);

        add(createPanel());
        setSize(250, 250);
        setLocationRelativeTo(null);
    }

    private JComponent createPanel() {
        JPanel panel = new JPanel();
        panel.add(new JCheckBox("JCheckBox"));
        panel.add(new JRadioButton("JRadioButton"));
        panel.add(new JTextField(15));
        panel.add(new JSlider());
        panel.add(new JCheckBox("JCheckBox"));
        panel.add(new JRadioButton("JRadioButton"));
        panel.add(new JTextField(15));
        panel.add(new JButton("JButton"));
        return panel;
    }

    public static void main(String[] args) throws Exception {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new GlassPaneDemo().setVisible(true);
            }
        });
    }

}

@@ -1385,22 +1385,18 @@
 rame %7B%0D%0A
-    //
+%0D%0A
     priv
@@ -1391,32 +1391,38 @@
 %0D%0A%0D%0A    private 
+final 
 JComponent initi
@@ -1420,16 +1420,9 @@
 ent 
-initialG
+g
 lass
@@ -1432,23 +1432,16 @@
 e = new 
-Initial
 GlassPan
@@ -1462,53 +1462,50 @@
 ate 
-JComponent betterGlassPane = new GlassPane();
+static final long serialVersionUID = 1L;%0D%0A
 %0D%0A%0D%0A
@@ -1595,24 +1595,30 @@
 );%0D%0A        
+final 
 JMenuBar bar
@@ -1645,16 +1645,22 @@
         
+final 
 JMenu me
@@ -2278,23 +2278,17 @@
     if (
-betterG
+g
 lassPane
@@ -2324,23 +2324,17 @@
         
-betterG
+g
 lassPane
@@ -2441,821 +2441,8 @@
 );%0D%0A
-        menu.addSeparator();%0D%0A%0D%0A        ButtonGroup group = new ButtonGroup();%0D%0A%0D%0A        final JMenuItem item1 = new JRadioButtonMenuItem(%22Initial GlassPane%22);%0D%0A        item1.setSelected(true);%0D%0A        group.add(item1);%0D%0A        menu.add(item1);%0D%0A%0D%0A        final JMenuItem item2 = new JRadioButtonMenuItem(%22Better GlassPane%22);%0D%0A        group.add(item2);%0D%0A        menu.add(item2);%0D%0A%0D%0A        ItemListener menuListener = new ItemListener() %7B%0D%0A            public void itemStateChanged(ItemEvent e) %7B%0D%0A                if (item1.isSelected()) %7B%0D%0A                    setGlassPane(betterGlassPane);%0D%0A                %7D else %7B%0D%0A                    setGlassPane(betterGlassPane);%0D%0A                %7D%0D%0A            %7D%0D%0A        %7D;%0D%0A        item1.addItemListener(menuListener);%0D%0A        item2.addItemListener(menuListener);%0D%0A%0D%0A
     
@@ -2515,15 +2515,9 @@
 ane(
-betterG
+g
 lass
@@ -2626,24 +2626,26 @@
 ;%0D%0A    %7D%0D%0A%0D%0A
+%0D%0A
     private 
@@ -2680,16 +2680,22 @@
         
+final 
 JPanel p
@@ -2712,24 +2712,114 @@
  JPanel();%0D%0A
+        panel.add(new JLabel(%22%3Chtml%3E%3Cem%3EPress Ctrl-D to togle glass pane%3C/em%3E%3C/html%3E%22));%0D%0A
         pane
@@ -3197,24 +3197,26 @@
 ;%0D%0A    %7D%0D%0A%0D%0A
+%0D%0A
     public s
@@ -3231,16 +3231,22 @@
 id main(
+final 
 String%5B%5D
@@ -3378,27 +3378,79 @@
     
-new GlassPaneDemo()
+final GlassPaneDemo frame = new GlassPaneDemo();%0D%0A                frame
 .set

Simplify code.