Use an annotation for tooltips rather than a separate static field.

This commit is contained in:
Ray J. Greenwell
2026-03-20 14:28:59 -07:00
parent e949041aa0
commit 4abbdc4c0a
2 changed files with 21 additions and 16 deletions
@@ -21,6 +21,7 @@ import com.threerings.presents.util.PresentsContext;
import com.threerings.presents.util.SafeSubscriber;
import com.threerings.admin.data.ConfigObject;
import com.threerings.admin.data.ToolTipText;
import static com.threerings.admin.Log.log;
@@ -113,25 +114,11 @@ public class ObjectEditorPanel extends ScrollablePanel
*/
protected static JPanel applyTip (ConfigObject object, Field field, JPanel editor)
{
String tipName = toUpperSnake(field.getName()) + "_TIP";
try {
Field tipField = object.getClass().getField(tipName);
if (tipField.getType() == String.class &&
Modifier.isStatic(tipField.getModifiers())) {
editor.setToolTipText((String) tipField.get(null));
}
} catch (NoSuchFieldException | IllegalAccessException e) {
// no tip constant for this field
}
ToolTipText tipAnno = field.getAnnotation(ToolTipText.class);
if (tipAnno != null) editor.setToolTipText(tipAnno.value());
return editor;
}
/** Converts a {@code lowerCamelCase} name to {@code UPPER_SNAKE_CASE}. */
private static String toUpperSnake (String name)
{
return name.replaceAll("([a-z0-9])([A-Z])", "$1_$2").toUpperCase();
}
protected PresentsContext _ctx;
protected String _key;
protected SafeSubscriber<ConfigObject> _safesub;
@@ -0,0 +1,18 @@
package com.threerings.admin.data;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.FIELD })
public @interface ToolTipText
{
/**
* The tool tip text to show an admin when they're editing a field.
*/
String value ();
}