net.coderazzi.filters.gui
Class CustomChoice

java.lang.Object
  extended by net.coderazzi.filters.gui.CustomChoice
All Implemented Interfaces:
Serializable

public abstract class CustomChoice
extends Object
implements Serializable

Class to specify a custom filter in the choices list.

A custom choice allows to specify custom filters that can be selected as a choice in the filter editor. A custom choice is associated always to a text, which the user can input to select the given choice.

It is also possible to specify how the custom filter is rendered; by default it is displayed the icon -if provided-, and the text, unless the user provides a custom renderer.

The order of the custom choices on the choices list can be modified with the precedence attribute. By default, custom choices are sorted by their textual representation. If a precedence is given, lower values are displayed first.

See Also:
Serialized Form

Field Summary
static int DEFAULT_PRECEDENCE
           
static CustomChoice MATCH_ALL
          Empty filter, returns all entries.
static int MATCH_ALL_PRECEDENCE
           
static CustomChoice MATCH_EMPTY
          Special empty filter, returns all entries with null or empty values.
 
Constructor Summary
CustomChoice(String representation)
          Creates a custom choice without associated icon, and with default precedence, to be handled exclusively as text.
CustomChoice(String representation, Icon icon)
          Creates a custom choice with associated icon and default precedence.
CustomChoice(String representation, Icon icon, int precedence)
          Full constructor.
 
Method Summary
static CustomChoice create(Object choice)
          Creates a CustomChoice that matches the given object; its stringfied format is the representation shown to the user.
static CustomChoice create(Object choice, String repr)
          Creates a CustomChoice that matches the given object, with the provided representation.
The choice can be a Pattern instance, in which case it is performed a complete regular expression match.
static Set<CustomChoice> createSet(Collection choices)
          Creates a set of CustomChoice instances, one for each provided choice.
static Set<CustomChoice> createSet(Object[] choices)
          Creates a set of CustomChoice instances, one for each provided choice.
 void decorateComponent(IFilterEditor editor, boolean isSelected, JComponent c, Graphics g)
          Decorates the choice on the given editor.
 Color getBackground(IFilterEditor editor, boolean isSelected)
          Returns the background color, or null to use the default one.
abstract  RowFilter getFilter(IFilterEditor editor)
          Returns the associated filter.
 Font getFont(IFilterEditor editor, boolean isSelected)
          Returns the font, or null to use the default one.
 Color getForeground(IFilterEditor editor, boolean isSelected)
          Returns the foreground color, or null to use the default one.
 Icon getIcon()
          Returns the associated icon, if any.
 int getPrecedence()
          Returns the precedence value.
 String getRepresentation()
          Returns the associated string.
 void setIcon(Icon icon)
          Sets the associated icon.
 void setPrecedence(int precedence)
          Sets the precedence value.
 void setRepresentation(String representation)
          Sets the representation value.
 String toString()
          Returns the string representation of the filter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_PRECEDENCE

public static final int DEFAULT_PRECEDENCE
See Also:
Constant Field Values

MATCH_ALL_PRECEDENCE

public static final int MATCH_ALL_PRECEDENCE
See Also:
Constant Field Values

MATCH_ALL

public static final CustomChoice MATCH_ALL
Empty filter, returns all entries.


MATCH_EMPTY

public static final CustomChoice MATCH_EMPTY
Special empty filter, returns all entries with null or empty values.

Constructor Detail

CustomChoice

public CustomChoice(String representation,
                    Icon icon,
                    int precedence)
Full constructor.


CustomChoice

public CustomChoice(String representation)
Creates a custom choice without associated icon, and with default precedence, to be handled exclusively as text.


CustomChoice

public CustomChoice(String representation,
                    Icon icon)
Creates a custom choice with associated icon and default precedence.

Method Detail

createSet

public static Set<CustomChoice> createSet(Object[] choices)
Creates a set of CustomChoice instances, one for each provided choice. The representation for each choice is the stringfied representation of the passed instance.


createSet

public static Set<CustomChoice> createSet(Collection choices)
Creates a set of CustomChoice instances, one for each provided choice. The representation for each choice is the stringfied representation of the passed instance.


create

public static CustomChoice create(Object choice)
Creates a CustomChoice that matches the given object; its stringfied format is the representation shown to the user.


create

public static CustomChoice create(Object choice,
                                  String repr)
Creates a CustomChoice that matches the given object, with the provided representation.
The choice can be a Pattern instance, in which case it is performed a complete regular expression match.


getBackground

public Color getBackground(IFilterEditor editor,
                           boolean isSelected)
Returns the background color, or null to use the default one.

Parameters:
editor - the editor where the choice is used
isSelected - true if the choice is selected
Returns:
null to use the default one

getForeground

public Color getForeground(IFilterEditor editor,
                           boolean isSelected)
Returns the foreground color, or null to use the default one.

Parameters:
editor - the editor where the choice is used
isSelected - true if the choice is selected
Returns:
null to use the default one

getFont

public Font getFont(IFilterEditor editor,
                    boolean isSelected)
Returns the font, or null to use the default one.

Parameters:
editor - the editor where the choice is used
isSelected - true if the choice is selected
Returns:
null to use the default one

getIcon

public Icon getIcon()
Returns the associated icon, if any.


setIcon

public void setIcon(Icon icon)
Sets the associated icon.


decorateComponent

public void decorateComponent(IFilterEditor editor,
                              boolean isSelected,
                              JComponent c,
                              Graphics g)
Decorates the choice on the given editor.

Parameters:
editor - the editor where the choice is used
isSelected - true if the choice is selected
c - the component to decorate
g - the decoration context

getPrecedence

public int getPrecedence()
Returns the precedence value.


setPrecedence

public void setPrecedence(int precedence)
Sets the precedence value. Choices with lower precedence are displayed first.


getRepresentation

public String getRepresentation()
Returns the associated string.


setRepresentation

public void setRepresentation(String representation)
Sets the representation value.


getFilter

public abstract RowFilter getFilter(IFilterEditor editor)
Returns the associated filter.


toString

public final String toString()
Returns the string representation of the filter.

Overrides:
toString in class Object