X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAnnotationLabels.java;h=94f8790d2235cfafc1c9723c7163f9a248b4eb55;hb=ccc53e88e3260886f5d3bdacc619c0f374be9b8f;hp=255e1ff69ce8e56e551826564460f745efaacc35;hpb=744e4ade5413aa7e8006a8d4d29fdb718489bf08;p=jalview.git diff --git a/src/jalview/gui/AnnotationLabels.java b/src/jalview/gui/AnnotationLabels.java index 255e1ff..94f8790 100755 --- a/src/jalview/gui/AnnotationLabels.java +++ b/src/jalview/gui/AnnotationLabels.java @@ -88,7 +88,7 @@ public class AnnotationLabels extends JPanel /** * height in pixels for allowing height adjuster to be active */ - private static int HEIGHT_ADJUSTER_HEIGHT = 10; + public static int HEIGHT_ADJUSTER_HEIGHT = 10; private static final Font font = new Font("Arial", Font.PLAIN, 11); @@ -138,6 +138,8 @@ public class AnnotationLabels extends JPanel private int annotationIdWidth = -1; + public static final String RESIZE_MARGINS_MARK_PREF = "RESIZE_MARGINS_MARK"; + /** * Creates a new AnnotationLabels object * @@ -1110,7 +1112,7 @@ public class AnnotationLabels extends JPanel if (av.hasHiddenColumns()) { Iterator it = av.getAlignment().getHiddenColumns() - .getVisContigsIterator(0, sq.getLength(), false); + .getVisContigsIterator(0, sq.getLength() + 1, false); omitHidden = new String[] { sq.getSequenceStringFromIterator(it) }; } @@ -1166,8 +1168,7 @@ public class AnnotationLabels extends JPanel RenderingHints.VALUE_ANTIALIAS_ON); } - drawComponent(g2, true, width); - + drawComponent(g2, true, width, true); } /** @@ -1182,7 +1183,7 @@ public class AnnotationLabels extends JPanel */ public void drawComponent(Graphics g, int width) { - drawComponent(g, false, width); + drawComponent(g, false, width, true); } /** @@ -1197,7 +1198,8 @@ public class AnnotationLabels extends JPanel * @param width * Width for scaling labels */ - public void drawComponent(Graphics g, boolean clip, int givenWidth) + public void drawComponent(Graphics g, boolean clip, int givenWidth, + boolean forGUI) { int width = givenWidth; IdwidthAdjuster iwa = null; @@ -1210,7 +1212,7 @@ public class AnnotationLabels extends JPanel Graphics2D g2d = (Graphics2D) g; Graphics dummy = g2d.create(); int newAnnotationIdWidth = drawLabels(dummy, clip, width, false, - null); + forGUI, null, false); dummy.dispose(); Dimension d = ap.calculateDefaultAlignmentIdWidth(); int alignmentIdWidth = d.width; @@ -1244,13 +1246,12 @@ public class AnnotationLabels extends JPanel } else { - Graphics2D g2d = (Graphics2D) g; - Graphics dummy = g2d.create(); - int newAnnotationIdWidth = drawLabels(dummy, clip, width, false, - null); - width = Math.max(newAnnotationIdWidth, givenWidth); + int newAnnotationIdWidth = drawLabels(g, clip, width, false, forGUI, + null, false); + width = newAnnotationIdWidth < givenWidth ? givenWidth + : Math.min(newAnnotationIdWidth, givenWidth); } - drawLabels(g, clip, width, true, null); + drawLabels(g, clip, width, true, forGUI, null, false); } /** @@ -1259,26 +1260,49 @@ public class AnnotationLabels extends JPanel * occur, but the widest label width will be returned. If g is null then * fmetrics must be supplied. * - * Returns the width of the annotation labels. - * * @param g - * Graphics2D instance (needed for font scaling) + * Graphics2D instance (used for rendering and font scaling if no + * fmetrics supplied) * @param clip * - true indicates that only current visible area needs to be * rendered * @param width * Width for scaling labels + * @param actuallyDraw + * - when false, no graphics are rendered to g0 + * @param forGUI + * - when false, GUI relevant marks like indicators for dragging + * annotation panel height are not rendered * @param fmetrics * FontMetrics if Graphics object g is null + * @param includeHidden + * - when true returned width includes labels in hidden row width + * calculation + * @return the width of the annotation labels. */ - public int drawLabels(Graphics g, boolean clip, int width, - boolean actuallyDraw, FontMetrics fmetrics) + public int drawLabels(Graphics g0, boolean clip, int width, + boolean actuallyDraw, boolean forGUI, FontMetrics fmetrics, + boolean includeHidden) { if (clip) { clip = Cache.getDefault("MOVE_SEQUENCE_ID_WITH_VISIBLE_ANNOTATIONS", true); } + Graphics g = null; + // create a dummy Graphics object if not drawing and one is supplied + if (g0 != null) + { + if (!actuallyDraw) + { + Graphics2D g2d = (Graphics2D) g0; + g = g2d.create(); + } + else + { + g = g0; + } + } int actualWidth = 0; if (g != null) { @@ -1298,6 +1322,17 @@ public class AnnotationLabels extends JPanel { g.setColor(Color.white); g.fillRect(0, 0, getWidth(), getHeight()); + + if (!Cache.getDefault(RESIZE_MARGINS_MARK_PREF, false) + && !av.getWrapAlignment() && forGUI) + { + g.setColor(Color.LIGHT_GRAY); + g.drawLine(0, HEIGHT_ADJUSTER_HEIGHT / 4, HEIGHT_ADJUSTER_WIDTH / 4, + HEIGHT_ADJUSTER_HEIGHT / 4); + g.drawLine(0, 3 * HEIGHT_ADJUSTER_HEIGHT / 4, + HEIGHT_ADJUSTER_WIDTH / 4, 3 * HEIGHT_ADJUSTER_HEIGHT / 4); + + } } if (actuallyDraw) @@ -1336,7 +1371,7 @@ public class AnnotationLabels extends JPanel for (int i = 0; i < aa.length; i++) { visible = true; - if (!aa[i].visible) + if (!aa[i].visible && !includeHidden) { hasHiddenRows = true; continue; @@ -1344,7 +1379,7 @@ public class AnnotationLabels extends JPanel olY = y; // look ahead to next annotation for (nexAA = i + 1; nexAA < aa.length - && !aa[nexAA].visible; nexAA++) + && (!aa[nexAA].visible && includeHidden); nexAA++) ; y += aa[i].height; if (clip) @@ -1355,7 +1390,7 @@ public class AnnotationLabels extends JPanel { if (debugRedraw) { - System.out.println("before vis: " + i); + jalview.bin.Console.outPrintln("before vis: " + i); } before = true; } @@ -1369,7 +1404,7 @@ public class AnnotationLabels extends JPanel { if (debugRedraw) { - System.out.println( + jalview.bin.Console.outPrintln( "Scroll offset: " + sOffset + " after vis: " + i); } after = true; @@ -1529,7 +1564,8 @@ public class AnnotationLabels extends JPanel } } - if (!resizePanel && dragEvent != null && aa != null) + if (!resizePanel && dragEvent != null && aa != null && selectedRow > -1 + && selectedRow < aa.length) { if (actuallyDraw && g != null) { @@ -1564,4 +1600,9 @@ public class AnnotationLabels extends JPanel public void mouseEntered(MouseEvent e) { } + + public void drawComponentNotGUI(Graphics idGraphics, int idWidth) + { + drawComponent(idGraphics, false, idWidth, false); + } }