com.lyonesgamer.propertygrid.properties.PropertyCategory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of JPropertyGrid Show documentation
Show all versions of JPropertyGrid Show documentation
A property editor component for Swing.
The newest version!
package com.lyonesgamer.propertygrid.properties;
import com.lyonesgamer.propertygrid.PGProperty;
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
/**
* A category of different properties.
*
* @author Tristan Patch
* @since 1.0
*/
public class PropertyCategory extends PGProperty {
/**
* The properties displayed under this category.
*/
protected List children = new ArrayList<>();
/**
* The renderer to use.
*/
protected CategoryRenderer renderer = new CategoryRenderer();
/**
* Creates a new category.
*
* @param name The name of the category displayed in the grid.
*/
public PropertyCategory(String name) {
super(name);
}
@Override
protected void doAfterAdded() {}
/**
* Does nothing.
* @param value The string to attempt to set from.
*/
@Override
public void setValueFromString(String value) {}
/**
* Does nothing.
* @param value The int to set this value from.
*/
@Override
public void setValueFromLong(long value) { }
/**
* Gets the name of the category.
*
* @return The name.
*/
@Override
public String getValue() {
return name;
}
/**
* Returns the value.
*
* @return The param wrapped in an optional.
*/
@Override
public String stringToValue(String value) {
return value;
}
/**
* Returns the value as a string.
*
* @param value The value to convert to a value type of this property.
* @return The value as a string.
*/
@Override
public String longToValue(long value) {
return Long.toString(value);
}
@Override
public String valueToString(String value) {
return value;
}
@Override
public void onSetValue(String value) {}
@Override
public boolean onValidateValue(String value) {
return true;
}
@Override
public PGCellEditor getEditor() {
return null;
}
@Override
public PGCellRenderer getRenderer() {
return renderer;
}
protected class CategoryRenderer extends JLabel implements PGCellRenderer {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column) {
setText(valueToString(getValue()));
setToolTipText(helpString);
return this;
}
}
}