gt:     pageGC = new GC(pageBuffer);
context: /*
   * Copyright (c) 2014, 2015 Eike Stepper (Berlin, Germany) and others.
   * All rights reserved. This program and the accompanying materials
   * are made available under the terms of the Eclipse Public License v1.0
   * which accompanies this distribution, and is available at
   * http://www.eclipse.org/legal/epl-v10.html
   *
   * Contributors:
   *    Eike Stepper - initial API and implementation
   */
  package org.eclipse.oomph.setup.ui.questionnaire;
  
  import org.eclipse.oomph.preferences.PreferencesFactory;
  import org.eclipse.oomph.setup.ui.questionnaire.AnimatedCanvas.Animator;
  
  import org.eclipse.emf.common.util.URI;
  
  import org.eclipse.swt.SWT;
  import org.eclipse.swt.events.KeyEvent;
  import org.eclipse.swt.graphics.Color;
  import org.eclipse.swt.graphics.Font;
  import org.eclipse.swt.graphics.GC;
  import org.eclipse.swt.graphics.Image;
  import org.eclipse.swt.graphics.Path;
  import org.eclipse.swt.graphics.Point;
  import org.eclipse.swt.graphics.Rectangle;
  import org.eclipse.swt.widgets.Display;
  
  import java.util.ArrayList;
  import java.util.List;
  
  /**
   * @author Eike Stepper
   */
  public class GearAnimator extends Animator
  {
    public static final String RECORDER_PREFERENCE_KEY = "RECORDER_PREFERENCE_KEY";
  
    public static final int NONE = -1;
  
    public static final int PAGE_WIDTH = 620;
  
    public static final int PAGE_HEIGHT = 420;
  
    public static final int BORDER = 30;
  
    public static final int GEARS = 7;
  
    private static final int TEETH = 8;
  
    private static final float ANGLE = 360 / TEETH;
  
    private static final double RADIAN = 2 * Math.PI / 360;
  
    private static final int EXIT = NONE - 1;
  
    private static final int BACK = EXIT - 1;
  
    private static final int NEXT = BACK - 1;
  
    private static final int CHOICES = NEXT - 1;
  
    private static final String[] TITLES = { "Welcome to Eclipse", "Refresh Resources Automatically?", "Show Line Numbers in Editors?",
        "Check Spelling in Text Editors?", "Execute Jobs in Background?", "Encode Text Files with UTF-8?", "Enable Preference Recorder?" };
  
    static final int BIG_FONT_PX = 48;
  
    static final int NORMAL_FONT_PX = (int)(BIG_FONT_PX * .75);
  
    private static Color WHITE;
  
    private static Color GRAY;
  
    private static Color DARK_GRAY;
  
    private final List<Listener> listeners = new ArrayList<Listener>();
  
    private Color purple;
  
    private Color tooltipColor;
  
    private Font tooltipFont;
  
    private Font bigFont;
  
    private Font hoverFont;
  
    private Font normalFont;
  
    private Font numberFont;
  
    private Image exit;
  
    private Image exitHover;
  
    private Image question;
  
    private final Image[] welcomeImages = new Image[2];
  
    private final Image[] summaryImages = new Image[2];
  
    private final Image[] backImages = new Image[2];
  
    private final Image[] nextImages = new Image[2];
  
    private final Image[] yesImages = new Image[5];
  
    private final Image[] noImages = new Image[5];
  
    private final Page[] pages = new Page[GEARS + 1];
  
    private final Point[] tooltipPoints = new Point[pages.length];
  
    private final Path[] gearPaths = new Path[GEARS + 1];
  
    private final Color[] gearBackground = new Color[2];
  
    private final Color[] gearForeground = new Color[2];
  
    private float radius;
  
    private int pageY;
  
    private int answerY;
  
    private int buttonR;
  
    private long startAnimation;
  
    private float speed;
  
    private float angle;
  
    private boolean overflow;
  
    private int selection;
  
    private int oldSelection = NONE;
  
    private int hover = NONE;
  
    private int oldHover = NONE;
  
    private Image pageBuffer;
  
    private GC pageGC;
  
    private Image oldPageBuffer;
  
    private GC oldPageGC;
  
    private boolean pageBufferUpdated;
  
    private boolean oldShowOverlay;
  
    private boolean summaryShown;
  
    private Rectangle exitBox;
  
    private Rectangle backBox;
  
    private Rectangle nextBox;
  
    public GearAnimator(Display display)
    {
      super(display);
      WHITE = display.getSystemColor(SWT.COLOR_WHITE);
      GRAY = display.getSystemColor(SWT.COLOR_GRAY);
      DARK_GRAY = display.getSystemColor(SWT.COLOR_DARK_GRAY);
    }
  
    @Override
    protected void init()
    {
      super.init();
      Display display = getDisplay();
  
      bigFont = createFont(BIG_FONT_PX, PAGE_WIDTH, TITLES);
      hoverFont = createFont(BIG_FONT_PX + 6, PAGE_WIDTH, TITLES);
      normalFont = createFont(NORMAL_FONT_PX, PAGE_WIDTH, TITLES);
      numberFont = createFont(24);
      tooltipFont = createFont(16);
  
      exit = loadImage("exit.png");
      exitHover = loadImage("exit_hover.png");
      question = loadImage("question.png");
  
      welcomeImages[0] = loadImage("welcome.png");
      welcomeImages[1] = loadImage("welcome_select.png");
  
      summaryImages[0] = loadImage("summary.png");
      summaryImages[1] = loadImage("summary_select.png");
  
      backImages[0] = loadImage("back.png");
      backImages[1] = loadImage("back_hover.png");
  
      nextImages[0] = loadImage("next.png");
      nextImages[1] = loadImage("next_hover.png");
  
      buttonR = nextImages[0].getBounds().height / 2;
      answerY = PAGE_HEIGHT + 4 * BORDER - buttonR;
  
      yesImages[0] = loadImage("yes.png");
      yesImages[1] = loadImage("yes_select.png");
      yesImages[2] = loadImage("yes_hover.png");
      yesImages[3] = loadImage("yes_big.png");
      yesImages[4] = loadImage("yes_badge.png");
  
      noImages[0] = loadImage("no.png");
      noImages[1] = loadImage("no_select.png");
      noImages[2] = loadImage("no_hover.png");
      noImages[3] = loadImage("no_big.png");
      noImages[4] = loadImage("no_badge.png");
  
      radius = 32;
      setSize((int)(GEARS * 2 * radius), (int)(2 * radius));
      pageY = getHeight() + 2 * BORDER;
  
      // Not selected.
      gearBackground[0] = createColor(169, 171, 202);
      gearForeground[0] = createColor(140, 132, 171);
  
      // Selected.
      gearBackground[1] = createColor(247, 148, 30);
      gearForeground[1] = createColor(207, 108, 0);
  
      purple = createColor(43, 34, 84);
      tooltipColor = createColor(253, 232, 206);
  
      pages[0] = new ImagePage(0, TITLES[0], 0, 0, 0, new TextAnswer(""));
      pages[1] = new PreferencePage(1, TITLES[1], 0, 5, 29, "/instance/org.eclipse.core.resources/refresh.lightweight.enabled");
      pages[2] = new PreferencePage(2, TITLES[2], 1, 19, 30, "/instance/org.eclipse.ui.editors/lineNumberRuler");
      pages[3] = new PreferencePage(3, TITLES[3], 1, 186, 37, "/instance/org.eclipse.ui.editors/spellingEnabled");
      pages[4] = new PreferencePage(4, TITLES[4], 0, 23, 160, "/instance/org.eclipse.ui.workbench/RUN_IN_BACKGROUND");
      pages[5] = new PreferencePage(5, TITLES[5], 0, 181, 95, "/instance/org.eclipse.core.resources/encoding", "UTF-8", null);
      pages[6] = new PreferencePage(6, TITLES[6], 1, 57, 82, RECORDER_PREFERENCE_KEY);
      pages[7] = new SummaryPage(7, "Summary");
  
      pageBuffer = new Image(display, PAGE_WIDTH, PAGE_HEIGHT);
  