GP-4154 - Theming - Fixed font issues; updated font usage with attributes

This commit is contained in:
dragonmacher 2024-02-23 13:13:06 -05:00
parent c5bad0a88f
commit b586d65a3b
91 changed files with 1309 additions and 1191 deletions

View file

@ -100,7 +100,7 @@ public class SystemUtilities {
}
/**
* Clean the specified user name to eliminate any spaces or leading domain name
* Clean the specified user name to eliminate any spaces or leading domain name
* which may be present (e.g., "MyDomain\John Doe" becomes "JohnDoe").
* @param name user name string to be cleaned-up
* @return the clean user name
@ -127,8 +127,8 @@ public class SystemUtilities {
}
/**
* Get the user that is running the application. This name may be modified to
* eliminate any spaces or leading domain name which may be present in Java's
* Get the user that is running the application. This name may be modified to
* eliminate any spaces or leading domain name which may be present in Java's
* {@code user.name} system property (see {@link #getCleanUserName(String)}).
* @return the user name
*/
@ -173,20 +173,15 @@ public class SystemUtilities {
}
/**
* Checks to see if the font size override setting is enabled and adjusts
* the given font as necessary to match the override setting. If the setting
* is not enabled, then <code>font</code> is returned.
* No longer supported. Use the theming system for fonts
*
* @param font
* The current font to adjust, if necessary.
* @return a font object with the proper size.
* @param font the font
* @return the same font passed in
* @deprecated Use the theming system for fonts
*/
@Deprecated(since = "11.1", forRemoval = true)
public static Font adjustForFontSizeOverride(Font font) {
if (FONT_SIZE_OVERRIDE_VALUE == null) {
return font;
}
return font.deriveFont((float) FONT_SIZE_OVERRIDE_VALUE.intValue());
return font;
}
/**
@ -350,10 +345,10 @@ public class SystemUtilities {
}
/**
* Returns a file that contains the given class. If the class is in a jar file, then
* the jar file will be returned. If the file is in a .class file, then the directory
* Returns a file that contains the given class. If the class is in a jar file, then
* the jar file will be returned. If the file is in a .class file, then the directory
* containing the package root will be returned (i.e. the "bin" directory).
*
*
* @param classObject the class for which to get the location
* @return the containing location
*/

View file

@ -42,12 +42,12 @@ public class ReflectionUtilities {
}
/**
* Locates the field of the name <code>fieldName</code> on the given
* class. If the given class does not contain the field, then this
* method will recursively call up <code>containingClass</code>'s
* implementation tree looking for a parent implementation of the
* Locates the field of the name <code>fieldName</code> on the given
* class. If the given class does not contain the field, then this
* method will recursively call up <code>containingClass</code>'s
* implementation tree looking for a parent implementation of the
* requested field.
*
*
* @param fieldName The name of the field to locate.
* @param containingClass The class that contains the desired field.
* @return The Field object that matches the given name, or null if not
@ -73,12 +73,12 @@ public class ReflectionUtilities {
}
/**
* Locates the field of the name <code>fieldName</code> on the given
* class. If the given class does not contain the field, then this
* method will recursively call up <code>containingClass</code>'s
* implementation tree looking for a parent implementation of the
* Locates the field of the name <code>fieldName</code> on the given
* class. If the given class does not contain the field, then this
* method will recursively call up <code>containingClass</code>'s
* implementation tree looking for a parent implementation of the
* requested field.
*
*
* @param fieldName The name of the field to locate.
* @param containingClass The class that contains the desired field.
* @return The Field object that matches the given name, or null if not
@ -104,12 +104,12 @@ public class ReflectionUtilities {
}
/**
* Locates the method of the name <code>methodName</code> on the given
* class. If the given class does not contain the method, then this
* method will recursively call up <code>containingClass</code>'s
* implementation tree looking for a parent implementation of the
* Locates the method of the name <code>methodName</code> on the given
* class. If the given class does not contain the method, then this
* method will recursively call up <code>containingClass</code>'s
* implementation tree looking for a parent implementation of the
* requested method.
*
*
* @param methodName The name of the method to locate.
* @param containingClass The class that contains the desired method.
* @param parameterTypes The parameters of the desired method (may be null).
@ -158,7 +158,7 @@ public class ReflectionUtilities {
/**
* Get the first field specification contained within containingClass which has the type classType.
* This method is only really useful if it is known that only a single field of
* This method is only really useful if it is known that only a single field of
* classType exists within the containingClass hierarchy.
* @param classType the class
* @param containingClass the class that contains a field of the given type
@ -184,40 +184,52 @@ public class ReflectionUtilities {
/**
* Returns the class name of the entry in the stack that comes before all references to the
* given classes. This is useful for figuring out at runtime who is calling a particular
* method.
* method.
* <p>
* This method can take multiple classes, but you really only need to pass the oldest
* This method can take multiple classes, but you really only need to pass the oldest
* class of disinterest.
*
*
* @param classes the classes to ignore
* @return the desired class name
*/
public static String getClassNameOlderThan(Class<?>... classes) {
Throwable t = createThrowableWithStackOlderThan(classes);
StackTraceElement[] stackTrace = t.getStackTrace();
return stackTrace[0].getClassName();
}
/**
* Creates a throwable whose stack trace is based upon the current call stack, with any
* information coming before, and including, the given classes removed.
* <p>
* This method can take multiple classes, but you really only need to pass the oldest
* class of disinterest.
*
* @param classes the classes to ignore
* @return the new throwable
* Returns the class name of the entry in the stack that comes before all references to the
* given patterns. This is useful for figuring out at runtime who is calling a particular
* method.
*
* @param patterns the patterns to ignore
* @return the desired class name
*/
public static Throwable createThrowableWithStackOlderThan(Class<?>... classes) {
public static String getClassNameOlderThan(String... patterns) {
Throwable t = createThrowableWithStackOlderThan(patterns);
StackTraceElement[] stackTrace = t.getStackTrace();
return stackTrace[0].getClassName();
}
List<String> toFind =
Arrays.stream(classes).map(c -> c.getName()).collect(Collectors.toList());
/**
* Creates a throwable whose stack trace is based upon the current call stack, with any
* information coming before, and including, the given patterns removed.
*
* @param patterns the strings to ignore (e.g., class or package names)
* @return the new throwable
* @see #createThrowableWithStackOlderThan(Class...)
*/
public static Throwable createThrowableWithStackOlderThan(String... patterns) {
return createThrowableWithStackOlderThan(List.of(patterns));
}
if (toFind.isEmpty()) {
// Always ignore our class. We get this for free if the client passes in any
// classes.
toFind.add(0, ReflectionUtilities.class.getName());
private static Throwable createThrowableWithStackOlderThan(List<String> patterns) {
if (patterns.isEmpty()) {
// always ignore our class. We get this for free if the client passes in any classes
patterns = new ArrayList<>();
patterns.add(0, ReflectionUtilities.class.getName());
}
Throwable t = new Throwable();
@ -227,7 +239,7 @@ public class ReflectionUtilities {
StackTraceElement element = trace[i];
String className = element.getClassName();
int nameIndex = toFind.indexOf(className);
int nameIndex = patterns.indexOf(className);
if (nameIndex != -1) {
lastIgnoreIndex = i;
}
@ -242,13 +254,13 @@ public class ReflectionUtilities {
if (lastIgnoreIndex == -1) {
Msg.error(ReflectionUtilities.class,
"Change call to ReflectionUtils. Did not find the " +
"following classes in the call stack: " + Arrays.toString(classes));
"following patterns in the call stack: " + patterns);
}
if (lastIgnoreIndex == trace.length - 1) {
Msg.error(ReflectionUtilities.class,
"Change call to ReflectionUtils. Call stack only contains the classes to ignore: " +
Arrays.toString(classes));
"Change call to ReflectionUtils. Call stack contains only ignored patterns: " +
patterns);
}
int startIndex = lastIgnoreIndex + 1;
@ -258,11 +270,27 @@ public class ReflectionUtilities {
}
/**
* Finds the first occurrence of the given pattern and then stops filtering when it finds
* Creates a throwable whose stack trace is based upon the current call stack, with any
* information coming before, and including, the given classes removed.
* <p>
* This method can take multiple classes, but you really only need to pass the oldest
* class of disinterest.
*
* @param classes the classes to ignore
* @return the new throwable
*/
public static Throwable createThrowableWithStackOlderThan(Class<?>... classes) {
List<String> patterns =
Arrays.stream(classes).map(c -> c.getName()).collect(Collectors.toList());
return createThrowableWithStackOlderThan(patterns);
}
/**
* Finds the first occurrence of the given pattern and then stops filtering when it finds
* something that is not that pattern
*
*
* @param trace the trace to update
* @param pattern the non-regex patterns used to perform a
* @param pattern the non-regex patterns used to perform a
* {@link String#contains(CharSequence)} on each {@link StackTraceElement} line
* @return the updated trace
*/
@ -296,12 +324,12 @@ public class ReflectionUtilities {
}
/**
* Uses the given <code>patterns</code> to remove elements from the given stack trace.
* Uses the given <code>patterns</code> to remove elements from the given stack trace.
* The current implementation will simply perform a <code>toString()</code> on each element and
* then check to see if that string contains any of the <code>patterns</code>.
*
*
* @param trace the trace to filter
* @param patterns the non-regex patterns used to perform a
* @param patterns the non-regex patterns used to perform a
* {@link String#contains(CharSequence)} on each {@link StackTraceElement}
* line.
* @return the filtered trace
@ -325,15 +353,15 @@ public class ReflectionUtilities {
/**
* A convenience method to create a throwable, filtering any lines that contain the given
* non-regex patterns. This can be useful for emitting diagnostic stack traces.
*
* @param patterns the non-regex patterns used to perform a
*
* @param patterns the non-regex patterns used to perform a
* {@link String#contains(CharSequence)} on each {@link StackTraceElement}
* line.
* @return the new throwable
*/
public static Throwable createFilteredThrowable(String... patterns) {
Throwable t = createThrowableWithStackOlderThan();
Throwable t = createThrowableWithStackOlderThan(new ArrayList<>());
StackTraceElement[] trace = t.getStackTrace();
StackTraceElement[] filtered = filterStackTrace(trace, patterns);
t.setStackTrace(filtered);
@ -341,40 +369,39 @@ public class ReflectionUtilities {
}
/**
* A convenience method to create a throwable, filtering boiler-plate Java-related
* lines (e.g., AWT, Swing, Security, etc).
* A convenience method to create a throwable, filtering boiler-plate Java-related
* lines (e.g., AWT, Swing, Security, etc).
* This can be useful for emitting diagnostic stack traces with reduced noise.
*
*
* @return the new throwable
*/
public static Throwable createJavaFilteredThrowable() {
Throwable t = createThrowableWithStackOlderThan();
Throwable t = createThrowableWithStackOlderThan(List.of());
return filterJavaThrowable(t);
}
/**
* A convenience method to create a throwable, filtering boiler-plate Java-related
* lines (e.g., AWT, Swing, Security, etc).
* This can be useful for emitting diagnostic stack traces with reduced noise.
*
* A convenience method to create a throwable, filtering boiler-plate Java-related
* lines (e.g., AWT, Swing, Security, etc).
* This can be useful for emitting diagnostic stack traces with reduced noise.
*
* <p>This method differs from {@link #createJavaFilteredThrowable()} in that this method
* returns a String, which is useful when printing log messages without having to directly
* print the stack trace.
*
*
* @return the new throwable
*/
public static String createJavaFilteredThrowableString() {
Throwable t = createThrowableWithStackOlderThan();
Throwable t = createThrowableWithStackOlderThan(List.of());
Throwable filtered = filterJavaThrowable(t);
return stackTraceToString(filtered);
}
/**
* A convenience method to take a throwable, filter boiler-plate Java-related
* lines (e.g., AWT, Swing, Security, etc).
* A convenience method to take a throwable, filter boiler-plate Java-related
* lines (e.g., AWT, Swing, Security, etc).
* This can be useful for emitting diagnostic stack traces with reduced noise.
*
*
* @param t the throwable to filter
* @return the throwable
*/
@ -418,15 +445,15 @@ public class ReflectionUtilities {
}
/**
* Returns an ordered set of interfaces and classes that are shared amongst the items in
* Returns an ordered set of interfaces and classes that are shared amongst the items in
* the list.
* <p>
* The order of the items is as they are first encountered, favoring interfaces before
* The order of the items is as they are first encountered, favoring interfaces before
* classes. Further, interface hierarchies are examined before concrete parent extensions.
* <p>
* If the given items have no parents in common, then the result will be a list with
* only <code>Object.class</code>.
*
*
* @param list the items to examine
* @return the set of items
*/
@ -461,15 +488,15 @@ public class ReflectionUtilities {
}
/**
* Returns an ordered set of parent interfaces and classes that are shared
* Returns an ordered set of parent interfaces and classes that are shared
* amongst the items in the list.
* <p>
* The order of the items is as they are first encountered, favoring interfaces before
* The order of the items is as they are first encountered, favoring interfaces before
* classes. Further, interface hierarchies are examined before concrete parent extensions.
* <p>
* If the given items have no parents in common, then the result will be a list with
* only <code>Object.class</code>.
*
*
* @param list the items to examine
* @return the set of items
*/
@ -494,9 +521,9 @@ public class ReflectionUtilities {
}
/**
* Turns the given {@link Throwable} into a String version of its
* Turns the given {@link Throwable} into a String version of its
* {@link Throwable#printStackTrace()} method.
*
*
* @param t the throwable
* @return the string
*/
@ -505,9 +532,9 @@ public class ReflectionUtilities {
}
/**
* Turns the given {@link Throwable} into a String version of its
* Turns the given {@link Throwable} into a String version of its
* {@link Throwable#printStackTrace()} method.
*
*
* @param message the preferred message to use. If null, the throwable message will be used
* @param t the throwable
* @return the string
@ -543,11 +570,11 @@ public class ReflectionUtilities {
/**
* Returns an order set of all interfaces implemented and classes extended for the entire
* type structure of the given class.
* type structure of the given class.
* <p>
* If <code>Object.class</code> is passed to this method, then it will be returned in the
* If <code>Object.class</code> is passed to this method, then it will be returned in the
* result of this method.
*
*
* @param c the class to introspect
* @return the set of parents
*/
@ -581,7 +608,7 @@ public class ReflectionUtilities {
/**
* Returns the type arguments for the given base class and extension.
*
*
* <p>Caveat: this lookup will only work if the given child class is a concrete class that
* has its type arguments specified. For example, these cases will work:
* <pre>
@ -592,17 +619,17 @@ public class ReflectionUtilities {
*
* // class definition
* public class MyList implements List&lt;String&gt; {
* </pre>
*
* </pre>
*
* Whereas this case will not work:
* <pre>
* // local variable with the type specified
* List&lt;String&gt; myList = new ArrayList&lt;String&gt;();
* </pre>
*
*
* <p>Note: a null entry in the result list will exist for any type that was unrecoverable
*
*
*
*
* @param <T> the type of the base and child class
* @param baseClass the base class
* @param childClass the child class
@ -618,7 +645,7 @@ public class ReflectionUtilities {
Type baseClassAsType =
walkClassHierarchyAndResolveTypes(baseClass, resolvedTypesDictionary, childClass);
// try to resolve type arguments defined by 'baseClass' to the raw runtime class
// try to resolve type arguments defined by 'baseClass' to the raw runtime class
Type[] baseClassDeclaredTypeArguments = getDeclaredTypeArguments(baseClassAsType);
return resolveBaseClassTypeArguments(resolvedTypesDictionary,
baseClassDeclaredTypeArguments);