net.coderazzi.filters.gui
Class CustomChoice

java.lang.Object
  extended by net.coderazzi.filters.gui.CustomChoice

public abstract class CustomChoice
extends Object

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.


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
 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 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

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.


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.


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


Copyright © 2011 coderazzi. All Rights Reserved.