From: Jim Procter Date: Fri, 6 May 2016 14:03:24 +0000 (+0100) Subject: JAL-192 JAL-2099 factored out calculation from rendering code #2 X-Git-Tag: Release_2_10_0~227^2~2^2~5 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=b636f0007e76155876da1dd75310a4cb153815d7;p=jalview.git JAL-192 JAL-2099 factored out calculation from rendering code #2 --- 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; } }