FilterTextField.java revision 88f16d892d54fd8c3e190cc1f6363638b11ae1a3
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2008 Sun Microsystems, Inc.
* Portions Copyright 2015 ForgeRock AS
*/
/**
* A text field with an icon with 'X' shape on the right. When the user clicks
* on that icon, the contents of the text field are cleared.
*
*/
public class FilterTextField extends JTextField
{
private static final long serialVersionUID = -2083433734204435457L;
private boolean displayClearIcon;
"/clear-filter.png");
private ImageIcon clearIconPressed =
"/clear-filter-down.png");
private ImageIcon refreshIcon =
private boolean mousePressed;
private boolean displayRefreshIcon;
/**
* The time during which the refresh icon is displayed by default.
*/
public static long DEFAULT_REFRESH_ICON_TIME = 750;
new LinkedHashSet<ActionListener>();
private boolean constructorBorderSet;
/**
* Default constructor.
*
*/
public FilterTextField()
{
super(15);
{
}
else
{
setBorder(new IconBorder());
}
constructorBorderSet = true;
{
/**
* {@inheritDoc}
*/
public void changedUpdate(DocumentEvent e)
{
insertUpdate(e);
}
/**
* {@inheritDoc}
*/
public void insertUpdate(DocumentEvent e)
{
{
repaint();
}
}
public void removeUpdate(DocumentEvent e)
{
insertUpdate(e);
}
});
addMouseListener(new MouseAdapter()
{
/**
* {@inheritDoc}
*/
{
if (p != mousePressed)
{
mousePressed = p;
repaint();
}
}
/**
* {@inheritDoc}
*/
{
{
setText("");
}
mousePressed = false;
}
});
}
/**
* Adds an action listener to this text field. When the user clicks on the
* 'X' shaped icon the listeners are notified.
* @param listener the action listener.
*/
{
}
/**
* Removes an action listener to this text field.
* @param listener the action listener.
*/
{
}
/**
* {@inheritDoc}
*/
{
if (constructorBorderSet)
{
{
}
}
}
/**
* Displays a refresh icon on the text field (this is used for instance in
* the browsers that use this text field to specify a filter: the refresh
* icon is displayed to show that the filter is being displayed).
* @param display whether to display the refresh icon or not.
*/
public void displayRefreshIcon(boolean display)
{
if (display != displayRefreshIcon)
{
repaint();
}
}
/**
* Returns <CODE>true</CODE> if the refresh icon is displayed and
* <CODE>false</CODE> otherwise.
* @return <CODE>true</CODE> if the refresh icon is displayed and
* <CODE>false</CODE> otherwise.
*/
public boolean isRefreshIconDisplayed()
{
return displayRefreshIcon;
}
/**
* Displays a refresh icon on the text field (this is used for instance in
* the browsers that use this text field to specify a filter: the refresh
* icon is displayed to show that the filter is being displayed).
* @param time the time (in miliseconds) that the icon will be displayed.
*
*/
public void displayRefreshIcon(final long time)
{
displayRefreshIcon = true;
repaint();
{
public void run()
{
try
{
}
catch (Throwable t)
{
}
finally
{
{
public void run()
{
displayRefreshIcon = false;
repaint();
}
});
}
}
});
t.start();
}
private static int id = 1;
private void notifyListeners()
{
"CLEAR_FILTER");
id ++;
{
}
}
private Rectangle getClearIconRectangle()
{
}
/**
* The border of this filter text field.
*
*/
private class IconBorder implements Border
{
/**
* {@inheritDoc}
*/
{
int rightInsets = 0;
if (displayClearIcon)
{
}
if (displayRefreshIcon)
{
}
}
/**
* {@inheritDoc}
*/
{
if (displayClearIcon || displayRefreshIcon)
{
int leftSpaceOfClearIcon = 0;
if (displayClearIcon)
{
y + margin);
}
if (displayRefreshIcon)
{
}
}
}
/**
* {@inheritDoc}
*/
public boolean isBorderOpaque()
{
return false;
}
}
{
return margin;
}
private ImageIcon getClearIcon()
{
return icon;
}
}