Package projetV1

Source Code of projetV1.DialogBox

package projetV1;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Label;
import org.eclipse.wb.swt.SWTResourceManager;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;

public class DialogBox extends Dialog {

  protected Object result;
  protected Shell shell;
  private int icon;
  private String title;
  private String message;
  private int i;
  private Button btnOui;
  private boolean v;

  public DialogBox(Shell parent, int icon, String title, String message) {
    super(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
    this.icon = icon;
    this.title = title;
    this.message = message;
    i = 0;
  }

  /**
   * Open the dialog.
   *
   * @return the result
   */
  public int open() {
    i=createContents();
   
    int x = (getParent().getShell().getLocation().x + (getParent()
        .getShell().getSize().x / 2)) - (shell.getSize().x) / 2;
    int y = (getParent().getShell().getLocation().y + (getParent()
        .getShell().getSize().y / 2)) - (shell.getSize().y) / 2;
    shell.setLocation(x, y);
    shell.open();
    shell.layout();
    Display display = getParent().getDisplay();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    return i;
  }

  private int createContents() {
    shell = new Shell(getParent(), getStyle());
    shell.setSize(320, 140);
    shell.setText(title);
    Label msg = new Label(shell, SWT.WRAP);
    msg.setBounds(54, 32, 250, 39);

    btnOui = new Button(shell, SWT.NONE);

    btnOui.setBounds(76, 77, 75, 25);
    btnOui.setText("Oui");
    btnOui.setVisible(false);
    btnOui.addMouseListener(new MouseAdapter() {
      @Override
      public void mouseUp(MouseEvent e) {
        i = 1;
        shell.dispose();
      }
    });

    Button btnNon = new Button(shell, SWT.NONE);
    btnNon.addMouseListener(new MouseAdapter() {
      @Override
      public void mouseUp(MouseEvent e) {
        shell.dispose();
      }
    });
    btnNon.setText("Non");
    btnNon.setBounds(157, 77, 75, 25);
    btnNon.setVisible(false);

    Button btnOk = new Button(shell, SWT.NONE);
    btnOk.addMouseListener(new MouseAdapter() {
      @Override
      public void mouseUp(MouseEvent e) {
        shell.dispose();
      }
    });
    btnOk.setBounds(120, 77, 75, 25);
    btnOk.setText("OK");
    btnOk.setVisible(false);
    String iconUrl;

    switch (icon) {
    case 1: {// Warning
      iconUrl = "/projetV1/images/bullet_error.png";
      btnOk.setVisible(true);
    }
      break;
    case 2: {// Info
      iconUrl = "/projetV1/images/bullet_info.png";
      btnOk.setVisible(true);
    }
      break;
    case 3: {// Error
      iconUrl = "/projetV1/images/bullet_deny.png";
      btnOk.setVisible(true);
    }
      break;
    case 4: {// Yes/NO
      iconUrl = "/projetV1/images/comment.png";
      btnOui.setVisible(true);
      btnNon.setVisible(true);
    }
      break;
    case 5: {// Success
      iconUrl = "/projetV1/images/bullet_accept.png";
      btnOk.setVisible(true);
    }
      break;
    default: {
      iconUrl = "";

    }
    }
    Label iconM = new Label(shell, SWT.NONE);
    iconM.setBounds(10, 20, 38, 38);
    iconM.setImage(SWTResourceManager.getImage(DialogBox.class, iconUrl));
    msg.setText(message);
    return i;
  }
}
TOP

Related Classes of projetV1.DialogBox

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.