/******************************************************************************* * 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.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Button; 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 FloorConfigureDialog extends Dialog implements KeyListener,SelectionListener { private boolean floorEnabled = true; private double floorHeight = 0.0; private Text floorHeightText = null; private Button floorEnabledButton = null; public FloorConfigureDialog(Shell shell) { super(shell); } @Override protected Control createDialogArea(Composite parent) { Composite composite = (Composite) super.createDialogArea(parent); Label label = new Label(composite, SWT.WRAP); label.setText("Configure floor"); 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()); floorEnabledButton = new Button(composite,SWT.CHECK); floorEnabledButton.setText("Enabled"); label = new Label(composite, SWT.WRAP); label.setText("Height"); label.setLayoutData(data); label.setFont(parent.getFont()); floorHeightText = new Text(composite,SWT.NONE); floorHeightText.addKeyListener(this); floorEnabledButton.addSelectionListener(this); floorEnabledButton.setSelection(floorEnabled); floorHeightText.setText(Double.toString(floorHeight)); return composite; } @Override protected void configureShell(Shell newShell) { super.configureShell(newShell); newShell.setText("Configure floor"); } public void keyPressed(KeyEvent e) { } public void keyReleased(KeyEvent e) { boolean ok = true; try { floorHeight = Double.parseDouble(floorHeightText.getText()); } catch (NumberFormatException err) { ok = false; } if (ok) { this.getButton(IDialogConstants.OK_ID).setEnabled(true); } else { this.getButton(IDialogConstants.OK_ID).setEnabled(false); } } public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { floorEnabled = floorEnabledButton.getSelection(); } public boolean isFloorEnabled() { return floorEnabled; } public double getFloorHeight() { return floorHeight; } }