Package view

Source Code of view.ConfigFrame

package view;

import model.Constants;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Layout;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import view.listener.CloseButtonListener;
import view.listener.StartButtonListener;
import control.Util;

public class ConfigFrame {

  private Display display;
  private Shell shell;
  private Label playerName, enemyName;
  private Text playerNameField, enemyNameField;
  private Button start, close;
  private Label sizeName;
  private Combo sizeNameCombo;

  public ConfigFrame() {

    display = Display.getCurrent() != null ? Display.getCurrent()
        : new Display();
    shell = new Shell(display);
    configureShell();
    keepAlive();
  }

  private void buildContent() {

    playerName = new Label(shell, SWT.NULL);
    playerName.setText(Constants.PLAYERNAMELABEL);

    playerNameField = new Text(shell, SWT.BORDER);
    playerNameField.setLayoutData(new GridData(100, 15));

    enemyName = new Label(shell, SWT.NULL);
    enemyName.setText(Constants.ENEMYNAMELABEL);

    enemyNameField = new Text(shell, SWT.BORDER);
    enemyNameField.setLayoutData(new GridData(100, 15));

    sizeName = new Label(shell, SWT.NULL);
    sizeName.setText(Constants.SIZELABEL);

    sizeNameCombo = new Combo(shell, SWT.DROP_DOWN | SWT.READ_ONLY);
    sizeNameCombo.setLayoutData(new GridData(100, 15));
    sizeNameCombo.setItems(Constants.ITEMS);

    start = new Button(shell, SWT.PUSH);
    start.setText(Constants.STARTBUTTONLABEL);
    start.addSelectionListener(new StartButtonListener());

    close = new Button(shell, SWT.PUSH);
    close.setText(Constants.CLOSEBUTTONLABEL);
    close.addSelectionListener(new CloseButtonListener(shell));

  }

  private void configureShell() {
    shell.setLayout(getShellLayout());
    shell.setText(Constants.SHELLTITLE);
    buildContent();
    shell.pack();
    Util.centerFrame(shell);
    shell.setVisible(true);
    shell.setFocus();
  }

  private Layout getShellLayout() {
    GridLayout layout = new GridLayout(2, false);
    layout.marginLeft = 10;
    layout.marginRight = 10;
    layout.marginTop = 10;
    layout.marginBottom = 10;
    return layout;
  }

  private void keepAlive() {

    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }

  }
}
TOP

Related Classes of view.ConfigFrame

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.