Example usage for javax.swing JViewport setViewPosition

List of usage examples for javax.swing JViewport setViewPosition

Introduction

In this page you can find the example usage for javax.swing JViewport setViewPosition.

Prototype

public void setViewPosition(Point p) 

Source Link

Document

Sets the view coordinates that appear in the upper left hand corner of the viewport, does nothing if there's no view.

Usage

From source file:neg.JRViewer.java

/**
 *
 *///from   ww w.jav a2s.c o  m
public void gotoHyperlink(JRPrintHyperlink hyperlink) {
    switch (hyperlink.getHyperlinkType()) {
    case JRHyperlink.HYPERLINK_TYPE_REFERENCE: {
        if (isOnlyHyperlinkListener()) {
            System.out.println("Hyperlink reference : " + hyperlink.getHyperlinkReference());
            System.out.println("Implement your own JRHyperlinkListener to manage this type of event.");
        }
        break;
    }
    case JRHyperlink.HYPERLINK_TYPE_LOCAL_ANCHOR: {
        if (hyperlink.getHyperlinkAnchor() != null) {
            Map anchorIndexes = jasperPrint.getAnchorIndexes();
            JRPrintAnchorIndex anchorIndex = (JRPrintAnchorIndex) anchorIndexes
                    .get(hyperlink.getHyperlinkAnchor());
            if (anchorIndex.getPageIndex() != pageIndex) {
                setPageIndex(anchorIndex.getPageIndex());
                refreshPage();
            }
            Container container = pnlInScroll.getParent();
            if (container instanceof JViewport) {
                JViewport viewport = (JViewport) container;

                int newX = (int) (anchorIndex.getElementAbsoluteX() * realZoom);
                int newY = (int) (anchorIndex.getElementAbsoluteY() * realZoom);

                int maxX = pnlInScroll.getWidth() - viewport.getWidth();
                int maxY = pnlInScroll.getHeight() - viewport.getHeight();

                if (newX < 0) {
                    newX = 0;
                }
                if (newX > maxX) {
                    newX = maxX;
                }
                if (newY < 0) {
                    newY = 0;
                }
                if (newY > maxY) {
                    newY = maxY;
                }

                viewport.setViewPosition(new Point(newX, newY));
            }
        }

        break;
    }
    case JRHyperlink.HYPERLINK_TYPE_LOCAL_PAGE: {
        int page = pageIndex + 1;
        if (hyperlink.getHyperlinkPage() != null) {
            page = hyperlink.getHyperlinkPage().intValue();
        }

        if (page >= 1 && page <= jasperPrint.getPages().size() && page != pageIndex + 1) {
            setPageIndex(page - 1);
            refreshPage();
            Container container = pnlInScroll.getParent();
            if (container instanceof JViewport) {
                JViewport viewport = (JViewport) container;
                viewport.setViewPosition(new Point(0, 0));
            }
        }

        break;
    }
    case JRHyperlink.HYPERLINK_TYPE_REMOTE_ANCHOR: {
        if (isOnlyHyperlinkListener()) {
            System.out.println("Hyperlink reference : " + hyperlink.getHyperlinkReference());
            System.out.println("Hyperlink anchor    : " + hyperlink.getHyperlinkAnchor());
            System.out.println("Implement your own JRHyperlinkListener to manage this type of event.");
        }
        break;
    }
    case JRHyperlink.HYPERLINK_TYPE_REMOTE_PAGE: {
        if (isOnlyHyperlinkListener()) {
            System.out.println("Hyperlink reference : " + hyperlink.getHyperlinkReference());
            System.out.println("Hyperlink page      : " + hyperlink.getHyperlinkPage());
            System.out.println("Implement your own JRHyperlinkListener to manage this type of event.");
        }
        break;
    }
    case JRHyperlink.HYPERLINK_TYPE_CUSTOM: {
        if (isOnlyHyperlinkListener()) {
            System.out.println("Hyperlink of type " + hyperlink.getLinkType());
            System.out.println("Implement your own JRHyperlinkListener to manage this type of event.");
        }
        break;
    }
    case JRHyperlink.HYPERLINK_TYPE_NONE:
    default: {
        break;
    }
    }
}

From source file:cn.pholance.datamanager.common.components.JRViewer.java

/**
 *
 *//*from   w w w  .  j  a va  2  s  . c  o m*/
public void gotoHyperlink(JRPrintHyperlink hyperlink) {
    switch (hyperlink.getHyperlinkTypeValue()) {
    case REFERENCE: {
        if (isOnlyHyperlinkListener()) {
            System.out.println("Hyperlink reference : " + hyperlink.getHyperlinkReference());
            System.out.println("Implement your own JRHyperlinkListener to manage this type of event.");
        }
        break;
    }
    case LOCAL_ANCHOR: {
        if (hyperlink.getHyperlinkAnchor() != null) {
            Map<String, JRPrintAnchorIndex> anchorIndexes = jasperPrint.getAnchorIndexes();
            JRPrintAnchorIndex anchorIndex = anchorIndexes.get(hyperlink.getHyperlinkAnchor());
            if (anchorIndex.getPageIndex() != pageIndex) {
                setPageIndex(anchorIndex.getPageIndex());
                refreshPage();
            }
            Container container = pnlInScroll.getParent();
            if (container instanceof JViewport) {
                JViewport viewport = (JViewport) container;

                int newX = (int) (anchorIndex.getElementAbsoluteX() * realZoom);
                int newY = (int) (anchorIndex.getElementAbsoluteY() * realZoom);

                int maxX = pnlInScroll.getWidth() - viewport.getWidth();
                int maxY = pnlInScroll.getHeight() - viewport.getHeight();

                if (newX < 0) {
                    newX = 0;
                }
                if (newX > maxX) {
                    newX = maxX;
                }
                if (newY < 0) {
                    newY = 0;
                }
                if (newY > maxY) {
                    newY = maxY;
                }

                viewport.setViewPosition(new Point(newX, newY));
            }
        }

        break;
    }
    case LOCAL_PAGE: {
        int page = pageIndex + 1;
        if (hyperlink.getHyperlinkPage() != null) {
            page = hyperlink.getHyperlinkPage().intValue();
        }

        if (page >= 1 && page <= jasperPrint.getPages().size() && page != pageIndex + 1) {
            setPageIndex(page - 1);
            refreshPage();
            Container container = pnlInScroll.getParent();
            if (container instanceof JViewport) {
                JViewport viewport = (JViewport) container;
                viewport.setViewPosition(new Point(0, 0));
            }
        }

        break;
    }
    case REMOTE_ANCHOR: {
        if (isOnlyHyperlinkListener()) {
            System.out.println("Hyperlink reference : " + hyperlink.getHyperlinkReference());
            System.out.println("Hyperlink anchor    : " + hyperlink.getHyperlinkAnchor());
            System.out.println("Implement your own JRHyperlinkListener to manage this type of event.");
        }
        break;
    }
    case REMOTE_PAGE: {
        if (isOnlyHyperlinkListener()) {
            System.out.println("Hyperlink reference : " + hyperlink.getHyperlinkReference());
            System.out.println("Hyperlink page      : " + hyperlink.getHyperlinkPage());
            System.out.println("Implement your own JRHyperlinkListener to manage this type of event.");
        }
        break;
    }
    case CUSTOM: {
        if (isOnlyHyperlinkListener()) {
            System.out.println("Hyperlink of type " + hyperlink.getLinkType());
            System.out.println("Implement your own JRHyperlinkListener to manage this type of event.");
        }
        break;
    }
    case NONE:
    default: {
        break;
    }
    }
}

From source file:ireport_5_6_0.view.JRViewer.java

/**
 *
 *///w  ww .j  av a 2 s.co  m
public void gotoHyperlink(JRPrintHyperlink hyperlink) {
    switch (hyperlink.getHyperlinkTypeValue()) {
    case REFERENCE: {
        if (isOnlyHyperlinkListener()) {
            System.out.println("Hyperlink reference : " + hyperlink.getHyperlinkReference());
            System.out.println("Implement your own JRHyperlinkListener to manage this type of event.");
        }
        break;
    }
    case LOCAL_ANCHOR: {
        if (hyperlink.getHyperlinkAnchor() != null) {
            Map<String, JRPrintAnchorIndex> anchorIndexes = jasperPrint.getAnchorIndexes();
            JRPrintAnchorIndex anchorIndex = anchorIndexes.get(hyperlink.getHyperlinkAnchor());
            if (anchorIndex.getPageIndex() != pageIndex) {
                setPageIndex(anchorIndex.getPageIndex());
                refreshPage();
            }
            Container container = pnlInScroll.getParent();
            if (container instanceof JViewport) {
                JViewport viewport = (JViewport) container;

                int newX = (int) (anchorIndex.getElementAbsoluteX() * realZoom);
                int newY = (int) (anchorIndex.getElementAbsoluteY() * realZoom);

                int maxX = pnlInScroll.getWidth() - viewport.getWidth();
                int maxY = pnlInScroll.getHeight() - viewport.getHeight();

                if (newX < 0) {
                    newX = 0;
                }
                if (newX > maxX) {
                    newX = maxX;
                }
                if (newY < 0) {
                    newY = 0;
                }
                if (newY > maxY) {
                    newY = maxY;
                }

                viewport.setViewPosition(new Point(newX, newY));
            }
        }
        break;
    }
    case LOCAL_PAGE: {
        int page = pageIndex + 1;
        if (hyperlink.getHyperlinkPage() != null) {
            page = hyperlink.getHyperlinkPage().intValue();
        }

        if (page >= 1 && page <= jasperPrint.getPages().size() && page != pageIndex + 1) {
            setPageIndex(page - 1);
            refreshPage();
            Container container = pnlInScroll.getParent();
            if (container instanceof JViewport) {
                JViewport viewport = (JViewport) container;
                viewport.setViewPosition(new Point(0, 0));
            }
        }
        break;
    }
    case REMOTE_ANCHOR: {
        if (isOnlyHyperlinkListener()) {
            System.out.println("Hyperlink reference : " + hyperlink.getHyperlinkReference());
            System.out.println("Hyperlink anchor    : " + hyperlink.getHyperlinkAnchor());
            System.out.println("Implement your own JRHyperlinkListener to manage this type of event.");
        }
        break;
    }
    case REMOTE_PAGE: {
        if (isOnlyHyperlinkListener()) {
            System.out.println("Hyperlink reference : " + hyperlink.getHyperlinkReference());
            System.out.println("Hyperlink page      : " + hyperlink.getHyperlinkPage());
            System.out.println("Implement your own JRHyperlinkListener to manage this type of event.");
        }
        break;
    }
    case CUSTOM: {
        if (isOnlyHyperlinkListener()) {
            System.out.println("Hyperlink of type " + hyperlink.getLinkType());
            System.out.println("Implement your own JRHyperlinkListener to manage this type of event.");
        }
        break;
    }
    case NONE:
    default: {
        break;
    }
    }
}

From source file:org.nuclos.client.ui.collect.result.SearchResultStrategy.java

private void adjustVerticalScrollBarForSearch(boolean bRefreshOnly) {
    final CollectController<Clct> cc = getCollectController();
    final JViewport viewport = cc.getResultPanel().getResultTableScrollPane().getViewport();
    if (bRefreshOnly) {
        final Rectangle rect = cc.getResultTable().getCellRect(0, 0, true);
        final Rectangle viewRect = viewport.getViewRect();
        // There seem to be different opinions about what scrollRectToVisible has to do at SUN and everywhere else...
        rect.setLocation(viewRect.x, viewRect.y);//rect.x - viewRect.x, rect.y - viewRect.y);
        viewport.scrollRectToVisible(rect);
    } else {/*w  w w  .j av a  2s  .  com*/
        Point viewPosition = viewport.getViewPosition();
        viewport.setViewPosition(new Point(viewPosition.x, 0));
    }
    final JScrollBar scrlbarVertical = cc.getResultPanel().getResultTableScrollPane().getVerticalScrollBar();
    scrlbarVertical.setValue(scrlbarVertical.getMinimum());
}