Esempio n. 1
0
 @Override // from BComponent
 protected void renderComponent(Renderer renderer) {
   Insets insets = getInsets();
   GL11.glTranslatef(0, _offset, 0);
   boolean scissored =
       intersectScissorBox(
           _srect,
           getAbsoluteX() + insets.left,
           getAbsoluteY() + insets.bottom,
           _width - insets.getHorizontal(),
           _height - insets.getVertical());
   try {
     // render our children
     for (int ii = 0, ll = getComponentCount(); ii < ll; ii++) {
       getComponent(ii).render(renderer);
     }
   } finally {
     restoreScissorState(scissored, _srect);
     GL11.glTranslatef(0, -_offset, 0);
   }
 }
Esempio n. 2
0
    @Override // from BComponent
    public void layout() {
      Insets insets = getInsets();
      int twidth = getWidth() - insets.getHorizontal();
      int theight = getHeight() - insets.getVertical();
      int gap = ((GroupLayout) getLayoutManager()).getGap();

      // first make sure all of our entries have been measured and
      // compute our total height and extent
      int totheight = 0;
      for (Entry<V, C> entry : _values) {
        if (entry.height < 0) {
          if (entry.component == null) {
            entry.component = createComponent(entry.value);
          }
          boolean remove = false;
          if (!entry.component.isAdded()) {
            add(entry.component);
            remove = true;
          }
          entry.height = entry.component.getPreferredSize(twidth, 0).height;
          if (remove) {
            remove(entry.component);
          }
        }
        totheight += entry.height;
      }
      if (_values.size() > 1) {
        totheight += (gap * _values.size() - 1);
      }
      int extent = Math.min(theight, totheight);

      // if our most recent value was added with _snap then we scroll to
      // the bottom on this layout and clear our snappy flag
      int value = _snap ? (totheight - extent) : _model.getValue();
      _snap = false;

      // if our extent or total height have changed, update the model
      // (because we're currently invalid, the resulting call to
      // invalidate() will have no effect)
      if (extent != _model.getExtent() || totheight != _model.getMaximum()) {
        _model.setRange(0, value, extent, totheight);
      }

      // now back up from the last component until we reach the first one
      // that's in view
      _offset = _model.getValue();
      int compIx = 0;
      for (int ii = 0; ii < _values.size(); ii++) {
        Entry<V, C> entry = _values.get(ii);
        if (_offset < entry.height) {
          compIx = ii;
          break;
        }
        _offset -= (entry.height + gap);

        // remove and clear out the components before our top component
        if (entry.component != null) {
          if (entry.component.isAdded()) {
            remove(entry.component);
          }
          entry.component = null;
        }
      }

      // compensate for the partially visible topmost component
      extent += _offset;

      // now add components until we use up our extent
      int topIx = compIx;
      while (compIx < _values.size() && extent > 0) {
        Entry<V, C> entry = _values.get(compIx);
        if (entry.component == null) {
          entry.component = createComponent(entry.value);
        }
        if (!entry.component.isAdded()) {
          add(compIx - topIx, entry.component);
        }
        extent -= (entry.height + gap);
        compIx++;
      }

      // lastly remove any components below the last visible component
      while (compIx < _values.size()) {
        Entry<V, C> entry = _values.get(compIx);
        if (entry.component != null) {
          if (entry.component.isAdded()) {
            remove(entry.component);
          }
          entry.component = null;
        }
        compIx++;
      }

      // now have the layout manager layout our added components
      super.layout();
    }