List of usage examples for javax.swing JViewport setViewPosition
public void setViewPosition(Point p)
From source file:edu.purdue.cc.bionet.ui.HeatMap.java
/** * Scales to the given zoom level, 1.0 being 100%, centered on the * given point./*www. j a v a 2 s . com*/ * * @param level The level to zoom to. * @param center The center point for the scaling operation. * @return The new zoom level. */ public float scaleTo(float level, Point2D center) { float oldZoom = this.currentZoom; this.currentZoom = Math.max(level, 0.99f); Dimension viewSize; if (level < 1.0f) { viewSize = this.scrollPane.getSize(); } else { viewSize = this.scrollPane.getViewport().getExtentSize(); } Dimension newSize = new Dimension((int) (viewSize.width * currentZoom), (int) (viewSize.height * currentZoom)); this.setPreferredSize(newSize); this.setSize(newSize); // translate the new view position so the mouse is in the same place // on the scaled view. JViewport vp = this.scrollPane.getViewport(); double centerX = center.getX(); double centerY = center.getY(); double viewPortMouseX = centerX - vp.getViewPosition().getX(); double viewPortMouseY = centerY - vp.getViewPosition().getY(); centerX *= currentZoom / oldZoom; centerY *= currentZoom / oldZoom; viewPortMouseX = centerX - viewPortMouseX; viewPortMouseY = centerY - viewPortMouseY; vp.setViewPosition(new Point((int) viewPortMouseX, (int) viewPortMouseY)); return this.currentZoom; }
From source file:de.codesourcery.jasm16.utils.ASTInspector.java
public void centerCurrentLineInScrollPane() { final Container container = SwingUtilities.getAncestorOfClass(JViewport.class, editorPane); if (container == null) { return;//www . j a v a2s. c om } try { final Rectangle r = editorPane.modelToView(editorPane.getCaretPosition()); final JViewport viewport = (JViewport) container; final int extentHeight = viewport.getExtentSize().height; final int viewHeight = viewport.getViewSize().height; int y = Math.max(0, r.y - (extentHeight / 2)); y = Math.min(y, viewHeight - extentHeight); viewport.setViewPosition(new Point(0, y)); } catch (BadLocationException ble) { } }
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 w ww. j a va2 s. com*/ } if (newX > maxX) { newX = maxX; } if (newY < 0) { newY = 0; } if (newY > maxY) { newY = maxY; } viewport.setViewPosition(new Point(newX, newY)); } }
From source file:edu.purdue.cc.bionet.ui.GraphVisualizer.java
/** * Scales to the given zoom level, 1.0 being 100%, centered on the * given point./* w w w.j a v a 2 s .c o m*/ * * @param level The level to zoom to. * @param center The center point for the scaling operation. * @return The new zoom level. */ public float scaleTo(float level, Point2D center) { if (this.scrollPane == null) return 1.0f; float oldZoom = this.currentZoom; this.currentZoom = Math.max(minimumZoom, level); // this.absoluteViewScaler.scale( this, level, center ); Dimension viewSize; if (level < 1.0f) { viewSize = this.scrollPane.getSize(); } else { viewSize = this.scrollPane.getViewport().getExtentSize(); } Dimension newSize = new Dimension((int) (viewSize.width * currentZoom), (int) (viewSize.height * currentZoom)); this.setPreferredSize(newSize); this.setSize(newSize); // new LayoutScaler( this.getGraphLayout( )).setSize( newSize ); if (Float.compare(level, 1.0f) <= 0) this.center(); // translate the new view position so the mouse is in the same place // on the scaled view. JViewport vp = this.scrollPane.getViewport(); double centerX = center.getX(); double centerY = center.getY(); double viewPortMouseX = centerX - vp.getViewPosition().getX(); double viewPortMouseY = centerY - vp.getViewPosition().getY(); centerX *= currentZoom / oldZoom; centerY *= currentZoom / oldZoom; viewPortMouseX = centerX - viewPortMouseX; viewPortMouseY = centerY - viewPortMouseY; vp.setViewPosition(new Point((int) viewPortMouseX, (int) viewPortMouseY)); return this.currentZoom; }
From source file:com.floreantpos.jasperreport.swing.JRViewerPanel.java
/** * *//*from w ww .j av a 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 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 ww w.ja va 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:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java
private void dragAndScroll(MouseEvent e) { // move view if near borders Point point = e.getPoint();//from w w w. ja va 2 s.c o m JViewport view = theScrollPane.getViewport(); Rectangle inner = view.getViewRect(); inner.grow(-10, -10); if (!inner.contains(point)) { Point orig = view.getViewPosition(); if (point.x < inner.x) orig.x -= 10; else if (point.x > (inner.x + inner.width)) orig.x += 10; if (point.y < inner.y) orig.y -= 10; else if (point.y > (inner.y + inner.height)) orig.y += 10; int maxx = getBounds().width - view.getViewRect().width; int maxy = getBounds().height - view.getViewRect().height; if (orig.x < 0) orig.x = 0; if (orig.x > maxx) orig.x = maxx; if (orig.y < 0) orig.y = 0; if (orig.y > maxy) orig.y = maxy; view.setViewPosition(orig); } }
From source file:de.codesourcery.jasm16.ide.ui.views.SourceCodeView.java
public final void centerCurrentLineInScrollPane() { final Runnable r = new Runnable() { @Override/*from w ww. ja v a2 s .c o m*/ public void run() { final Container container = SwingUtilities.getAncestorOfClass(JViewport.class, editorPane); if (container == null) { return; } try { final Rectangle r = editorPane.modelToView(editorPane.getCaretPosition()); if (r == null) { return; } final JViewport viewport = (JViewport) container; final int extentHeight = viewport.getExtentSize().height; final int viewHeight = viewport.getViewSize().height; int y = Math.max(0, r.y - (extentHeight / 2)); y = Math.min(y, viewHeight - extentHeight); viewport.setViewPosition(new Point(0, y)); } catch (BadLocationException ble) { LOG.error("centerCurrentLineInScrollPane(): ", ble); } } }; UIUtils.invokeLater(r); }
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 a v a 2s . co 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;/*from w ww.j av a 2 s .com*/ } if (newX > maxX) { newX = maxX; } if (newY < 0) { newY = 0; } if (newY > maxY) { newY = maxY; } viewport.setViewPosition(new Point(newX, newY)); } }