From b79022c537bbad882b8a53c1014f5840432cd28e Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Fri, 6 May 2016 14:51:38 +0100 Subject: [PATCH] JAL-192 JAL-2099 factored out calculation from rendering code #1 --- src/jalview/gui/ScalePanel.java | 49 ++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/src/jalview/gui/ScalePanel.java b/src/jalview/gui/ScalePanel.java index 108bf24..14ce3fe 100755 --- a/src/jalview/gui/ScalePanel.java +++ b/src/jalview/gui/ScalePanel.java @@ -35,6 +35,8 @@ import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; +import java.util.ArrayList; +import java.util.List; import javax.swing.JMenuItem; import javax.swing.JPanel; @@ -549,12 +551,13 @@ public class ScalePanel extends JPanel implements MouseMotionListener, { scalestartx += 5; } - + List marks = new ArrayList(); String string; int maxX = 0, refN, iadj; // todo: add a 'reference origin column' to set column number relative to for (int i = scalestartx; i < endx; i += 5) { + Object[] amark = new Object[3]; if (((i - refSp) % 10) == 0) { if (refSeq == null) @@ -582,26 +585,44 @@ public class ScalePanel extends JPanel implements MouseMotionListener, string = String.valueOf(refN) + refSeq.getCharAt(iadj); } } - if ((i - startx - 1) * avCharWidth > maxX) + amark[0] = Boolean.TRUE; + amark[1] = Integer.valueOf(i - startx - 1); + amark[2] = string; + + } + else + { + amark[0] = Boolean.FALSE; + amark[1] = Integer.valueOf(i - startx - 1); + amark[2] = null; + } + marks.add(amark); + } + maxX=0; + for (Object[] mark : marks) + { + boolean major = Boolean.valueOf((Boolean) mark[0]); + int mpos = ((Integer) mark[1]).intValue(); // (i - startx - 1) + String mstring = (String) mark[2]; + if (mstring != null) + { + if (mpos * avCharWidth > maxX) { - gg.drawString(string, (i - startx - 1) * avCharWidth, y); - maxX = (i - startx + 1) * avCharWidth + fm.stringWidth(string); + gg.drawString(mstring, mpos * avCharWidth, y); + maxX = (mpos + 2) * avCharWidth + fm.stringWidth(mstring); } - - gg.drawLine(((i - startx - 1) * avCharWidth) + (avCharWidth / 2), - y + 2, - ((i - startx - 1) * avCharWidth) + (avCharWidth / 2), y - + (yOf * 2)); + } + if (major) + { + gg.drawLine((mpos * avCharWidth) + (avCharWidth / 2), y + 2, + (mpos * avCharWidth) + (avCharWidth / 2), y + (yOf * 2)); } else { - gg.drawLine(((i - startx - 1) * avCharWidth) + (avCharWidth / 2), y - + yOf, - ((i - startx - 1) * avCharWidth) + (avCharWidth / 2), y - + (yOf * 2)); + gg.drawLine((mpos * avCharWidth) + (avCharWidth / 2), y + yOf, + (mpos * avCharWidth) + (avCharWidth / 2), y + (yOf * 2)); } } - if (av.hasHiddenColumns()) { if (reveal != null && reveal[0] > startx && reveal[0] < endx) -- 1.7.10.2