Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 package com.generalrobotix.ui.view.graph;
00011
00012 import org.eclipse.jface.dialogs.Dialog;
00013 import org.eclipse.jface.dialogs.IDialogConstants;
00014 import org.eclipse.jface.dialogs.MessageDialog;
00015 import org.eclipse.swt.SWT;
00016 import org.eclipse.swt.events.KeyEvent;
00017 import org.eclipse.swt.events.KeyListener;
00018 import org.eclipse.swt.layout.RowLayout;
00019 import org.eclipse.swt.widgets.Composite;
00020 import org.eclipse.swt.widgets.Control;
00021 import org.eclipse.swt.widgets.Label;
00022 import org.eclipse.swt.widgets.Scale;
00023 import org.eclipse.swt.widgets.Shell;
00024 import org.eclipse.swt.widgets.Text;
00025
00026 import com.generalrobotix.ui.util.MessageBundle;
00027
00028
00035 public class HRangeDialog extends Dialog {
00036
00037
00038
00039
00040 public static final int RANGE_UPDATED = 1;
00041 public static final int POS_UPDATED = 2;
00042
00043 private static final int MARKER_POS_STEPS = 100;
00044
00045
00046
00047 int updateFlag_;
00048 double hRange_;
00049 double maxHRange_;
00050 double minHRange_;
00051 double markerPos_;
00052 Text hRangeField_;
00053 Scale markerSlider_;
00054 private boolean first_;
00055 private Shell shell_;
00056
00057
00063 public HRangeDialog(Shell shell) {
00064 super(shell);
00065 shell_ = shell;
00066 }
00067
00068 protected void configureShell(Shell newShell) {
00069 super.configureShell(newShell);
00070 newShell.setText(MessageBundle.get("dialog.graph.hrange.title"));
00071 }
00072
00073 protected Control createDialogArea(Composite parent) {
00074 Composite composite = (Composite)super.createDialogArea(parent);
00075 composite.setLayout(new RowLayout(SWT.VERTICAL));
00076 Composite comp0 = new Composite(composite, SWT.NONE);
00077 comp0.setLayout(new RowLayout());
00078
00079 Label label1 = new Label(comp0, SWT.NONE);
00080 label1.setText(MessageBundle.get("dialog.graph.hrange.hrange"));
00081
00082 hRangeField_ = new Text(comp0, SWT.BORDER);
00083 hRangeField_.setText(String.format("%10.3f", hRange_));
00084 first_ = true;
00085 hRangeField_.addKeyListener(new KeyListener(){
00086 public void keyPressed(KeyEvent e) {
00087 if(first_){
00088 hRangeField_.setText("");
00089 first_ = false;
00090 }
00091 }
00092 public void keyReleased(KeyEvent e) {
00093 }
00094 });
00095 hRangeField_.setFocus();
00096
00097 Label label2 = new Label(comp0, SWT.NONE);
00098 label2.setText(MessageBundle.get("dialog.graph.hrange.unit"));
00099
00100 Composite comp1 = new Composite(composite, SWT.NONE);
00101 comp1.setLayout(new RowLayout());
00102
00103 Label label3 = new Label(comp1, SWT.NONE);
00104 label3.setText(MessageBundle.get("dialog.graph.hrange.markerpos"));
00105
00106 markerSlider_ = new Scale(comp1, SWT.HORIZONTAL);
00107 markerSlider_.setMinimum(0);
00108 markerSlider_.setMaximum(MARKER_POS_STEPS);
00109 markerSlider_.setIncrement(10);
00110 markerSlider_.setSelection((int)(markerPos_ * MARKER_POS_STEPS));
00111
00112 updateFlag_ = 0;
00113 return composite;
00114 }
00115
00116 protected void buttonPressed(int buttonId) {
00117 if (buttonId == IDialogConstants.OK_ID) {
00118 double range;
00119 try {
00120 range = Double.parseDouble(hRangeField_.getText());
00121 } catch (NumberFormatException ex) {
00122
00123 MessageDialog.openError(shell_,
00124 MessageBundle.get("dialog.graph.hrange.invalidinput.title"),
00125 MessageBundle.get("dialog.graph.hrange.invalidinput.message"));
00126
00127 hRangeField_.setFocus();
00128 return;
00129 }
00130
00131 if (range < minHRange_ || range > maxHRange_) {
00132
00133 MessageDialog.openError(shell_,
00134 MessageBundle.get("dialog.graph.hrange.invalidrange.title"),
00135 MessageBundle.get("dialog.graph.hrange.invalidrange.message")
00136 + "\n(" + minHRange_ + " - " + maxHRange_ + ")" );
00137 hRangeField_.setFocus();
00138 return;
00139 }
00140 double pos = markerSlider_.getSelection() / (double)MARKER_POS_STEPS;
00141
00142 updateFlag_ = 0;
00143 if (range != hRange_) {
00144 hRange_ = range;
00145 updateFlag_ += RANGE_UPDATED;
00146 }
00147 if (pos != markerPos_) {
00148 markerPos_ = pos;
00149 updateFlag_ += POS_UPDATED;
00150 }
00151 }
00152 setReturnCode(buttonId);
00153 close();
00154 super.buttonPressed(buttonId);
00155 }
00156
00157
00158
00159
00165 public void setHRange(
00166 double hRange
00167 ) {
00168 hRange_ = hRange;
00169 }
00170
00176 public void setMaxHRange(
00177 double maxHRange
00178 ) {
00179 maxHRange_ = maxHRange;
00180 }
00181
00187 public void setMinHRange(
00188 double minHRange
00189 ) {
00190 minHRange_ = minHRange;
00191 }
00192
00198 public void setMarkerPos(
00199 double markerPos
00200 ) {
00201 markerPos_ = markerPos;
00202 }
00203
00209 public double getHRange() {
00210 return hRange_;
00211 }
00212
00218 public double getMarkerPos() {
00219 return markerPos_;
00220 }
00221
00227 public int getUpdateFlag() {
00228 return updateFlag_;
00229 }
00230
00231 }