summaryrefslogtreecommitdiff
path: root/src/main/java/sevenUnitsGUI/TabbedView.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/sevenUnitsGUI/TabbedView.java')
-rw-r--r--src/main/java/sevenUnitsGUI/TabbedView.java257
1 files changed, 171 insertions, 86 deletions
diff --git a/src/main/java/sevenUnitsGUI/TabbedView.java b/src/main/java/sevenUnitsGUI/TabbedView.java
index 997acc3..8be58f5 100644
--- a/src/main/java/sevenUnitsGUI/TabbedView.java
+++ b/src/main/java/sevenUnitsGUI/TabbedView.java
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2022 Adrien Hopkins
+ * Copyright (C) 2022, 2024, 2025 Adrien Hopkins
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@@ -24,13 +24,16 @@ import java.awt.event.ItemEvent;
import java.awt.event.KeyEvent;
import java.util.AbstractSet;
import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.Set;
+import java.util.function.Consumer;
import java.util.function.Function;
import javax.swing.BorderFactory;
@@ -64,8 +67,8 @@ import sevenUnits.utils.UncertainDouble;
/**
* A View that separates its functions into multiple tabs
*
- * @since v0.4.0
* @since 2022-02-19
+ * @since v0.4.0
*/
final class TabbedView implements ExpressionConversionView, UnitConversionView {
/**
@@ -73,8 +76,8 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
*
* @param <E> type of item in list
*
- * @since v0.4.0
* @since 2022-02-19
+ * @since v0.4.0
*/
private static final class JComboBoxItemSet<E> extends AbstractSet<E> {
private final JComboBox<E> comboBox;
@@ -82,6 +85,7 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
/**
* @param comboBox combo box to get items from
* @since 2022-02-19
+ * @since v0.4.0
*/
public JComboBoxItemSet(JComboBox<E> comboBox) {
this.comboBox = comboBox;
@@ -101,9 +105,8 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
public E next() {
if (this.hasNext())
return JComboBoxItemSet.this.comboBox.getItemAt(this.index++);
- else
- throw new NoSuchElementException(
- "Iterator has finished iteration");
+ throw new NoSuchElementException(
+ "Iterator has finished iteration");
}
};
}
@@ -119,10 +122,10 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
* The standard types of rounding, corresponding to the options on the
* TabbedView's settings panel.
*
- * @since v0.4.0
* @since 2022-04-18
+ * @since v0.4.0
*/
- private static enum StandardRoundingType {
+ private enum StandardRoundingType {
/**
* Rounds to a fixed number of significant digits. Precision is used,
* representing the number of significant digits to round to.
@@ -144,8 +147,8 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
* Creates a TabbedView.
*
* @param args command line arguments
- * @since v0.4.0
* @since 2022-02-19
+ * @since v0.4.0
*/
public static void main(String[] args) {
// This view doesn't need to do anything, the side effects of creating it
@@ -195,15 +198,19 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
/** The text box for prefix data in the prefix viewer */
private final JTextArea prefixTextBox;
- // SETTINGS STUFF
+ // INFO & SETTINGS STUFF
+ final JTextArea infoTextArea;
+ private final JComboBox<String> localeSelector;
private StandardRoundingType roundingType;
private int precision;
+ private final Map<String, Consumer<String>> localizedTextSetters;
+
/**
* Creates the view and makes it visible to the user
- *
- * @since v0.4.0
+ *
* @since 2022-02-19
+ * @since v0.4.0
*/
public TabbedView() {
// enable system look and feel
@@ -218,21 +225,25 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
// initialize important components
this.presenter = new Presenter(this);
- this.frame = new JFrame("7Units " + ProgramInfo.VERSION);
+ this.frame = new JFrame("7Units (Unlocalized)");
this.frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
// master components (those that contain everything else within them)
this.masterPane = new JTabbedPane();
this.frame.add(this.masterPane);
+ this.localizedTextSetters = new HashMap<>();
+
// ============ UNIT CONVERSION TAB ============
- final JPanel convertUnitPanel = new JPanel();
+ final var convertUnitPanel = new JPanel();
this.masterPane.addTab("Convert Units", convertUnitPanel);
+ this.localizedTextSetters.put("tv.convert_units.title",
+ txt -> this.masterPane.setTitleAt(0, txt));
this.masterPane.setMnemonicAt(0, KeyEvent.VK_U);
convertUnitPanel.setLayout(new BorderLayout());
{ // panel for input part
- final JPanel inputPanel = new JPanel();
+ final var inputPanel = new JPanel();
convertUnitPanel.add(inputPanel, BorderLayout.CENTER);
inputPanel.setLayout(new GridLayout(1, 3));
inputPanel.setBorder(new EmptyBorder(6, 6, 3, 6));
@@ -240,7 +251,7 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
this.fromSearch = new SearchBoxList<>();
inputPanel.add(this.fromSearch);
- final JPanel inBetweenPanel = new JPanel();
+ final var inBetweenPanel = new JPanel();
inputPanel.add(inBetweenPanel);
inBetweenPanel.setLayout(new BorderLayout());
@@ -249,7 +260,7 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
this.dimensionSelector
.addItemListener(e -> this.presenter.updateView());
- final JLabel arrowLabel = new JLabel("-->");
+ final var arrowLabel = new JLabel("-->");
inBetweenPanel.add(arrowLabel, BorderLayout.CENTER);
arrowLabel.setHorizontalAlignment(SwingConstants.CENTER);
@@ -258,12 +269,14 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
}
{ // panel for submit and output, and also value entry
- final JPanel outputPanel = new JPanel();
+ final var outputPanel = new JPanel();
convertUnitPanel.add(outputPanel, BorderLayout.PAGE_END);
outputPanel.setLayout(new BorderLayout());
outputPanel.setBorder(new EmptyBorder(3, 6, 6, 6));
- final JLabel valuePrompt = new JLabel("Value to convert: ");
+ final var valuePrompt = new JLabel();
+ this.localizedTextSetters.put("tv.convert_units.value_prompt",
+ valuePrompt::setText);
outputPanel.add(valuePrompt, BorderLayout.LINE_START);
this.valueInput = new JTextField();
@@ -271,6 +284,8 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
// conversion button
this.convertUnitButton = new JButton("Convert");
+ this.localizedTextSetters.put("tv.convert_units.convert_btn",
+ this.convertUnitButton::setText);
outputPanel.add(this.convertUnitButton, BorderLayout.LINE_END);
this.convertUnitButton
.addActionListener(e -> this.presenter.convertUnits());
@@ -283,23 +298,31 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
}
// ============ EXPRESSION CONVERSION TAB ============
- final JPanel convertExpressionPanel = new JPanel();
+ final var convertExpressionPanel = new JPanel();
this.masterPane.addTab("Convert Unit Expressions",
convertExpressionPanel);
+ this.localizedTextSetters.put("tv.convert_expressions.title",
+ txt -> this.masterPane.setTitleAt(1, txt));
this.masterPane.setMnemonicAt(1, KeyEvent.VK_E);
convertExpressionPanel.setLayout(new GridLayout(4, 1));
// from and to expressions
this.fromEntry = new JTextField();
convertExpressionPanel.add(this.fromEntry);
- this.fromEntry.setBorder(BorderFactory.createTitledBorder("From"));
+ this.localizedTextSetters.put("tv.convert_expressions.from",
+ txt -> this.fromEntry
+ .setBorder(BorderFactory.createTitledBorder(txt)));
this.toEntry = new JTextField();
convertExpressionPanel.add(this.toEntry);
- this.toEntry.setBorder(BorderFactory.createTitledBorder("To"));
+ this.localizedTextSetters.put("tv.convert_expressions.to",
+ txt -> this.toEntry
+ .setBorder(BorderFactory.createTitledBorder(txt)));
// button to convert
- this.convertExpressionButton = new JButton("Convert");
+ this.convertExpressionButton = new JButton();
+ this.localizedTextSetters.put("tv.convert_expressions.convert_btn",
+ this.convertExpressionButton::setText);
convertExpressionPanel.add(this.convertExpressionButton);
this.convertExpressionButton
@@ -309,13 +332,16 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
// output of conversion
this.expressionOutput = new JTextArea(2, 32);
convertExpressionPanel.add(this.expressionOutput);
- this.expressionOutput
- .setBorder(BorderFactory.createTitledBorder("Output"));
+ this.localizedTextSetters.put("tv.convert_expressions.output",
+ txt -> this.expressionOutput
+ .setBorder(BorderFactory.createTitledBorder(txt)));
this.expressionOutput.setEditable(false);
// =========== UNIT VIEWER ===========
- final JPanel unitLookupPanel = new JPanel();
+ final var unitLookupPanel = new JPanel();
this.masterPane.addTab("Unit Viewer", unitLookupPanel);
+ this.localizedTextSetters.put("tv.unit_viewer.title",
+ txt -> this.masterPane.setTitleAt(2, txt));
this.masterPane.setMnemonicAt(2, KeyEvent.VK_V);
unitLookupPanel.setLayout(new GridLayout());
@@ -331,8 +357,10 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
this.unitTextBox.setLineWrap(true);
// ============ PREFIX VIEWER =============
- final JPanel prefixLookupPanel = new JPanel();
+ final var prefixLookupPanel = new JPanel();
this.masterPane.addTab("Prefix Viewer", prefixLookupPanel);
+ this.localizedTextSetters.put("tv.prefix_viewer.title",
+ txt -> this.masterPane.setTitleAt(3, txt));
this.masterPane.setMnemonicAt(3, KeyEvent.VK_P);
prefixLookupPanel.setLayout(new GridLayout(1, 2));
@@ -349,23 +377,24 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
// ============ INFO PANEL ============
- final JPanel infoPanel = new JPanel();
+ final var infoPanel = new JPanel();
this.masterPane.addTab("\uD83D\uDEC8", // info (i) character
new JScrollPane(infoPanel));
- final JTextArea infoTextArea = new JTextArea();
- infoTextArea.setEditable(false);
- infoTextArea.setOpaque(false);
- infoPanel.add(infoTextArea);
- infoTextArea.setText(Presenter.getAboutText());
+ this.infoTextArea = new JTextArea();
+ this.infoTextArea.setEditable(false);
+ this.infoTextArea.setOpaque(false);
+ infoPanel.add(this.infoTextArea);
// ============ SETTINGS PANEL ============
+ this.localeSelector = new JComboBox<>();
this.masterPane.addTab("\u2699",
new JScrollPane(this.createSettingsPanel()));
this.masterPane.setMnemonicAt(5, KeyEvent.VK_S);
// ============ FINALIZE CREATION OF VIEW ============
this.presenter.postViewInitialize();
+ this.updateText();
this.frame.pack();
this.frame.setVisible(true);
}
@@ -375,40 +404,46 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
* code more organized, as this function is massive!)
*
* @since 2022-02-19
+ * @since v0.4.0
*/
private JPanel createSettingsPanel() {
- final JPanel settingsPanel = new JPanel();
+ final var settingsPanel = new JPanel();
settingsPanel
.setLayout(new BoxLayout(settingsPanel, BoxLayout.PAGE_AXIS));
// ============ ROUNDING SETTINGS ============
{
- final JPanel roundingPanel = new JPanel();
+ final var roundingPanel = new JPanel();
settingsPanel.add(roundingPanel);
- roundingPanel.setBorder(new TitledBorder("Rounding Settings"));
+ this.localizedTextSetters.put("tv.settings.rounding.title",
+ txt -> roundingPanel.setBorder(new TitledBorder(txt)));
roundingPanel.setLayout(new GridBagLayout());
// rounding rule selection
- final ButtonGroup roundingRuleButtons = new ButtonGroup();
+ final var roundingRuleButtons = new ButtonGroup();
this.roundingType = this.getPresenterRoundingType()
.orElseThrow(() -> new AssertionError(
"Presenter loaded non-standard rounding rule"));
this.precision = this.getPresenterPrecision().orElse(6);
- final JLabel roundingRuleLabel = new JLabel("Rounding Rule:");
+ final var roundingRuleLabel = new JLabel();
+ this.localizedTextSetters.put("tv.settings.rounding.rule",
+ roundingRuleLabel::setText);
roundingPanel.add(roundingRuleLabel, new GridBagBuilder(0, 0)
.setAnchor(GridBagConstraints.LINE_START).build());
// sigDigSlider needs to be first so that the rounding-type buttons can
// show and hide it
- final JLabel sliderLabel = new JLabel("Precision:");
+ final var sliderLabel = new JLabel();
+ this.localizedTextSetters.put("tv.settings.rounding.precision",
+ sliderLabel::setText);
sliderLabel.setVisible(
this.roundingType != StandardRoundingType.UNCERTAINTY);
roundingPanel.add(sliderLabel, new GridBagBuilder(0, 4)
.setAnchor(GridBagConstraints.LINE_START).build());
- final JSlider sigDigSlider = new JSlider(0, 12);
+ final var sigDigSlider = new JSlider(0, 12);
roundingPanel.add(sigDigSlider, new GridBagBuilder(0, 5)
.setAnchor(GridBagConstraints.LINE_START).build());
@@ -428,8 +463,9 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
});
// significant digit rounding
- final JRadioButton fixedPrecision = new JRadioButton(
- "Fixed Precision");
+ final var fixedPrecision = new JRadioButton();
+ this.localizedTextSetters.put("tv.settings.rounding.fixed_sigfig",
+ fixedPrecision::setText);
if (this.roundingType == StandardRoundingType.SIGNIFICANT_DIGITS) {
fixedPrecision.setSelected(true);
}
@@ -444,8 +480,9 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
.setAnchor(GridBagConstraints.LINE_START).build());
// decimal place rounding
- final JRadioButton fixedDecimals = new JRadioButton(
- "Fixed Decimal Places");
+ final var fixedDecimals = new JRadioButton();
+ this.localizedTextSetters.put("tv.settings.rounding.fixed_places",
+ fixedDecimals::setText);
if (this.roundingType == StandardRoundingType.DECIMAL_PLACES) {
fixedDecimals.setSelected(true);
}
@@ -460,8 +497,9 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
.setAnchor(GridBagConstraints.LINE_START).build());
// scientific rounding
- final JRadioButton relativePrecision = new JRadioButton(
- "Uncertainty-Based Rounding");
+ final var relativePrecision = new JRadioButton();
+ this.localizedTextSetters.put("tv.settings.rounding.uncertainty",
+ relativePrecision::setText);
if (this.roundingType == StandardRoundingType.UNCERTAINTY) {
relativePrecision.setSelected(true);
}
@@ -478,10 +516,10 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
// ============ PREFIX REPETITION SETTINGS ============
{
- final JPanel prefixRepetitionPanel = new JPanel();
+ final var prefixRepetitionPanel = new JPanel();
settingsPanel.add(prefixRepetitionPanel);
- prefixRepetitionPanel
- .setBorder(new TitledBorder("Prefix Repetition Settings"));
+ this.localizedTextSetters.put("tv.settings.repetition.title",
+ txt -> prefixRepetitionPanel.setBorder(new TitledBorder(txt)));
prefixRepetitionPanel.setLayout(new GridBagLayout());
final var prefixRule = this.getPresenterPrefixRule()
@@ -489,9 +527,11 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
"Presenter loaded non-standard prefix rule"));
// prefix rules
- final ButtonGroup prefixRuleButtons = new ButtonGroup();
+ final var prefixRuleButtons = new ButtonGroup();
- final JRadioButton noRepetition = new JRadioButton("No Repetition");
+ final var noRepetition = new JRadioButton();
+ this.localizedTextSetters.put("tv.settings.repetition.no",
+ noRepetition::setText);
if (prefixRule == DefaultPrefixRepetitionRule.NO_REPETITION) {
noRepetition.setSelected(true);
}
@@ -504,7 +544,9 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
prefixRepetitionPanel.add(noRepetition, new GridBagBuilder(0, 0)
.setAnchor(GridBagConstraints.LINE_START).build());
- final JRadioButton noRestriction = new JRadioButton("No Restriction");
+ final var noRestriction = new JRadioButton();
+ this.localizedTextSetters.put("tv.settings.repetition.any",
+ noRestriction::setText);
if (prefixRule == DefaultPrefixRepetitionRule.NO_RESTRICTION) {
noRestriction.setSelected(true);
}
@@ -517,8 +559,9 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
prefixRepetitionPanel.add(noRestriction, new GridBagBuilder(0, 1)
.setAnchor(GridBagConstraints.LINE_START).build());
- final JRadioButton customRepetition = new JRadioButton(
- "Complex Repetition");
+ final var customRepetition = new JRadioButton();
+ this.localizedTextSetters.put("tv.settings.repetition.complex",
+ customRepetition::setText);
if (prefixRule == DefaultPrefixRepetitionRule.COMPLEX_REPETITION) {
customRepetition.setSelected(true);
}
@@ -534,18 +577,20 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
// ============ SEARCH SETTINGS ============
{
- final JPanel searchingPanel = new JPanel();
+ final var searchingPanel = new JPanel();
settingsPanel.add(searchingPanel);
- searchingPanel.setBorder(new TitledBorder("Search Settings"));
+ this.localizedTextSetters.put("tv.settings.search.title",
+ txt -> searchingPanel.setBorder(new TitledBorder(txt)));
searchingPanel.setLayout(new GridBagLayout());
// searching rules
- final ButtonGroup searchRuleButtons = new ButtonGroup();
+ final var searchRuleButtons = new ButtonGroup();
final var searchRule = this.presenter.getSearchRule();
- final JRadioButton noPrefixes = new JRadioButton(
- "Never Include Prefixed Units");
+ final var noPrefixes = new JRadioButton();
+ this.localizedTextSetters.put("tv.settings.search.no_prefixes",
+ noPrefixes::setText);
noPrefixes.addActionListener(e -> {
this.presenter.setSearchRule(PrefixSearchRule.NO_PREFIXES);
this.presenter.updateView();
@@ -555,8 +600,9 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
searchingPanel.add(noPrefixes, new GridBagBuilder(0, 0)
.setAnchor(GridBagConstraints.LINE_START).build());
- final JRadioButton commonPrefixes = new JRadioButton(
- "Include Common Prefixes");
+ final var commonPrefixes = new JRadioButton();
+ this.localizedTextSetters.put("tv.settings.search.common_prefixes",
+ commonPrefixes::setText);
commonPrefixes.addActionListener(e -> {
this.presenter.setSearchRule(PrefixSearchRule.COMMON_PREFIXES);
this.presenter.updateView();
@@ -566,8 +612,9 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
searchingPanel.add(commonPrefixes, new GridBagBuilder(0, 1)
.setAnchor(GridBagConstraints.LINE_START).build());
- final JRadioButton alwaysInclude = new JRadioButton(
- "Include All Single Prefixes");
+ final var alwaysInclude = new JRadioButton();
+ this.localizedTextSetters.put("tv.settings.search.all_prefixes",
+ alwaysInclude::setText);
alwaysInclude.addActionListener(e -> {
this.presenter
.setSearchRule(this.presenter.getUniversalSearchRule());
@@ -592,34 +639,66 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
// ============ OTHER SETTINGS ============
{
- final JPanel miscPanel = new JPanel();
+ final var miscPanel = new JPanel();
settingsPanel.add(miscPanel);
miscPanel.setLayout(new GridBagLayout());
- final JCheckBox oneWay = new JCheckBox("Convert One Way Only");
+ final var oneWay = new JCheckBox();
+ this.localizedTextSetters.put("tv.settings.oneway", oneWay::setText);
oneWay.setSelected(this.presenter.oneWayConversionEnabled());
oneWay.addItemListener(e -> {
this.presenter.setOneWayConversionEnabled(
e.getStateChange() == ItemEvent.SELECTED);
this.presenter.saveSettings();
});
- miscPanel.add(oneWay, new GridBagBuilder(0, 0)
+ miscPanel.add(oneWay, new GridBagBuilder(0, 0, 2, 1)
.setAnchor(GridBagConstraints.LINE_START).build());
- final JCheckBox showAllVariations = new JCheckBox(
- "Show Duplicate Units & Prefixes");
+ final var showAllVariations = new JCheckBox();
+ this.localizedTextSetters.put("tv.settings.show_duplicate",
+ showAllVariations::setText);
showAllVariations.setSelected(this.presenter.duplicatesShown());
showAllVariations.addItemListener(e -> {
this.presenter
.setShowDuplicates(e.getStateChange() == ItemEvent.SELECTED);
this.presenter.saveSettings();
});
- miscPanel.add(showAllVariations, new GridBagBuilder(0, 1)
+ miscPanel.add(showAllVariations, new GridBagBuilder(0, 1, 2, 1)
+ .setAnchor(GridBagConstraints.LINE_START).build());
+
+ final var useDefaultFiles = new JCheckBox();
+ this.localizedTextSetters.put("tv.settings.use_default_files",
+ useDefaultFiles::setText);
+ useDefaultFiles.setSelected(this.presenter.usingDefaultDatafiles());
+ useDefaultFiles.addItemListener(e -> {
+ this.presenter.setUseDefaultDatafiles(
+ e.getStateChange() == ItemEvent.SELECTED);
+ this.presenter.saveSettings();
+ });
+ miscPanel.add(useDefaultFiles, new GridBagBuilder(0, 2, 2, 1)
.setAnchor(GridBagConstraints.LINE_START).build());
- final JButton unitFileButton = new JButton("Manage Unit Data Files");
+ final var localeLabel = new JLabel();
+ this.localizedTextSetters.put("tv.settings.locale",
+ localeLabel::setText);
+ miscPanel.add(localeLabel, new GridBagBuilder(0, 3, 1, 1)
+ .setAnchor(GridBagConstraints.LINE_START).build());
+
+ this.presenter.getAvailableLocales().stream().sorted()
+ .forEachOrdered(this.localeSelector::addItem);
+ this.localeSelector.setSelectedItem(this.presenter.getUserLocale());
+ this.localeSelector.addItemListener(e -> {
+ this.presenter.setUserLocale((String) e.getItem());
+ this.presenter.saveSettings();
+ });
+ miscPanel.add(localeSelector, new GridBagBuilder(1, 3, 1, 1)
+ .setAnchor(GridBagConstraints.LINE_END).build());
+
+ final var unitFileButton = new JButton();
+ this.localizedTextSetters.put("tv.settings.unitfiles.button",
+ unitFileButton::setText);
unitFileButton.setEnabled(false);
- miscPanel.add(unitFileButton, new GridBagBuilder(0, 2)
+ miscPanel.add(unitFileButton, new GridBagBuilder(0, 4, 2, 1)
.setAnchor(GridBagConstraints.LINE_START).build());
}
@@ -662,8 +741,8 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
/**
* @return the precision of the presenter's rounding rule, if that is
* meaningful
- * @since v0.4.0
* @since 2022-04-18
+ * @since v0.4.0
*/
private OptionalInt getPresenterPrecision() {
final var presenterRule = this.presenter.getNumberDisplayRule();
@@ -671,18 +750,17 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
return OptionalInt
.of(((StandardDisplayRules.FixedDecimals) presenterRule)
.decimalPlaces());
- else if (presenterRule instanceof StandardDisplayRules.FixedPrecision)
+ if (presenterRule instanceof StandardDisplayRules.FixedPrecision)
return OptionalInt
.of(((StandardDisplayRules.FixedPrecision) presenterRule)
.significantFigures());
- else
- return OptionalInt.empty();
+ return OptionalInt.empty();
}
/**
* @return presenter's prefix repetition rule
- * @since v0.4.0
* @since 2022-04-19
+ * @since v0.4.0
*/
private Optional<DefaultPrefixRepetitionRule> getPresenterPrefixRule() {
final var prefixRule = this.presenter.getPrefixRepetitionRule();
@@ -694,25 +772,24 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
/**
* Determines which rounding type the presenter is currently using, if any.
*
- * @since v0.4.0
* @since 2022-04-18
+ * @since v0.4.0
*/
private Optional<StandardRoundingType> getPresenterRoundingType() {
final var presenterRule = this.presenter.getNumberDisplayRule();
if (Objects.equals(presenterRule,
StandardDisplayRules.uncertaintyBased()))
return Optional.of(StandardRoundingType.UNCERTAINTY);
- else if (presenterRule instanceof StandardDisplayRules.FixedDecimals)
+ if (presenterRule instanceof StandardDisplayRules.FixedDecimals)
return Optional.of(StandardRoundingType.DECIMAL_PLACES);
- else if (presenterRule instanceof StandardDisplayRules.FixedPrecision)
+ if (presenterRule instanceof StandardDisplayRules.FixedPrecision)
return Optional.of(StandardRoundingType.SIGNIFICANT_DIGITS);
- else
- return Optional.empty();
+ return Optional.empty();
}
@Override
public Optional<String> getSelectedDimensionName() {
- final String selectedItem = (String) this.dimensionSelector
+ final var selectedItem = (String) this.dimensionSelector
.getSelectedItem();
return Optional.ofNullable(selectedItem);
}
@@ -780,8 +857,7 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
@Override
public void showExpressionConversionOutput(UnitConversionRecord uc) {
- this.expressionOutput.setText(String.format("%s = %s %s", uc.fromName(),
- uc.outputValueString(), uc.toName()));
+ this.expressionOutput.setText(uc.toString());
}
@Override
@@ -806,9 +882,9 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
/**
* Sets the presenter's rounding rule to the one specified by the current
* settings
- *
- * @since v0.4.0
+ *
* @since 2022-04-18
+ * @since v0.4.0
*/
private void updatePresenterRoundingRule() {
final Function<UncertainDouble, String> roundingRule;
@@ -828,4 +904,13 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
this.presenter.setNumberDisplayRule(roundingRule);
this.presenter.saveSettings();
}
+
+ @Override
+ public void updateText() {
+ this.frame.setTitle(this.presenter.getLocalizedText("tv.title")
+ .replace("[v]", ProgramInfo.VERSION.toString()));
+ this.infoTextArea.setText(this.presenter.getAboutText());
+ this.localizedTextSetters.forEach(
+ (id, action) -> action.accept(this.presenter.getLocalizedText(id)));
+ }
}