Package gui

Source Code of gui.SimulationNameChanger

package gui;

import com.cloudgarden.resource.SWTResourceManager;
import core.simulation.Simulation;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.events.*;

import utils.ErrorMessage;


/**
* Esta clase implementa el mecanismo para renombrado de simulaciones
* almacenadas en la base de datos.
*/
public class SimulationNameChanger extends Dialog
{

  private Shell       dialogShell;
  private CLabel       title;
  private Button      button;
  private Label       separator1;
  private Text       edit;
  private Label       name;
  private Composite     editBox;
  private Label       separator;
  private Label       msg;


 
  public SimulationNameChanger(Shell parent, int style)
  {
    super(parent, style);
  }

 
  public void open()
  {
    try
    {
      Shell parent = getParent();
      dialogShell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);

      {
        //Register as a resource user - SWTResourceManager will
        //handle the obtaining and disposing of resources
        SWTResourceManager.registerResourceUser(dialogShell);
      }


      GridLayout dialogShellLayout = new GridLayout();
      dialogShell.setLayout(dialogShellLayout);
      dialogShellLayout.verticalSpacing = 3;
      dialogShellLayout.marginWidth = 0;
      dialogShellLayout.marginHeight = 0;
      dialogShellLayout.horizontalSpacing = 3;
      dialogShellLayout.marginLeft = 3;
      dialogShellLayout.marginRight = 3;
      dialogShell.layout();
      dialogShell.pack();
      dialogShell.setSize(345, 200);
      {
        title = new CLabel(dialogShell, SWT.NONE);
        title.setText("Atenci�n!");
        GridData titleLData = new GridData();
        titleLData.grabExcessHorizontalSpace = true;
        titleLData.horizontalAlignment = GridData.FILL;
        title.setLayoutData(titleLData);
        title.setImage(SWTResourceManager.getImage("resources/icons/iconmisc/Warning.png"));
        title.setForeground(SWTResourceManager.getColor(128, 128, 128));
        title.setFont(SWTResourceManager.getFont("Tahoma", 9, 1, false, false));
      }
      {
        GridData separatorLData = new GridData();
        separatorLData.horizontalAlignment = GridData.FILL;
        separatorLData.grabExcessHorizontalSpace = true;
        separator = new Label(dialogShell, SWT.SEPARATOR
          | SWT.HORIZONTAL);
        separator.setLayoutData(separatorLData);
      }
      {
        msg = new Label(dialogShell, SWT.CENTER | SWT.WRAP);
        GridData msgLData = new GridData();
        msgLData.verticalIndent = 3;
        msgLData.grabExcessHorizontalSpace = true;
        msg.setLayoutData(msgLData);
        msg.setText"El nombre de la simulaci�n ingresada ya se " +
                "encuentra en el listado de simulaciones realizadas. " +
                "Seleccione otro nombre.");
      }
      {
        editBox = new Composite(dialogShell, SWT.NONE);
        GridLayout editBoxLayout = new GridLayout();
        editBoxLayout.numColumns = 2;
        editBoxLayout.verticalSpacing = 0;
        editBoxLayout.marginWidth = 0;
        editBoxLayout.marginHeight = 0;
        editBoxLayout.horizontalSpacing = 0;
        GridData editBoxLData = new GridData();
        editBoxLData.horizontalAlignment = GridData.FILL;
        editBoxLData.grabExcessHorizontalSpace = true;
        editBoxLData.heightHint = 16;
        editBoxLData.verticalIndent = 6;
        editBox.setLayoutData(editBoxLData);
        editBox.setLayout(editBoxLayout);
        {
          name = new Label(editBox, SWT.RIGHT);
          GridData nameLData = new GridData();
          nameLData.horizontalAlignment = GridData.END;
          nameLData.heightHint = 13;
          nameLData.widthHint = 54;
          nameLData.grabExcessHorizontalSpace = true;
          name.setLayoutData(nameLData);
          name.setText("Nombre: ");
        }
        {
          GridData editLData = new GridData();
          editLData.heightHint = 13;
          editLData.horizontalAlignment = GridData.CENTER;
          editLData.grabExcessHorizontalSpace = true;
          editLData.widthHint = 175;
          edit = new Text(editBox, SWT.NONE);
          edit.setText(Simulation.getCurrent().getName());
          edit.setLayoutData(editLData);
        }
      }
      {
        GridData separator1LData = new GridData();
        separator1LData.horizontalAlignment = GridData.FILL;
        separator1LData.grabExcessHorizontalSpace = true;
        separator1 = new Label(dialogShell, SWT.SEPARATOR
          | SWT.HORIZONTAL);
        separator1.setLayoutData(separator1LData);
      }
      {
        button = new Button(dialogShell, SWT.PUSH | SWT.CENTER);
        GridData buttonLData = new GridData();
        buttonLData.horizontalAlignment = GridData.CENTER;
        buttonLData.verticalIndent = 5;
        button.setLayoutData(buttonLData);
        button.setText("Aceptar");
        button.addSelectionListener(new SelectionAdapter() {
          public void widgetSelected(SelectionEvent evt) {
            buttonWidgetSelected(evt);
          }
        });
      }
      dialogShell.open();
      Display display = dialogShell.getDisplay();
      while (!dialogShell.isDisposed()) {
        if (!display.readAndDispatch())
          display.sleep();
      }
    }
    catch (Exception e)
    {
      ErrorMessage.customMessage(e.getMessage(), ErrorMessage.ERROR_MESSAGE, getParent());
    }
  }
 
 
  private void buttonWidgetSelected(SelectionEvent evt)
  {
    if ( edit.getText().length() > 0 )
    {
      Simulation.getCurrent().setName(edit.getText());
      dialogShell.close();
    }
  }

}
TOP

Related Classes of gui.SimulationNameChanger

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.