示例#1
0
  /**
   * GlyphGutter copy pasted bolerplate method. It invokes {@link #paintView} that contains actual
   * business logic.
   */
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    Rectangle clip = g.getClipBounds();

    JTextComponent component = editorUI.getComponent();
    if (component == null) return;

    BaseTextUI textUI = (BaseTextUI) component.getUI();
    View rootView = Utilities.getDocumentView(component);
    if (rootView == null) return;

    g.setColor(backgroundColor());
    g.fillRect(clip.x, clip.y, clip.width, clip.height);

    AbstractDocument doc = (AbstractDocument) component.getDocument();
    doc.readLock();
    try {
      foldHierarchy.lock();
      try {
        int startPos = textUI.getPosFromY(clip.y);
        int startViewIndex = rootView.getViewIndex(startPos, Position.Bias.Forward);
        int rootViewCount = rootView.getViewCount();

        if (startViewIndex >= 0 && startViewIndex < rootViewCount) {
          int clipEndY = clip.y + clip.height;
          for (int i = startViewIndex; i < rootViewCount; i++) {
            View view = rootView.getView(i);
            Rectangle rec = component.modelToView(view.getStartOffset());
            if (rec == null) {
              break;
            }
            int y = rec.y;
            paintView(view, g, y);
            if (y >= clipEndY) {
              break;
            }
          }
        }

      } finally {
        foldHierarchy.unlock();
      }
    } catch (BadLocationException ble) {
      Mercurial.LOG.log(Level.WARNING, null, ble);
    } finally {
      doc.readUnlock();
    }
  }
示例#2
0
    /**
     * Creates a view that can be used to represent the current piece of the flow. This can be
     * either an entire view from the logical view, or a fragment of the logical view.
     *
     * @param fv the view holding the flow
     * @param startOffset the start location for the view being created
     * @param spanLeft the about of span left to fill in the row
     * @param rowIndex the row the view will be placed into
     */
    protected View createView(FlowView fv, int startOffset, int spanLeft, int rowIndex) {
      // Get the child view that contains the given starting position
      View lv = getLogicalView(fv);
      int childIndex = lv.getViewIndex(startOffset, Position.Bias.Forward);
      View v = lv.getView(childIndex);
      if (startOffset == v.getStartOffset()) {
        // return the entire view
        return v;
      }

      // return a fragment.
      v = v.createFragment(startOffset, v.getEndOffset());
      return v;
    }