/** * ************************************************************************ Delete String * * @param origOffset Offeset * @param length length * @throws BadLocationException */ @Override public void remove(int origOffset, int length) throws BadLocationException { log.finest("Offset=" + origOffset + " Length=" + length); if (origOffset < 0 || length < 0) throw new IllegalArgumentException("MDocNumber.remove - invalid argument"); int offset = origOffset; if (length != 1) { super.remove(offset, length); return; } /** Manual Entry */ String content = getText(); // remove all Thousands if (content.indexOf(m_groupingSeparator) != -1) { StringBuffer result = new StringBuffer(); for (int i = 0; i < content.length(); i++) { if (content.charAt(i) == m_groupingSeparator && i != origOffset) { if (i < offset) offset--; } else result.append(content.charAt(i)); } super.remove(0, content.length()); super.insertString(0, result.toString(), null); m_tc.setCaretPosition(offset); } // remove Thousands super.remove(offset, length); } // remove
public void setValue(Number value) { this.value = value; this.stringValue = (value != null) ? value.toString() : null; if (value != null) { try { Number num = convertValue(value); String text = (num == null ? "" : num.toString()); super.remove(0, getLength()); super.insertString(0, text, null); this.stringValue = (num == null ? null : num.toString()); this.value = num; } catch (RuntimeException re) { throw re; } catch (Exception ex) { throw new RuntimeException(ex.getMessage(), ex); } } else { try { super.remove(0, getLength()); } catch (BadLocationException ex) {; } } }
@Override public void insertString(int offs, String val, AttributeSet attr) throws BadLocationException { if (val.length() == 0) super.insertString(offs, val, attr); if (val.length() == 1) { int numChars = 1; if (offs < getLength() - 1) { String nextChar = getText(offs + 1, 1); if (nextChar.equals("-")) { numChars = 2; val = val + "-"; } } String testString = getText(0, offs) + val + getText(offs + numChars, getLength() - (offs + numChars)); try { dateFormatter.parse(testString); } catch (Exception e) { // LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e); return; } super.remove(offs, numChars); super.insertString(offs, val, attr); } else if (val.matches(testRegex)) { super.remove(0, getLength()); super.insertString(getLength(), val, attr); } }
public void remove(int offs, int len) throws BadLocationException { StringBuffer sb = new StringBuffer(getText(0, getLength())); sb.delete(offs, offs + len); if (sb.length() == 0) { super.remove(offs, len); stringValue = null; value = null; } else { Number num = decode(sb.toString()); super.remove(offs, len); stringValue = sb.toString(); value = num; } }
/** Handle remove. */ public void remove(int offs, int length) throws BadLocationException { int sourceLength = getLength(); // Allow user to restore uninitialized state again by removing all if (offs == 0 && sourceLength == length) { super.remove(0, sourceLength); return; } // Do custom remove String sourceText = getText(0, sourceLength); StringBuffer strBuffer = new StringBuffer(sourceText.substring(0, offs)); int counter; for (counter = offs; counter < offs + length; counter++) { // Only remove digits and intDelims char currChar = sourceText.charAt(counter); if (Character.isDigit(currChar) || currChar == intDelim) { continue; } strBuffer.append(currChar); } // Append last part of sourceText if (counter < sourceLength) { strBuffer.append(sourceText.substring(counter)); } // Set text in field super.remove(0, sourceLength); insertString(0, strBuffer.toString(), (AttributeSet) getDefaultRootElement()); // Set caret pos int newDiff = sourceLength - getLength() - 1; if (newDiff < 0) { newDiff = 0; } if (offs - newDiff < 0) { newDiff = 0; } textField.setCaretPosition(offs - newDiff); }
/* * @see javax.swing.text.Document#remove(int, int) */ public void remove(int offs, int len) throws BadLocationException { // Mutators hold write lock & will deadlock if use is not thread safe super.remove(offs, len); setPropertyInternal(getText(0, getLength())); }
/** Used to reset the contents of this document */ public void clear() { try { super.remove(0, getLength()); setMark(); } catch (BadLocationException e) { } }
@Override public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { String CPF = getText(0, getLength()); for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); if (!Character.isDigit(c)) { return; } } if (CPF.length() < tamanho) { super.remove(0, getLength()); StringBuilder s = new StringBuilder(CPF + str); if (s.length() == 3) { s.insert(3, "."); } else if (s.length() == 7) { s.insert(7, "."); } else if (s.length() == 11) { s.insert(11, "-"); } super.insertString(0, s.toString(), a); } }
void shiftLeft() { javax.swing.text.PlainDocument doc = (javax.swing.text.PlainDocument) getDocument(); try { int currentLine = offsetToLine(doc, getSelectionStart()); int endLine = offsetToLine(doc, getSelectionEnd()); // The two following cases are to take care of selections that include // only the very edge of a line of text, either at the top or bottom // of the selection. Because these lines do not have *any* highlighted // text, it does not make sense to modify these lines. ~Forrest (9/22/2006) if (endLine > currentLine && getSelectionEnd() == lineToStartOffset(doc, endLine)) { endLine--; } if (endLine > currentLine && getSelectionStart() == (lineToEndOffset(doc, currentLine) - 1)) { currentLine++; } while (currentLine <= endLine) { int lineStart = lineToStartOffset(doc, currentLine); int lineEnd = lineToEndOffset(doc, currentLine); String text = doc.getText(lineStart, lineEnd - lineStart); if (text.length() > 0 && text.charAt(0) == ' ') { doc.remove(lineStart, 1); } currentLine++; } } catch (javax.swing.text.BadLocationException ex) { throw new IllegalStateException(ex); } }
public void remove(int offs, int len) throws BadLocationException { // return immediately when selecting an item if (selecting) return; super.remove(offs, len); if (!strictMatching) { setSelectedItem(getText(0, getLength()), getText(0, getLength())); adaptor.getTextComponent().setCaretPosition(offs); } }
public void setDateTime(LocalDate date) { try { super.remove(0, getLength()); final String dateText = dateFormatter.format(date); super.insertString(0, dateText, null); } catch (BadLocationException e) { LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e); } }
/** * Sets the text of this AutoCompleteDocument to the given text. * * @param text the text that will be set for this document */ private void setText(String text) { try { // remove all text and insert the completed string super.remove(0, getLength()); super.insertString(0, text, null); } catch (BadLocationException e) { throw new RuntimeException(e.toString()); } }
public void setValue(String text) { try { super.remove(0, getLength()); insertString(0, text, null); } catch (BadLocationException ex) { this.stringValue = null; this.value = null; } }
public void remove(int offs, int len) throws BadLocationException { String oldText = LTextField.this.getText(); super.remove(offs, len); SplitPaneViewer.clearViewerStatus(LTextField.this); // Log.print("setChanged from remove true"); if (!isReplacing) { setChanged(true); firePropertyChange("text", oldText, LTextField.super.getText()); } }
private void finalizeValue() { try { if (this.value == null) return; Number num = convertValue(this.value); String snum = formatValue(num); super.remove(0, getLength()); super.insertString(0, snum, null); this.stringValue = snum; this.value = num; } catch (Exception ex) {; } }
/** Reads PounderModel from XML data on given InputStream. * */ public PounderModel readModel(InputStream in) throws Exception { PounderData pd = read(in); PounderModel ret = new PounderModel(); if (pd.testInstanceFactory != null) ret.getLoadedTestObjects().addElement(pd.testInstanceFactory.getSetupClass()); ret.setTestInstanceFactory(pd.testInstanceFactory); ret.getRecord().addItems(pd.items); PlainDocument comment = ret.getComment(); comment.remove(0, comment.getLength()); if (pd.comment != null) comment.insertString(0, pd.comment, null); return ret; }
public final void showFormattedText(boolean show) { try { super.remove(0, getLength()); Number num = getValue(); if (num == null) return; if (show) { String snum = formatValue(num); super.insertString(0, snum, null); } else { super.insertString(0, num.toString(), null); } } catch (BadLocationException ex) { } }
/** Read data from given File and place it in given PounderModel. * */ public void readToModel(PounderModel pm, File f) throws Exception { PounderData pd = read(new FileInputStream(f)); PounderModel ret = new PounderModel(); if (pd.testInstanceFactory != null) pm.getLoadedTestObjects().addElement(pd.testInstanceFactory.getSetupClass()); pm.setTestInstanceFactory(pd.testInstanceFactory); pm.getRecord().clear(); pm.getRecord().addItems(pd.items); pm.getFileModel().setFile(f); PlainDocument comment = pm.getComment(); comment.remove(0, comment.getLength()); if (pd.comment != null) comment.insertString(0, pd.comment, null); }
@Override public void remove(int offs, int len) throws BadLocationException { int start = offs; int end = offs + len; int markStart = mark; int markEnd = getLength(); if ((end < markStart) || (start > markEnd)) { // no overlap return; } // Determine interval intersection int cutStart = Math.max(start, markStart); int cutEnd = Math.min(end, markEnd); super.remove(cutStart, cutEnd - cutStart); }
public void remove(int offs, int len) throws BadLocationException { // return immediately when selecting an item if (selecting) return; if (hitBackspace) { // user hit backspace => move the selection backwards // old item keeps being selected if (offs > 0) { if (hitBackspaceOnSelection) offs--; } else { // User hit backspace with the cursor positioned on the start => beep getToolkit() .beep(); // when available use: // UIManager.getLookAndFeel().provideErrorFeedback(comboBox); } highlightCompletedText(offs); } else { super.remove(offs, len); } }
/** * Delete String * * @param offset offset * @param length length * @throws BadLocationException */ @Override public void remove(int offset, int length) throws BadLocationException { log.finest("Offset=" + offset + ",Length=" + length); // begin of string if (offset == 0 || length == 0) { // empty the field // if the length is 0 or greater or equal with the mask length - teo_sarca, [ 1660595 ] Date // field: incorrect functionality on paste if (length >= m_mask.length() || length == 0) super.remove(offset, length); return; } // one position behind delimiter if (offset - 1 >= 0 && offset - 1 < m_mask.length() && m_mask.charAt(offset - 1) == DELIMITER) { if (offset - 2 >= 0) m_tc.setCaretPosition(offset - 2); else return; } else m_tc.setCaretPosition(offset - 1); } // deleteString
public void insertString(int ii, String s, AttributeSet attributeset) throws BadLocationException { if (s == null || "".equals(s)) return; String base = getText(0, ii); String match = getMatch(base + s); if (match == null) { super.insertString(ii, s, attributeset); return; } int jj = ii + s.length(); super.remove(0, getLength()); super.insertString(0, base + s + match.substring(jj), attributeset); setSelectionStart(jj); setSelectionEnd(getLength()); }
void uncomment() { javax.swing.text.PlainDocument doc = (javax.swing.text.PlainDocument) getDocument(); try { int currentLine = offsetToLine(doc, getSelectionStart()); int endLine = offsetToLine(doc, getSelectionEnd()); // The two following cases are to take care of selections that include // only the very edge of a line of text, either at the top or bottom // of the selection. Because these lines do not have *any* highlighted // text, it does not make sense to modify these lines. ~Forrest (9/22/2006) if (endLine > currentLine && getSelectionEnd() == lineToStartOffset(doc, endLine)) { endLine--; } if (endLine > currentLine && getSelectionStart() == (lineToEndOffset(doc, currentLine) - 1)) { currentLine++; } while (currentLine <= endLine) { int lineStart = lineToStartOffset(doc, currentLine); int lineEnd = lineToEndOffset(doc, currentLine); String text = doc.getText(lineStart, lineEnd - lineStart); int semicolonPos = text.indexOf(';'); if (semicolonPos != -1) { boolean allSpaces = true; for (int i = 0; i < semicolonPos; i++) { if (!Character.isWhitespace(text.charAt(i))) { allSpaces = false; break; } } if (allSpaces) { doc.remove(lineStart + semicolonPos, 1); } } currentLine++; } } catch (javax.swing.text.BadLocationException ex) { throw new IllegalStateException(ex); } }
/** Call Calendar Dialog */ private void startDateDialog() { log.config(""); // Date Dialog String result = getText(); Timestamp ts = null; try { ts = new Timestamp(m_format.parse(result).getTime()); } catch (Exception pe) { ts = new Timestamp(System.currentTimeMillis()); } ts = VDate.startCalendar(m_tc, ts, m_format, m_displayType, m_title); result = m_format.format(ts); // move to field try { super.remove(0, getText().length()); super.insertString(0, result, null); } catch (BadLocationException ble) { log.log(Level.SEVERE, "", ble); } } // startDateDialog
private final void updateText(String textValue) { try { if (textValue == null) { textValue = ""; } String currentValue = getText(0, getLength()); if (isFiring() && !textValue.equals(currentValue)) { setFiring(false); // Mutators hold write lock & will deadlock // if use is not thread-safe super.remove(0, getLength()); super.insertString(0, textValue, null); } } catch (BadLocationException b) { LOG.log( Level.SEVERE, "A BadLocationException happened\n" + "The string to set was: " + getProperty(), b); } finally { setFiring(true); } }
@Override public void remove(int offs, int len) throws BadLocationException { super.remove(offs, len); }
/** * ************************************************************************ Insert String * * @param origOffset * @param string * @param attr * @throws BadLocationException */ @Override public void insertString(int origOffset, String string, AttributeSet attr) throws BadLocationException { log.finest("Offset=" + origOffset + " String=" + string + " Length=" + string.length()); if (origOffset < 0 || string == null) throw new IllegalArgumentException("Invalid argument"); int offset = origOffset; int length = string.length(); // From DataBinder (assuming correct format) if (length != 1) { super.insertString(offset, string, attr); return; } /** Manual Entry */ String content = getText(); // remove all Thousands if (content.indexOf(m_groupingSeparator) != -1) { StringBuffer result = new StringBuffer(); for (int i = 0; i < content.length(); i++) { if (content.charAt(i) == m_groupingSeparator) { if (i < offset) offset--; } else result.append(content.charAt(i)); } super.remove(0, content.length()); super.insertString(0, result.toString(), attr); // m_tc.setCaretPosition(offset); // ADebug.trace(ADebug.l6_Database, "Clear Thousands (" + m_format.toPattern() + ")" + content // + " -> " + result.toString()); content = result.toString(); } // remove Thousands /** * ******************************************************************** Check Character entered */ char c = string.charAt(0); if (Character.isDigit(c)) // c >= '0' && c <= '9') { // ADebug.trace(ADebug.l6_Database, "Digit=" + c); super.insertString(offset, string, attr); return; } // Decimal - remove other decimals // Thousand - treat as Decimal else if (c == m_decimalSeparator || c == m_groupingSeparator || c == '.' || c == ',') { // log.info("Decimal=" + c + " (ds=" + m_decimalSeparator + "; gs=" + m_groupingSeparator + // ")"); // no decimals on integers if (m_displayType == DisplayType.Integer) return; int pos = content.indexOf(m_decimalSeparator); // put decimal in String decimal = String.valueOf(m_decimalSeparator); super.insertString(offset, decimal, attr); // remove other decimals if (pos != 0) { content = getText(); StringBuffer result = new StringBuffer(); int correction = 0; for (int i = 0; i < content.length(); i++) { if (content.charAt(i) == m_decimalSeparator) { if (i == offset) result.append(content.charAt(i)); else if (i < offset) correction++; } else result.append(content.charAt(i)); } super.remove(0, content.length()); super.insertString(0, result.toString(), attr); m_tc.setCaretPosition(offset - correction + 1); } // remove other decimals } // decimal or thousand // something else else if (VNumber.AUTO_POPUP || "=+-/*%".indexOf(c) > -1) { // Minus - put minus on start of string if (c == m_minusSign && offset == 0) { // no minus possible if (m_displayType == DisplayType.Integer) return; // add at start of string else super.insertString(0, "-", attr); } else { log.fine("Input=" + c + " (" + (int) c + ")"); if (c == m_percentSign && offset > 0) { // don't convert integers to percent. 1% = 0? if (m_displayType == DisplayType.Integer) return; // divide by 100 else { String value = getText(); BigDecimal percentValue = new BigDecimal(0.0); try { if (value != null && value.length() > 0) { Number number = m_format.parse(value); percentValue = new BigDecimal(number.toString()); percentValue = percentValue.divide( new BigDecimal(100.0), m_format.getMaximumFractionDigits(), BigDecimal.ROUND_HALF_UP); m_tc.setText(m_format.format(percentValue)); } } catch (ParseException pe) { log.info("InvalidEntry - " + pe.getMessage()); } } } else { String result = VNumber.startCalculator(m_tc, getText(), m_format, m_displayType, m_title, c); super.remove(0, content.length()); // insertString(0, result, attr); m_tc.setText(result); } } } else ADialog.beep(); } // insertString
/** Handle string insertion. */ public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { // Store source data int sourceLength = getLength(); String sourceText = getText(0, sourceLength); StringBuffer strBuffer = new StringBuffer(sourceText); // Check if old value is zero if (offs == 0 && sourceLength > 0 && str.length() > 0) { long oldValue; try { oldValue = myFormat.parse(strBuffer.toString()).longValue(); if (oldValue == 0) { strBuffer.deleteCharAt(0); } } catch (Exception e) { } } // Now add new string strBuffer.insert(offs, str); BigDecimal value; try { value = new BigDecimal(myFormat.parse(strBuffer.toString()).doubleValue()); } catch (Exception e) { if (sourceLength > 0) { if (sourceText.startsWith(",")) { sourceText = "0" + sourceText; } value = new BigDecimal(getRealString(sourceText)); } else { value = new BigDecimal(0.0); } } // Set the new value if (textField == null) { return; } textField.setValue(new Money(value, textField.getValue().getCurrency()), false); super.remove(0, sourceLength); super.insertString(0, myFormat.format(value.doubleValue()), a); // Set caret to correct caret position if (!"".equals(sourceText)) // <=> initilized { int lengthDiff = getLength() - sourceLength; int caretPos = lengthDiff + offs; int caretDiff = sourceLength - offs; // Adjust for columns after centSperator (currently Diff < 3) if ((caretDiff > 0 && caretDiff < 3) || (value.abs().longValue() < 10 && caretPos == 0)) { caretPos += 1; } if (caretPos < 0) { caretPos = 0; } textField.setCaretPosition(caretPos); } else { textField.setCaretPosition(1); } }
public void forceRemove(int offset, int len) throws BadLocationException { super.remove(offset, len); }
public void replace(int i, int j, String s, AttributeSet attributeset) throws BadLocationException { super.remove(i, j); insertString(i, s, attributeset); }