Package com.drakulo.games.ais.ui.component

Source Code of com.drakulo.games.ais.ui.component.Confirm

package com.drakulo.games.ais.ui.component;

import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Rectangle;

import com.drakulo.games.ais.core.Settings;
import com.drakulo.games.ais.ui.component.button.TextButton;

public class Confirm extends UIComponent {
  private static final int WIDTH = 250;

  /** The confirm message */
//  private String message;
  /** Cancel button */
  private TextButton cancelButton;
  /** OK button */
  private TextButton okButton;
  /** Confirm box layout */
  private Rectangle box;
  /** Confirmation result */
  protected Boolean confirmed;

  public Confirm(String message) {
//    this.message = message;
    this.cancelButton = new TextButton("Cancel");
    this.okButton = new TextButton("OK");
    this.confirmed = null;

    int height = 100;

    int x = Settings.WIDTH / 2 - WIDTH / 2;
    int y = 100;

    this.box = new Rectangle(x, y, WIDTH, height);

    this.cancelButton.setActionHandler(new ActionHandler() {

      @Override
      public void run() {
        Confirm.this.confirmed = Boolean.FALSE;
      }
    });
    this.okButton.setActionHandler(new ActionHandler() {

      @Override
      public void run() {
        Confirm.this.confirmed = Boolean.TRUE;
      }
    });
  }

  @Override
  public void render(Graphics g) throws SlickException {
    g.setColor(Color.lightGray);
    g.fill(this.box);
    g.setColor(Color.gray);
    g.draw(this.box);
  }

  @Override
  public void update(Input input) throws SlickException {
    this.okButton.update(input);
    this.cancelButton.update(input);
  }

  public Boolean confirmed() {
    return this.confirmed;
  }

  public void setText(String message) {
//    this.message = message;
    // TODO handle line wrap
  }
}
TOP

Related Classes of com.drakulo.games.ais.ui.component.Confirm

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.