コード例 #1
0
 /** {@inheritDoc} */
 @Override
 protected void uninstallListeners(JComponent c) {
   super.uninstallListeners(c);
   c.removePropertyChangeListener(this);
   if (viewportViewFocusHandler != null) {
     JViewport viewport = ((JScrollPane) c).getViewport();
     viewport.removeContainerListener(viewportViewFocusHandler);
     if (viewport.getView() != null) {
       viewport.getView().removeFocusListener(viewportViewFocusHandler);
     }
     viewportViewFocusHandler = null;
   }
 }
コード例 #2
0
 public void actionPerformed(ActionEvent e) {
   PrintJob pjob = getToolkit().getPrintJob(textViewerFrame, "Printing Nslm", null);
   if (pjob != null) {
     Graphics pg = pjob.getGraphics();
     if (pg != null) {
       // todo: this should print from
       // the file not from the screen.
       // if (editor1!=null) {
       //    editor1.print(pg); //print crashes, must use printAll
       // }
       // if (scroller1!=null) {
       //    scroller1.printAll(pg); //is clipping on left
       // }
       if (scroller1 != null) {
         JViewport jvp = scroller1.getViewport();
         jvp.printAll(pg);
       }
       pg.dispose();
     }
     pjob.end();
   }
 }
コード例 #3
0
  /**
   * 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));
    }
  }