/**
   * scrolls to selected line number
   *
   * @param lineNumber the line number to scroll to
   * @param toTop display on the top row
   * @return true if .. , false if
   */
  public boolean scrollToLine(final int lineNumber, final boolean toTop) {
    final int lineNumbers = m_sourceModel.getLineNumbers();

    if ((lineNumber >= 0) && (lineNumber < lineNumbers)) {
      int viewColumnIndex = 0;

      Rectangle rect = m_sourceCode.getCellRect(lineNumber, viewColumnIndex, true);

      JViewport viewport = (JViewport) m_sourceCode.getParent();

      if (toTop) {
        Rectangle lastRect = m_sourceCode.getCellRect(lineNumbers - 1, viewColumnIndex, true);
        viewport.scrollRectToVisible(lastRect);
      }

      Point pt = viewport.getViewPosition();
      rect.setLocation(rect.x - pt.x, rect.y - pt.y);

      // Scroll the area into view

      viewport.scrollRectToVisible(rect);

      m_sourceCode.repaint();

      return true;
    }
    return false;
  }
  public void scrollToAttribute(Attribute a) {
    if (!a.getDescriptor().getConfig().equals(getConfig())) {
      logger.fine("Cannot scroll to attribute that isn't attached to this type of descriptor");
      return;
    }
    int rowIndex = getCurrentModel().getRowForDescriptor(a.getDescriptor());
    int colIndex = getCurrentModel().getColumnForAttribute(a);
    JScrollPane scrollPane = (JScrollPane) this.getComponent(0);
    JViewport viewport = (JViewport) scrollPane.getViewport();
    EnhancedTable table = (EnhancedTable) viewport.getView();

    // This rectangle is relative to the table where the
    // northwest corner of cell (0,0) is always (0,0).
    Rectangle rect = table.getCellRect(rowIndex, colIndex, true);

    // The location of the viewport relative to the table
    Point pt = viewport.getViewPosition();

    // Translate the cell location so that it is relative
    // to the view, assuming the northwest corner of the
    // view is (0,0)
    rect.setLocation(rect.x - pt.x, rect.y - pt.y);

    // Scroll the area into view
    viewport.scrollRectToVisible(rect);
  }
Example #3
0
  public void selectField(String fieldName) {
    int idx = listModel.indexOf(fieldName);
    if (idx >= 0) list.setSelectedIndex(idx);

    // Make sure it is visible:
    JViewport viewport = sp.getViewport();
    viewport.scrollRectToVisible(list.getCellBounds(idx, idx));
  }
Example #4
0
 private void scrollToCenterPath(final GeneralPath geoBoundaryPath, final JViewport viewport) {
   final GeneralPath pixelPath =
       ProductUtils.convertToPixelPath(geoBoundaryPath, wmPainter.getGeoCoding());
   final Rectangle viewRect = viewport.getViewRect();
   final Rectangle pathBounds = pixelPath.getBounds();
   setCenter(viewRect, new Point((int) pathBounds.getCenterX(), (int) pathBounds.getCenterY()));
   final Dimension bounds =
       new Dimension(scaledImage.getWidth(null), scaledImage.getHeight(null));
   ensureRectIsInBounds(viewRect, bounds);
   viewport.scrollRectToVisible(viewRect);
 }
Example #5
0
  public void scrollToCellLocation(int rowIndex, int colIndex) {

    if (!(getParent() instanceof JViewport)) {
      return;
    }

    JViewport scrollPane = (JViewport) getParent();
    Rectangle rect = getCellRect(rowIndex, colIndex, true);
    Point p = scrollPane.getViewPosition();
    rect.setLocation(rect.x - p.x, rect.y - p.y);
    scrollPane.scrollRectToVisible(rect);
  }
Example #6
0
  @Override
  public void update(Observable o, Object arg) {
    SortedSet<Feature> fs = model.selectionModel().getFeatureSelection();

    if (fs.size() == 1) {

      if (fs.first().type() == listModel.getType()) {
        int row = listModel.getRow(fs.first());
        // getSelectionModel().setSelectionInterval(row, row);
        if (!(getParent() instanceof JViewport)) {
          return;
        }
        JViewport viewport = (JViewport) getParent();

        // This rectangle is relative to the table where the
        // northwest corner of cell (0,0) is always (0,0).
        Rectangle rect = getCellRect(row, 0, true);

        // The location of the view relative to the table
        Rectangle viewRect = viewport.getViewRect();

        int topVisible = viewport.getViewRect().y;
        int bottomVisible = viewport.getViewRect().height + topVisible;

        /* When the cell is visible, don't do anything */
        if (rect.y > topVisible && rect.y + rect.height < bottomVisible) {
          return;
        }
        // Translate the cell location so that it is relative
        // to the view, assuming the northwest corner of the
        // view is (0,0).
        rect.setLocation(rect.x - viewRect.x, rect.y - viewRect.y);

        // Calculate location of rect if it were at the center of view
        int centerX = (viewRect.width - rect.width) / 2;
        int centerY = (viewRect.height - rect.height) / 2;

        // Fake the location of the cell so that scrollRectToVisible
        // will move the cell to the center
        if (rect.x < centerX) {
          centerX = -centerX;
        }
        if (rect.y < centerY) {
          centerY = -centerY;
        }
        rect.translate(centerX, centerY);

        // Scroll the area into view.
        viewport.scrollRectToVisible(rect);
      }
    }
  }
Example #7
0
  /**
   * Assumes table is contained in a JScrollPane. Scrolls the cell (rowIndex, vColIndex) so that it
   * is visible within the viewport.
   */
  public static void scrollToVisible(JTable table, int row, int col) {
    if (!(table.getParent() instanceof JViewport)) return;

    JViewport viewport = (JViewport) table.getParent();

    // This rectangle is relative to the table where the
    // northwest corner of cell (0,0) is always (0,0).
    Rectangle rect = table.getCellRect(row, col, true);

    // The location of the viewport relative to the table
    Point pt = viewport.getViewPosition();

    // Translate the cell location so that it is relative
    // to the view, assuming the northwest corner of the
    // view is (0,0)
    rect.setLocation(rect.x - pt.x, rect.y - pt.y);

    // Scroll the area into view
    viewport.scrollRectToVisible(rect);
  }
  public void scrollToColumnLocation(int colIndex) {
    JTable scrollTable = transposedSpreadsheetSubform.getScrollTable();
    scrollTable.setColumnSelectionInterval(colIndex, colIndex);

    JViewport scrollPane = transposedSpreadsheetSubform.getFrozenTable().getViewport();
    Rectangle rect = scrollTable.getCellRect(1, colIndex, true);
    Point p = scrollPane.getViewPosition();
    rect.setLocation(rect.x - p.x, rect.y - p.y);

    scrollPane.scrollRectToVisible(rect);

    Map<Integer, Color> columnToColor = new HashMap<Integer, Color>();
    columnToColor.put(colIndex, new Color(28, 117, 188, 70));

    transposedSpreadsheetSubform.changeTableRenderer(
        transposedSpreadsheetSubform.getScrollTable(),
        new SubFormCellRenderer(
            UIHelper.VER_11_PLAIN, UIHelper.DARK_GREEN_COLOR, null, columnToColor));

    transposedSpreadsheetSubform.validate();
    transposedSpreadsheetSubform.repaint();
  }
  /**
   * Method to check that the current position is in the viewing area and if not scroll to center
   * the current position if possible
   */
  public void checkScroll() {
    // get the x and y position in pixels
    int xPos = (int) (colIndex * zoomFactor);
    int yPos = (int) (rowIndex * zoomFactor);

    // only do this if the image is larger than normal
    if (zoomFactor > 1) {

      // get the rectangle that defines the current view
      JViewport viewport = scrollPane.getViewport();
      Rectangle rect = viewport.getViewRect();
      int rectMinX = (int) rect.getX();
      int rectWidth = (int) rect.getWidth();
      int rectMaxX = rectMinX + rectWidth - 1;
      int rectMinY = (int) rect.getY();
      int rectHeight = (int) rect.getHeight();
      int rectMaxY = rectMinY + rectHeight - 1;

      // get the maximum possible x and y index
      int macolIndexX = (int) (picture.getWidth() * zoomFactor) - rectWidth - 1;
      int macolIndexY = (int) (picture.getHeight() * zoomFactor) - rectHeight - 1;

      // calculate how to position the current position in the middle of the viewing
      // area
      int viewX = xPos - (int) (rectWidth / 2);
      int viewY = yPos - (int) (rectHeight / 2);

      // reposition the viewX and viewY if outside allowed values
      if (viewX < 0) viewX = 0;
      else if (viewX > macolIndexX) viewX = macolIndexX;
      if (viewY < 0) viewY = 0;
      else if (viewY > macolIndexY) viewY = macolIndexY;

      // move the viewport upper left point
      viewport.scrollRectToVisible(new Rectangle(viewX, viewY, rectWidth, rectHeight));
    }
  }