summaryrefslogtreecommitdiff
path: root/src/org/unitConverter/converterGUI/UnitConverterGUI.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/unitConverter/converterGUI/UnitConverterGUI.java')
-rw-r--r--src/org/unitConverter/converterGUI/UnitConverterGUI.java22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/org/unitConverter/converterGUI/UnitConverterGUI.java b/src/org/unitConverter/converterGUI/UnitConverterGUI.java
index 8c70df4..f7c3479 100644
--- a/src/org/unitConverter/converterGUI/UnitConverterGUI.java
+++ b/src/org/unitConverter/converterGUI/UnitConverterGUI.java
@@ -32,6 +32,7 @@ import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
+import java.util.NoSuchElementException;
import java.util.Set;
import java.util.function.Predicate;
@@ -270,14 +271,14 @@ final class UnitConverterGUI {
final Unit to;
try {
from = this.database.evaluateUnitExpression(fromUnitString);
- } catch (final IllegalArgumentException e) {
+ } catch (final IllegalArgumentException | NoSuchElementException e) {
this.view.showErrorDialog("Parse Error",
"Could not recognize text in From entry: " + e.getMessage());
return;
}
try {
to = this.database.getUnitFromExpression(toUnitString);
- } catch (final IllegalArgumentException e) {
+ } catch (final IllegalArgumentException | NoSuchElementException e) {
this.view.showErrorDialog("Parse Error",
"Could not recognize text in To entry: " + e.getMessage());
return;
@@ -304,9 +305,10 @@ final class UnitConverterGUI {
}
final LinearUnitValue converted = from2.convertTo(to2);
- this.view.setExpressionConverterOutputText(
- (useSlash ? "1 / " : "") + String.format("%s = %s",
- fromUnitString, this.getRoundedString(converted)));
+ this.view.setExpressionConverterOutputText((useSlash ? "1 / " : "")
+ + String.format("%s = %s", fromUnitString,
+ this.getRoundedString(converted, false)));
+ final String toString = this.getRoundedString(converted, false);
return;
} else {
// convert to UnitValue
@@ -384,18 +386,19 @@ final class UnitConverterGUI {
}
/**
- * Like {@link LinearUnitValue#toString(boolean)} with parameter
- * {@code false}, but obeys this unit converter's rounding settings.
+ * Like {@link LinearUnitValue#toString(boolean)}, but obeys this unit
+ * converter's rounding settings.
*
* @since 2020-08-04
*/
- private final String getRoundedString(final LinearUnitValue value) {
+ private final String getRoundedString(final LinearUnitValue value,
+ boolean showUncertainty) {
switch (this.roundingType) {
case DECIMAL_PLACES:
case SIGNIFICANT_DIGITS:
return this.getRoundedString(value.asUnitValue());
case SCIENTIFIC:
- return value.toString(false);
+ return value.toString(showUncertainty);
default:
throw new AssertionError("Invalid switch condition.");
}
@@ -992,7 +995,6 @@ final class UnitConverterGUI {
final JRadioButton relativePrecision = new JRadioButton(
"Scientific Precision");
- relativePrecision.setEnabled(false);
relativePrecision.addActionListener(e -> this.presenter
.setRoundingType(RoundingType.SCIENTIFIC));
roundingRuleButtons.add(relativePrecision);