Java Code Examples for javax.swing.JViewport#setView()

The following examples show how to use javax.swing.JViewport#setView() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InternalSourceViewerComponent.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public InternalSourceViewerComponent(String text, int offset, int endOffset, InternalSourceAppearance appearance) {
    super(new BorderLayout());
    
    sourceArea = new SourceArea();
    
    this.appearance = appearance;
    appearance.addListener(this);
    propertyChange(null);
    
    sourceArea.setText(text);
    setOffset(offset, endOffset);
    
    lineNumbersPanel = new JPanel(new BorderLayout());
    lineNumbersPanel.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 10));
    lineNumbers = new LineNumbers(sourceArea);
    lineNumbersPanel.add(lineNumbers, BorderLayout.EAST);
    
    lineNumbersViewport = new JViewport();
    lineNumbersViewport.setView(lineNumbersPanel);
    lineNumbersViewport.setPreferredSize(lineNumbersPanel.getPreferredSize());
    
    JScrollPane scrollPane = new JScrollPane(sourceArea);
    scrollPane.setBorder(BorderFactory.createEmptyBorder());
    scrollPane.setViewportBorder(BorderFactory.createEmptyBorder());
    scrollPane.setRowHeader(lineNumbersViewport);
    
    add(scrollPane, BorderLayout.CENTER);
}
 
Example 2
Source File: PDFViewerTopComponent.java    From Open-LaTeX-Studio with MIT License 5 votes vote down vote up
private void refreshDisplayPane() {
    JPanel pdfImagePanel = pdfDisplay.drawPreviewOnJPanel();
   
    if (pdfImagePanel != null) {
        JViewport vp = jScrollPane1.getViewport();
        Point p = vp.getViewPosition();
        vp.setView(pdfImagePanel);
        vp.setViewPosition(p);
    }
    
    jTextField1.setText(String.valueOf(pdfDisplay.getSelectedPage()));
    jLabel2.setText("of " + pdfDisplay.getTotalPages());
}
 
Example 3
Source File: PeriodicTasksService.java    From Open-LaTeX-Studio with MIT License 5 votes vote down vote up
private void drawPreview() {
    JPanel pdfImagePanel = pdfDisplay.drawPreviewOnJPanel();
   
    if (pdfImagePanel != null) {
        JViewport vp = jScrollPane.getViewport();
        Point p = vp.getViewPosition();
        vp.setView(pdfImagePanel);
        vp.setViewPosition(p);

    }
    
    jLabel.setText("of " + pdfDisplay.getTotalPages());
}
 
Example 4
Source File: MMDEditor.java    From netbeans-mmd-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public void onScaledByMouse(
        @Nonnull final MindMapPanel source,
        @Nonnull final Point mousePoint,
        final double oldScale,
        final double newScale,
        @Nonnull final Dimension oldSize,
        @Nonnull final Dimension newSize
) {
  if (Double.compare(oldScale, newScale) != 0) {
    this.scrollPane.setViewportView(source);
    final JViewport viewport = this.scrollPane.getViewport();

    final Rectangle viewPos = viewport.getViewRect();

    final Dimension size = source.getSize();
    final Dimension extentSize = viewport.getExtentSize();

    if (extentSize.width < size.width || extentSize.height < size.height) {

      final int dx = mousePoint.x - viewPos.x;
      final int dy = mousePoint.y - viewPos.y;

      final double scaleX = newSize.getWidth() / oldSize.getWidth();
      final double scaleY = newSize.getHeight() / oldSize.getHeight();

      final int newMouseX = (int) (Math.round(mousePoint.x * scaleX));
      final int newMouseY = (int) (Math.round(mousePoint.y * scaleY));

      viewPos.x = Math.max(0, newMouseX - dx);
      viewPos.y = Math.max(0, newMouseY - dy);
      viewport.setView(source);

      source.scrollRectToVisible(viewPos);
    } else {
      viewPos.x = 0;
      viewPos.y = 0;
      source.scrollRectToVisible(viewPos);
    }
    this.scrollPane.repaint();
  }
}
 
Example 5
Source File: MMDGraphEditor.java    From netbeans-mmd-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public void onScaledByMouse(
    @Nonnull final MindMapPanel source,
    @Nonnull final Point mousePoint,
    final double oldScale,
    final double newScale,
    @Nonnull final Dimension oldSize,
    @Nonnull final Dimension newSize
) {
  if (Double.compare(oldScale, newScale) != 0) {
    final JViewport viewport = this.mainScrollPane.getViewport();

    final Rectangle viewPos = viewport.getViewRect();

    final Dimension size = source.getSize();
    final Dimension extentSize = viewport.getExtentSize();

    if (extentSize.width < size.width || extentSize.height < size.height) {

      final int dx = mousePoint.x - viewPos.x;
      final int dy = mousePoint.y - viewPos.y;

      final double scaleX = newSize.getWidth() / oldSize.getWidth();
      final double scaleY = newSize.getHeight() / oldSize.getHeight();

      final int newMouseX = (int) (Math.round(mousePoint.x * scaleX));
      final int newMouseY = (int) (Math.round(mousePoint.y * scaleY));

      viewPos.x = Math.max(0, newMouseX - dx);
      viewPos.y = Math.max(0, newMouseY - dy);
      viewport.setView(source);

      source.scrollRectToVisible(viewPos);
    } else {
      viewPos.x = 0;
      viewPos.y = 0;
      source.scrollRectToVisible(viewPos);
    }

    this.mainScrollPane.revalidate();
    this.mainScrollPane.repaint();
  }
}