-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the ability to time-shift with fractional input, e.g. 365,330.75 days. Input can now be floating point rather than integer. Input must be a non-fractional number of seconds.
- Loading branch information
Tom Brauer
committed
Jul 1, 2024
1 parent
8dec8e5
commit 2632b29
Showing
3 changed files
with
101 additions
and
29 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
vortex-api/src/main/java/mil/army/usace/hec/vortex/math/ShiftTimeUnit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package mil.army.usace.hec.vortex.math; | ||
|
||
public enum ShiftTimeUnit { | ||
DAYS("Days", 86400), | ||
HOURS("Hours", 3600), | ||
MINUTES("Minutes", 60), | ||
SECONDS("Seconds", 1); | ||
|
||
private final String displayString; | ||
private final int toSeconds; | ||
|
||
ShiftTimeUnit(String displayString, int toSeconds) { | ||
this.displayString = displayString; | ||
this.toSeconds = toSeconds; | ||
} | ||
|
||
public int toSeconds() { | ||
return toSeconds; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return displayString; | ||
} | ||
|
||
public static ShiftTimeUnit fromString(String string) { | ||
for (ShiftTimeUnit value : values()) { | ||
String displayString = value.toString(); | ||
if (displayString.equalsIgnoreCase(string)) | ||
return value; | ||
} | ||
throw new IllegalArgumentException("Time unit string + \"" + string + "\" not recognized"); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
vortex-ui/src/main/java/mil/army/usace/hec/vortex/ui/ShiftTimeUnitComboBox.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package mil.army.usace.hec.vortex.ui; | ||
|
||
import mil.army.usace.hec.vortex.math.ShiftTimeUnit; | ||
|
||
import javax.swing.*; | ||
import java.util.Arrays; | ||
|
||
class ShiftTimeUnitComboBox extends JComboBox<String> { | ||
|
||
ShiftTimeUnitComboBox() { | ||
String[] selections = Arrays.stream(ShiftTimeUnit.values()) | ||
.map(ShiftTimeUnit::toString) | ||
.toArray(String[]::new); | ||
|
||
setModel(new DefaultComboBoxModel<>(selections)); | ||
|
||
setSelectedIndex(1); | ||
} | ||
|
||
ShiftTimeUnit getSelected() { | ||
String selected = String.valueOf(getSelectedItem()); | ||
return ShiftTimeUnit.fromString(selected); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters