Example #1
0
  /** Update the child views in response to a document event. */
  void updateChildren(DocumentEvent e, Shape a) {

    Element elem = getElement();
    DocumentEvent.ElementChange ec = e.getChange(elem);

    // This occurs when syntax highlighting only changes on lines
    // (i.e. beginning a multiline comment).
    if (e.getType() == DocumentEvent.EventType.CHANGE) {
      // System.err.println("Updating the damage due to a CHANGE event...");
      // FIXME:  Make me repaint more intelligently.
      getContainer().repaint();
      // damageLineRange(startLine,endLine, a, host);
    } else if (ec != null) {

      // the structure of this element changed.
      Element[] removedElems = ec.getChildrenRemoved();
      Element[] addedElems = ec.getChildrenAdded();
      View[] added = new View[addedElems.length];

      for (int i = 0; i < addedElems.length; i++) added[i] = new WrappedLine(addedElems[i]);
      // System.err.println("Replacing " + removedElems.length +
      // " children with " + addedElems.length);
      replace(ec.getIndex(), removedElems.length, added);

      // should damge a little more intelligently.
      if (a != null) {
        preferenceChanged(null, true, true);
        getContainer().repaint();
      }
    }

    // update font metrics which may be used by the child views
    updateMetrics();
  }
Example #2
0
 /**
  * A change in the text fields.
  *
  * @param e the document event.
  */
 private void documentChanged(DocumentEvent e) {
   if (e.getDocument().equals(fileCountField.getDocument())) {
     // set file count only if its un integer
     try {
       int newFileCount = Integer.valueOf(fileCountField.getText());
       fileCountField.setForeground(Color.black);
       LoggingUtilsActivator.getPacketLoggingService()
           .getConfiguration()
           .setLogfileCount(newFileCount);
     } catch (Throwable t) {
       fileCountField.setForeground(Color.red);
     }
   } else if (e.getDocument().equals(fileSizeField.getDocument())) {
     // set file size only if its un integer
     try {
       int newFileSize = Integer.valueOf(fileSizeField.getText());
       fileSizeField.setForeground(Color.black);
       LoggingUtilsActivator.getPacketLoggingService()
           .getConfiguration()
           .setLimit(newFileSize * 1000);
     } catch (Throwable t) {
       fileSizeField.setForeground(Color.red);
     }
   }
 }
Example #3
0
 @Override
 public void insertUpdate(DocumentEvent e) {
   try {
     // Check for change in lines only if a newline
     // character is inserted.
     String insertion = e.getDocument().getText(e.getOffset(), e.getLength());
     if (insertion.contains("\n")) documentChanged();
   } catch (BadLocationException ex) {
     /* nothing to do */
   }
 }
Example #4
0
  /**
   * Forwards the given <code>DocumentEvent</code> to the child views that need to be notified of
   * the change to the model. If there were changes to the element this view is responsible for,
   * that should be considered when forwarding (i.e. new child views should not get notified).
   *
   * @param ec changes to the element this view is responsible for (may be <code>null</code> if
   *     there were no changes).
   * @param e the change information from the associated document
   * @param a the current allocation of the view
   * @param f the factory to use to rebuild if the view has children
   * @see #insertUpdate
   * @see #removeUpdate
   * @see #changedUpdate
   * @since 1.3
   */
  protected void forwardUpdate(
      DocumentEvent.ElementChange ec, DocumentEvent e, Shape a, ViewFactory f) {
    Element elem = getElement();
    int pos = e.getOffset();
    int index0 = getViewIndex(pos, Position.Bias.Forward);
    if (index0 == -1 && e.getType() == DocumentEvent.EventType.REMOVE && pos >= getEndOffset()) {
      // Event beyond our offsets. We may have represented this, that is
      // the remove may have removed one of our child Elements that
      // represented this, so, we should foward to last element.
      index0 = getViewCount() - 1;
    }
    int index1 = index0;
    View v = (index0 >= 0) ? getView(index0) : null;
    if (v != null) {
      if ((v.getStartOffset() == pos) && (pos > 0)) {
        // If v is at a boundary, forward the event to the previous
        // view too.
        index0 = Math.max(index0 - 1, 0);
      }
    }
    if (e.getType() != DocumentEvent.EventType.REMOVE) {
      index1 = getViewIndex(pos + e.getLength(), Position.Bias.Forward);
      if (index1 < 0) {
        index1 = getViewCount() - 1;
      }
    }
    int hole0 = index1 + 1;
    int hole1 = hole0;
    Element[] addedElems = (ec != null) ? ec.getChildrenAdded() : null;
    if ((addedElems != null) && (addedElems.length > 0)) {
      hole0 = ec.getIndex();
      hole1 = hole0 + addedElems.length - 1;
    }

    // forward to any view not in the forwarding hole
    // formed by added elements (i.e. they will be updated
    // by initialization.
    index0 = Math.max(index0, 0);
    for (int i = index0; i <= index1; i++) {
      if (!((i >= hole0) && (i <= hole1))) {
        v = getView(i);
        if (v != null) {
          Shape childAlloc = getChildAllocation(i, a);
          forwardUpdateToView(v, e, childAlloc, f);
        }
      }
    }
  }
 /**
  * Gives notification that something was inserted into the document in a location that this view
  * is responsible for. This is implemented to simply update the children.
  *
  * @param changes The change information from the associated document.
  * @param a the current allocation of the view
  * @param f the factory to use to rebuild if the view has children
  * @see View#insertUpdate
  */
 public void insertUpdate(DocumentEvent changes, Shape a, ViewFactory f) {
   updateChildren(changes, a);
   Rectangle alloc = ((a != null) && isAllocationValid()) ? getInsideAllocation(a) : null;
   int pos = changes.getOffset();
   View v = getViewAtPosition(pos, alloc);
   if (v != null) v.insertUpdate(changes, alloc, f);
 }
 private boolean handleEmptyTextField(DocumentEvent e) {
   if (e.getDocument().getLength() <= 0) {
     button.setEnabled(false);
     alreadyEnabled = false;
     return true;
   }
   return false;
 }
Example #7
0
  /**
   * Repaint the region of change covered by the given document event. Damages the line that begins
   * the range to cover the case when the insert/remove is only on one line. If lines are added or
   * removed, damages the whole view. The longest line is checked to see if it has changed.
   */
  protected void updateDamage(DocumentEvent changes, Shape a, ViewFactory f) {
    Component host = getContainer();
    updateMetrics();
    Element elem = getElement();
    DocumentEvent.ElementChange ec = changes.getChange(elem);
    Element[] added = (ec != null) ? ec.getChildrenAdded() : null;
    Element[] removed = (ec != null) ? ec.getChildrenRemoved() : null;
    if (((added != null) && (added.length > 0)) || ((removed != null) && (removed.length > 0))) {
      // lines were added or removed...
      if (added != null) {
        int addedAt = ec.getIndex(); // FIXME: Is this correct?????
        for (int i = 0; i < added.length; i++) possiblyUpdateLongLine(added[i], addedAt + i);
      }
      if (removed != null) {
        for (int i = 0; i < removed.length; i++) {
          if (removed[i] == longLine) {
            longLineWidth = -1; // Must do this!!
            calculateLongestLine();
            break;
          }
        }
      }
      preferenceChanged(null, true, true);
      host.repaint();
    }

    // This occurs when syntax highlighting only changes on lines
    // (i.e. beginning a multiline comment).
    else if (changes.getType() == DocumentEvent.EventType.CHANGE) {
      // System.err.println("Updating the damage due to a CHANGE event...");
      int startLine = changes.getOffset();
      int endLine = changes.getLength();
      damageLineRange(startLine, endLine, a, host);
    } else {
      Element map = getElement();
      int line = map.getElementIndex(changes.getOffset());
      damageLineRange(line, line, a, host);
      if (changes.getType() == DocumentEvent.EventType.INSERT) {
        // check to see if the line is longer than current
        // longest line.
        Element e = map.getElement(line);
        if (e == longLine) {
          // We must recalculate longest line's width here
          // because it has gotten longer.
          longLineWidth = getLineWidth(line);
          preferenceChanged(null, true, false);
        } else {
          // If long line gets updated, update the status bars too.
          if (possiblyUpdateLongLine(e, line)) preferenceChanged(null, true, false);
        }
      } else if (changes.getType() == DocumentEvent.EventType.REMOVE) {
        if (map.getElement(line) == longLine) {
          // removed from longest line... recalc
          longLineWidth = -1; // Must do this!
          calculateLongestLine();
          preferenceChanged(null, true, false);
        }
      }
    }
  }
Example #8
0
    public void insertUpdate(DocumentEvent evt) {
      documentChanged(evt);

      int offset = evt.getOffset();
      int length = evt.getLength();

      int newStart;
      int newEnd;

      if (selectionStart > offset || (selectionStart == selectionEnd && selectionStart == offset))
        newStart = selectionStart + length;
      else newStart = selectionStart;

      if (selectionEnd >= offset) newEnd = selectionEnd + length;
      else newEnd = selectionEnd;

      select(newStart, newEnd);
    }
Example #9
0
 /**
  * Forwards the <code>DocumentEvent</code> to the give child view. This simply messages the view
  * with a call to <code>insertUpdate</code>, <code>removeUpdate</code>, or <code>changedUpdate
  * </code> depending upon the type of the event. This is called by <a
  * href="#forwardUpdate">forwardUpdate</a> to forward the event to children that need it.
  *
  * @param v the child view to forward the event to
  * @param e the change information from the associated document
  * @param a the current allocation of the view
  * @param f the factory to use to rebuild if the view has children
  * @see #forwardUpdate
  * @since 1.3
  */
 protected void forwardUpdateToView(View v, DocumentEvent e, Shape a, ViewFactory f) {
   DocumentEvent.EventType type = e.getType();
   if (type == DocumentEvent.EventType.INSERT) {
     v.insertUpdate(e, a, f);
   } else if (type == DocumentEvent.EventType.REMOVE) {
     v.removeUpdate(e, a, f);
   } else {
     v.changedUpdate(e, a, f);
   }
 }
Example #10
0
 public void insertUpdate(DocumentEvent e) {
   Document doc = e.getDocument();
   try {
     prop.set(doc.getText(0, doc.getLength()));
   } catch (BadLocationException b) {
     // Once again, no idea what this is supposed to be.
     // I don't think I like this interface much :-(.
     System.out.println(b);
   }
 }
Example #11
0
    public void removeUpdate(DocumentEvent evt) {
      documentChanged(evt);

      int offset = evt.getOffset();
      int length = evt.getLength();

      int newStart;
      int newEnd;

      if (selectionStart > offset) {
        if (selectionStart > offset + length) newStart = selectionStart - length;
        else newStart = offset;
      } else newStart = selectionStart;

      if (selectionEnd > offset) {
        if (selectionEnd > offset + length) newEnd = selectionEnd - length;
        else newEnd = offset;
      } else newEnd = selectionEnd;

      select(newStart, newEnd);
    }
Example #12
0
  protected void documentChanged(DocumentEvent evt) {
    DocumentEvent.ElementChange ch = evt.getChange(document.getDefaultRootElement());

    int count;
    if (ch == null) count = 0;
    else count = ch.getChildrenAdded().length - ch.getChildrenRemoved().length;

    int line = getLineOfOffset(evt.getOffset());
    if (count == 0) {
      painter.invalidateLine(line);
    }
    // do magic stuff
    else if (line < firstLine) {
      setFirstLine(firstLine + count);
    }
    // end of magic stuff
    else {
      painter.invalidateLineRange(line, firstLine + visibleLines);
      updateScrollBars();
    }
  }
 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;
     }
   }
 }
Example #14
0
 /**
  * Gives notification from the document that attributes were changed in a location that this view
  * is responsible for. To reduce the burden to subclasses, this functionality is spread out into
  * the following calls that subclasses can reimplement:
  *
  * <ol>
  *   <li><a href="#updateChildren">updateChildren</a> is called if there were any changes to the
  *       element this view is responsible for. If this view has child views that are represent the
  *       child elements, then this method should do whatever is necessary to make sure the child
  *       views correctly represent the model.
  *   <li><a href="#forwardUpdate">forwardUpdate</a> is called to forward the DocumentEvent to the
  *       appropriate child views.
  *   <li><a href="#updateLayout">updateLayout</a> is called to give the view a chance to either
  *       repair its layout, to reschedule layout, or do nothing.
  * </ol>
  *
  * @param e the change information from the associated document
  * @param a the current allocation of the view
  * @param f the factory to use to rebuild if the view has children
  * @see View#changedUpdate
  */
 public void changedUpdate(DocumentEvent e, Shape a, ViewFactory f) {
   if (getViewCount() > 0) {
     Element elem = getElement();
     DocumentEvent.ElementChange ec = e.getChange(elem);
     if (ec != null) {
       if (!updateChildren(ec, e, f)) {
         // don't consider the element changes they
         // are for a view further down.
         ec = null;
       }
     }
     forwardUpdate(ec, e, a, f);
     updateLayout(ec, e, a);
   }
 }