/** This method initializes lookforShell. */
  protected void createLookforShell() {
    GridData gridData2 = new GridData();
    gridData2.horizontalAlignment = GridData.FILL;
    gridData2.verticalAlignment = GridData.CENTER;
    GridData gridData1 = new GridData();
    gridData1.grabExcessHorizontalSpace = false;
    gridData1.horizontalAlignment = GridData.FILL;
    gridData1.verticalAlignment = GridData.CENTER;
    gridData1.grabExcessVerticalSpace = false;
    GridLayout gridLayout1 = new GridLayout();
    gridLayout1.numColumns = 5;
    gridLayout1.makeColumnsEqualWidth = true;
    // this line has to be commented in order to open with VISUAL EDITOR
    lookforShell = new Shell(PlatformUI.getWorkbench().getDisplay().getActiveShell());

    // lookforShell = new Shell();
    lookforShell.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
    createCTabFolder();
    lookforShell.setLayout(gridLayout1);
    lookforShell.setSize(new Point(501, 313));
    new Label(lookforShell, SWT.NONE);
    new Label(lookforShell, SWT.NONE);
    new Label(lookforShell, SWT.NONE);
    OKbutton = new Button(lookforShell, SWT.NONE);
    OKbutton.setText(Messages.AbstractLookForEditorShell_OK);
    OKbutton.setLayoutData(gridData1);
    OKbutton.setEnabled(false);
    cancelbutton = new Button(lookforShell, SWT.NONE);
    cancelbutton.setText(Messages.AbstractLookForEditorShell_Cancel);
    cancelbutton.setLayoutData(gridData2);
  }
  private void createDialog(Shell applicationShell) {
    if (dialog == null || dialog.isDisposed()) {
      dialog = new Shell(applicationShell, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.APPLICATION_MODAL);

      if (applicationShell.getImage() != null) {
        dialog.setImage(applicationShell.getImage());
      }

      dialog.addListener(
          SWT.Close,
          new Listener() {
            public void handleEvent(Event event) {
              hideCustomPanelChildren();
            }
          });

      dialog.addDisposeListener(
          new DisposeListener() {
            public void widgetDisposed(DisposeEvent arg0) {
              disposeImages();
            }
          });

      if (fileDialogMode != VFS_DIALOG_SAVEAS) {
        dialog.setText(Messages.getString("VfsFileChooserDialog.openFile")); // $NON-NLS-1$
      } else {
        dialog.setText(Messages.getString("VfsFileChooserDialog.saveAs")); // $NON-NLS-1$
      }
      dialog.setLayout(new GridLayout());
      dialog.setBackgroundMode(SWT.INHERIT_FORCE);
      dialog.setBackground(dialog.getDisplay().getSystemColor(SWT.COLOR_WHITE));
      createCustomUIPanel(dialog);
    }
  }
  private void createControls() {
    Display display = UIUtils.getDisplay();

    if (tipShell != null) {
      return;
    }

    tipShell = new Shell(display, SWT.ON_TOP | SWT.TOOL);
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 2;
    gridLayout.marginWidth = 2;
    gridLayout.marginHeight = 2;
    tipShell.setLayout(gridLayout);

    tipShell.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));

    tipLabelImage = new Label(tipShell, SWT.NONE);
    tipLabelImage.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
    tipLabelImage.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
    tipLabelImage.setLayoutData(
        new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER));

    tipLabelText = new Label(tipShell, SWT.NONE);
    tipLabelText.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
    tipLabelText.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
    tipLabelText.setLayoutData(
        new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER));
  }
  /**
   * This method initializes hyperLinkShell.
   *
   * @wbp.parser.entryPoint
   */
  protected void createHyperLinkShell() {
    GridData gridData9 = new GridData();
    gridData9.grabExcessHorizontalSpace = true;
    gridData9.verticalAlignment = GridData.FILL;
    gridData9.horizontalSpan = 2;
    gridData9.horizontalAlignment = GridData.FILL;
    GridData gridData8 = new GridData();
    gridData8.horizontalAlignment = GridData.FILL;
    gridData8.grabExcessHorizontalSpace = true;
    gridData8.horizontalSpan = 2;
    gridData8.verticalAlignment = GridData.FILL;
    GridLayout gridLayout2 = new GridLayout();
    gridLayout2.numColumns = 14;
    gridLayout2.makeColumnsEqualWidth = true;

    // this line has to be commented in order to open with VISUAL EDITOR
    hyperLinkShell = new Shell(PlatformUI.getWorkbench().getDisplay().getActiveShell());

    // hyperLinkShell = new Shell();
    hyperLinkShell.setText(Messages.AbstractHyperLinkManagerShell_HyperLink);
    hyperLinkShell.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
    createCTabFolder();
    hyperLinkShell.setLayout(gridLayout2);
    hyperLinkShell.setSize(new Point(687, 308));
    OkButton = new Button(hyperLinkShell, SWT.NONE);
    OkButton.setText(Messages.AbstractHyperLinkManagerShell_OK);
    OkButton.setLayoutData(gridData9);
    cancelButton = new Button(hyperLinkShell, SWT.NONE);
    cancelButton.setText(Messages.AbstractHyperLinkManagerShell_Cancel);
    cancelButton.setLayoutData(gridData8);
  }
Esempio n. 5
0
  public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new GridLayout());

    // Set the shell background to something different
    shell.setBackground(display.getSystemColor(SWT.COLOR_RED));

    // Tell the shell to give its children the same background color or image
    shell.setBackgroundMode(SWT.INHERIT_DEFAULT);

    // Optionally trying creating a patterned image for the shell background
    //    final Image backImage = new Image(display,10,10);
    //    GC gc = new GC(backImage);
    //    gc.drawLine(0,0,9,9);
    //    gc.dispose();
    //    shell.addDisposeListener(new DisposeListener() {
    //		public void widgetDisposed(DisposeEvent e) {
    //			backImage.dispose();
    //		}
    //	});
    //    shell.setBackgroundImage(backImage);

    PGroup group = new PGroup(shell, SWT.SMOOTH);
    group.setText("Example");
    group.setLayout(new FillLayout());
    group.setBackground(display.getSystemColor(SWT.COLOR_WHITE));

    Composite groupClient = new Composite(group, SWT.NONE);
    groupClient.setBackground(display.getSystemColor(SWT.COLOR_WHITE));

    groupClient.setLayout(new GridLayout());

    Label label = new Label(groupClient, SWT.NONE);
    label.setText("Contents");
    Button button = new Button(groupClient, SWT.PUSH);
    button.setText("Contents");
    Scale scale = new Scale(groupClient, SWT.HORIZONTAL);

    shell.setSize(200, 200);
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
  }
  public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display, SWT.SHELL_TRIM);
    shell.setBounds(0, 0, 25, 25);
    shell.setLayout(new GridLayout());
    shell.setBackground(READY_COLOUR);
    RotationButtonComposite sliderComposite = new RotationButtonComposite(shell, SWT.UP, "Test");
    shell.setText(sliderComposite.getClass().getName());
    sliderComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
    shell.pack();
    shell.open();

    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    display.dispose();
  }
Esempio n. 7
0
 public static void main(String args[]) {
   Display display = new Display();
   Shell shell = new Shell(display);
   shell.setLayout(null);
   Text hello = new Text(shell, SWT.MULTI);
   shell.setText("Java应用程序");
   shell.setSize(200, 100);
   Color color = new Color(Display.getCurrent(), 255, 255, 255);
   shell.setBackground(color);
   hello.setText("Hello,SWT World!\n\n你好,SWT世界!");
   hello.pack();
   shell.open();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) {
       display.sleep();
     }
   }
   display.dispose();
 }
 /**
  * Opens the dialog and returns the input
  *
  * @return String
  */
 public String open() {
   // Create the dialog window
   Shell shell = new Shell(getParent(), getStyle());
   shell.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
   shell.setText(getText());
   shell.setSize(900, 400);
   Point location = getParent().getShell().getLocation();
   Point size = getParent().getShell().getSize();
   shell.setLocation((location.x + size.x - 300) / 2, (location.y + size.y - 150) / 2);
   createContents(shell);
   shell.open();
   Display display = getParent().getDisplay();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) {
       display.sleep();
     }
   }
   return null;
 }
Esempio n. 9
0
  MapShell(Display parent) {
    display = parent;
    mapShell = new Shell(display, SWT.MIN | SWT.CLOSE | SWT.RESIZE);
    mapShell.setText(RadarConsts.PROGRAM_NAME + " " + RadarConsts.VERSION);
    mapShell.addDisposeListener(
        new DisposeListener() {
          public void widgetDisposed(DisposeEvent e) {
            saveWindowPosition();
          }
        });
    mapShell.addListener(
        SWT.Resize,
        new Listener() {
          public void handleEvent(Event event) {
            renderMap();
          }
        });

    mapShell.setBackground(parent.getSystemColor(SWT.COLOR_BLACK));
  }
Esempio n. 10
0
 public ToolTipHandler(org.eclipse.swt.widgets.Shell parent) {
   final org.eclipse.swt.widgets.Display display = parent.getDisplay();
   this.parentShell = parent;
   tipShell = new org.eclipse.swt.widgets.Shell(parent, SWT.ON_TOP | SWT.TOOL);
   org.eclipse.swt.layout.GridLayout gridLayout = new org.eclipse.swt.layout.GridLayout();
   gridLayout.numColumns = 2;
   gridLayout.marginWidth = 2;
   gridLayout.marginHeight = 2;
   tipShell.setLayout(gridLayout);
   tipShell.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
   tipLabelImage = new org.eclipse.swt.widgets.Label(tipShell, SWT.NONE);
   tipLabelImage.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
   tipLabelImage.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
   tipLabelImage.setLayoutData(
       new org.eclipse.swt.layout.GridData(
           GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER));
   tipLabelText = new org.eclipse.swt.widgets.Label(tipShell, SWT.NONE);
   tipLabelText.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
   tipLabelText.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
   tipLabelText.setLayoutData(
       new org.eclipse.swt.layout.GridData(
           (-(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER))));
 }
  public static void main(String[] args) {

    Mode connectMode = Mode.PRIVATE;
    String modeStr = System.getProperties().getProperty("connection");
    if (modeStr != null) { // override default connection mode
      if (0 == modeStr.compareToIgnoreCase(Mode.LOCAL.mode)) {
        connectMode = Mode.LOCAL;
      } else if (0 == modeStr.compareToIgnoreCase(Mode.PRIVATE.mode)) {
        connectMode = Mode.PRIVATE;
      } else if (0 == modeStr.compareToIgnoreCase(Mode.PUBLIC.mode)) {
        connectMode = Mode.PUBLIC;
      }
    }

    // initialize logger
    s_logger.setLevel(Level.TRACE);
    System.out.println("Connect Mode = " + connectMode);
    Appender appender;
    TTCCLayout layout = new TTCCLayout();
    layout.setDateFormat("ISO8601");
    if (connectMode == Mode.PUBLIC) {
      String homeDir = System.getProperty("user.home");
      String timeStamp =
          new SimpleDateFormat("yyyyMMdd_HHmmss").format(Calendar.getInstance().getTime());
      String logFile = homeDir + "/granny_roomba_" + timeStamp + ".txt";
      try {
        appender = new FileAppender(layout, logFile);
      } catch (IOException e) {
        System.err.println("Could not create log file: " + logFile);
        e.printStackTrace();
        return;
      }
    } else {
      appender = new ConsoleAppender(layout, ConsoleAppender.SYSTEM_OUT);
    }
    s_logger.addAppender(appender);

    Display display = new Display();

    Shell shell = new Shell(display);
    shell.setBackground(display.getSystemColor(SWT.COLOR_BLACK));

    GridLayout gl = new GridLayout();
    gl.marginBottom = 4;
    gl.marginTop = 4;
    gl.marginLeft = 4;
    gl.marginRight = 4;
    shell.setLayout(gl);
    Image image = new Image(display, SwtKeyboardController.class.getResourceAsStream(IMAGE_FILE));

    Group group = new Group(shell, SWT.NONE);
    GridData gd = new GridData();
    //	gd.horizontalAlignment = GridData.FILL_HORIZONTAL;
    //	gd.verticalAlignment = GridData.FILL_VERTICAL;
    //	gd.grabExcessHorizontalSpace = true;
    //	gd.grabExcessVerticalSpace = true;
    //	gd.horizontalAlignment = GridData.CENTER;

    // WTF: why these dimension have to be smaller
    // than the real image!!!
    gd.heightHint = 294;
    gd.widthHint = 464;

    group.setLayoutData(gd);
    //	group.setSize(240, 320);
    group.setBackgroundImage(image);

    // Create client and keyboard dispatcher
    String host = connectMode.host;
    int servoPort = connectMode.servoPort;
    int locoPort = connectMode.locoPort;

    ServoClient servoClient = new ServoClient(host, servoPort);
    CreateLocomotorClient locoClient = new CreateLocomotorClient(host, locoPort);

    servoClient.connect();
    locoClient.connect();

    boolean connected = true;
    // check if connection is up
    try {
      int ret = locoClient.getStatus();
      if (ret < 0) {
        MessageBox msg = new MessageBox(shell, SWT.OK);
        String text = "Connection to GrannyRoomba failed!\nTry again later.\n";
        text += "connection=" + modeStr + " host=" + host + "\n";
        text += "servoPort=" + servoPort + " locoPort=" + locoPort + "\n";
        int sendTimeoutMs = Integer.getInteger("send_timeout", 1000);
        int recvTimeoutMs = Integer.getInteger("recv_timeout", 2000);
        text += "sendTimeoutMs=" + sendTimeoutMs + " recvTimeoutMs=" + recvTimeoutMs;
        msg.setMessage(text);
        msg.open();
        connected = false;
      }
    } catch (Exception e) {
      s_logger.error("could not connect to server for unknown reason!");
      s_logger.info(e);
      connected = false;
    }

    if (connected) {

      SwtKeyboardController kc = new SwtKeyboardController(servoClient, locoClient);
      shell.addKeyListener(kc.controller());
      shell.addFocusListener(kc.stopper());

      shell.pack();
      shell.open();

      while (!shell.isDisposed() && kc.connected()) {
        if (!display.readAndDispatch()) display.sleep();
      }
      if (kc.connected()) {
        locoClient.stop(0);
        kc.cancel();
      }
    }

    locoClient.disconnect();
    servoClient.disconnect();

    image.dispose();
    display.dispose();
  }
Esempio n. 12
0
  @SuppressWarnings("unchecked")
  private BalloonWindow(Display display, Shell parent, final int style) {
    this.style = style;
    int shellStyle = style & (SWT.ON_TOP | SWT.TOOL);
    this.shell =
        (display != null)
            ? new Shell(display, SWT.NO_TRIM | shellStyle)
            : new Shell(parent, SWT.NO_TRIM | shellStyle);
    this.contents = new Composite(shell, SWT.NONE);

    final Color c = new Color(shell.getDisplay(), 255, 255, 225);
    shell.setBackground(c);
    shell.setForeground(shell.getDisplay().getSystemColor(SWT.COLOR_BLACK));
    contents.setBackground(shell.getBackground());
    contents.setForeground(shell.getForeground());

    selectionControls.add(shell);
    selectionControls.add(contents);

    final Listener globalListener =
        new Listener() {
          @Override
          public void handleEvent(Event event) {
            Widget w = event.widget;
            for (int i = selectionControls.size() - 1; i >= 0; i--) {
              if (selectionControls.get(i) == w) {
                if ((style & SWT.CLOSE) != 0) {
                  for (int j = selectionListeners.size() - 1; j >= 0; j--)
                    ((Listener) selectionListeners.get(j)).handleEvent(event);
                } else {
                  shell.close();
                }
                event.doit = false;
              }
            }
          }
        };

    shell.addListener(
        SWT.Show,
        new Listener() {
          @Override
          public void handleEvent(Event event) {
            if (!addedGlobalListener) {
              shell.getDisplay().addFilter(SWT.MouseDown, globalListener);
              addedGlobalListener = true;
            }
          }
        });

    shell.addListener(
        SWT.Hide,
        new Listener() {
          @Override
          public void handleEvent(Event event) {
            if (addedGlobalListener) {
              shell.getDisplay().removeFilter(SWT.MouseDown, globalListener);
              addedGlobalListener = false;
            }
          }
        });

    shell.addListener(
        SWT.Dispose,
        new Listener() {
          @Override
          public void handleEvent(Event event) {
            if (addedGlobalListener) {
              shell.getDisplay().removeFilter(SWT.MouseDown, globalListener);
              addedGlobalListener = false;
            }
            c.dispose();
          }
        });
  }
  /** Create contents of the dialog. */
  private void createContents() {
    shell = new Shell(getParent(), getStyle());
    shell.setSize(624, 617);
    shell.setText(getText());
    GridLayout gl_shell = new GridLayout(1, false);
    gl_shell.horizontalSpacing = 0;
    gl_shell.marginHeight = 0;
    gl_shell.verticalSpacing = 0;
    gl_shell.marginWidth = 0;
    shell.setLayout(gl_shell);
    shell.setBackground(ColorRepository.getColor(ColorRepository.BG_CONTENTS));
    //		shell.setBackgroundMode(SWT.TRANSPARENT);

    CLabel lblTitle = new CLabel(shell, SWT.CENTER);
    lblTitle.setForeground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
    GridData gd_lblTitle = new GridData(SWT.FILL, SWT.CENTER, true, false);
    gd_lblTitle.heightHint = 44;
    lblTitle.setLayoutData(gd_lblTitle);
    lblTitle.setFont(titleFont);
    lblTitle.setBackgroundImage(ImageRepository.getImage(ImageRepository.POPUP_TITLE_BG));
    lblTitle.setText("2차 계량 - 대상 차량 선택");

    Composite compContents = new Composite(shell, SWT.NONE);
    compContents.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
    compContents.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    GridLayout gl_compContents = new GridLayout(1, false);
    gl_compContents.marginTop = 10;
    gl_compContents.marginRight = 10;
    gl_compContents.marginLeft = 10;
    gl_compContents.marginBottom = 10;
    gl_compContents.verticalSpacing = 0;
    gl_compContents.marginWidth = 0;
    gl_compContents.marginHeight = 0;
    compContents.setLayout(gl_compContents);

    compCenter = new Composite(compContents, SWT.BORDER);
    compCenter.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
    compCenter.setLayout(new GridLayout(2, false));

    car = new CarComposite(compCenter, SWT.NONE);
    car.addFocusListener(
        new FocusAdapter() {
          @Override
          public void focusLost(FocusEvent e) {
            filter();
          }
        });
    car.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
    car.setFont(defaultFont);
    car.setTitle("차량 번호: ");
    car.addFocusListener(new HelpAdapter("차량번호를 입력하거나 목록에서 선택 후 Enter."));

    Button btnSearch = new Button(compCenter, SWT.NONE);
    btnSearch.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            select();
          }
        });
    btnSearch.setFont(btnFont);
    btnSearch.setText(" 조 회 ");

    initGird(compContents);

    Composite btn = new Composite(shell, SWT.NONE);
    btn.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
    btn.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    btn.setBackgroundMode(SWT.INHERIT_FORCE);
    if (user.hasAuth(DTSConstants.AUTH_DEL_FST)) {
      btn.setLayout(new GridLayout(4, false));
    } else {
      btn.setLayout(new GridLayout(3, false));
    }

    Button btnSave = new Button(btn, SWT.NONE);
    GridData gd_btnSave = new GridData(SWT.RIGHT, SWT.FILL, true, false);
    gd_btnSave.heightHint = 36;
    gd_btnSave.widthHint = 130;
    btnSave.setLayoutData(gd_btnSave);
    btnSave.setFont(btnFont);
    btnSave.setText("2차 계량");
    btnSave.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            onClickOK();
          }
        });

    Button btnPrint = new Button(btn, SWT.NONE);
    GridData gd_btnPrint = new GridData(SWT.RIGHT, SWT.FILL, true, false);
    gd_btnPrint.heightHint = 36;
    gd_btnPrint.widthHint = 130;
    btnPrint.setLayoutData(gd_btnPrint);
    btnPrint.setFont(btnFont);
    btnPrint.setText("전표 출력");
    btnPrint.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            Grid g = gridViewer.getGrid();
            if (g.getSelectionIndex() == -1) {
              MessageDialog.openInformation(
                  shell, "데이터 선택 필요", "선택된 데이터가 없습니다. \n\n목록에서 선택 후 작업하세요.");
              return;
            } else {
              if (listData != null && listData.length > g.getSelectionIndex()) {
                TsWgtInfDTO dto = listData[g.getSelectionIndex()];

                PrintUtil.print(dto, preferences.getInt(DTSPreConstants.GN_PRINT_COUNT));
              }
            }
          }
        });

    if (user.hasAuth(DTSConstants.AUTH_DEL_FST)) {
      Button btnDelete = new Button(btn, SWT.NONE);
      GridData gd_btnDelete = new GridData(SWT.CENTER, SWT.FILL, true, false);
      gd_btnDelete.heightHint = 36;
      gd_btnDelete.widthHint = 130;
      btnDelete.setLayoutData(gd_btnDelete);
      btnDelete.setFont(btnFont);
      btnDelete.setText("삭 제");
      btnDelete.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              onClickDelete();
            }
          });
    }
    Button btnCancel = new Button(btn, SWT.NONE);
    btnCancel.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            shell.close();
          }
        });
    GridData gd_btnCancel = new GridData(SWT.LEFT, SWT.FILL, true, false);
    gd_btnCancel.heightHint = 36;
    gd_btnCancel.widthHint = 130;
    btnCancel.setLayoutData(gd_btnCancel);
    btnCancel.setFont(btnFont);
    btnCancel.setText("취  소");

    lblHelp = new CLabel(shell, SWT.LEFT);
    lblHelp.setForeground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
    GridData gd_lblHelp = new GridData(SWT.FILL, SWT.CENTER, true, false);
    gd_lblHelp.heightHint = 25;
    lblHelp.setLayoutData(gd_lblHelp);
    lblHelp.setText("도움말:");
    lblHelp.setFont(helpFont);
    lblHelp.setBackgroundImage(ImageRepository.getImage(ImageRepository.POPUP_HELP_BG));

    shell.addListener(
        SWT.Traverse,
        new Listener() {
          public void handleEvent(Event event) {
            if (event.detail == SWT.TRAVERSE_ESCAPE) {
              event.doit = false;
            }
          }
        });
  } // createContents
  public static void main(String[] args) {
    final Display display = new Display();
    // Shell must be created with style SWT.NO_TRIM
    final Shell shell = new Shell(display, SWT.NO_TRIM | SWT.ON_TOP);
    shell.setBackground(display.getSystemColor(SWT.COLOR_RED));
    // define a region that looks like a key hole
    Region region = new Region();
    region.add(circle(67, 67, 67));
    region.subtract(circle(20, 67, 50));
    region.subtract(new int[] {67, 50, 55, 105, 79, 105});
    // define the shape of the shell using setRegion
    shell.setRegion(region);
    Rectangle size = region.getBounds();
    shell.setSize(size.width, size.height);
    // add ability to move shell around
    Listener l =
        new Listener() {
          /** The x/y of the MouseDown, relative to top-left of the shell. */
          Point origin;

          @Override
          public void handleEvent(Event e) {
            switch (e.type) {
              case SWT.MouseDown:
                Point point = shell.toDisplay(e.x, e.y);
                Point loc = shell.getLocation();
                origin = new Point(point.x - loc.x, point.y - loc.y);
                break;
              case SWT.MouseUp:
                origin = null;
                break;
              case SWT.MouseMove:
                if (origin != null) {
                  Point p = display.map(shell, null, e.x, e.y);
                  shell.setLocation(p.x - origin.x, p.y - origin.y);
                }
                break;
            }
          }
        };
    shell.addListener(SWT.MouseDown, l);
    shell.addListener(SWT.MouseUp, l);
    shell.addListener(SWT.MouseMove, l);
    // add ability to close shell
    Button b = new Button(shell, SWT.PUSH);
    b.setBackground(shell.getBackground());
    b.setText("close");
    b.pack();
    b.setLocation(10, 68);
    b.addListener(
        SWT.Selection,
        new Listener() {
          @Override
          public void handleEvent(Event e) {
            shell.close();
          }
        });
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    region.dispose();
    display.dispose();
  }
Esempio n. 15
0
  private void initGui() {

    GridLayout layout = new GridLayout(2, true);
    shell.setLayout(layout);
    shell.setBackground(MainGui.pOPUP_BG);

    {
      Label evtOccSpanLab = new Label(shell, SWT.NONE);
      GridData labelLayoutData = new GridData(SWT.FILL, SWT.TOP, true, false);
      evtOccSpanLab.setLayoutData(labelLayoutData);
      evtOccSpanLab.setBackground(MainGui.pOPUP_BG);
      evtOccSpanLab.setFont(MainGui.DEFAULTFONT);
      evtOccSpanLab.setText("Trend event days span");
      evtOccSpanLab.setToolTipText(
          "Trend events can be represented with a validity span, reflected in the width of the bars.\nZero means that the trend event is valid until an other event occurs.");

      final Text evtOccSpanTxt = new Text(shell, SWT.NONE);
      GridData txtLayoutData = new GridData(SWT.FILL, SWT.TOP, true, false);
      evtOccSpanTxt.setLayoutData(txtLayoutData);
      evtOccSpanTxt.setFont(MainGui.DEFAULTFONT);
      evtOccSpanTxt.setText("" + barChartSettings.getMaxFill());

      Listener listener =
          new Listener() {
            public void handleEvent(Event e) {
              try {
                barChartSettings.setMaxFill(Integer.valueOf(evtOccSpanTxt.getText()));
                action.action(null);
              } catch (NumberFormatException pe) {
                UserDialog inst = new UserDialog(shell, pe.getMessage(), null);
                inst.open();
                evtOccSpanTxt.setText("" + barChartSettings.getMaxFill());
              }
            }
          };
      evtOccSpanTxt.addListener(SWT.FocusOut, listener);
      evtOccSpanTxt.addListener(SWT.DefaultSelection, listener);
    }
    {
      final Button isReachTop = new Button(shell, SWT.CHECK);
      GridData layoutData = new GridData(SWT.FILL, SWT.TOP, true, false);
      layoutData.horizontalSpan = 2;
      isReachTop.setLayoutData(layoutData);
      isReachTop.setBackground(MainGui.pOPUP_BG);
      isReachTop.setFont(MainGui.DEFAULTFONT);
      isReachTop.setText("Draw bars to the top");
      isReachTop.setToolTipText(
          "All the bars will at the top, overlapping each other with transparency.\nIf unchecked, bars stop at label level.");
      isReachTop.addSelectionListener(
          new SelectionListener() {

            @Override
            public void widgetSelected(SelectionEvent e) {
              handle();
            }

            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
              handle();
            }

            private void handle() {
              barChartSettings.setIsReachTop(isReachTop.getSelection());
              action.action(null);
            }
          });
      isReachTop.setSelection(barChartSettings.getIsReachTop());
    }
    {
      final Button isZeroBase = new Button(shell, SWT.CHECK);
      GridData layoutData = new GridData(SWT.FILL, SWT.TOP, true, false);
      layoutData.horizontalSpan = 2;
      isZeroBase.setLayoutData(layoutData);
      isZeroBase.setBackground(MainGui.pOPUP_BG);
      isZeroBase.setFont(MainGui.DEFAULTFONT);
      isZeroBase.setText("Draw bars to the base");
      isZeroBase.setToolTipText(
          "All the bars will start at zero, overlapping each other with transparency.\nIf unchecked, bars stop at label level.");
      isZeroBase.addSelectionListener(
          new SelectionListener() {

            @Override
            public void widgetSelected(SelectionEvent e) {
              handle();
            }

            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
              handle();
            }

            private void handle() {
              barChartSettings.setIsZerobased(isZeroBase.getSelection());
              action.action(null);
            }
          });
      isZeroBase.setSelection(barChartSettings.getIsZeroBased());
    }
    {
      sideBySide = new Button(shell, SWT.CHECK);
      GridData layoutData = new GridData(SWT.FILL, SWT.TOP, true, false);
      layoutData.horizontalSpan = 2;
      sideBySide.setLayoutData(layoutData);
      sideBySide.setBackground(MainGui.pOPUP_BG);
      sideBySide.setFont(MainGui.DEFAULTFONT);
      sideBySide.setText("Display side by side");
      sideBySide.setToolTipText(
          "Bar are displayed side by side, form top to bottom.\n"
              + "For this to be working, the event validity days span has to be above the number of indicators involved.");
      sideBySide.addSelectionListener(
          new SelectionListener() {

            @Override
            public void widgetSelected(SelectionEvent e) {
              handle();
            }

            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
              handle();
            }

            private void handle() {
              barChartSettings.setSideBySide(sideBySide.getSelection());
              action.action(null);
            }
          });
      sideBySide.addMouseMoveListener(
          new MouseMoveListener() {

            @Override
            public void mouseMove(MouseEvent e) {
              sideBySide.setToolTipText(
                  "Bar are displayed side by side, form top to bottom.\n"
                      + "For this to be working, the event validity days span has to be above the number of indicators involved.\n"
                      + "I.e. : "
                      + chartTarget.getChartedEvtDefsTrends().size());
            }
          });
      sideBySide.setSelection(barChartSettings.getSideBySide());
    }
    {
      final Button isGradient = new Button(shell, SWT.CHECK);
      GridData layoutData = new GridData(SWT.FILL, SWT.TOP, true, false);
      layoutData.horizontalSpan = 2;
      isGradient.setLayoutData(layoutData);
      isGradient.setBackground(MainGui.pOPUP_BG);
      isGradient.setFont(MainGui.DEFAULTFONT);
      isGradient.setText("Progressive opacity");
      isGradient.setToolTipText(
          "Bar are displayed using a progressive opacity.\nIf unchecked, bars are using the same opacity");
      isGradient.addSelectionListener(
          new SelectionListener() {

            @Override
            public void widgetSelected(SelectionEvent e) {
              handle();
            }

            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
              handle();
            }

            private void handle() {
              barChartSettings.setIsGradient(isGradient.getSelection());
              action.action(null);
            }
          });
      isGradient.setSelection(barChartSettings.getIsGradiant());
    }
    {
      final Spinner alphaSpinner = new Spinner(shell, SWT.WRAP | SWT.READ_ONLY);
      GridData layoutData = new GridData(SWT.FILL, SWT.TOP, false, false);
      layoutData.horizontalSpan = 2;
      alphaSpinner.setLayoutData(layoutData);
      alphaSpinner.setFont(MainGui.DEFAULTFONT);
      int digits = 1;
      alphaSpinner.setDigits(digits);
      alphaSpinner.setMinimum(5);
      alphaSpinner.setMaximum(EventDefinition.loadMaxPassPrefsEventInfo().size() * 10);
      alphaSpinner.setIncrement(5);
      alphaSpinner.setSelection((int) (barChartSettings.getAlphaDividend() * Math.pow(10, digits)));
      alphaSpinner.setToolTipText(
          "For a better visibility of the result, You can change the opacity of the charted trend.\n"
              + "You must select a share in the portfolio to display its analysis\n"
              + "You also must choose the trends you want to display using the '"
              + ChartIndicatorDisplay.TRENDBUTTXT
              + "' button.");
      alphaSpinner.addSelectionListener(
          new SelectionAdapter() {

            public void widgetSelected(SelectionEvent e) {
              int selection = alphaSpinner.getSelection();
              int digits = alphaSpinner.getDigits();
              barChartSettings.setAlphaDividend(selection / Math.pow(10, digits));
            }
          });
      alphaSpinner.addListener(
          SWT.MouseExit,
          new Listener() {

            public void handleEvent(Event arg0) {
              if (!barChartSettings.getAlphaDividend().equals(initialAlphaDividend)) {
                action.action(null);
                initialAlphaDividend = barChartSettings.getAlphaDividend();
              }
            }
          });
    }
  }
Esempio n. 16
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();
  }