Methods Summary |
---|
public void | createDecimalText(org.eclipse.swt.widgets.Composite parent)Creates the {@link Text} control for the decimal display of the coordinate.
The control is expected to be placed in a Composite using a {@link GridLayout}.
mDecimalText = createTextControl(parent, "-199.999999", new ModifyListener() {
public void modifyText(ModifyEvent event) {
if (mManualTextChange > 0) {
return;
}
try {
mValue = Double.parseDouble(mDecimalText.getText());
setValueIntoSexagesimalControl(mValue);
mValueValidity = true;
} catch (NumberFormatException e) {
// wrong format empty the sexagesimal controls.
mValueValidity = false;
resetSexagesimalControls();
}
}
});
|
public void | createSexagesimalDegreeText(org.eclipse.swt.widgets.Composite parent)Creates the {@link Text} control for the "degree" display of the coordinate in sexagesimal
mode.
The control is expected to be placed in a Composite using a {@link GridLayout}.
mSexagesimalDegreeText = createTextControl(parent, "-199", mSexagesimalListener); //$NON-NLS-1$
|
public void | createSexagesimalMinuteText(org.eclipse.swt.widgets.Composite parent)Creates the {@link Text} control for the "minute" display of the coordinate in sexagesimal
mode.
The control is expected to be placed in a Composite using a {@link GridLayout}.
mSexagesimalMinuteText = createTextControl(parent, "99", mSexagesimalListener); //$NON-NLS-1$
|
public void | createSexagesimalSecondText(org.eclipse.swt.widgets.Composite parent)Creates the {@link Text} control for the "second" display of the coordinate in sexagesimal
mode.
The control is expected to be placed in a Composite using a {@link GridLayout}.
mSexagesimalSecondText = createTextControl(parent, "99.999", mSexagesimalListener); //$NON-NLS-1$
|
private org.eclipse.swt.widgets.Text | createTextControl(org.eclipse.swt.widgets.Composite parent, java.lang.String defaultString, org.eclipse.swt.events.ModifyListener listener)Creates a {@link Text} with a given parent, default string and a {@link ModifyListener}
// create the control
Text text = new Text(parent, SWT.BORDER | SWT.LEFT | SWT.SINGLE);
// add the standard listener to it.
text.addModifyListener(listener);
// compute its size/
mManualTextChange++;
text.setText(defaultString);
text.pack();
Point size = text.computeSize(SWT.DEFAULT, SWT.DEFAULT);
text.setText(""); //$NON-NLS-1$
mManualTextChange--;
GridData gridData = new GridData();
gridData.widthHint = size.x;
text.setLayoutData(gridData);
return text;
|
public double | getValue()Returns the current value set in the control(s).
This value can be erroneous, and a check with {@link #isValueValid()} should be performed
before any call to this method.
return mValue;
|
private double | getValueFromSexagesimalControls()
double degrees = Double.parseDouble(mSexagesimalDegreeText.getText());
double minutes = Double.parseDouble(mSexagesimalMinuteText.getText());
double seconds = Double.parseDouble(mSexagesimalSecondText.getText());
boolean isPositive = (degrees >= 0.);
degrees = Math.abs(degrees);
double value = degrees + minutes / 60. + seconds / 3600.;
return isPositive ? value : - value;
|
public boolean | isValueValid()Returns whether the value in the control(s) is valid.
return mValueValidity;
|
private void | resetDecimalControls()
mManualTextChange++;
mDecimalText.setText(""); //$NON-NLS-1$
mManualTextChange--;
|
private void | resetSexagesimalControls()
mManualTextChange++;
mSexagesimalDegreeText.setText(""); //$NON-NLS-1$
mSexagesimalMinuteText.setText(""); //$NON-NLS-1$
mSexagesimalSecondText.setText(""); //$NON-NLS-1$
mManualTextChange--;
|
public void | setEnabled(boolean enabled)Enables or disables all the {@link Text} controls.
mDecimalText.setEnabled(enabled);
mSexagesimalDegreeText.setEnabled(enabled);
mSexagesimalMinuteText.setEnabled(enabled);
mSexagesimalSecondText.setEnabled(enabled);
|
public void | setValue(double value)Sets the coordinate into the {@link Text} controls.
mValue = value;
mValueValidity = true;
setValueIntoDecimalControl(value);
setValueIntoSexagesimalControl(value);
|
private void | setValueIntoDecimalControl(double value)
mManualTextChange++;
mDecimalText.setText(String.format("%.6f", value));
mManualTextChange--;
|
private void | setValueIntoSexagesimalControl(double value)
// get the sign and make the number positive no matter what.
boolean isPositive = (value >= 0.);
value = Math.abs(value);
// get the degree
double degrees = Math.floor(value);
// get the minutes
double minutes = Math.floor((value - degrees) * 60.);
// get the seconds.
double seconds = (value - degrees) * 3600. - minutes * 60.;
mManualTextChange++;
mSexagesimalDegreeText.setText(
Integer.toString(isPositive ? (int)degrees : (int)- degrees));
mSexagesimalMinuteText.setText(Integer.toString((int)minutes));
mSexagesimalSecondText.setText(String.format("%.3f", seconds)); //$NON-NLS-1$
mManualTextChange--;
|