Example usage for javax.swing JViewport getHeight

List of usage examples for javax.swing JViewport getHeight

Introduction

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

Prototype

@BeanProperty(bound = false)
public int getHeight() 

Source Link

Document

Returns the current height of this component.

Usage

From source file:Main.java

public static void addMiddleButtonDragSupport(Component targetComponent) {
    MouseInputAdapter mia = new MouseInputAdapter() {
        int m_XDifference, m_YDifference;
        boolean m_dragging = false;

        public void mouseDragged(MouseEvent e) {
            if (!m_dragging)
                return;

            Component target = e.getComponent();
            Container c = target.getParent();
            if (c instanceof JViewport) {
                JViewport jv = (JViewport) c;
                Point p = jv.getViewPosition();
                int newX = p.x - (e.getX() - m_XDifference);
                int newY = p.y - (e.getY() - m_YDifference);

                int maxX = target.getWidth() - jv.getWidth();
                int maxY = target.getHeight() - jv.getHeight();
                if (newX < 0)
                    newX = 0;//ww w. j  a v a  2 s .  c o  m
                if (newX > maxX)
                    newX = maxX;
                if (newY < 0)
                    newY = 0;
                if (newY > maxY)
                    newY = maxY;

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

        Cursor oldCursor;

        public void mousePressed(MouseEvent e) {
            if (SwingUtilities.isMiddleMouseButton(e)) {
                m_dragging = true;
                oldCursor = e.getComponent().getCursor();
                e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
                m_XDifference = e.getX();
                m_YDifference = e.getY();
            }
        }

        public void mouseReleased(MouseEvent e) {
            if (m_dragging) {
                e.getComponent().setCursor(oldCursor);
                m_dragging = false;
            }
        }
    };
    targetComponent.addMouseMotionListener(mia);
    targetComponent.addMouseListener(mia);
}

From source file:Main.java

public Main() {
    super();//  ww  w.j av a2 s . c o m
    JTree tree = new JTree();
    for (int i = 0; i < tree.getRowCount(); i++) {
        tree.expandRow(i);
    }

    final JScrollPane pane = new JScrollPane(tree) {
        Dimension prefSize = new Dimension(200, 150);

        public Dimension getPreferredSize() {
            return prefSize;
        }
    };

    pane.getVerticalScrollBar().addAdjustmentListener(e -> {
        JViewport vp = pane.getViewport();
        if (vp.getView().getHeight() <= vp.getHeight() + vp.getViewPosition().y) {
            System.out.println("End");
        }
    });

    add(pane);
}

From source file:Main.java

public GrabAndScrollLabel(ImageIcon i) {
    super(i);/*  w ww  . j a v  a  2s  .  co m*/

    MouseInputAdapter mia = new MouseInputAdapter() {
        int xDiff, yDiff;
        Container c;

        public void mouseDragged(MouseEvent e) {
            c = GrabAndScrollLabel.this.getParent();
            if (c instanceof JViewport) {
                JViewport jv = (JViewport) c;
                Point p = jv.getViewPosition();
                int newX = p.x - (e.getX() - xDiff);
                int newY = p.y - (e.getY() - yDiff);

                int maxX = GrabAndScrollLabel.this.getWidth() - jv.getWidth();
                int maxY = GrabAndScrollLabel.this.getHeight() - jv.getHeight();
                if (newX < 0)
                    newX = 0;
                if (newX > maxX)
                    newX = maxX;
                if (newY < 0)
                    newY = 0;
                if (newY > maxY)
                    newY = maxY;

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

        public void mousePressed(MouseEvent e) {
            setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
            xDiff = e.getX();
            yDiff = e.getY();
        }

        public void mouseReleased(MouseEvent e) {
            setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
        }
    };
    addMouseMotionListener(mia);
    addMouseListener(mia);
}

From source file:GrabAndDragDemo.java

public GrabAndScrollLabel(ImageIcon i) {
    super(i);//from w  ww  .  j a va2  s . co m

    MouseInputAdapter mia = new MouseInputAdapter() {
        int xDiff, yDiff;

        boolean isDragging;

        Container c;

        public void mouseDragged(MouseEvent e) {
            c = GrabAndScrollLabel.this.getParent();
            if (c instanceof JViewport) {
                JViewport jv = (JViewport) c;
                Point p = jv.getViewPosition();
                int newX = p.x - (e.getX() - xDiff);
                int newY = p.y - (e.getY() - yDiff);

                int maxX = GrabAndScrollLabel.this.getWidth() - jv.getWidth();
                int maxY = GrabAndScrollLabel.this.getHeight() - jv.getHeight();
                if (newX < 0)
                    newX = 0;
                if (newX > maxX)
                    newX = maxX;
                if (newY < 0)
                    newY = 0;
                if (newY > maxY)
                    newY = maxY;

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

        public void mousePressed(MouseEvent e) {
            setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
            xDiff = e.getX();
            yDiff = e.getY();
        }

        public void mouseReleased(MouseEvent e) {
            setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
        }
    };
    addMouseMotionListener(mia);
    addMouseListener(mia);
}

From source file:com.floreantpos.jasperreport.swing.JRViewerPanel.java

void pnlLinksMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pnlLinksMouseDragged
    // Add your handling code here:

    Container container = pnlInScroll.getParent();
    if (container instanceof JViewport) {
        JViewport viewport = (JViewport) container;
        Point point = viewport.getViewPosition();
        int newX = point.x - (evt.getX() - downX);
        int newY = point.y - (evt.getY() - downY);

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

        if (newX < 0) {
            newX = 0;/*from www . ja  v a  2 s .c o  m*/
        }
        if (newX > maxX) {
            newX = maxX;
        }
        if (newY < 0) {
            newY = 0;
        }
        if (newY > maxY) {
            newY = maxY;
        }

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

From source file:com.floreantpos.jasperreport.swing.JRViewerPanel.java

/**
 *
 *//*from ww  w .  j a va2 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 anchorIndexes = viewerContext.getJasperPrint().getAnchorIndexes();
            JRPrintAnchorIndex anchorIndex = (JRPrintAnchorIndex) anchorIndexes
                    .get(hyperlink.getHyperlinkAnchor());
            if (anchorIndex.getPageIndex() != viewerContext.getPageIndex()) {
                viewerContext.setPageIndex(anchorIndex.getPageIndex());
                viewerContext.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 = viewerContext.getPageIndex() + 1;
        if (hyperlink.getHyperlinkPage() != null) {
            page = hyperlink.getHyperlinkPage().intValue();
        }

        if (page >= 1 && page <= viewerContext.getJasperPrint().getPages().size()
                && page != viewerContext.getPageIndex() + 1) {
            viewerContext.setPageIndex(page - 1);
            viewerContext.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:net.sf.jasperreports.swing.JRViewerPanel.java

@Override
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.");
        }//from   w  w  w.  j  ava  2  s  .  c  o m
        break;
    }
    case LOCAL_ANCHOR: {
        if (hyperlink.getHyperlinkAnchor() != null) {
            Map<String, JRPrintAnchorIndex> anchorIndexes = viewerContext.getJasperPrint().getAnchorIndexes();
            JRPrintAnchorIndex anchorIndex = anchorIndexes.get(hyperlink.getHyperlinkAnchor());
            if (anchorIndex.getPageIndex() != viewerContext.getPageIndex()) {
                viewerContext.setPageIndex(anchorIndex.getPageIndex());
                viewerContext.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 = viewerContext.getPageIndex() + 1;
        if (hyperlink.getHyperlinkPage() != null) {
            page = hyperlink.getHyperlinkPage();
        }

        if (page >= 1 && page <= viewerContext.getJasperPrint().getPages().size()
                && page != viewerContext.getPageIndex() + 1) {
            viewerContext.setPageIndex(page - 1);
            viewerContext.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:cn.pholance.datamanager.common.components.JRViewer.java

void pnlLinksMouseDragged(MouseEvent evt) {//GEN-FIRST:event_pnlLinksMouseDragged
    // Add your handling code here:

    Container container = pnlInScroll.getParent();
    if (container instanceof JViewport) {
        JViewport viewport = (JViewport) container;
        Point point = viewport.getViewPosition();
        int newX = point.x - (evt.getX() - downX);
        int newY = point.y - (evt.getY() - downY);

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

        if (newX < 0) {
            newX = 0;//from   w w  w . j av  a2  s. c o m
        }
        if (newX > maxX) {
            newX = maxX;
        }
        if (newY < 0) {
            newY = 0;
        }
        if (newY > maxY) {
            newY = maxY;
        }

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

From source file:ireport_5_6_0.view.JRViewer.java

void pnlLinksMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pnlLinksMouseDragged
    // Add your handling code here:
    Container container = pnlInScroll.getParent();
    if (container instanceof JViewport) {
        JViewport viewport = (JViewport) container;
        Point point = viewport.getViewPosition();
        int newX = point.x - (evt.getX() - downX);
        int newY = point.y - (evt.getY() - downY);

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

        if (newX < 0) {
            newX = 0;//  ww  w. j  a  v a  2 s.  c  o m
        }
        if (newX > maxX) {
            newX = maxX;
        }
        if (newY < 0) {
            newY = 0;
        }
        if (newY > maxY) {
            newY = maxY;
        }

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

From source file:neg.JRViewer.java

/**
 *
 *///from   w w w. ja  v  a2  s  .com
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;
    }
    }
}