package gui.dialogs;
import gui.NeuralNetworkBaseItem;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import components.neuralnetwork.ExternalNeuralNetwork;
public class CreateNeuralNet extends Dialog {
private Combo combo;
private Text text_2;
private Text text_1;
private Text text;
protected NeuralNetworkBaseItem result;
protected Shell shell;
private DirectoryDialog directoryDialog;
/**
* Create the dialog
* @param parent
* @param style
*/
public CreateNeuralNet(Shell parent, int style) {
super(parent, style);
this.directoryDialog = new DirectoryDialog(parent, SWT.APPLICATION_MODAL);
}
/**
* Create the dialog
* @param parent
*/
public CreateNeuralNet(Shell parent) {
this(parent, SWT.NONE);
}
/**
* Open the dialog
* @return the result
*/
public NeuralNetworkBaseItem open() {
createContents();
result = null;
shell.open();
shell.layout();
Display display = getParent().getDisplay();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
return result;
}
/**
* Create contents of the dialog
*/
protected void createContents() {
shell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
shell.setSize(416, 322);
shell.setText("Crear red neuronal");
final Label nombreLabel = new Label(shell, SWT.NONE);
nombreLabel.setText("Nombre:");
nombreLabel.setBounds(27, 26, 41, 13);
text = new Text(shell, SWT.BORDER);
text.setBounds(92, 23, 135, 25);
final Label descripcionLabel = new Label(shell, SWT.NONE);
descripcionLabel.setText("Descripci�n:");
descripcionLabel.setBounds(27, 75, 57, 13);
text_2 = new Text(shell, SWT.BORDER | SWT.WRAP | SWT.MULTI | SWT.V_SCROLL);
text_2.setBounds(92, 72, 250, 75);
final Label directorioLabel = new Label(shell, SWT.NONE);
directorioLabel.setText("Directorio:");
directorioLabel.setBounds(27, 165, 57, 13);
text_1 = new Text(shell, SWT.BORDER);
text_1.setBounds(92, 162, 245, 25);
final Button buscarButton = new Button(shell, SWT.NONE);
buscarButton.setText("Buscar...");
buscarButton.setBounds(343, 162, 57, 23);
buscarButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent evt)
{
buscarButtonWidgetSelected(evt);
}
});
final Label tipoLabel = new Label(shell, SWT.NONE);
tipoLabel.setText("Tipo:");
tipoLabel.setBounds(27, 208, 25, 13);
combo = new Combo(shell, SWT.READ_ONLY);
for (int i=0; i<ExternalNeuralNetwork.getTotalTypes(); i++)
combo.setItems(new String[] {ExternalNeuralNetwork.getTypeName(i)});
combo.select(0);
combo.setBounds(92, 205, 157, 21);
final Button aceptarButton = new Button(shell, SWT.NONE);
aceptarButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
result = new NeuralNetworkBaseItem();
result.setName(text.getText());
result.setDescription(text_2.getText());
result.setPath(text_1.getText());
result.setType(combo.getSelectionIndex());
shell.close();
}
});
aceptarButton.setText("Aceptar");
aceptarButton.setBounds(92, 246, 57, 23);
final Button cancelarButton = new Button(shell, SWT.NONE);
cancelarButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
shell.close();
}
});
cancelarButton.setText("Cancelar");
cancelarButton.setBounds(205, 246, 65, 23);
//
}
private void buscarButtonWidgetSelected(SelectionEvent evt)
{
String pathName = directoryDialog.open();
text_1.setText(pathName!=null?pathName:"");
}
}