public void capture() {
    if (startDelay == 0) {
      processCapture();

      return;
    }

    if (restartWithBeep) {
      timer = 0;
      display.beep();
      display.timerExec(
          1000,
          new Runnable() {
            public void run() {
              beep();
            }
          });
    } else {
      display.timerExec(
          startDelay,
          new Runnable() {
            public void run() {
              processCapture();
            }
          });
    }
  }
  private void onTTAutoCloseTimer() {

    //		System.out.println(UI.timeStampNano() + " onTTAutoCloseTimer\t");
    //		// TODO remove SYSTEM.OUT.PRINTLN

    final boolean isKeepOpened = onDisplayMouseMove();

    if (isKeepOpened) {

      // start again to check again
      _display.timerExec(AUTO_CLOSE_INTERVAL, _ttAutoCloseTimer);
    }
  }
 public ShowBriefly(String message) {
   Display display = WPManager.getDisplay();
   shell = new Shell(display, SWT.DIALOG_TRIM);
   Label label = new Label(shell, SWT.HORIZONTAL);
   label.setText(message);
   shell.open();
   display.timerExec(
       60000,
       new Runnable() {
         @Override
         public void run() {
           endShow();
         }
       });
 }
 public static void main(String[] args) {
   Display display = new Display();
   Shell shell = new Shell(display);
   shell.setSize(200, 200);
   shell.open();
   display.timerExec(
       5000,
       new Runnable() {
         public void run() {
           System.out.println("5000");
         }
       });
   display.timerExec(
       2000,
       new Runnable() {
         public void run() {
           System.out.println("2000");
         }
       });
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
   }
   display.dispose();
 }
  private void onDispose(final Event event) {

    if (_shell == null || _shell.isDisposed()) {
      return;
    }

    // hide tooltip definitively

    removeOwnerShellListener();
    removeDisplayFilterListener();

    // deactivate auto close timer
    _display.timerExec(-1, _ttAutoCloseTimer);

    _shell.dispose();
  }
  private void ttShow() {

    // shell is not yet fading in

    if (canShowToolTip() == false) {
      return;
    }

    // ensure tooltip is closed when mouse is not hovering the tooltip or application
    _display.timerExec(AUTO_CLOSE_INTERVAL, _ttAutoCloseTimer);

    _isShellFadingIn = true;
    _isShellFadingOut = false;

    animation10_Start();
  }
  public void beep() {
    timer += 1000;

    if (timer < startDelay) {
      display.beep();

      display.timerExec(
          1000,
          new Runnable() {
            public void run() {
              beep();
            }
          });
    } else {
      processCapture();
    }
  }
  public static void main(String[] args) {

    final Display display = new Display();

    Shell shell = new Shell(display);

    shell.pack();

    shell.open();

    final int TIME_OUT = 3000;

    final Runnable runnable =
        new Runnable() {

          public void run() {

            System.out.println("Idle for " + (TIME_OUT / 1000) + " seconds");

            display.timerExec(TIME_OUT, this);
          }
        };

    display.addFilter(
        SWT.KeyDown,
        new Listener() {

          public void handleEvent(Event event) {

            display.timerExec(TIME_OUT, runnable);
          }
        });

    display.timerExec(TIME_OUT, runnable);

    while (!shell.isDisposed()) {

      if (!display.readAndDispatch()) display.sleep();
    }

    display.dispose();
  }
Exemple #9
0
  /**
   * Start the animation.
   *
   * @exception SWTException
   *     <ul>
   *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
   *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
   *     </ul>
   */
  public synchronized void start() {
    checkWidget();
    if (active) return;

    active = true;
    showStripes = true;

    final Display display = getDisplay();
    final Runnable[] timer = new Runnable[1];
    timer[0] =
        new Runnable() {
          public void run() {
            if (!active) return;
            GC gc = new GC(AnimatedProgress.this);
            paintStripes(gc);
            gc.dispose();
            display.timerExec(SLEEP, timer[0]);
          }
        };
    display.timerExec(SLEEP, timer[0]);
  }
Exemple #10
0
  public void init() {

    display = new Display();
    shell = new Shell(display, SWT.SHELL_TRIM);
    shell.setText(TXT_WINDOW_TITLE);

    // shell.setLayout(new GridLayout(2, false));
    shell.setLayout(new GridLayout(1, false));

    initMenus();

    // left pane: whiteboard
    {
      Composite compositeWhiteboard =
          new Composite(shell, SWT.EMBEDDED | SWT.NO_BACKGROUND | SWT.BORDER);

      GridData gdWhiteboard =
          new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);

      compositeWhiteboard.setLayoutData(gdWhiteboard);

      clientWhiteboard = new ClientWhiteboardSWT(compositeWhiteboard);
      clientWhiteboard.init(this);

      clientWhiteboard.setLayoutActive(true);
    }

    // right pane: buttons + comments
    {
      /*
      Composite compositeRight = new Composite(shell, SWT.NONE);
      GridData gdRight = new GridData(GridData.FILL_VERTICAL);

      compositeRight.setLayoutData(gdRight);

      compositeRight.setLayout(new GridLayout());
       */
      Composite compositeBottom = new Composite(shell, SWT.NONE);
      GridData gdBottom = new GridData(GridData.FILL_HORIZONTAL);

      compositeBottom.setLayoutData(gdBottom);

      compositeBottom.setLayout(new GridLayout(3, false));

      // scores
      {
        Composite compositeScores = new Composite(compositeBottom, SWT.NONE);
        compositeScores.setLayout(new GridLayout(1, false));
        compositeScores.setLayoutData(
            new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING));

        scores = new Label[TypeScore.values().length];
        scoreslab = new Label[TypeScore.values().length];
        rg = new Label[TypeScore.values().length];
        rglab = new Label[TypeScore.values().length];
        scoreevo = new Label[TypeScore.values().length];
        rgevo = new Label[TypeScore.values().length];
        int i = 0;
        scvalprec = new HashMap<Integer, Double>(TypeScore.values().length, 1.0f);
        scrgprec = new HashMap<Integer, Double>(TypeScore.values().length, 1.0f);
        // AD TXT_TOOLTIP_HIGH_SCORE=new ArrayList(TypeScore.values().length); /*
        TXT_TOOLTIP_HIGH_SCORE = new ArrayList<String>(TypeScore.values().length); // */

        for (TypeScore sc : TypeScore.values()) {
          scvalprec.put(i, (double) 0);
          scrgprec.put(i, (double) 1);
          //					compositeSc.setLayout(new RowLayout(SWT.HORIZONTAL));
          Composite compositeSc = new Composite(compositeScores, SWT.NONE);
          GridLayout layoutName = new GridLayout(6, false);
          GridData gdSc =
              new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING);
          compositeSc.setBackground(LOOK_COLOR_BACKGROUND_SUBSPACES);
          compositeSc.setLayout(layoutName);
          compositeSc.setLayoutData(gdSc);

          scoreslab[i] = new Label(compositeSc, SWT.READ_ONLY);
          scoreslab[i].setText(sc.nom + ":");
          scoreslab[i].setBackground(LOOK_COLOR_BACKGROUND_SUBSPACES);
          scoreslab[i].setLayoutData(
              new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_END));
          scoreslab[i].setToolTipText(sc.tooltip);
          scores[i] = new Label(compositeSc, SWT.READ_ONLY);
          scores[i].setText(" 0000");
          scores[i].setBackground(LOOK_COLOR_BACKGROUND_SUBSPACES);
          scores[i].setLayoutData(
              new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_END));
          TXT_TOOLTIP_HIGH_SCORE.add(i, "High Scores");
          scores[i].setToolTipText(TXT_TOOLTIP_HIGH_SCORE.get(i));
          scoreevo[i] = new Label(compositeSc, SWT.READ_ONLY);
          scoreevo[i].setText(" (==)");
          scoreevo[i].setBackground(LOOK_COLOR_BACKGROUND_SUBSPACES);
          scoreevo[i].setLayoutData(
              new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_END));
          rglab[i] = new Label(compositeSc, SWT.READ_ONLY);
          rglab[i].setText(" Rg:");
          rglab[i].setBackground(LOOK_COLOR_BACKGROUND_SUBSPACES);
          rglab[i].setLayoutData(
              new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_END));
          rg[i] = new Label(compositeSc, SWT.READ_ONLY);
          rg[i].setText(" 00");
          rg[i].setBackground(LOOK_COLOR_BACKGROUND_SUBSPACES);
          rg[i].setLayoutData(
              new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_END));
          rgevo[i] = new Label(compositeSc, SWT.READ_ONLY);
          rgevo[i].setText(" (==)");
          rgevo[i].setBackground(LOOK_COLOR_BACKGROUND_SUBSPACES);
          rgevo[i].setLayoutData(
              new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_END));
          i++;
        }

        {
          // init the timer for refreshing this
          display.timerExec(
              PERIOD_REFRESH_SCORES,
              new Runnable() {
                public void run() {
                  majScores();
                  display.timerExec(PERIOD_REFRESH_SCORES, this);
                }
              });
        }
      }

      // comments
      {
        Composite compositeComments = new Composite(compositeBottom, SWT.NONE);

        GridData gdComments = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL);
        compositeComments.setLayoutData(gdComments);

        compositeComments.setLayout(new GridLayout());

        // it is initialy empty, as no idea is selected
        ideaCommentTree = new Tree(compositeComments, SWT.VIRTUAL | SWT.BORDER);

        ideaCommentTree.setLayoutData(
            new GridData(GridData.FILL_BOTH | GridData.GRAB_VERTICAL | GridData.GRAB_HORIZONTAL));

        // this Rennable is used to refresh comments displayed in the bottom part.
        // what ? this should be somewhere else ? hum... that's called anarchy. Or collaborative
        // work ?
        ideaCommentTreeFillerRunnable =
            new Runnable() {
              @Override
              public void run() {
                selectedIdeas = clientWhiteboard.getSelectionControl().getSelectedIdeas();
                if (!selectedIdeas.isEmpty()) {
                  ideaCommentTree.removeAll();
                  for (IIdea i : selectedIdeas) {
                    try {
                      clientCore.displayIdeaComments(i.getUniqueId(), ideaCommentTreeFiller);
                    } catch (RemoteException e) {
                      displayError("an anormal remote exception happened.", e);
                    }
                  }
                }
              }
            };

        // make the tree resets its data when a new idea is selected
        clientWhiteboard
            .getSelectionControl()
            .addListener(
                new ISelectionListener() {
                  @Override
                  public void notifySelectionChanged() {
                    display.asyncExec(ideaCommentTreeFillerRunnable);
                  }
                });
      }

      // buttons
      {
        Composite compositeButtons = new Composite(compositeBottom, SWT.NONE);

        GridData gdButtons =
            new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING);

        compositeButtons.setLayoutData(gdButtons);

        compositeButtons.setLayout(new RowLayout(SWT.VERTICAL));

        buttonAddIdea = new Button(compositeButtons, SWT.PUSH);
        buttonAddIdea.setText("Ajouter une idée");
        buttonAddIdea.addSelectionListener(
            new SelectionListener() {

              @Override
              public void widgetSelected(SelectionEvent arg0) {
                clickCreateIdea();
              }

              @Override
              public void widgetDefaultSelected(SelectionEvent arg0) {
                clickCreateIdea();
              }
            });

        buttonComment = new Button(compositeButtons, SWT.PUSH);
        buttonComment.setText("Commenter / Miser");
        buttonComment.addSelectionListener(
            new SelectionListener() {

              @Override
              public void widgetSelected(SelectionEvent arg0) {
                clickVoteOnIdea();
              }

              @Override
              public void widgetDefaultSelected(SelectionEvent arg0) {
                clickVoteOnIdea();
              }
            });

        buttonAddItem = new Button(compositeButtons, SWT.PUSH);
        buttonAddItem.setText("Ajouter un item");
        buttonAddItem.addSelectionListener(
            new SelectionListener() {

              @Override
              public void widgetSelected(SelectionEvent arg0) {
                clickCreateItem();
              }

              @Override
              public void widgetDefaultSelected(SelectionEvent arg0) {
                clickCreateItem();
              }
            });
      }
    }

    clientCore = new DelegatingClientCore(clientWhiteboard);

    updateStates();

    updateShellTitle();
  }
  private void animation20_Runnable() {

    //		final long start = System.nanoTime();

    if (_shell == null || _shell.isDisposed() || _shell.isVisible() == false) {
      return;
    }

    try {
      /*
       * endAlpha will be the final fadeIn/fadeOut value when the animation stops
       */
      int finalFadeAlpha = -1;

      int currentAlpha = _shell.getAlpha();
      boolean isLoopBreak = false;

      _animationMoveCounter++;

      while (true) {

        int newAlpha = -1;

        if (_isShellFadingIn) {

          final int shellStartX = _shellStartLocation.x;
          final int shellStartY = _shellStartLocation.y;
          final int shellEndX = _shellEndLocation.x;
          final int shellEndY = _shellEndLocation.y;

          final Point shellCurrentLocation = _shell.getLocation();

          final boolean isInTarget =
              shellCurrentLocation.x == shellEndX && shellCurrentLocation.y == shellEndY;

          final int diffAlpha = ALPHA_OPAQUE / _fadeInSteps;

          newAlpha = currentAlpha + diffAlpha;
          if (newAlpha > ALPHA_OPAQUE) {
            newAlpha = ALPHA_OPAQUE;
          }
          finalFadeAlpha = ALPHA_OPAQUE;

          if (isInTarget && currentAlpha == ALPHA_OPAQUE) {

            // target is reached and fully visible, stop animation

            _isShellFadingIn = false;

            return;

          } else {

            if (isInTarget == false) {

              // move to target

              final int diffX = shellStartX - shellEndX;
              final int diffY = shellStartY - shellEndY;

              final double moveX = (double) diffX / MOVE_STEPS * _animationMoveCounter;
              final double moveY = (double) diffY / MOVE_STEPS * _animationMoveCounter;

              final int shellCurrentX = (int) (shellStartX - moveX);
              final int shellCurrentY = (int) (shellStartY - moveY);

              _shell.setLocation(shellCurrentX, shellCurrentY);
            }
          }

        } else if (_isShellFadingOut) {

          if (_fadeOutDelayCounter++ < FADE_OUT_DELAY_STEPS) {

            // delay fade out

            _display.timerExec(FADE_TIME_INTERVAL, _animationTimer);

            return;
          }

          final int alphaDiff = ALPHA_OPAQUE / _fadeOutSteps;

          newAlpha = currentAlpha - alphaDiff;
          finalFadeAlpha = 0;

          if (newAlpha <= 0) {

            // shell is not visible any more, hide it now

            _shell.setAlpha(0);

            // hide shell
            setShellVisible(false);

            _isShellFadingOut = false;

            return;
          }
        }

        if (newAlpha == -1) {

          return;

        } else {

          if (newAlpha != currentAlpha) {
            _shell.setAlpha(newAlpha);
          }

          if (_shell.getAlpha() != newAlpha) {

            // platform do not support shell alpha, this occured on Ubuntu 12.04

            if (isLoopBreak) {
              break;
            }

            // loop only once
            isLoopBreak = true;

            currentAlpha = finalFadeAlpha;

            continue;

          } else {

            _display.timerExec(FADE_TIME_INTERVAL, _animationTimer);

            break;
          }
        }
      }

    } catch (final Exception err) {
      StatusUtil.log(err);
    } finally {

      //			final float timeDiff = (float) (System.nanoTime() - start) / 1000000;
      //			System.out.println(UI.timeStampNano() + " animation20_Runnable:\t" + timeDiff + " ms\t" +
      // " ms");
      //			// TODO remove SYSTEM.OUT.PRINTLN
    }
  }
 public void run() {
   if (mShell.isDisposed()) return;
   if (mRCEditor == null) return;
   mRCEditor.updateOutput();
   mDisplay.timerExec(400, this);
 }
Exemple #13
0
  protected void createContents() {
    shlPonyTrivia = new Shell();
    shlPonyTrivia.setBackground(SWTResourceManager.getColor(255, 240, 245));
    shlPonyTrivia.setSize(800, 600);
    shlPonyTrivia.setText("Pony Trivia");
    shlPonyTrivia.setLayout(new FormLayout());
    shlPonyTrivia.setMinimumSize(shlPonyTrivia.getSize());

    final Label lblFlower = new Label(shlPonyTrivia, SWT.NONE);
    lblFlower.setBackground(SWTResourceManager.getColor(255, 240, 245));
    FormData fd_lblFlower = new FormData();
    fd_lblFlower.left = new FormAttachment(0, 10);
    lblFlower.setLayoutData(fd_lblFlower);
    lblFlower.setImage(
        SWTResourceManager.getImage(GameScreen.class, "/ponytrivia/gui/res/flower.gif"));

    final Label lblDevil = new Label(shlPonyTrivia, SWT.NONE);
    lblDevil.setBackground(SWTResourceManager.getColor(255, 240, 245));
    FormData fd_lblDevil = new FormData();
    fd_lblDevil.right = new FormAttachment(100, -10);
    fd_lblDevil.top = new FormAttachment(lblFlower, 0, SWT.TOP);
    lblDevil.setLayoutData(fd_lblDevil);
    lblDevil.setImage(
        SWTResourceManager.getImage(GameScreen.class, "/ponytrivia/gui/res/hell_boy.gif"));

    Composite composite = new Composite(shlPonyTrivia, SWT.NONE);
    composite.setBackground(SWTResourceManager.getColor(255, 240, 245));
    composite.setLocation(10, -227);
    composite.setLayout(new FormLayout());
    FormData fd_composite = new FormData();
    fd_composite.bottom = new FormAttachment(100, -10);
    fd_composite.left = new FormAttachment(0, 10);
    fd_composite.right = new FormAttachment(100, -10);
    composite.setLayoutData(fd_composite);

    final Button btnNext = new Button(composite, SWT.NONE);
    btnNext.setEnabled(false);
    FormData fd_btnNext = new FormData();
    fd_btnNext.right = new FormAttachment(100, -10);
    btnNext.setLayoutData(fd_btnNext);
    btnNext.setText("Next");

    final Button btnFiftyFifty = new Button(composite, SWT.NONE);
    fd_btnNext.left = new FormAttachment(btnFiftyFifty, 0, SWT.LEFT);
    btnFiftyFifty.setToolTipText("");
    FormData fd_btnFiftyFifty = new FormData();
    fd_btnFiftyFifty.right = new FormAttachment(100, -10);
    btnFiftyFifty.setLayoutData(fd_btnFiftyFifty);
    btnFiftyFifty.setImage(
        SWTResourceManager.getImage(GameScreen.class, "/ponytrivia/gui/res/lifebelt.gif"));

    Composite composite_1 = new Composite(composite, SWT.NONE);
    composite_1.setBackground(SWTResourceManager.getColor(255, 240, 245));
    fd_btnNext.top = new FormAttachment(composite_1, 4);
    fd_btnFiftyFifty.bottom = new FormAttachment(composite_1, -6);
    composite_1.setLayout(new FillLayout(SWT.VERTICAL));
    FormData fd_composite_1 = new FormData();
    fd_composite_1.left = new FormAttachment(0, 10);
    fd_composite_1.right = new FormAttachment(100, -10);
    fd_composite_1.top = new FormAttachment(0, 90);
    fd_composite_1.bottom = new FormAttachment(100, -44);
    composite_1.setLayoutData(fd_composite_1);

    SelectionAdapter enableNext =
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent arg0) {
            if (shlPonyTrivia.isDisposed()) {
              return;
            }
            btnNext.setEnabled(true);
          }
        };

    final Button btnAnswer_1 = new Button(composite_1, SWT.RADIO);
    btnAnswer_1.addSelectionListener(enableNext);
    btnAnswer_1.setText("Answer 1");
    btnAnswer_1.setBackground(SWTResourceManager.getColor(255, 240, 245));

    final Button btnAnswer_2 = new Button(composite_1, SWT.RADIO);
    btnAnswer_2.addSelectionListener(enableNext);
    btnAnswer_2.setText("Answer 2");
    btnAnswer_2.setBackground(SWTResourceManager.getColor(255, 240, 245));

    final Button btnAnswer_3 = new Button(composite_1, SWT.RADIO);
    btnAnswer_3.addSelectionListener(enableNext);
    btnAnswer_3.setText("Answer 3");
    btnAnswer_3.setBackground(SWTResourceManager.getColor(255, 240, 245));

    final Button btnAnswer_4 = new Button(composite_1, SWT.RADIO);
    btnAnswer_4.addSelectionListener(enableNext);
    btnAnswer_4.setText("Answer 4");
    btnAnswer_4.setBackground(SWTResourceManager.getColor(255, 240, 245));

    Composite composite_2 = new Composite(composite, SWT.NONE);
    FormData fd_composite_2 = new FormData();
    fd_composite_2.right = new FormAttachment(btnFiftyFifty, -6);
    fd_composite_2.bottom = new FormAttachment(0, 84);
    fd_composite_2.top = new FormAttachment(0, 10);
    fd_composite_2.left = new FormAttachment(0, 10);
    composite_2.setLayoutData(fd_composite_2);
    composite_2.setLayout(new FillLayout(SWT.HORIZONTAL));

    final Label lblQuestionText = new Label(composite_2, SWT.NONE);
    lblQuestionText.setBackground(SWTResourceManager.getColor(255, 240, 245));
    lblQuestionText.setText("Question Text");

    Composite composite_3 = new Composite(shlPonyTrivia, SWT.NONE);
    composite_3.setBackground(SWTResourceManager.getColor(255, 240, 245));
    fd_lblFlower.top = new FormAttachment(composite_3, 37);
    composite_3.setLayout(new FormLayout());
    FormData fd_composite_3 = new FormData();
    fd_composite_3.left = new FormAttachment(0);
    fd_composite_3.right = new FormAttachment(100);
    fd_composite_3.top = new FormAttachment(0, 10);
    fd_composite_3.bottom = new FormAttachment(0, 51);
    composite_3.setLayoutData(fd_composite_3);

    final Label lblTime = new Label(composite_3, SWT.NONE);
    lblTime.setBackground(SWTResourceManager.getColor(255, 240, 245));
    FormData fd_lblTime = new FormData();
    fd_lblTime.top = new FormAttachment(0, 10);
    fd_lblTime.left = new FormAttachment(0, 10);
    lblTime.setLayoutData(fd_lblTime);
    lblTime.setText("Remaining Time: 30");

    final Label lblScore = new Label(composite_3, SWT.NONE);
    lblScore.setBackground(SWTResourceManager.getColor(255, 240, 245));
    FormData fd_lblScore = new FormData();
    fd_lblScore.left = new FormAttachment(100, -89);
    fd_lblScore.top = new FormAttachment(lblTime, 0, SWT.TOP);
    fd_lblScore.right = new FormAttachment(100, -10);
    lblScore.setLayoutData(fd_lblScore);
    lblScore.setText("Score: 0");

    final Composite composite_4 = new Composite(shlPonyTrivia, SWT.NONE);
    composite_4.setBackground(SWTResourceManager.getColor(255, 240, 245));
    fd_composite.top = new FormAttachment(0, 222);
    composite_4.setLayout(null);
    FormData fd_composite_4 = new FormData();
    fd_composite_4.bottom = new FormAttachment(composite, -6);
    fd_composite_4.top = new FormAttachment(composite_3, 6);
    fd_composite_4.right = new FormAttachment(lblDevil, -6);
    fd_composite_4.left = new FormAttachment(lblFlower, 6);
    composite_4.setLayoutData(fd_composite_4);

    final Label lblGrass = new Label(composite_4, SWT.NONE);
    lblGrass.setBounds(10, 129, 589, 20);

    final Label lblPony = new Label(composite_4, SWT.NONE);
    lblPony.setBackground(SWTResourceManager.getColor(255, 240, 245));
    lblPony.setBounds(260, 37, 84, 86);
    lblPony.setAlignment(SWT.CENTER);
    lblPony.setImage(imgKitty1);
    lblGrass.setBackground(SWTResourceManager.getColor(0, 204, 102));

    ////////////////////////////////////////////////////////////////////////////////// 0/////////

    final Button answerButtons[] =
        new Button[] {btnAnswer_1, btnAnswer_2, btnAnswer_3, btnAnswer_4};

    composite_4.addListener(
        SWT.Resize,
        new Listener() {
          public void handleEvent(Event e) {
            if (shlPonyTrivia.isDisposed()) {
              return;
            }

            Rectangle r = lblGrass.getBounds();
            r.width = composite_4.getBounds().width - 6;
            lblGrass.setBounds(r);

            int x =
                (int)
                    ((lblGrass.getBounds().width / 2)
                        * (1 - ((double) gameState.pony_pos) / config.questions_to_win));
            lblPony.setLocation(x - lblPony.getBounds().width / 2, lblPony.getLocation().y);
          }
        });

    final Runnable updateTimeLabel =
        new Runnable() {
          private Color original = lblTime.getForeground();

          @Override
          public void run() {
            if (shlPonyTrivia.isDisposed()) {
              return;
            }
            lblTime.setText("Remaining time: " + Math.max(0, gameState.remaining_time));
            if (gameState.remaining_time <= config.alotted_time / 3) {
              lblTime.setForeground(display.getSystemColor(SWT.COLOR_RED));
            } else {
              lblTime.setForeground(original);
            }
          }
        };
    updateTimeLabel.run();

    final Color origButtonColor = btnAnswer_1.getBackground();

    final Runnable updateQuestion =
        new Runnable() {
          @Override
          public void run() {
            if (shlPonyTrivia.isDisposed()) {
              return;
            }
            QuestionInfo qi;
            qi = questionRegistry.getQuestion();
            lblQuestionText.setText(qi.questionText);
            for (int i = 0; i < answerButtons.length; i++) {
              Button btn = answerButtons[i];
              btn.setText(qi.answers.get(i));
              btn.setEnabled(true);
              btn.setBackground(origButtonColor);
              btn.setSelection(false);
            }
            gameState.correctAnswerIndex = qi.correctAnswerIndex;
          }
        };
    updateQuestion.run();

    final SelectionAdapter answerQuestion =
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent arg0) {
            if (shlPonyTrivia.isDisposed()) {
              return;
            }

            int delta = lblGrass.getBounds().width / (2 * config.questions_to_win);
            int timeout = 1000;
            gameState.enabled = false;
            btnNext.setEnabled(false);

            final Button correct = answerButtons[gameState.correctAnswerIndex];

            if (correct.getSelection()) {
              gameState.total_score +=
                  10 + (gameState.remaining_time < 0 ? 0 : gameState.remaining_time);
              delta = -delta;
              correct.setBackground(new Color(display, 150, 250, 150));
              lblPony.setImage(imgKitty1);
              gameState.pony_pos += 1;
            } else {
              gameState.total_score -= 10;
              correct.setBackground(new Color(display, 250, 150, 150));
              timeout = 1500;
              lblPony.setImage(imgKitty2);
              gameState.pony_pos -= 1;
            }
            if (gameState.total_score < 0) {
              gameState.total_score = 0;
            }
            lblScore.setText("Score: " + gameState.total_score);
            gameState.question_number += 1;

            gameState.turnsBeforeEnablingFiftyFifty -= 1;

            class AnimatePony implements Runnable {
              private int delta;
              private int cnt;
              private int timeout;
              private final int steps = 20;
              private Point origPony;
              private Point origFlower;
              private Point origDevil;

              public AnimatePony(int delta, int timeout) {
                this.delta = delta;
                this.timeout = timeout;
                cnt = 0;
                origPony = lblPony.getLocation();
                origFlower = lblFlower.getLocation();
                origDevil = lblDevil.getLocation();
              }

              @Override
              public void run() {
                cnt++;
                Point p = lblPony.getLocation();
                double height = Math.abs(Math.sin(((double) cnt / steps) * 3 * Math.PI));
                lblPony.setLocation(p.x + delta / steps, origPony.y - (int) (10 * height));

                if (delta < 0) {
                  lblFlower.setLocation(
                      origFlower.x,
                      origFlower.y - (int) (10 * Math.sin((double) cnt / steps * Math.PI)));
                } else {
                  lblDevil.setLocation(
                      origDevil.x,
                      origDevil.y - (int) (10 * Math.sin((double) cnt / steps * Math.PI)));
                }

                if (cnt < steps) {
                  display.timerExec(timeout / steps, this);
                }
              }
            }

            display.timerExec(0, new AnimatePony(delta, (int) (timeout * 0.9)));

            display.timerExec(
                timeout,
                new Runnable() {
                  @Override
                  public void run() {
                    if (gameState.pony_pos >= config.questions_to_win) {
                      shlPonyTrivia.setEnabled(false);

                      try {
                        insertHighscore.insert(config.playerId, gameState.total_score);
                        schema.commit();
                      } catch (SQLException e) {
                        e.printStackTrace();
                      }

                      WinScreen.run(display);
                      shlPonyTrivia.close();
                      return;
                    }
                    if (gameState.pony_pos <= -config.questions_to_win) {
                      shlPonyTrivia.setEnabled(false);

                      try {
                        insertHighscore.insert(config.playerId, gameState.total_score);
                        schema.commit();
                      } catch (SQLException e) {
                        e.printStackTrace();
                      }

                      LoseScreen.run(display);
                      shlPonyTrivia.close();
                      return;
                    }
                    if (gameState.turnsBeforeEnablingFiftyFifty <= 0) {
                      gameState.turnsBeforeEnablingFiftyFifty = 0;
                      btnFiftyFifty.setEnabled(true);
                    }
                    updateTimeLabel.run();
                    updateQuestion.run();
                    gameState.remaining_time = config.alotted_time;
                    gameState.enabled = true;
                  }
                });
          }
        };

    btnFiftyFifty.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent arg0) {
            if (shlPonyTrivia.isDisposed()) {
              return;
            }
            btnFiftyFifty.setEnabled(false);
            gameState.turnsBeforeEnablingFiftyFifty = config.initalTurnsForFiftyFifty;
            ArrayList<Integer> discarded = new ArrayList<Integer>();
            discarded.add(0);
            discarded.add(1);
            discarded.add(2);
            discarded.add(3);
            discarded.remove(gameState.correctAnswerIndex);
            Collections.shuffle(discarded);
            discarded.remove(2);
            for (int i : discarded) {
              Button btn = answerButtons[i];
              btn.setEnabled(false);
              btn.setSelection(false);
              btn.setBackground(new Color(display, 50, 50, 50));
            }
          }
        });

    final Runnable timer =
        new Runnable() {
          public void run() {
            if (shlPonyTrivia.isDisposed()) {
              return;
            }
            gameState.remaining_time -= 1;
            display.timerExec(1000, this);
            updateTimeLabel.run();
            if (gameState.remaining_time <= 0 && gameState.enabled) {
              for (Button btn : answerButtons) {
                btn.setSelection(false);
              }
              answerQuestion.widgetSelected(null);
            }
          }
        };
    display.timerExec(1000, timer);

    btnNext.addSelectionListener(answerQuestion);

    bgMusicThread.setDaemon(true);
    bgMusicThread.start();
  }