From b1affe92460637211f560d70ee5c8770f3952822 Mon Sep 17 00:00:00 2001 From: Adrien Hopkins Date: Sun, 10 Apr 2022 14:22:29 -0500 Subject: Created API for settings and unit/prefix viewing --- src/main/java/sevenUnitsGUI/Presenter.java | 60 +++++++++++++++++++--- src/main/java/sevenUnitsGUI/TabbedView.java | 36 ++++++++++++- .../java/sevenUnitsGUI/UnitConversionView.java | 2 +- src/main/java/sevenUnitsGUI/View.java | 56 ++++++++++++++++++++ src/main/java/sevenUnitsGUI/ViewBot.java | 35 ++++++++++++- 5 files changed, 179 insertions(+), 10 deletions(-) (limited to 'src/main/java/sevenUnitsGUI') diff --git a/src/main/java/sevenUnitsGUI/Presenter.java b/src/main/java/sevenUnitsGUI/Presenter.java index 9f8fe69..b38f90b 100644 --- a/src/main/java/sevenUnitsGUI/Presenter.java +++ b/src/main/java/sevenUnitsGUI/Presenter.java @@ -91,7 +91,7 @@ public final class Presenter { * @return text in About file * @since 2022-02-19 */ - static final String getAboutText() { + public static final String getAboutText() { return Presenter.getLinesFromResource("/about.txt").stream() .map(Presenter::withoutComments).collect(Collectors.joining("\n")) .replaceAll("\\[VERSION\\]", ProgramInfo.VERSION.toString()); @@ -155,7 +155,7 @@ public final class Presenter { /** * The rule used for parsing input numbers. Any number-string inputted into - * this program will be parsed using this method. + * this program will be parsed using this method. Not implemented yet. */ private Function numberParsingRule; @@ -380,6 +380,25 @@ public final class Presenter { return this.showDuplicateUnits; } + /** + * @return the rule that is used by this presenter to convert numbers into + * strings + * @since 2022-04-10 + */ + public Function getNumberDisplayRule() { + return this.numberDisplayRule; + } + + /** + * @return the rule that is used by this presenter to convert strings into + * numbers + * @since 2022-04-10 + */ + @SuppressWarnings("unused") // not implemented yet + private Function getNumberParsingRule() { + return this.numberParsingRule; + } + /** * @return true iff the One-Way Conversion feature is available (views that * show units as a list will have metric units removed from the From @@ -392,11 +411,12 @@ public final class Presenter { } /** - * Loads settings from the user's settings file and applies them to the view. + * Loads settings from the user's settings file and applies them to the + * presenter. * * @since 2021-12-15 */ - public void loadSettings() {} + private void loadSettings() {} /** * Completes creation of the presenter. This part of the initialization @@ -416,12 +436,32 @@ public final class Presenter { void prefixSelected() {} /** - * Gets user settings from the view then saves them to the user's settings - * file. + * Saves the presenter's settings to the user settings file. * * @since 2021-12-15 */ - public void saveSettings() {} + private void saveSettings() {} + + /** + * @param numberDisplayRule the new rule that will be used by this presenter + * to convert numbers into strings + * @since 2022-04-10 + */ + public void setNumberDisplayRule( + Function numberDisplayRule) { + this.numberDisplayRule = numberDisplayRule; + } + + /** + * @param numberParsingRule the new rule that will be used by this presenter + * to convert strings into numbers + * @since 2022-04-10 + */ + @SuppressWarnings("unused") // not implemented yet + private void setNumberParsingRule( + Function numberParsingRule) { + this.numberParsingRule = numberParsingRule; + } /** * @param oneWayConversionEnabled whether not one-way conversion should be @@ -443,6 +483,12 @@ public final class Presenter { this.updateView(); } + /** + * Runs whenever a unit name is selected in the unit viewer. Gets the + * description of a unit and displays it. + * + * @since 2022-04-10 + */ void unitNameSelected() {} /** diff --git a/src/main/java/sevenUnitsGUI/TabbedView.java b/src/main/java/sevenUnitsGUI/TabbedView.java index ed45011..fd48965 100644 --- a/src/main/java/sevenUnitsGUI/TabbedView.java +++ b/src/main/java/sevenUnitsGUI/TabbedView.java @@ -56,6 +56,8 @@ import javax.swing.border.EmptyBorder; import javax.swing.border.TitledBorder; import sevenUnits.ProgramInfo; +import sevenUnits.unit.UnitType; +import sevenUnits.utils.NameSymbol; /** * A View that separates its functions into multiple tabs @@ -306,6 +308,8 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView { this.prefixTextBox.setEditable(false); this.prefixTextBox.setLineWrap(true); + // ============ INFO PANEL ============ + final JPanel infoPanel = new JPanel(); this.masterPane.addTab("\uD83D\uDEC8", // info (i) character new JScrollPane(infoPanel)); @@ -572,6 +576,16 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView { return new HashSet<>(this.toSearch.getItems()); } + @Override + public Optional getViewedPrefixName() { + throw new UnsupportedOperationException("Not implemented yet"); + } + + @Override + public Optional getViewedUnitName() { + throw new UnsupportedOperationException("Not implemented yet"); + } + @Override public void setDimensionNames(Set dimensionNames) { this.dimensionSelector.removeAllItems(); @@ -590,6 +604,16 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView { this.toSearch.setItems(units); } + @Override + public void setViewablePrefixNames(Set prefixNames) { + throw new UnsupportedOperationException("Not implemented yet"); + } + + @Override + public void setViewableUnitNames(Set unitNames) { + throw new UnsupportedOperationException("Not implemented yet"); + } + @Override public void showErrorMessage(String title, String message) { JOptionPane.showMessageDialog(this.frame, message, title, @@ -602,9 +626,19 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView { uc.outputValueString(), uc.toName())); } + @Override + public void showPrefix(NameSymbol name, String multiplierString) { + throw new UnsupportedOperationException("Not implemented yet"); + } + + @Override + public void showUnit(NameSymbol name, String definition, + String dimensionName, UnitType type) { + throw new UnsupportedOperationException("Not implemented yet"); + } + @Override public void showUnitConversionOutput(UnitConversionRecord uc) { this.unitOutput.setText(uc.toString()); } - } diff --git a/src/main/java/sevenUnitsGUI/UnitConversionView.java b/src/main/java/sevenUnitsGUI/UnitConversionView.java index 9d3a67b..6a95aa5 100644 --- a/src/main/java/sevenUnitsGUI/UnitConversionView.java +++ b/src/main/java/sevenUnitsGUI/UnitConversionView.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2021 Adrien Hopkins + * Copyright (C) 2021-2022 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 diff --git a/src/main/java/sevenUnitsGUI/View.java b/src/main/java/sevenUnitsGUI/View.java index e78c9cc..da3749e 100644 --- a/src/main/java/sevenUnitsGUI/View.java +++ b/src/main/java/sevenUnitsGUI/View.java @@ -16,6 +16,12 @@ */ package sevenUnitsGUI; +import java.util.Optional; +import java.util.Set; + +import sevenUnits.unit.UnitType; +import sevenUnits.utils.NameSymbol; + /** * An object that controls user interaction with 7Units * @@ -23,6 +29,35 @@ package sevenUnitsGUI; * @since 2021-12-15 */ public interface View { + /** + * @return name of prefix currently being viewed + * @since 2022-04-10 + */ + Optional getViewedPrefixName(); + + /** + * @return name of unit currently being viewed + * @since 2022-04-10 + */ + Optional getViewedUnitName(); + + /** + * Sets the list of prefixes that are available to be viewed in a prefix + * viewer + * + * @param prefixNames prefix names to view + * @since 2022-04-10 + */ + void setViewablePrefixNames(Set prefixNames); + + /** + * Sets the list of units that are available to be viewed in a unit viewer + * + * @param unitNames unit names to view + * @since 2022-04-10 + */ + void setViewableUnitNames(Set unitNames); + /** * Shows an error message. * @@ -32,4 +67,25 @@ public interface View { * @since 2021-12-15 */ void showErrorMessage(String title, String message); + + /** + * Shows information about a prefix to the user. + * + * @param name name(s) and symbol of prefix + * @param multiplierString string representation of prefix multiplier + * @since 2022-04-10 + */ + void showPrefix(NameSymbol name, String multiplierString); + + /** + * Shows information about a unit to the user. + * + * @param name name(s) and symbol of unit + * @param definition unit's definition string + * @param dimensionName name of unit's dimension + * @param type type of unit (metric/semi-metric/non-metric) + * @since 2022-04-10 + */ + void showUnit(NameSymbol name, String definition, String dimensionName, + UnitType type); } diff --git a/src/main/java/sevenUnitsGUI/ViewBot.java b/src/main/java/sevenUnitsGUI/ViewBot.java index 0195dd6..9f9a524 100644 --- a/src/main/java/sevenUnitsGUI/ViewBot.java +++ b/src/main/java/sevenUnitsGUI/ViewBot.java @@ -23,6 +23,9 @@ import java.util.Objects; import java.util.Optional; import java.util.Set; +import sevenUnits.unit.UnitType; +import sevenUnits.utils.NameSymbol; + /** * A class that simulates a View (supports both unit and expression conversion) * for testing. Getters and setters work as expected. @@ -145,6 +148,16 @@ final class ViewBot implements UnitConversionView, ExpressionConversionView { return Collections.unmodifiableSet(this.toUnits); } + @Override + public Optional getViewedPrefixName() { + throw new UnsupportedOperationException("Not implemented yet"); + } + + @Override + public Optional getViewedUnitName() { + throw new UnsupportedOperationException("Not implemented yet"); + } + @Override public void setDimensionNames(Set dimensionNames) { this.dimensionNames = Objects.requireNonNull(dimensionNames, @@ -236,6 +249,16 @@ final class ViewBot implements UnitConversionView, ExpressionConversionView { this.toUnits = Objects.requireNonNull(units, "units may not be null"); } + @Override + public void setViewablePrefixNames(Set prefixNames) { + throw new UnsupportedOperationException("Not implemented yet"); + } + + @Override + public void setViewableUnitNames(Set unitNames) { + throw new UnsupportedOperationException("Not implemented yet"); + } + @Override public void showErrorMessage(String title, String message) { System.err.printf("%s: %s%n", title, message); @@ -247,6 +270,17 @@ final class ViewBot implements UnitConversionView, ExpressionConversionView { System.out.println("Expression Conversion: " + uc); } + @Override + public void showPrefix(NameSymbol name, String multiplierString) { + throw new UnsupportedOperationException("Not implemented yet"); + } + + @Override + public void showUnit(NameSymbol name, String definition, + String dimensionName, UnitType type) { + throw new UnsupportedOperationException("Not implemented yet"); + } + @Override public void showUnitConversionOutput(UnitConversionRecord uc) { this.unitConversions.add(uc); @@ -265,5 +299,4 @@ final class ViewBot implements UnitConversionView, ExpressionConversionView { public List unitConversionList() { return Collections.unmodifiableList(this.unitConversions); } - } -- cgit v1.2.3