87 lines
2.4 KiB
Java
87 lines
2.4 KiB
Java
|
package envoy.client;
|
||
|
|
||
|
import java.io.Serializable;
|
||
|
import java.util.HashMap;
|
||
|
import java.util.Map;
|
||
|
|
||
|
import javax.swing.JComponent;
|
||
|
|
||
|
import envoy.client.ui.PrimaryToggleSwitch;
|
||
|
|
||
|
/**
|
||
|
* Project: <strong>envoy-clientChess</strong><br>
|
||
|
* File: <strong>SettingsItem.java</strong><br>
|
||
|
* Created: <strong>23.12.2019</strong><br>
|
||
|
*
|
||
|
* @author Kai S. K. Engelbart
|
||
|
*/
|
||
|
public class SettingsItem<T> implements Serializable {
|
||
|
|
||
|
private T value;
|
||
|
private Class<? extends JComponent> componentClass;
|
||
|
private String userFriendlyName, description;
|
||
|
|
||
|
private static final Map<Class<?>, Class<? extends JComponent>> componentClasses = new HashMap<>();
|
||
|
|
||
|
private static final long serialVersionUID = 2146837835556852218L;
|
||
|
|
||
|
static {
|
||
|
componentClasses.put(boolean.class, PrimaryToggleSwitch.class);
|
||
|
}
|
||
|
|
||
|
public SettingsItem(T value, String userFriendlyName, String description) {
|
||
|
this(value, componentClasses.get(value.getClass()));
|
||
|
this.userFriendlyName = userFriendlyName;
|
||
|
this.description = description;
|
||
|
}
|
||
|
|
||
|
public SettingsItem(T value, Class<? extends JComponent> componentClass) {
|
||
|
this.value = value;
|
||
|
this.componentClass = componentClass;
|
||
|
}
|
||
|
|
||
|
public JComponent getComponent() throws ReflectiveOperationException, SecurityException {
|
||
|
if (componentClass == null) throw new NullPointerException("Component class is null");
|
||
|
return componentClass.getConstructor(SettingsItem.class).newInstance(this);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @return the value
|
||
|
*/
|
||
|
public T get() { return value; }
|
||
|
|
||
|
/**
|
||
|
* @param value the value to set
|
||
|
*/
|
||
|
public void set(T value) { this.value = value; }
|
||
|
|
||
|
/**
|
||
|
* @return the componentClass
|
||
|
*/
|
||
|
public Class<? extends JComponent> getComponentClass() { return componentClass; }
|
||
|
|
||
|
/**
|
||
|
* @param componentClass the componentClass to set
|
||
|
*/
|
||
|
public void setComponentClass(Class<? extends JComponent> componentClass) { this.componentClass = componentClass; }
|
||
|
|
||
|
/**
|
||
|
* @return the userFriendlyName
|
||
|
*/
|
||
|
public String getUserFriendlyName() { return userFriendlyName; }
|
||
|
|
||
|
/**
|
||
|
* @param userFriendlyName the userFriendlyName to set
|
||
|
*/
|
||
|
public void setUserFriendlyName(String userFriendlyName) { this.userFriendlyName = userFriendlyName; }
|
||
|
|
||
|
/**
|
||
|
* @return the description
|
||
|
*/
|
||
|
public String getDescription() { return description; }
|
||
|
|
||
|
/**
|
||
|
* @param description the description to set
|
||
|
*/
|
||
|
public void setDescription(String description) { this.description = description; }
|
||
|
}
|