From e74668b91c247e7395362e8e411c3e1a13ec10d1 Mon Sep 17 00:00:00 2001 From: Adrien Hopkins Date: Thu, 15 Aug 2024 16:51:45 -0500 Subject: Add ability to convert expression to sum of units --- CHANGELOG.org | 3 +++ 1 file changed, 3 insertions(+) (limited to 'CHANGELOG.org') diff --git a/CHANGELOG.org b/CHANGELOG.org index 9696497..ad2f09b 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -1,5 +1,8 @@ * Changelog All notable changes in this project will be shown in this file. +** Unreleased +*** Added +- *Allowed conversion to a sum of units (e.g. 4/3 ft \rightarrow 1 ft + 4 in).* ** v0.5.0 - [2024-03-24 Sun] *** Added - *Added specifications for all types data files used by 7Units.* -- cgit v1.2.3 From 6feabb35336fa3ca1faaff203f50086dc018b5ce Mon Sep 17 00:00:00 2001 From: Adrien Hopkins Date: Thu, 22 Aug 2024 11:49:52 -0500 Subject: Update changelog --- CHANGELOG.org | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'CHANGELOG.org') diff --git a/CHANGELOG.org b/CHANGELOG.org index ad2f09b..344b4a0 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -3,6 +3,13 @@ All notable changes in this project will be shown in this file. ** Unreleased *** Added - *Allowed conversion to a sum of units (e.g. 4/3 ft \rightarrow 1 ft + 4 in).* +- *Allowed exponents on units to be non-integer numbers.* + The resulting exponents are rounded to the nearest integer, and the user is warned if this rounding changes the value by more than normal floating-point error. +- Add more information to the loading-success message. +*** Changed +- *Errors in unit/dimension files are shown in popups, rather than crashing the program.* +*** Fixed +- Fixed encoding of \pm character in values with uncertainty. ** v0.5.0 - [2024-03-24 Sun] *** Added - *Added specifications for all types data files used by 7Units.* -- cgit v1.2.3 From b0242b898653f2dc23f2187deec9db0bb652751d Mon Sep 17 00:00:00 2001 From: Adrien Hopkins Date: Thu, 22 Aug 2024 12:19:30 -0500 Subject: Add loading counts to About tab --- CHANGELOG.org | 2 +- src/main/java/sevenUnitsGUI/Presenter.java | 88 ++++++++++++++++++++++------- src/main/java/sevenUnitsGUI/TabbedView.java | 2 +- src/main/resources/about.txt | 4 ++ 4 files changed, 73 insertions(+), 23 deletions(-) (limited to 'CHANGELOG.org') diff --git a/CHANGELOG.org b/CHANGELOG.org index 344b4a0..78bb9a1 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -5,7 +5,7 @@ All notable changes in this project will be shown in this file. - *Allowed conversion to a sum of units (e.g. 4/3 ft \rightarrow 1 ft + 4 in).* - *Allowed exponents on units to be non-integer numbers.* The resulting exponents are rounded to the nearest integer, and the user is warned if this rounding changes the value by more than normal floating-point error. -- Add more information to the loading-success message. +- Added more information to the loading-success message, and added it to the about tab. *** Changed - *Errors in unit/dimension files are shown in popups, rather than crashing the program.* *** Fixed diff --git a/src/main/java/sevenUnitsGUI/Presenter.java b/src/main/java/sevenUnitsGUI/Presenter.java index 4ff2d65..c46ee53 100644 --- a/src/main/java/sevenUnitsGUI/Presenter.java +++ b/src/main/java/sevenUnitsGUI/Presenter.java @@ -74,6 +74,9 @@ public final class Presenter { private static final String DEFAULT_DIMENSIONS_FILEPATH = "/dimensionfile.txt"; /** The default place where exceptions are stored. */ private static final String DEFAULT_EXCEPTIONS_FILEPATH = "/metric_exceptions.txt"; + /** A Predicate that returns true iff the argument is a full base unit */ + private static final Predicate IS_FULL_BASE = unit -> unit instanceof LinearUnit + && ((LinearUnit) unit).isBase(); /** * Adds default units and dimensions to a database. @@ -119,13 +122,17 @@ public final class Presenter { } /** - * @return text in About file - * @since 2022-02-19 + * Determines where to wrap {@code toWrap} with a max line length of + * {@code maxLineLength}. If no good spot is found, returns -1. + * + * @since 2024-08-22 */ - public static final String getAboutText() { - return Presenter.getLinesFromResource("/about.txt").stream() - .map(Presenter::withoutComments).collect(Collectors.joining("\n")) - .replaceAll("\\[VERSION\\]", ProgramInfo.VERSION.toString()); + private static final int findLineSplit(String toWrap, int maxLineLength) { + for (int i = maxLineLength - 1; i >= 0; i--) { + if (Character.isWhitespace(toWrap.charAt(i))) + return i; + } + return -1; } /** @@ -241,6 +248,30 @@ public final class Presenter { return index == -1 ? line : line.substring(0, index); } + /** + * Wraps a string, ensuring no line is longer than {@code maxLineLength}. + * + * @since 2024-08-22 + */ + private static final String wrapString(String toWrap, int maxLineLength) { + final StringBuilder wrapped = new StringBuilder(toWrap.length()); + String remaining = toWrap; + while (remaining.length() > maxLineLength) { + final int spot = findLineSplit(toWrap, maxLineLength); + if (spot == -1) { + wrapped.append(remaining.substring(0, maxLineLength)); + wrapped.append("-\n"); + remaining = remaining.substring(maxLineLength).stripLeading(); + } else { + wrapped.append(remaining.substring(0, spot)); + wrapped.append("\n"); + remaining = remaining.substring(spot + 1).stripLeading(); + } + } + wrapped.append(remaining); + return wrapped.toString(); + } + /** * The view that this presenter communicates with */ @@ -349,21 +380,8 @@ public final class Presenter { this.loadSettings(CONFIG_FILE); } - // a Predicate that returns true iff the argument is a full base unit - final Predicate isFullBase = unit -> unit instanceof LinearUnit - && ((LinearUnit) unit).isBase(); - // print out unit counts - System.out.printf( - "Successfully loaded %d unique units with %d names (%d base units), %d unique prefixes with %d names, %d unit sets, and %d named dimensions.%n", - this.database.unitMapPrefixless(false).size(), - this.database.unitMapPrefixless(true).size(), - this.database.unitMapPrefixless(false).values().stream() - .filter(isFullBase).count(), - this.database.prefixMap(false).size(), - this.database.prefixMap(true).size(), - this.database.unitSetMap().size(), - this.database.dimensionMap().size()); + System.out.println(this.loadStatMsg()); } /** @@ -706,6 +724,17 @@ public final class Presenter { return this.showDuplicates; } + /** + * @return text in About file + * @since 2022-02-19 + */ + public final String getAboutText() { + return Presenter.getLinesFromResource("/about.txt").stream() + .map(Presenter::withoutComments).collect(Collectors.joining("\n")) + .replaceAll("\\[VERSION\\]", ProgramInfo.VERSION.toString()) + .replaceAll("\\[LOADSTATS\\]", wrapString(this.loadStatMsg(), 72)); + } + /** * Gets a name for this dimension using the database * @@ -891,6 +920,23 @@ public final class Presenter { } } + /** + * @return a message showing how much stuff has been loaded + * @since 2024-08-22 + */ + private String loadStatMsg() { + return String.format( + "Successfully loaded %d unique units with %d names (%d base units), %d unique prefixes with %d names, %d unit sets, and %d named dimensions.", + this.database.unitMapPrefixless(false).size(), + this.database.unitMapPrefixless(true).size(), + this.database.unitMapPrefixless(false).values().stream() + .filter(IS_FULL_BASE).count(), + this.database.prefixMap(false).size(), + this.database.prefixMap(true).size(), + this.database.unitSetMap().size(), + this.database.dimensionMap().size()); + } + /** * @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 @@ -1072,7 +1118,7 @@ public final class Presenter { * @param u unit to show * @since 2022-04-16 */ - private final void showUnit(Unit u) { + private void showUnit(Unit u) { final var nameSymbol = u.getNameSymbol(); final boolean isBase = u instanceof BaseUnit || u instanceof LinearUnit && ((LinearUnit) u).isBase(); diff --git a/src/main/java/sevenUnitsGUI/TabbedView.java b/src/main/java/sevenUnitsGUI/TabbedView.java index a71de44..6542541 100644 --- a/src/main/java/sevenUnitsGUI/TabbedView.java +++ b/src/main/java/sevenUnitsGUI/TabbedView.java @@ -357,7 +357,7 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView { infoTextArea.setEditable(false); infoTextArea.setOpaque(false); infoPanel.add(infoTextArea); - infoTextArea.setText(Presenter.getAboutText()); + infoTextArea.setText(this.presenter.getAboutText()); // ============ SETTINGS PANEL ============ this.masterPane.addTab("\u2699", diff --git a/src/main/resources/about.txt b/src/main/resources/about.txt index 782b422..4c33f8c 100644 --- a/src/main/resources/about.txt +++ b/src/main/resources/about.txt @@ -9,6 +9,10 @@ like "10 m/s + (25^2 - 5^2) mi/hr". This software was written by Adrien Hopkins . +Unit/Prefix/Dimension Statistics: + +[LOADSTATS] + Copyright Notice: Unit Converter Copyright (C) 2018-2024 Adrien Hopkins -- cgit v1.2.3 From dfdcf58c8751db95f024528aa38dd81eb2364f39 Mon Sep 17 00:00:00 2001 From: Adrien Hopkins Date: Sun, 23 Feb 2025 20:53:06 -0500 Subject: Bump version number to 1.0.0b1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Compared to version 0.5.0, this release: - allows conversion to sums of units (e.g. 4/3 ft → 1 ft + 4 in) - allows non-integer exponents in expressions - adds the ability to change the UI language - gracefully handles datafile errors - adds more information to the loading-success message, and adds it to the About tab - allows the user to not use the default datafiles No new features will be added until the release of version 1.0.0. --- CHANGELOG.org | 3 +++ README.org | 2 +- docs/roadmap.org | 9 --------- src/main/java/sevenUnits/ProgramInfo.java | 4 ++-- 4 files changed, 6 insertions(+), 12 deletions(-) (limited to 'CHANGELOG.org') diff --git a/CHANGELOG.org b/CHANGELOG.org index 78bb9a1..0798904 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -5,7 +5,10 @@ All notable changes in this project will be shown in this file. - *Allowed conversion to a sum of units (e.g. 4/3 ft \rightarrow 1 ft + 4 in).* - *Allowed exponents on units to be non-integer numbers.* The resulting exponents are rounded to the nearest integer, and the user is warned if this rounding changes the value by more than normal floating-point error. +- *Added the ability to change the language of 7Units's UI.* + This does not affect the names of units, prefixes and dimensions. - Added more information to the loading-success message, and added it to the about tab. +- Added the ability to not use the default data files. *** Changed - *Errors in unit/dimension files are shown in popups, rather than crashing the program.* *** Fixed diff --git a/README.org b/README.org index cf8de11..279c378 100644 --- a/README.org +++ b/README.org @@ -1,4 +1,4 @@ -* 7Units Version 1.0.0-alpha.1 +* 7Units Version 1.0.0-beta.1 (this project uses Semantic Versioning) ** What is it? This is a unit converter, which allows you to convert between different units, and includes a GUI which can read unit data from a file (using some unit math) and convert between units that you type in, and has a unit and prefix viewer to check the units that have been loaded in. diff --git a/docs/roadmap.org b/docs/roadmap.org index 04ea0a5..963c17d 100644 --- a/docs/roadmap.org +++ b/docs/roadmap.org @@ -3,15 +3,6 @@ Here is a list of the unfinished requirements for version 1.0.0. When everythin These requirements are subject to change. I intend to finish version 1.0.0 by [2025-04-27 Sun]. -Feature Requirements: -- 7Units should be able to parse unit files from [[https://www.gnu.org/software/units/][GNU Units]], the program that inspired it. -- 7Units's expression converter should support most or all of the conversion features supported by GNU Units: - - (/Mostly Done/) Converting to sums of units (it should also be possible to do this in the unit converter with preset combinations) - - (/Optional/) Inverse nonlinear conversion with the tilde prefix - - (/Optional/) Nonlinear units should be specifiable in unit files. - - /Any other feature not listed should be considered optional./ -- (/Optional/) It should be possible to add, edit and remove units and prefixes from the GUI unit and prefix viewers. - Documentation/Testing Requirements: - 7Units should be fully documented. - 7Units should have automated testing with a code coverage of at least 2/3 (ideally at least 5/6). diff --git a/src/main/java/sevenUnits/ProgramInfo.java b/src/main/java/sevenUnits/ProgramInfo.java index 573c5c7..fee3cea 100644 --- a/src/main/java/sevenUnits/ProgramInfo.java +++ b/src/main/java/sevenUnits/ProgramInfo.java @@ -26,9 +26,9 @@ import sevenUnits.utils.SemanticVersionNumber; */ public final class ProgramInfo { - /** The version number (1.0.0-alpha.1) */ + /** The version number (1.0.0-beta.1) */ public static final SemanticVersionNumber VERSION = SemanticVersionNumber - .preRelease(1, 0, 0, "alpha", 1); + .preRelease(1, 0, 0, "beta", 1); private ProgramInfo() { // this class is only for static variables, you shouldn't be able to -- cgit v1.2.3 From 34f0321a31e728fa66057d0decd9a938d133d596 Mon Sep 17 00:00:00 2001 From: Adrien Hopkins Date: Sun, 15 Jun 2025 19:15:04 -0500 Subject: Update changelog for release 1.0.0 --- CHANGELOG.org | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'CHANGELOG.org') diff --git a/CHANGELOG.org b/CHANGELOG.org index 0798904..01b3b34 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -1,6 +1,7 @@ * Changelog All notable changes in this project will be shown in this file. -** Unreleased +** v1.0.0 - [2025-06-15 Sun] +This version is the first one with a stable public API; as per Semantic Versioning all backwards incompatible changes will be put on a major version. *** Added - *Allowed conversion to a sum of units (e.g. 4/3 ft \rightarrow 1 ft + 4 in).* - *Allowed exponents on units to be non-integer numbers.* @@ -9,10 +10,14 @@ All notable changes in this project will be shown in this file. This does not affect the names of units, prefixes and dimensions. - Added more information to the loading-success message, and added it to the about tab. - Added the ability to not use the default data files. +- Added the ability to generate Javadoc automatically. *** Changed - *Errors in unit/dimension files are shown in popups, rather than crashing the program.* +- Significantly increased number and coverage of automated tests (~./gradlew test~). *** Fixed - Fixed encoding of \pm character in values with uncertainty. +- ExpressionParser uses the correct order internally. + /Note: this failure was only visible if you call the submethods; the public method fixed the problem on its own. This was fixed primarily to improve testing./ ** v0.5.0 - [2024-03-24 Sun] *** Added - *Added specifications for all types data files used by 7Units.* -- cgit v1.2.3