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

package example;

import java.awt.*;
import java.awt.geom.Ellipse2D;
import java.awt.image.BufferedImage;
import javax.swing.*;

public final class MainPanel extends JPanel {
  private MainPanel() {
    super(new BorderLayout());
    add(new ColorWheel());
    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 ColorWheel extends JPanel {
  private static final int SIZE = 180;
  private final transient BufferedImage image;

  protected ColorWheel() {
    super();
    image = updateImage();
    setPreferredSize(new Dimension(320, 240));
  }

  @Override public void paintComponent(Graphics g) {
    super.paintComponent(g);

    // SIZE = 32 * 6; // Drawing breaks on Corretto 1.8.0_212
    int s = SIZE;
    Graphics2D g2 = (Graphics2D) g.create();

    // Soft Clipping
    GraphicsConfiguration gc = g2.getDeviceConfiguration();
    BufferedImage buf = gc.createCompatibleImage(s, s, Transparency.TRANSLUCENT);
    Graphics2D g2d = buf.createGraphics();

    g2d.setComposite(AlphaComposite.Src);
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.fill(new Ellipse2D.Float(0f, 0f, s, s));

    g2d.setComposite(AlphaComposite.SrcAtop);
    g2d.drawImage(image, 0, 0, this);
    g2d.dispose();

    g2.drawImage(buf, (getWidth() - s) / 2, (getHeight() - s) / 2, this);
    g2.dispose();
  }

  // Colors: a Color Dialog | Java Graphics
  // https://javagraphics.blogspot.com/2007/04/jcolorchooser-making-alternative.html
  //   https://javagraphics.java.net/
  //   http://www.javased.com/index.php?source_dir=SPREAD/src/colorpicker/swing/ColorPickerPanel.java
  private BufferedImage updateImage() {
    BufferedImage img = new BufferedImage(SIZE, SIZE, BufferedImage.TYPE_INT_ARGB);
    int[] row = new int[SIZE];
    float size = (float) SIZE;
    float radius = size / 2f;

    for (int yidx = 0; yidx < SIZE; yidx++) {
      float y = yidx - size / 2f;
      for (int xidx = 0; xidx < SIZE; xidx++) {
        float x = xidx - size / 2f;
        double theta = Math.atan2(y, x) - 3d * Math.PI / 2d;
        if (theta < 0) {
          theta += 2d * Math.PI;
        }
        double r = Math.sqrt(x * x + y * y);
        float hue = (float) (theta / (2d * Math.PI));
        float sat = Math.min((float) (r / radius), 1f);
        float bri = 1f;
        row[xidx] = Color.HSBtoRGB(hue, sat, bri);
      }
      img.getRaster().setDataElements(0, yidx, SIZE, 1, row);
    }
    return img;
  }
}

@@ -1323,21 +1323,24 @@
 erride p
-ublic
+rotected
  void pa
@@ -1400,70 +1400,8 @@
 );%0A%0A
-    // SIZE = 32 * 6; // Drawing breaks on Corretto 1.8.0_212%0A
     
@@ -2559,18 +2559,16 @@
 t yi
-dx
  = 0; yi
 dx %3C
@@ -2563,18 +2563,16 @@
  = 0; yi
-dx
  %3C SIZE;
@@ -2574,18 +2574,16 @@
 SIZE; yi
-dx
 ++) %7B%0A  
@@ -2598,18 +2598,16 @@
 t y = yi
-dx
  - size 
@@ -2633,18 +2633,16 @@
 t xi
-dx
  = 0; xi
 dx %3C
@@ -2637,18 +2637,16 @@
  = 0; xi
-dx
  %3C SIZE;
@@ -2648,18 +2648,16 @@
 SIZE; xi
-dx
 ++) %7B%0A  
@@ -2674,18 +2674,16 @@
 t x = xi
-dx
  - size 
@@ -3010,18 +3010,16 @@
   row%5Bxi
-dx
 %5D = Colo
@@ -3100,10 +3100,8 @@
 , yi
-dx
 , SI

use of protected void paintComponent(...) instead of public