From b636f0007e76155876da1dd75310a4cb153815d7 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Fri, 6 May 2016 15:03:24 +0100 Subject: [PATCH] JAL-192 JAL-2099 factored out calculation from rendering code #2 --- src/jalview/gui/ScalePanel.java | 83 +++++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 34 deletions(-) diff --git a/src/jalview/gui/ScalePanel.java b/src/jalview/gui/ScalePanel.java index 14ce3fe..8a3138d 100755 --- a/src/jalview/gui/ScalePanel.java +++ b/src/jalview/gui/ScalePanel.java @@ -526,6 +526,54 @@ public class ScalePanel extends JPanel implements MouseMotionListener, // Draw the scale numbers gg.setColor(Color.black); + List marks = calculateMarks(startx, endx); + int 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(mstring, mpos * avCharWidth, y); + maxX = (mpos + 2) * avCharWidth + fm.stringWidth(mstring); + } + } + if (major) + { + gg.drawLine((mpos * avCharWidth) + (avCharWidth / 2), y + 2, + (mpos * avCharWidth) + (avCharWidth / 2), y + (yOf * 2)); + } + else + { + 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) + { + gg.drawString(MessageManager.getString("label.reveal_columns"), + reveal[0] * avCharWidth, 0); + } + } + + } + + /** + * calculate positions markers on the alignment ruler + * + * @return List { Object { .. } } Boolean: true/false for major/minor mark, + * Integer: marker position in alignment column coords, String: null + * or a String to be rendered at the position. + */ + public List calculateMarks(int startx, int endx) + { + new ArrayList(); + int scalestartx = (startx / 10) * 10; SequenceI refSeq = av.getAlignment().getSeqrep(); @@ -598,39 +646,6 @@ public class ScalePanel extends JPanel implements MouseMotionListener, } 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(mstring, mpos * avCharWidth, y); - maxX = (mpos + 2) * avCharWidth + fm.stringWidth(mstring); - } - } - if (major) - { - gg.drawLine((mpos * avCharWidth) + (avCharWidth / 2), y + 2, - (mpos * avCharWidth) + (avCharWidth / 2), y + (yOf * 2)); - } - else - { - 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) - { - gg.drawString(MessageManager.getString("label.reveal_columns"), - reveal[0] * avCharWidth, 0); - } - } - + return marks; } } -- 1.7.10.2