public void replace(FilterBypass fb, int offs, int length, String str, AttributeSet a)
     throws BadLocationException {
   if (isValidTemperature(false, fb, offs, str, length)) {
     fb.replace(offs, length, str, a);
     doValueUpdate(fb);
   }
 } // replace
 public void insertString(FilterBypass fb, int offs, String str, AttributeSet a)
     throws BadLocationException {
   if (isValidTemperature(true, fb, offs, str, 0)) {
     fb.insertString(offs, str, a);
     doValueUpdate(fb);
   }
 } // insertString
Exemplo n.º 3
0
    public void insertString(FilterBypass fb, int offs, String str, AttributeSet a)
        throws BadLocationException {
      if ("\n".equals(str)) {
        str = addWhiteSpace(fb.getDocument(), offs);
        if (fb.getDocument().getText(offs - 2, 1).equals("{")) {
          str = str + "Meow";
        }
      }

      super.insertString(fb, offs, str, a);
    }
 /**
  * This function inserts or replaces the user's input in a string buffer, to create the text
  * which would be on screen if we allowed it. We declare to throw bad location due to
  * doc.getText, but since the paramters are coming from the farmework, that should never
  * happen.... in theory. If insert is true we insert, if false we replace. Length parameter only
  * used when replacing.
  */
 private StringBuffer getTextPrototype(
     boolean insert, FilterBypass fb, int offs, String str, int length)
     throws BadLocationException {
   Document doc = fb.getDocument();
   String text = doc.getText(0, doc.getLength());
   StringBuffer sb = new StringBuffer(text);
   if (insert) {
     sb.insert(offs, str);
   } else {
     sb.replace(offs, offs + length, str);
   }
   return sb;
 } // end of getTextPrototype
    /**
     * Updates the shared value instance if updateValue is true. Always forces the redraw of
     * everything.
     */
    protected void doValueUpdate(FilterBypass fb) throws BadLocationException {
      Document doc = fb.getDocument();
      String text = doc.getText(0, doc.getLength());
      if (text.isEmpty()) {
        text = "0";
      }

      if (updateValue == true) {
        try {
          Double value = new Double(text);
          double newValue = multiplier.getValueToBeSet(value.doubleValue());
          cValue.setValue(newValue);
        } catch (NumberFormatException e) {
          // do nothing, since we allow '-'
        }
      }
      topContainer.forceRedraw();
    }
  @Override
  public void insertString(
      FilterBypass filterBypass, int offset, String text, AttributeSet attributeSet)
      throws BadLocationException {
    text = trimHexadecimal(text);
    Document document = filterBypass.getDocument();
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(document.getText(0, document.getLength()));
    stringBuilder.insert(offset, text);

    if (isValidInput(stringBuilder.toString(), 0)) {
      super.insertString(filterBypass, offset, text, attributeSet);
    } else {
      Toolkit.getDefaultToolkit().beep();
    }
  }
Exemplo n.º 7
0
    public void replace(FilterBypass fb, int offs, int length, String str, AttributeSet a)
        throws BadLocationException {
      if ("\n".equals(str)) str = addWhiteSpace(fb.getDocument(), offs);

      super.replace(fb, offs, length, str, a);
    }
 public void setDot(FilterBypass fb, int dot, Bias bias) {
   if (dot < initialPos) {
     dot = Math.min(initialPos, run.getDocument().getLength());
   }
   fb.setDot(dot, bias);
 }