Exemple #1
0
 /** Centers the graph in the display. */
 public void center() {
   // toggle the scrollbars back and forth to center the image
   JScrollBar sb = scrollPane.getHorizontalScrollBar();
   sb.setValue(sb.getMaximum());
   sb.setValue(sb.getMinimum());
   sb.setValue((sb.getMaximum() + sb.getMinimum()) / 2);
   sb = scrollPane.getVerticalScrollBar();
   sb.setValue(sb.getMaximum());
   sb.setValue(sb.getMinimum());
   sb.setValue((sb.getMaximum() + sb.getMinimum()) / 2);
 }
 @Override
 public void focusGained(FocusEvent fe) {
   if (-1 == table.getSelectedRow() && table.getRowCount() > 0) {
     table.setRowSelectionInterval(0, 0);
     JScrollBar scrollbar = scrollpane.getVerticalScrollBar();
     scrollbar.setValue(scrollbar.getMinimum());
   }
   if (-1 == table.getSelectedColumn()) {
     table.setColumnSelectionInterval(0, 0);
   }
 }
    // {{{ restoreSelection() method
    public void restoreSelection(Set<String> savedChecked, Set<String> savedSelection) {
      for (int i = 0, c = getRowCount(); i < c; i++) {
        Object obj = filteredEntries.get(i);
        String name = obj.toString();
        if (obj instanceof Entry) {
          name = ((Entry) obj).plugin.jar;
        }
        if (pluginSet.contains(name)) setValueAt(true, i, 0);
        else setValueAt(savedChecked.contains(name), i, 0);
      }
      if (table == null) return;

      table.setColumnSelectionInterval(0, 0);
      if (!savedSelection.isEmpty()) {
        int i = 0;
        int rowCount = getRowCount();
        for (; i < rowCount; i++) {
          String name = filteredEntries.get(i).toString();
          if (savedSelection.contains(name)) {
            table.setRowSelectionInterval(i, i);
            break;
          }
        }
        ListSelectionModel lsm = table.getSelectionModel();
        for (; i < rowCount; i++) {
          String name = filteredEntries.get(i).toString();
          if (savedSelection.contains(name)) {
            lsm.addSelectionInterval(i, i);
          }
        }
      } else {
        if (table.getRowCount() != 0) table.setRowSelectionInterval(0, 0);
        JScrollBar scrollbar = scrollpane.getVerticalScrollBar();
        scrollbar.setValue(scrollbar.getMinimum());
      }
    } // }}}
  protected void layoutHScrollbar(JScrollBar sb) {
    if (AbstractLookAndFeel.getTheme().isLinuxStyleScrollBarOn()) {
      Dimension sbSize = sb.getSize();
      Insets sbInsets = sb.getInsets();
      int sizeW = sbSize.width - sbInsets.left - sbInsets.right;

      /*
       * Height and top edge of the buttons and thumb.
       */
      int itemY = sbInsets.top;
      int itemH = sbSize.height - (sbInsets.top + sbInsets.bottom); // Math.min(itemW, sizeH / 2);
      int itemW = Math.min(itemH, sizeW / 2); // sbSize.width - (sbInsets.left + sbInsets.right);

      /* Nominal locations of the buttons, assuming their preferred
       * size will fit.
       */
      int decrButtonX = sbSize.width - sbInsets.right - itemW - itemW + 1;
      int incrButtonX = sbSize.width - sbInsets.right - itemW;

      /* Compute the width and origin of the thumb. The case
       * where the thumb is at the right edge is handled specially
       * to avoid numerical problems in computing thumbX.  Enforce
       * the thumbs min/max dimensions. If the thumb doesn't
       * fit in the track (trackW) we'll hide it later.
       */
      float trackW = sbSize.width - sbInsets.left - sbInsets.right - itemH - itemH + 1;
      float min = sb.getMinimum();
      float max = sb.getMaximum();
      float extent = sb.getVisibleAmount();
      float range = max - min;
      float value = sb.getValue();

      int maxThumbW = getMaximumThumbSize().width;
      int minThumbW = getMinimumThumbSize().width;
      int thumbW = (range <= 0) ? maxThumbW : (int) (trackW * (extent / range));
      thumbW = Math.max(thumbW, minThumbW);
      thumbW = Math.min(thumbW, maxThumbW);

      int thumbX = decrButtonX - thumbW;
      if (value < (max - extent)) {
        float thumbRange = trackW - thumbW;
        thumbX = (int) (0.5f + (thumbRange * ((value - min) / (range - extent))));
      }

      /* If the thumb isn't going to fit, zero it's bounds.  Otherwise
       * make sure it fits between the buttons.  Note that setting the
       * thumbs bounds will cause a repaint.
       */
      if (thumbW > trackW) {
        setThumbBounds(0, 0, 0, 0);
      } else {
        setThumbBounds(thumbX, itemY, thumbW, itemH);
      }
      decrButton.setBounds(decrButtonX, itemY, itemW, itemH);
      incrButton.setBounds(incrButtonX, itemY, itemW, itemH);

      /* Update the trackRect field.
       */
      trackRect.setBounds(0, itemY, (int) trackW, itemH);

    } else {
      super.layoutHScrollbar(sb);
    }
  }
  protected void alternateLayoutVScrollbar(JScrollBar sb) {
    Dimension sbSize = sb.getSize();
    Insets sbInsets = sb.getInsets();

    /*
     * Width and left edge of the buttons and thumb.
     */
    int itemW = sbSize.width - (sbInsets.left + sbInsets.right);
    int itemX = sbInsets.left;

    /* Nominal locations of the buttons, assuming their preferred
     * size will fit.
     */
    int incrButtonH = incrButton.getPreferredSize().height;
    int incrButtonY = sbSize.height - (sbInsets.bottom + incrButtonH);

    int decrButtonH = decrButton.getPreferredSize().height;
    int decrButtonY = incrButtonY - decrButtonH;

    /* The thumb must fit within the height left over after we
     * subtract the preferredSize of the buttons and the insets.
     */
    int sbInsetsH = sbInsets.top + sbInsets.bottom;
    int sbButtonsH = decrButtonH + incrButtonH;
    float trackH = sbSize.height - (sbInsetsH + sbButtonsH);

    /* Compute the height and origin of the thumb.   The case
     * where the thumb is at the bottom edge is handled specially
     * to avoid numerical problems in computing thumbY.  Enforce
     * the thumbs min/max dimensions.  If the thumb doesn't
     * fit in the track (trackH) we'll hide it later.
     */
    float min = sb.getMinimum();
    float extent = sb.getVisibleAmount();
    float range = sb.getMaximum() - min;
    float value = sb.getValue();

    int thumbH = (range <= 0) ? getMaximumThumbSize().height : (int) (trackH * (extent / range));
    thumbH = Math.max(thumbH, getMinimumThumbSize().height);
    thumbH = Math.min(thumbH, getMaximumThumbSize().height);

    int thumbY = decrButtonY - thumbH; // incrButtonY - thumbH;
    if (sb.getValue() < (sb.getMaximum() - sb.getVisibleAmount())) {
      float thumbRange = trackH - thumbH;
      thumbY = (int) (0.5f + (thumbRange * ((value - min) / (range - extent))));
      // thumbY +=  decrButtonY + decrButtonH;
    }

    /* If the buttons don't fit, allocate half of the available
     * space to each and move the lower one (incrButton) down.
     */
    int sbAvailButtonH = (sbSize.height - sbInsetsH);
    if (sbAvailButtonH < sbButtonsH) {
      incrButtonH = decrButtonH = sbAvailButtonH / 2;
      incrButtonY = sbSize.height - (sbInsets.bottom + incrButtonH);
    }
    decrButton.setBounds(itemX, decrButtonY, itemW, decrButtonH);
    incrButton.setBounds(itemX, incrButtonY, itemW, incrButtonH);

    /* Update the trackRect field.
     */
    int itrackY = sbInsets.top;
    int itrackH = decrButtonY - itrackY;
    trackRect.setBounds(itemX, itrackY, itemW, itrackH);

    /* If the thumb isn't going to fit, zero it's bounds.  Otherwise
     * make sure it fits between the buttons.  Note that setting the
     * thumbs bounds will cause a repaint.
     */
    if (thumbH >= (int) trackH) {
      setThumbBounds(0, 0, 0, 0);
    } else {
      if ((thumbY + thumbH) > decrButtonY) {
        thumbY = decrButtonY - thumbH;
      }
      /*	    if (thumbY  < (decrButtonY + decrButtonH)) {
      thumbY = decrButtonY + decrButtonH + 1;
      }*/
      setThumbBounds(itemX, thumbY, itemW, thumbH);
    }
  }
  protected void alternateLayoutHScrollbar(JScrollBar sb) {
    Dimension sbSize = sb.getSize();
    Insets sbInsets = sb.getInsets();

    /* Height and top edge of the buttons and thumb.
     */
    int itemH = sbSize.height - (sbInsets.top + sbInsets.bottom);
    int itemY = sbInsets.top;

    /* Nominal locations of the buttons, assuming their preferred
     * size will fit.
     */
    int incrButtonW = incrButton.getPreferredSize().width;
    int incrButtonX = sbSize.width - (sbInsets.right + incrButtonW);

    int decrButtonW = decrButton.getPreferredSize().width;
    int decrButtonX = incrButtonX - decrButtonW;

    /* The thumb must fit within the width left over after we
     * subtract the preferredSize of the buttons and the insets.
     */
    int sbInsetsW = sbInsets.left + sbInsets.right;
    int sbButtonsW = decrButtonW + incrButtonW;
    float trackW = sbSize.width - (sbInsetsW + sbButtonsW);

    /* Compute the width and origin of the thumb.  Enforce
     * the thumbs min/max dimensions.  The case where the thumb
     * is at the right edge is handled specially to avoid numerical
     * problems in computing thumbX.  If the thumb doesn't
     * fit in the track (trackH) we'll hide it later.
     */
    float min = sb.getMinimum();
    float extent = sb.getVisibleAmount();
    float range = sb.getMaximum() - min;
    float value = sb.getValue();

    int thumbW = (range <= 0) ? getMaximumThumbSize().width : (int) (trackW * (extent / range));
    thumbW = Math.max(thumbW, getMinimumThumbSize().width);
    thumbW = Math.min(thumbW, getMaximumThumbSize().width);

    int thumbX = decrButtonX - thumbW;
    if (sb.getValue() < (sb.getMaximum() - sb.getVisibleAmount())) {
      float thumbRange = trackW - thumbW;
      thumbX = (int) (0.5f + (thumbRange * ((value - min) / (range - extent))));
      // thumbX +=  decrButtonX + decrButtonW;
    }

    /* If the buttons don't fit, allocate half of the available
     * space to each and move the right one (incrButton) over.
     */
    int sbAvailButtonW = (sbSize.width - sbInsetsW);
    if (sbAvailButtonW < sbButtonsW) {
      incrButtonW = decrButtonW = sbAvailButtonW / 2;
      incrButtonX = sbSize.width - (sbInsets.right + incrButtonW);
    }

    decrButton.setBounds(decrButtonX, itemY, decrButtonW, itemH);
    incrButton.setBounds(incrButtonX, itemY, incrButtonW, itemH);

    /* Update the trackRect field.
     */
    int itrackX = sbInsets.left; // decrButtonX + decrButtonW;
    int itrackW = decrButtonX - itrackX;
    trackRect.setBounds(itrackX, itemY, itrackW, itemH);

    /* Make sure the thumb fits between the buttons.  Note
     * that setting the thumbs bounds causes a repaint.
     */
    if (thumbW >= (int) trackW) {
      setThumbBounds(0, 0, 0, 0);
    } else {
      if (thumbX + thumbW > incrButtonX) {
        thumbX = incrButtonX - thumbW;
      }
      /*if (thumbX  < decrButtonX + decrButtonW) {
      thumbX = decrButtonX + decrButtonW + 1;
      }*/
      setThumbBounds(thumbX, itemY, thumbW, itemH);
    }
  }
 private void scrollToTheLastList(JScrollPane scroll, ScrollTo to) {
   JScrollBar bar = scroll.getHorizontalScrollBar();
   bar.setValue(to.equals(ScrollTo.last) ? bar.getMaximum() : bar.getMinimum());
 }