public void remove(int offs, int len) throws BadLocationException { String currentText = getText(0, getLength()); String beforeOffset = currentText.substring(0, offs); String afterOffset = currentText.substring(len + offs, currentText .length()); String proposedResult = beforeOffset + afterOffset; if (proposedResult.length() == 0) { // Just empty the document super.remove(offs, len); } else { ppos.setIndex(0); formatter.parseObject(proposedResult, ppos); // Now check if the entire string could be parsed if (ppos.getIndex() == proposedResult.length()) { // Parsed OK super.remove(offs, len); } else { // Parse failed Toolkit.getDefaultToolkit().beep(); } } } }
/** * Constructs a FloatField with the default values and initialized with a * value. * * @param value * The intitial float value the field will display. * @param enabled * Indicates if the field should initially be enabled for * editing. */ public FloatField(float value, boolean enabled) { super(11); setDocument(new TexCoordDocument()); formatter = new DecimalFormat(); formatter.setMaximumFractionDigits(6); formatter.setMinimumFractionDigits(1); formatter.setMaximumIntegerDigits(6); formatter.setDecimalSeparatorAlwaysShown(true); formatter.setGroupingUsed(false); setValue(value); setEnabled(enabled); }
/** * Constructs a FloatField with the default values and initialized with a * value. * * @param value * The intitial float value the field will display. */ public FloatField(float value) { super(11); setDocument(new TexCoordDocument()); formatter = new DecimalFormat(); formatter.setMaximumFractionDigits(6); formatter.setMinimumFractionDigits(1); formatter.setMaximumIntegerDigits(6); formatter.setDecimalSeparatorAlwaysShown(true); formatter.setGroupingUsed(false); setValue(value); }
/** * Constructs a FloatField with the default values and initialized to 0.0. */ public FloatField() { super(11); setDocument(new TexCoordDocument()); formatter = new DecimalFormat(); formatter.setMaximumFractionDigits(6); formatter.setMinimumFractionDigits(1); formatter.setMaximumIntegerDigits(6); formatter.setDecimalSeparatorAlwaysShown(true); formatter.setGroupingUsed(false); setValue(0.0f); }