// -*- mode:java; encoding:utf-8 -*-
// vim:set fileencoding=utf-8:
// @homepage@

package example;

import java.awt.*;
import javax.swing.*;

public final class MainPanel extends JPanel {
  private MainPanel() {
    super(new BorderLayout());

    JCheckBox check = new JCheckBox("0x01_FF_00_00");
    JButton button = new JButton("Stop 5sec");
    button.addActionListener(e -> {
      Window w = SwingUtilities.getWindowAncestor(getRootPane());
      JDialog dialog = new JDialog(w, Dialog.ModalityType.APPLICATION_MODAL);
      dialog.setUndecorated(true);
      dialog.setBounds(w.getBounds());
      dialog.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
      int color = check.isSelected() ? 0x22_FF_00_00 : 0x01_FF_00_00;
      dialog.setBackground(new Color(color, true));
      new BackgroundTask() {
        @Override public void done() {
          if (!isDisplayable()) {
            cancel(true);
            return;
          }
          dialog.setVisible(false);
        }
      }.execute();
      dialog.setVisible(true);
    });

    JPanel p = new JPanel();
    p.add(check);
    p.add(new JTextField(10));
    p.add(button);
    add(p, BorderLayout.NORTH);
    add(new JScrollPane(new JTextArea(100, 80)));
    setPreferredSize(new Dimension(320, 240));
  }

  public static void main(String[] args) {
    EventQueue.invokeLater(MainPanel::createAndShowGui);
  }

  private static void createAndShowGui() {
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
      ex.printStackTrace();
      Toolkit.getDefaultToolkit().beep();
    }
    JFrame frame = new JFrame("@title@");
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.getContentPane().add(new MainPanel());
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  }
}

class BackgroundTask extends SwingWorker<String, Void> {
  @Override public String doInBackground() throws InterruptedException {
    Thread.sleep(5000);
    return "Done";
  }
}

@@ -277,18 +277,18 @@
 kBox(%220x
-01
+22
 _FF_00_0
@@ -725,18 +725,18 @@
  : 0x01_
-FF
+00
 _00_00;%0A
@@ -2116,16 +2116,17 @@
 .sleep(5
+_
 000);%0A  

fix JCheckBox text