Use an annotation for tooltips rather than a separate static field.
This commit is contained in:
@@ -21,6 +21,7 @@ import com.threerings.presents.util.PresentsContext;
|
|||||||
import com.threerings.presents.util.SafeSubscriber;
|
import com.threerings.presents.util.SafeSubscriber;
|
||||||
|
|
||||||
import com.threerings.admin.data.ConfigObject;
|
import com.threerings.admin.data.ConfigObject;
|
||||||
|
import com.threerings.admin.data.ToolTipText;
|
||||||
|
|
||||||
import static com.threerings.admin.Log.log;
|
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)
|
protected static JPanel applyTip (ConfigObject object, Field field, JPanel editor)
|
||||||
{
|
{
|
||||||
String tipName = toUpperSnake(field.getName()) + "_TIP";
|
ToolTipText tipAnno = field.getAnnotation(ToolTipText.class);
|
||||||
try {
|
if (tipAnno != null) editor.setToolTipText(tipAnno.value());
|
||||||
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
|
|
||||||
}
|
|
||||||
return editor;
|
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 PresentsContext _ctx;
|
||||||
protected String _key;
|
protected String _key;
|
||||||
protected SafeSubscriber<ConfigObject> _safesub;
|
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 ();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user