-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
General housekeeping cleanup #306
Merged
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6899dc6
Rename widget classes to end with "Widget", rename WidgetPropertySheet
SamCarlberg dbdecdb
Use ~/Shuffleboard instead of ~/Smartdashboard
SamCarlberg 9a4d5a9
Show grid highlight when resizing tiles
SamCarlberg 72df8d4
Preview size of dropped widgets from the gallery
SamCarlberg 8bce86f
Set text overrun of layout labels to be leading ellipsis
SamCarlberg 5004419
Move primitive data types and adapters to API module
SamCarlberg 6c316ef
Merge branch 'master' into housekeeping
SamCarlberg 32fe094
Enforce minimum tile size
SamCarlberg f1bfbe0
Fix SpeedControllerWidget
SamCarlberg c1bb77a
Disable god class check on TilePane, fix WidgetSaverTest NPE
SamCarlberg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,16 +1,25 @@ | ||
package edu.wpi.first.shuffleboard.api.data; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
import com.google.common.primitives.Primitives; | ||
|
||
import edu.wpi.first.shuffleboard.api.data.types.AllType; | ||
import edu.wpi.first.shuffleboard.api.data.types.BooleanArrayType; | ||
import edu.wpi.first.shuffleboard.api.data.types.BooleanType; | ||
import edu.wpi.first.shuffleboard.api.data.types.MapType; | ||
import edu.wpi.first.shuffleboard.api.data.types.NoneType; | ||
import edu.wpi.first.shuffleboard.api.data.types.NumberArrayType; | ||
import edu.wpi.first.shuffleboard.api.data.types.NumberType; | ||
import edu.wpi.first.shuffleboard.api.data.types.RawByteType; | ||
import edu.wpi.first.shuffleboard.api.data.types.StringArrayType; | ||
import edu.wpi.first.shuffleboard.api.data.types.StringType; | ||
import edu.wpi.first.shuffleboard.api.data.types.UnknownType; | ||
import edu.wpi.first.shuffleboard.api.util.Registry; | ||
import edu.wpi.first.shuffleboard.api.util.TestUtils; | ||
import edu.wpi.first.shuffleboard.api.util.TypeUtils; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
import com.google.common.collect.ImmutableCollection; | ||
import com.google.common.collect.ImmutableSet; | ||
import com.google.common.primitives.Primitives; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.Comparator; | ||
|
@@ -24,17 +33,91 @@ | |
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
/** | ||
* Registry of data types in shuffleboard. This class also provides data types for various "wildcard" types, as well as | ||
* types for primitive and arrays of primitive data. These types are always registered and may not be unregistered. | ||
*/ | ||
public class DataTypes extends Registry<DataType> { | ||
|
||
// TODO replace with DI eg Guice | ||
private static DataTypes defaultInstance = null; | ||
|
||
// Catchall or wildcard types | ||
/** | ||
* Represents the type of "null" or non-present data. Differs from {@link UnknownType} in that <i>no</i> data is | ||
* present for this type, while data <i>is</i> present but of an unknown type for the latter. | ||
*/ | ||
public static final DataType None = new NoneType(); | ||
|
||
/** | ||
* Represents the type of <i>all</i> data; a widget that can accept this data type can accept data of <i>any</i> | ||
* type. | ||
*/ | ||
public static final DataType All = new AllType(); | ||
|
||
/** | ||
* Represents an "unknown" data type; that is, data is present, but the type could not be determined. | ||
*/ | ||
public static final DataType Unknown = new UnknownType(); | ||
|
||
public static final ComplexDataType<MapData> Map = new MapType(); | ||
|
||
// Primitive types | ||
/** | ||
* The type corresponding to <i>boolean</i> data. | ||
*/ | ||
public static final DataType<Boolean> Boolean = new BooleanType(); | ||
|
||
/** | ||
* The type corresponding to a boolean array (<tt>boolean[]</tt>). | ||
*/ | ||
public static final DataType<boolean[]> BooleanArray = new BooleanArrayType(); | ||
|
||
/** | ||
* The type corresponding to <i>numeric</i> data. | ||
*/ | ||
public static final DataType<Number> Number = new NumberType(); | ||
|
||
/** | ||
* The type corresponding to an array of numeric data (<tt>double[]</tt>). Note that number arrays <i>must</i> be | ||
* implemented as <tt>double[]</tt> in order to be represented by this type. | ||
*/ | ||
public static final DataType<double[]> NumberArray = new NumberArrayType(); | ||
|
||
/** | ||
* The type corresponding to text data. | ||
*/ | ||
public static final DataType<String> String = new StringType(); | ||
|
||
/** | ||
* The type corresponding to an array of strings (<tt>String[]</tt>). | ||
*/ | ||
public static final DataType<String[]> StringArray = new StringArrayType(); | ||
|
||
/** | ||
* The type corresponding to an array of raw bytes (<tt>byte[]</tt>). | ||
*/ | ||
public static final DataType<byte[]> ByteArray = new RawByteType(); | ||
|
||
/** | ||
* The default data types. None of these may be unregistered. | ||
*/ | ||
private static final ImmutableCollection<DataType<?>> defaultTypes = ImmutableSet.of( | ||
// catchall | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. catch-all |
||
None, | ||
All, | ||
Unknown, | ||
Map, | ||
// primitives | ||
Boolean, | ||
BooleanArray, | ||
Number, | ||
NumberArray, | ||
String, | ||
StringArray, | ||
ByteArray | ||
); | ||
|
||
private final Map<String, DataType> dataTypes = new TreeMap<>(); | ||
|
||
private final Map<Class, Optional<DataType>> typeCache = new HashMap<>(); | ||
|
@@ -52,14 +135,11 @@ public static DataTypes getDefault() { | |
} | ||
|
||
/** | ||
* Creates a new data type registry. The registry will initially contain {@link #None}, {@link #All}, | ||
* {@link #Unknown}, and {@link #Map}, none of why may be unregistered. | ||
* Creates a new data type registry. The registry will initially contain the default data types, none of which may be | ||
* unregistered. | ||
*/ | ||
public DataTypes() { | ||
register(None); | ||
register(All); | ||
register(Unknown); | ||
register(Map); | ||
registerAll(defaultTypes); | ||
} | ||
|
||
/** | ||
|
@@ -91,6 +171,10 @@ public void register(DataType dataType) { | |
|
||
@Override | ||
public void unregister(DataType dataType) { | ||
requireNonNull(dataType, "dataType"); | ||
if (defaultTypes.contains(dataType)) { | ||
throw new IllegalArgumentException("A default data type cannot be unregistered: '" + dataType + "'"); | ||
} | ||
dataTypes.remove(dataType.getName()); | ||
typeCache.remove(dataType.getJavaClass()); | ||
removeItem(dataType); | ||
|
2 changes: 1 addition & 1 deletion
2
...gin/base/data/types/BooleanArrayType.java → ...oard/api/data/types/BooleanArrayType.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
2 changes: 1 addition & 1 deletion
2
...d/plugin/base/data/types/BooleanType.java → ...ffleboard/api/data/types/BooleanType.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
2 changes: 1 addition & 1 deletion
2
...ugin/base/data/types/NumberArrayType.java → ...board/api/data/types/NumberArrayType.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
2 changes: 1 addition & 1 deletion
2
...rd/plugin/base/data/types/NumberType.java → ...uffleboard/api/data/types/NumberType.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
2 changes: 1 addition & 1 deletion
2
...d/plugin/base/data/types/RawByteType.java → ...ffleboard/api/data/types/RawByteType.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
2 changes: 1 addition & 1 deletion
2
...ugin/base/data/types/StringArrayType.java → ...board/api/data/types/StringArrayType.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
2 changes: 1 addition & 1 deletion
2
...rd/plugin/base/data/types/StringType.java → ...uffleboard/api/data/types/StringType.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
7 changes: 3 additions & 4 deletions
7
...ng/serialization/BooleanArrayAdapter.java → ...ng/serialization/BooleanArrayAdapter.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
11 changes: 5 additions & 6 deletions
11
...rding/serialization/ByteArrayAdapter.java → ...rding/serialization/ByteArrayAdapter.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
7 changes: 3 additions & 4 deletions
7
...ing/serialization/NumberArrayAdapter.java → ...ing/serialization/NumberArrayAdapter.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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Catch-all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's just an alternate spelling.