/******************************************************************************* * Copyright (c) 2007- VTT Technical Research Centre of Finland. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ package org.simantics.processeditor.dialogs; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.swt.SWT; import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.events.KeyListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; public class PipelineDialog extends Dialog implements KeyListener{ Text pipeRadiusText; Text turnRadiusText; double pipeDiameter = 0.0; double turnRadius = 0.0; public PipelineDialog(Shell parentShell) { super(parentShell); } public PipelineDialog(Shell parentShell, double pipeRadius, double turnRadius) { super(parentShell); this.pipeDiameter = pipeRadius; this.turnRadius = turnRadius; } @Override protected void configureShell(Shell newShell) { super.configureShell(newShell); newShell.setText("Configure new pipeline"); } @Override protected Control createDialogArea(Composite parent) { Composite composite = (Composite) super.createDialogArea(parent); Label label = new Label(composite, SWT.WRAP); label.setText("Input pipeline specifications"); GridData data = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER); data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH); label.setLayoutData(data); label.setFont(parent.getFont()); label = new Label(composite, SWT.WRAP); label.setText("Pipe diameter"); label.setLayoutData(data); label.setFont(parent.getFont()); pipeRadiusText = new Text(composite,SWT.BORDER); pipeRadiusText.setLayoutData(data); label = new Label(composite, SWT.WRAP); label.setText("Pipe elbow/turn radius"); label.setLayoutData(data); label.setFont(parent.getFont()); turnRadiusText = new Text(composite,SWT.BORDER); turnRadiusText.setLayoutData(data); pipeRadiusText.addKeyListener(this); turnRadiusText.addKeyListener(this); if (pipeDiameter > 0.0 && turnRadius > 0.0) { pipeRadiusText.setText(Double.toString(pipeDiameter)); turnRadiusText.setText(Double.toString(turnRadius)); } return composite; } @Override public int open() { return super.open(); } public void keyPressed(KeyEvent e) { } public void keyReleased(KeyEvent e) { boolean ok = true; try { pipeDiameter = Double.parseDouble(pipeRadiusText.getText()); turnRadius = Double.parseDouble(turnRadiusText.getText()); if (pipeDiameter <= 0.0) ok = false; if (turnRadius <= 0.0) ok = false; } catch (NumberFormatException err) { ok = false; } if (ok) { this.getButton(IDialogConstants.OK_ID).setEnabled(true); } else { this.getButton(IDialogConstants.OK_ID).setEnabled(false); } } public double getPipeDiameter() { return pipeDiameter; } public double getTurnRadius() { return turnRadius; } }