/[classpath]/classpath/javax/swing/text/DefaultFormatter.java
ViewVC logotype

Diff of /classpath/javax/swing/text/DefaultFormatter.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by rabbit78, Mon Jun 6 15:19:52 2005 UTC revision 1.2 by rabbit78, Wed Jun 8 14:41:44 2005 UTC
# Line 87  public class DefaultFormatter Line 87  public class DefaultFormatter
87        throws BadLocationException        throws BadLocationException
88      {      {
89        super.remove(bypass, offset, length);        super.remove(bypass, offset, length);
90          checkValidInput();
91        commitIfAllowed();        commitIfAllowed();
92      }      }
93            
# Line 105  public class DefaultFormatter Line 106  public class DefaultFormatter
106                                String text, AttributeSet attributes)                                String text, AttributeSet attributes)
107        throws BadLocationException        throws BadLocationException
108      {      {
109        super.insertString(bypass, offset, text, attributes);        if (overwriteMode == true)
110            replace(bypass, offset, text.length(), text, attributes);
111          else
112            super.insertString(bypass, offset, text, attributes);
113          checkValidInput();
114        commitIfAllowed();        commitIfAllowed();
115      }      }
116    
# Line 126  public class DefaultFormatter Line 131  public class DefaultFormatter
131        throws BadLocationException        throws BadLocationException
132      {      {
133        super.replace(bypass, offset, length, text, attributes);        super.replace(bypass, offset, length, text, attributes);
134          checkValidInput();
135        commitIfAllowed();        commitIfAllowed();
136      }      }
137    
# Line 145  public class DefaultFormatter Line 151  public class DefaultFormatter
151              // ignore invalid edits              // ignore invalid edits
152            }            }
153      }      }
154    
155        /**
156         * Checks if the value in the input field is valid. If the
157         * property allowsInvalid is set to <code>false</code>, then
158         * the string in the input field is not allowed to be entered.
159         *
160         * @param doc the document of the input field
161         * @param value the current (old) value of the input field
162         */
163        private void checkValidInput()
164        {
165          JFormattedTextField ftf = getFormattedTextField();
166          try
167            {
168              Object newval = stringToValue(ftf.getText());
169            }
170          catch (ParseException ex)
171            {
172              if (!allowsInvalid)
173                {
174                  // roll back the input if invalid edits are not allowed
175                  try
176                    {
177                      ftf.setText(valueToString(ftf.getValue()));
178                    }
179                  catch (ParseException pe)
180                    {
181                      // if that happens, something serious must be wrong
182                      throw new AssertionError("values must be parseable");
183                    }
184                }
185            }
186        }
187    }    }
188    
189    /** The serialVersoinUID. */    /** The serialVersoinUID. */

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26