001package org.biojava.bio.gui.sequence; 002 003import java.awt.Graphics2D; 004import java.awt.geom.Point2D; 005import java.awt.geom.Rectangle2D; 006 007import org.biojava.bio.symbol.Location; 008import org.biojava.bio.symbol.RangeLocation; 009 010/** 011 * 012 * 013 * @author Matthew Pocock 014 * @author Kalle Näslund 015 * @since 1.4 016 */ 017public final class GUITools { 018 private GUITools() {} 019 020 public static Location getVisibleRange(SequenceRenderContext src, Graphics2D g2) { 021 Rectangle2D clip = g2.getClipBounds(); 022 023 int min = Math.max( 024 src.getRange().getMin(), 025 src.graphicsToSequence( 026 new Point2D.Double(clip.getMinX(), clip.getMinY()) 027 ) - 1 ); 028 029 int max = Math.min( 030 src.getRange().getMax(), 031 src.graphicsToSequence( 032 new Point2D.Double(clip.getMaxX(), clip.getMaxY()) 033 ) + 1 ); 034 035 // this happens when the clip region doesnt overlap with the SymbolList range 036 if( min > max ) { 037 return Location.empty; 038 } 039 else { 040 return new RangeLocation(min, max); 041 } 042 } 043 044 public static Rectangle2D createOuterBounds(CircularRendererContext crc, 045 double depth) 046 { 047 // do we need some extra data in crc to deal with origins not at 0? 048 double outer = crc.getRadius() + depth; 049 050 return new Rectangle2D.Double(-outer, -outer, 2.0 * outer, 2.0 * outer); 051 } 052 053 public static Rectangle2D createInnerBounds(CircularRendererContext crc) { 054 // do we need some extra data in crc to deal with origins not at 0? 055 double outer = crc.getRadius(); 056 057 return new Rectangle2D.Double(-outer, -outer, 2.0 * outer, 2.0 * outer); 058 } 059}