I have a custom mask edit field sub class of jformatted text field implementing the maskformatter. As i have specified the mask and in case suppose i need to enter one character, it gives a parseexception as the mask has not been fulfilled.
In the ui when this component is called, suppose for a serial number field i call EditField ef = new EditField("######");
max input is 5 digits. When the user enters 2 digit value and tabs off the value is clearing and I get a parseexception. Kindly see the processFocusEvent().
This is my code
/*
* Created on Feb 1, 2005
*
*
* Teller
*/
package com.bsis.touchpoint.core.ui;
/**
* @author pdwarkanathan
*
* TODO To change the template for this generated type comment go to
* Window - Preferences -
Java - Code Style - Code Templates
*/
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusListener;
import java.awt.event.FocusEvent;
import java.awt.event.KeyEvent;
import java.awt.event.TextListener;
import java.lang.ref.WeakReference;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.InputVerifier;
import javax.swing.JComponent;
import javax.swing.JFormattedTextField;
import javax.swing.text.DefaultFormatter;
import javax.swing.text.DefaultFormatterFactory;
import javax.swing.text.MaskFormatter;
import com.bsis.touchpoint.core.message.Message;
import com.bsis.touchpoint.core.message.MessageDispatcher;
import com.bsis.touchpoint.core.ui.focusmanager.TpICustomFocusManagerSupport;
import com.bsis.touchpoint.core.ui.validation.TpIValidate;
import com.bsis.touchpoint.core.ui.validation.TpIValidationManager;
import com.bsis.touchpoint.core.util.FontSizeCalculator;
public class TpMaskEditField extends JFormattedTextField implements
TpICommon, TpIForDataEntry, TpIValidate, TpICustomFocusManagerSupport,
TpIInteractsWithUser, TpIColorSchemeSupport {
/**
* Needed for implementation of TpICommon: Contains a reference to any type
* of object.
*/
private Object m_Cargo;
/**
* The next component in the tab sequence order. Needed to implement
* TpICustomFocusManagerSupport
*
* @see com.bsis.touchpoint.core.ui.focusmanager.TpICustomFocusManagerSupport#setNextFocus
* @see com.bsis.touchpoint.core.ui.focusmanager.TpICustomFocusManagerSupport#getNextFocus
*/
private WeakReference m_NextFocusComponent = null;
/**
* The previous component in the tab sequence order. Needed to implement
* TpICustomFocusManagerSupport
*
* @see com.bsis.touchpoint.core.ui.focusmanager.TpICustomFocusManagerSupport#setPreviousFocus
* @see com.bsis.touchpoint.core.ui.focusmanager.TpICustomFocusManagerSupport#getPreviousFocus
*/
private WeakReference m_previousFocusComponent = null;
/**
* The Tab Sequence for the current component. Needed to implement
* TpICustomFocusManagerSupport
*
* @see com.bsis.touchpoint.core.ui.focusmanager.TpICustomFocusManagerSupport#setTabSequence
* @see com.bsis.touchpoint.core.ui.focusmanager.TpICustomFocusManagerSupport#getTabSequence
*/
private int m_TabSequence = DEFAULT_TAB_SEQUENCE;
// Needed for implementation of TpIForDataEntry:
/**
* Contains a value indicating the required status of the container.
*/
private boolean m_Required = false;
/**
* Contains a value indicating the failed status set during the most recent
* call to validateSelf().
*/
private boolean m_FailedValidate = false;
/**
* Contains a description of the container.
*/
private
String m_Description = null;
/**
* Reflects whether this object is "read only" or not
*/
private boolean m_ReadOnly = false;
private boolean m_Enabled = true;
private boolean m_ReadOnlyStateFrozen = false;
private boolean m_EnabledStateFrozen = false;
private List m_AttributeList = new ArrayList();
private int m_MaximumTextLength = -1;
private MaskFormatter formatterMask = null;
/**
* This is the default constructor
*
*/
public TpMaskEditField(){
maskFieldInit();
}
/**
* Constructor that takes a string argument and creates a MaskFormatter with the specified mask
* @param mask - the edit mask used for the control
*/
public TpMaskEditField(String mask){
try {
formatterMask = new MaskFormatter(mask);
formatterMask.setValueContainsLiteralCharacters(false);
formatterMask.setAllowsInvalid(true);//done to temporarily allow invalid
}catch (ParseException exc){
System.err.println("formatter exception" + exc.getMessage());
}
this.setFormatterFactory(new DefaultFormatterFactory(formatterMask));
maskFieldInit();
}
/**
* Constructor that takes a format argument
*
*/
public TpMaskEditField(DefaultFormatter format) {
super(format);
maskFieldInit();
}
/**
* initializes the control
*
*/
private void maskFieldInit(){
// this.addCaretListener(new MyCaretListener());
// setForeground(TpStyleSheet.getColor(
// TpStyleSheet.NAME_ENTRY_FIELD + "." +
// TpStyleSheet.NAME_DEFAULT + "." +
// TpStyleSheet.SUFFIX_FOREGROUND_COLOR));
// setBackground(TpStyleSheet.getColor(
// TpStyleSheet.NAME_ENTRY_FIELD + "." +
// TpStyleSheet.NAME_DEFAULT + "." +
// TpStyleSheet.SUFFIX_BACKGROUND_COLOR));
// this.setSelectionColor(TpStyleSheet.getColor(
// TpStyleSheet.NAME_ENTRY_FIELD + "." +
// TpStyleSheet.NAME_SELECTED + "." +
// TpStyleSheet.SUFFIX_BACKGROUND_COLOR));
// this.setSelectedTextColor(TpStyleSheet.getColor(
// TpStyleSheet.NAME_ENTRY_FIELD + "." +
// TpStyleSheet.NAME_SELECTED + "." +
// TpStyleSheet.SUFFIX_FOREGROUND_COLOR));
// setPreferredSize(new Dimension(100, 21));
setPreferredSize(new Dimension(100, 21));
setBounds(0, 0, 0, 0);
this.setForeground(TpStyleSheet.getColor(TpStyleSheet.NAME_ENTRY_FIELD
+ "." + TpStyleSheet.NAME_DEFAULT + "."
+ TpStyleSheet.SUFFIX_FOREGROUND_COLOR));
this.setBackground(TpStyleSheet.getColor(TpStyleSheet.NAME_ENTRY_FIELD
+ "." + TpStyleSheet.NAME_DEFAULT + "."
+ TpStyleSheet.SUFFIX_BACKGROUND_COLOR));
this.setSelectionColor(TpStyleSheet
.getColor(TpStyleSheet.NAME_ENTRY_FIELD + "."
+ TpStyleSheet.NAME_SELECTED + "."
+ TpStyleSheet.SUFFIX_BACKGROUND_COLOR));
this.setSelectedTextColor(TpStyleSheet
.getColor(TpStyleSheet.NAME_ENTRY_FIELD + "."
+ TpStyleSheet.NAME_SELECTED + "."
+ TpStyleSheet.SUFFIX_FOREGROUND_COLOR));
setFont(new Font(FontSizeCalculator.getFontType(), Font.PLAIN,
FontSizeCalculator.getIdealApplicationFontSize()));
// addFocusListener(new TpMaskEditFieldFocusAdapter(this));
//setInputVerifier(new TpMaskEditFieldVerifier());
setCaretPosition(0);
setFocusLostBehavior(JFormattedTextField.COMMIT);
}
/**
* "Getter" method for the "Cargo" property.
*
* @see TpICommon#getCargo
*/
public Object getCargo() {
return m_Cargo;
}
/**
* "Setter" method for the "Cargo" property.
*
* @see TpICommon#setCargo
*/
public void setCargo(Object newCargo) {
m_Cargo = newCargo;
}
/**
* Returns the formatting mask.
* @return String mask
*/
public String getMask(){
return formatterMask.getMask();
}
/**
* Sets the mask dictating the legal characters.
* @param mask
*/
public void setMask(String mask){
try {
formatterMask = new MaskFormatter(mask);
formatterMask.setValueContainsLiteralCharacters(false);
}catch (ParseException exc){
System.err.println("formatter exception" + exc.getMessage());
}
DefaultFormatterFactory defaultFormatter = new DefaultFormatterFactory();
defaultFormatter.setDefaultFormatter(formatterMask);
defaultFormatter.setDisplayFormatter(formatterMask);
defaultFormatter.setEditFormatter(formatterMask);
//defaultFormatter.setNullFormatter(formatterMask);
this.setFormatterFactory(defaultFormatter);
//this.setFormatter(formatterMask);
//this.setFormatterFactory(new DefaultFormatterFactory(formatterMask));
}
private ArrayList m_TextListeners = new ArrayList();
private TextEvent m_TextEvent = null;
/** Adds a text listener to this component */
public void addTextListener(TextListener textListener) {
if (!m_TextListeners.contains(textListener)) {
m_TextListeners.add(textListener);
}
}
/** Removes a text listener from this component */
public void removeTextListener(TextListener textListener) {
m_TextListeners.remove(textListener);
}
/** Fires a text changed event to all interested listeners */
protected void fireTextValueChanged() {
Iterator E = m_TextListeners.iterator();
while (E.hasNext()) {
TextListener listener = (TextListener)E.next();
listener.textValueChanged(m_TextEvent);
}
}
/**
* Enables or Disables this component if the EnabledStateFrozen property is
* not set.
*
* @param newEnabledState -
* The new state of enablement
*/
public void setEnabled(boolean newEnabledState) {
if (!isEnabledStateFrozen()) {
m_Enabled = newEnabledState;
super.setEnabled(m_Enabled);
if (newEnabledState) {
this.removeColorSchemeAttribute(TpStyleSheet.ATTRIBUTE_TYPE_DISABLED);
} else {
this.addColorSchemeAttribute(TpStyleSheet.ATTRIBUTE_TYPE_DISABLED);
}
}
}
/**
* Method to retrieve the state of this object.
*
* @return Enabled state of this object.
* @see TpIInteractsWithUser#getEnabled
*/
public boolean getEnabled() {
return isEnabled();
}
/**
* Method to check the state of this object.
*
* @return Enabled state of this object.
* @see TpIInteractsWithUser#isEnabled
*/
public boolean isEnabled() {
return m_Enabled;
}
/**
* Returns whether or not this control's enable state can be altered.
*
* @param newEnabledStateFrozenState -
* New value for this attribute.
*/
public void setEnabledStateFrozen(boolean newEnabledStateFrozenState) {
m_EnabledStateFrozen = newEnabledStateFrozenState;
}
/**
* Gets whether or not this control's enable state can be altered.
*
* @return - current EnabledStateFrozen state.
*/
public boolean getEnabledStateFrozen() {
return isEnabledStateFrozen();
}
/**
* Gets whether or not this control's enable state can be altered.
*
* @return - current EnabledStateFrozen state.
*/
public boolean isEnabledStateFrozen() {
return m_EnabledStateFrozen;
}
/**
* Setter for the readonly state of this component.
*
* @param newReadOnlyState -
* New value for this state.
*/
public void setReadOnly(boolean newReadOnlyState) {
if (!isReadOnlyStateFrozen()) {
m_ReadOnly = newReadOnlyState;
setEditable(!m_ReadOnly);
if (newReadOnlyState) {
this.addColorSchemeAttribute(TpStyleSheet.ATTRIBUTE_TYPE_READ_ONLY);
} else {
this.removeColorSchemeAttribute(TpStyleSheet.ATTRIBUTE_TYPE_READ_ONLY);
}
}
}
/**
* States whether or not this object is "read only"
*
* @return Read only state
*/
public boolean isReadOnly() {
return getReadOnly();
}
/**
* "Getter" for the "ReadOnly" property
*
* @return Read only state
*/
public boolean getReadOnly() {
return m_ReadOnly;
}
/**
* Returns whether or not this control's read only state can be altered.
*
* @param newReadOnlyStateFrozenState -
* New value for this attribute.
*/
public void setReadOnlyStateFrozen(boolean newReadOnlyStateFrozenState) {
m_ReadOnlyStateFrozen = newReadOnlyStateFrozenState;
}
/**
* Gets whether or not this control's read only state can be altered.
*
* @return - current ReadOnlyStateFrozen state.
*/
public boolean getReadOnlyStateFrozen() {
return m_ReadOnlyStateFrozen;
}
/**
* Gets whether or not this control's read only state can be altered.
*
* @return - current ReadOnlyStateFrozen state.
*/
public boolean isReadOnlyStateFrozen() {
return getReadOnlyStateFrozen();
}
// Convenience method
/**
* This is a convenience method for setting the for manipulating read only
* and enabled properties all at once.
*/
public void setAlwaysEnabledAndReadOnly(boolean newEnabledState,
boolean newFrozenEnabledState, boolean newReadOnlyState,
boolean newFrozenReadOnlyState) {
setEnabledStateFrozen(false);
setEnabled(newEnabledState);
setEnabledStateFrozen(newFrozenEnabledState);
setReadOnlyStateFrozen(false);
setReadOnly(newReadOnlyState);
setReadOnlyStateFrozen(newFrozenReadOnlyState);
}
/**
* This method will return the description of the control.
*
* @return String - The description of the control.
* @see TpIContainsData#getDescription
*/
public String getDescription() {
if (m_Description == null) {
return getClass().getName();
} else {
return m_Description;
}
}
/**
* This method will set the description of the control.
*
* @param newDescription
* The new description of the control.
* @see TpIContainsData#setDescription
*/
public void setDescription(String newDescription) {
m_Description = newDescription;
}
private class TpMaskEditFieldFocusAdapter extends FocusAdapter {
TpMaskEditField m_editField = null;
public TpMaskEditFieldFocusAdapter(TpMaskEditField p) {
m_editField = p;
}
public void focusLost(FocusEvent e) {
String text = m_editField.getDataString().trim();
System.out.println(" the value" + text);
if (text.length() == 0) {
setValue(null);
setFocusLostBehavior(COMMIT);
m_editField.setCaretPosition(0);
} else {
setValue(text);
}
}
public void focusGained(FocusEvent e){
m_editField.setCaretPosition(0);
}
}
/**
* If all text is deleted, a null value is set.
*
* @see javax.swing.JFormattedTextFieldt#processFocusEvent(java.awt.event.FocusEvent)
*/
protected void processFocusEvent(FocusEvent e) {
String text = this.getDataString().trim();
System.out.println("$$$$$$$$$$$$" + text);
if ( e.getID() == FocusEvent.FOCUS_LOST) {
System.out.println("focus llost " );
if ( getTextWithoutMask().length() == 0 || text == null || text.equalsIgnoreCase("null")){
setValue(null);
// try{
// Object value = formatterMask.stringToValue(this.getText());
// setValue(value);
// //setValue(null);
// }catch(ParseException pe){
// System.out.println("&&&&&&&&&+++++" + pe.getMessage());
// }
//setFocusLostBehavior(JFormattedTextField.COMMIT);
}
}
super.processFocusEvent(e);
}
private class TpMaskEditFieldVerifier extends InputVerifier {
public boolean verify(JComponent input) {
if (input instanceof TpMaskEditField) {
TpMaskEditField maskField = (TpMaskEditField)input;
AbstractFormatter formatter = maskField.getFormatter();
if (formatter != null) {
String text = maskField.getText();
try {
formatter.stringToValue(text);
return true;
} catch (ParseException pe) {
return false;
}
}
}
return true;
}
public boolean shouldYieldFocus(JComponent input) {
return verify(input);
}
}
/**
* This method will clear the data value in the control.
*
* @see TpIContainsData#clearValue
*/
public void clearValue() {
setValue("");
}
/**
* This method will return the Required state of the control.
*
* @return boolean - the Required state of the control.
* @see TpIForDataEntry#getRequired
*/
public boolean getRequired() {
return isRequired();
}
/**
* This method will return the Required state of the control.
*
* @return boolean - the Required state of the control.
* @see TpIForDataEntry#isRequired
*/
public boolean isRequired() {
return m_Required;
}
/**
* This method will set the Required state of the control.
*
* @param newRequiredState
* The new required state of the control
* @see TpIForDataEntry#setRequired.
*/
public void setRequired(boolean newRequiredState) {
m_Required = newRequiredState;
if (newRequiredState) {
this.addColorSchemeAttribute(TpStyleSheet.ATTRIBUTE_TYPE_REQUIRED);
} else {
this.removeColorSchemeAttribute(TpStyleSheet.ATTRIBUTE_TYPE_REQUIRED);
}
}
/**
* This method sets the Content of the component
*
* @see TpIForDataEntry#setContent
* @param newContent data to insert into component passed as an Object.
*/
public void setContent(Object newContent) throws UiContentException {
if (newContent == null) {
setValue("");
} else {
setValue(newContent.toString());
}
}
/**
* This method gets the data in the TpMaskEditField component.
* The commitEdit()is called before the getValue to ensure the value reflects the Text
* @return Object data from component.
*/
public Object getContent() {
try{
commitEdit();
}catch(ParseException exc){
exc.printStackTrace();
}
return getValue();
}
/**
* Answer the text without any mask characters. This is primarily of use
* when we have a MaskFormatter; if not, this will return the same value
* as {@link javax.swing.text.JTextComponent#getText}.
*/
public String getTextWithoutMask() {
String text = null;
boolean literalCharacterFlag = false;
AbstractFormatter fmt = getFormatter();
MaskFormatter maskFmt = null;
// If our formatter is a MaskFormatter, then check if the value
// will contain the mask characters. If so, set it to not do that.
if ( fmt instanceof MaskFormatter ) {
maskFmt = (MaskFormatter) fmt;
literalCharacterFlag = maskFmt.getValueContainsLiteralCharacters();
if ( literalCharacterFlag )
maskFmt.setValueContainsLiteralCharacters( false );
}
try {
// Get the object which the text is converted to. Then format that
// object as our string, if it is not already a string.
Object obj = fmt.stringToValue( getText() );
if ( obj instanceof String )
text = (String) obj;
else
text = fmt.valueToString( obj );
} catch (ParseException e) {
// Eat this exception; the string is invalid, so no text. A text field
// would return an empty string, so we will too
text = "";
}
// If we changed the value so it does not contain mask characters,
// change it back to the way it was
if ( literalCharacterFlag && maskFmt != null ) {
maskFmt.setValueContainsLiteralCharacters( literalCharacterFlag );
}
return text;
}
/**
* This method sets the data to the control
*
* @param String value
*/
public void setDataString(String value)
throws UiMaskDataException {
//setValue(value);
try {
setContent(value);
}catch(UiContentException uice){
MessageDispatcher.sendMessage(MessageDispatcher.ERROR,
"setDataString", uice.getMessage());
}
}
/**
* This method gets the data from the control
*
* @return String - Returns the data, as String
*/
public String getDataString() {
//return (getValue()).toString();
return String.valueOf(getContent());
}
/**
* This method will request focus for this control.
*/
public void setErrorFocus() {
super.grabFocus();
}
/**
* This method will validate the data in the control. It will set the
* FailedValidate property occordingly.
*
* @return boolean - Is the data valid or not.
* @see TpIValidate#validateSelf
*/
public boolean validateSelf(TpIValidationManager validationManager) {
//boolean empty = (getDataString().trim().equals("")) || (getDataString() == null);
setFailedValidate(false);
if (isRequired()) {
if (getValue().equals("") || getValue() == null) {
setFailedValidate(true);
Message errorMsg = new Message(getDescription()
+ " is required.");
validationManager.addError(errorMsg);
}
}
return !isFailedValidate();
}
/**
* This method will return the FailedValidate state of the control.
*
* @return boolean - the FailedValidate state of the control.
* @see TpIValidate#getFailedValidate
*/
public boolean getFailedValidate() {
return isFailedValidate();
}
/**
* This method will return the FailedValidate state of the control.
*
* @return boolean - the FailedValidate state of the control.
* @see TpIValidate#isFailedValidate
*/
public boolean isFailedValidate() {
return m_FailedValidate;
}
/**
* This method will set the FailedValidate state of the control.
*
* @param newFailedValidateState
* The new FailedValidate state.
* @see TpIValidate#setFailedValidate
*/
public void setFailedValidate(boolean newFailedValidateState) {
m_FailedValidate = newFailedValidateState;
if (newFailedValidateState) {
this.addColorSchemeAttribute(TpStyleSheet.ATTRIBUTE_TYPE_INVALID);
} else {
this.removeColorSchemeAttribute(TpStyleSheet.ATTRIBUTE_TYPE_INVALID);
}
repaint();
}
//END OF IMPLEMENTATION OF TpIValidate
/**
* Sets the String's Maximum length
*/
public void setMaxStringLength(int newMaxStringLength) {
if (newMaxStringLength < -1)
newMaxStringLength = -1;
m_MaximumTextLength = newMaxStringLength;
//String dataString = (getValue()).toString();
String dataString = getText();
if (dataString.length() > m_MaximumTextLength
&& m_MaximumTextLength != -1) {
dataString = dataString.substring(0, m_MaximumTextLength);
}
//setValue(dataString);
setText(dataString);
}
/**
* Gets the String's Maximum length
*/
public int getMaxStringLength() {
return m_MaximumTextLength;
}
// Methods needed to support TpICustomFocusManagerSupport
/**
* Set the Next component in the tab sequence. Needed to implement
* TpICustomFocusManagerSupport
*
* @see com.bsis.touchpoint.core.ui.focusmanager.TpICustomFocusManagerSupport#setNextFocus
* @see com.bsis.touchpoint.core.ui.focusmanager.TpICustomFocusManagerSupport#getNextFocus
*/
public void setNextFocusComponent(JComponent newNextFocusComponent) {
if (newNextFocusComponent == null)
m_NextFocusComponent = null;
else
m_NextFocusComponent = new WeakReference(newNextFocusComponent);
}
/**
* Set the Previous component in the tab sequence. Needed to implement
* TpICustomFocusManagerSupport
*
* @see com.bsis.touchpoint.core.ui.focusmanager.TpICustomFocusManagerSupport#setPreviousFocus
* @see com.bsis.touchpoint.core.ui.focusmanager.TpICustomFocusManagerSupport#getPreviousFocus
* @param JComponent
* newPreviousFocusComponent
*/
public void setPreviousFocusComponent(JComponent newPreviousFocusComponent) {
if (newPreviousFocusComponent == null)
m_previousFocusComponent = null;
else
m_previousFocusComponent = new WeakReference(
newPreviousFocusComponent);
}
/**
* Get the Previous component in the tab sequence. Needed to implement
* TpICustomFocusManagerSupport
*
* @see com.bsis.touchpoint.core.ui.focusmanager.TpICustomFocusManagerSupport#setPreviousFocus
* @see com.bsis.touchpoint.core.ui.focusmanager.TpICustomFocusManagerSupport#getPreviousFocus
* @returns JComponent PreviousFocusComponent
*/
public JComponent getPreviousFocusComponent() {
if (m_previousFocusComponent == null)
return null;
else
return (JComponent) m_previousFocusComponent.get();
}
/**
* Get the Next component in the tab sequence. Needed to implement
* TpICustomFocusManagerSupport
*
* @see com.bsis.touchpoint.core.ui.focusmanager.TpICustomFocusManagerSupport#setNextFocus
* @see com.bsis.touchpoint.core.ui.focusmanager.TpICustomFocusManagerSupport#getNextFocus
* @returns JComponent NextFocusComponent
*/
public JComponent getNextFocusComponent() {
if (m_NextFocusComponent == null)
return null;
else
return (JComponent) m_NextFocusComponent.get();
}
/**
* Get the tab sequence number. Needed to implement
* TpICustomFocusManagerSupport
*
* @see com.bsis.touchpoint.core.ui.focusmanager.TpICustomFocusManagerSupport#setTabSequence
* @see com.bsis.touchpoint.core.ui.focusmanager.TpICustomFocusManagerSupport#getTabSequence
* @returns int
*/
public int getTabSequence() {
return m_TabSequence;
}
/**
* Set the tab sequence number. Needed to implement
* TpICustomFocusManagerSupport
*
* @see com.bsis.touchpoint.core.ui.focusmanager.TpICustomFocusManagerSupport#setTabSequence
* @see com.bsis.touchpoint.core.ui.focusmanager.TpICustomFocusManagerSupport#getTabSequence
*/
public void setTabSequence(int newTabSequence) {
m_TabSequence = newTabSequence;
}
// END OF IMPLEMENTATION OF TpICustomFocusManagerSupport
/**
* Returns if this control is part of the focus loop.
*
* @return If this control is part of the focus loop.
*/
public boolean isFocusTraversable() {
return (!isReadOnly() && isEnabled());
}
//// TpIColorSchemeSupport implementation
/**
* This method adds a color scheme attribute to the list of color scheme
* attributes associated with this control.
*
* @param newAttribute
* the new attribute to add to the list.
*/
public void addColorSchemeAttribute(int newAttribute) {
Integer attr = new Integer(newAttribute);
if (!m_AttributeList.contains(attr))
m_AttributeList.add(attr);
TpStyleSheet.refreshColors(this);
}
/**
* This method removes a color scheme attribute from the list of color
* scheme attributes associated with this control.
*
* @param attribute
* the attribute to remove from the list.
*/
public void removeColorSchemeAttribute(int attribute) {
m_AttributeList.remove(new Integer(attribute));
TpStyleSheet.refreshColors(this);
}
/**
* Gets the control type of the control. Control types are enumerated in
* TpStyleSheet.
*
* @return the control type of the control.
*/
public int getColorSchemeControlType() {
return TpStyleSheet.CONTROL_TYPE_ENTRY_FIELD;
}
/**
* Returns the list of color scheme attributes associated with this control.
* This operation should return a list sorted by priority.
*
* @return the list of color scheme attributes associated with this control.
*/
public List getColorSchemeAttributeList() {
return m_AttributeList;
}
/**
* Updates the colors of a control based on the color scheme attributes
* associated with this control. This method should only be called by
* TpStyleSheet.
*
* @param foreground
* the color scheme foreground color
* @param background
* the color scheme background color
*/
public void setColorSchemeColors(Color foreground, Color background) {
setForeground(foreground);
setBackground(background);
repaint();
}
/**
* This method is overriden because for some strange reason the escape key
* event doesnt reach the parent in 1.3
*/
public void processKeyEvent(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ESCAPE
&& e.getID() == KeyEvent.KEY_PRESSED) {
getParent().dispatchEvent(e);
}
super.processKeyEvent(e);
}
}
[ April 28, 2005: Message edited by: purushottaman dwarkanathan ]