private void addText(String str, String styleName, JTextPane pane) {
   Document doc = pane.getDocument();
   int len = doc.getLength();
   try {
     doc.insertString(len, str, pane.getStyle(styleName));
   } catch (javax.swing.text.BadLocationException e) {
   }
 }
 /**
  * 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();
    }
 void updateTheLabel(DocumentEvent e) {
   Document doc = (Document) e.getDocument();
   String text = null;
   try {
     text = doc.getText(0, doc.getLength());
     doc = null;
   } catch (BadLocationException ex) {
     text = null;
   }
   if (text != null) {
     try {
       double number = Double.parseDouble(text);
       if (number > 1) {
         label.setText(labelPair.getPlural());
       } else {
         label.setText(labelPair.getSingular());
       }
     } catch (NumberFormatException ex) {
       // Do nothing
     } finally {
       text = null;
     }
   }
 }