From f38aa05c9798d0dd2ddc70833001c55a3fd5b612 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Mon, 18 Jul 2016 16:36:44 +0100 Subject: [PATCH] JAL-2099 JAL-2100 port scale number / hidden column mark changes to applet --- src/jalview/appletgui/ScalePanel.java | 75 ++++++++++++++----------------- src/jalview/appletgui/SeqCanvas.java | 36 ++++++++------- src/jalview/gui/ScalePanel.java | 27 +++++------ src/jalview/gui/SeqCanvas.java | 12 ++--- src/jalview/renderer/ScaleRenderer.java | 39 +++++++++------- 5 files changed, 94 insertions(+), 95 deletions(-) diff --git a/src/jalview/appletgui/ScalePanel.java b/src/jalview/appletgui/ScalePanel.java index 71ecb13..0f71818 100755 --- a/src/jalview/appletgui/ScalePanel.java +++ b/src/jalview/appletgui/ScalePanel.java @@ -22,6 +22,8 @@ package jalview.appletgui; import jalview.datamodel.ColumnSelection; import jalview.datamodel.SequenceGroup; +import jalview.renderer.ScaleRenderer; +import jalview.renderer.ScaleRenderer.ScaleMark; import jalview.util.MessageManager; import java.awt.Color; @@ -36,6 +38,7 @@ import java.awt.event.InputEvent; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; +import java.util.List; public class ScalePanel extends Panel implements MouseMotionListener, MouseListener @@ -407,7 +410,8 @@ public class ScalePanel extends Panel implements MouseMotionListener, // Fill the selected columns ColumnSelection cs = av.getColumnSelection(); gg.setColor(new Color(220, 0, 0)); - int avcharWidth = av.getCharWidth(), avcharHeight = av.getCharHeight(); + int avCharWidth = av.getCharWidth(); + int avcharHeight = av.getCharHeight(); for (int sel : cs.getSelected()) { // TODO: JAL-2001 - provide a fast method to list visible selected in a @@ -419,7 +423,7 @@ public class ScalePanel extends Panel implements MouseMotionListener, if ((sel >= startx) && (sel <= endx)) { - gg.fillRect((sel - startx) * avcharWidth, 0, avcharWidth, + gg.fillRect((sel - startx) * avCharWidth, 0, avCharWidth, getSize().height); } } @@ -427,43 +431,36 @@ public class ScalePanel extends Panel implements MouseMotionListener, // Draw the scale numbers gg.setColor(Color.black); - int scalestartx = (startx / 10) * 10; - int widthx = 1 + endx - startx; - - FontMetrics fm = gg.getFontMetrics(av.getFont()); - int y = avcharHeight - fm.getDescent(); - - if ((scalestartx % 10) == 0) - { - scalestartx += 5; - } - - String string; int maxX = 0; + List marks = new ScaleRenderer().calculateMarks(av, startx, + endx); - for (int i = scalestartx; i < endx; i += 5) + FontMetrics fm = gg.getFontMetrics(av.getFont()); + int y = avcharHeight; + int yOf = fm.getDescent(); + y -= yOf; + for (ScaleMark mark : marks) { - if ((i % 10) == 0) + boolean major = mark.major; + int mpos = mark.column; // (i - startx - 1) + String mstring = mark.text; + if (mstring != null) { - string = String.valueOf(av.getColumnSelection() - .adjustForHiddenColumns(i)); - if ((i - startx - 1) * avcharWidth > maxX) + 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 - + (fm.getDescent() * 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 - + fm.getDescent(), ((i - startx - 1) * avcharWidth) - + (avcharWidth / 2), y + (fm.getDescent() * 2)); + gg.drawLine((mpos * avCharWidth) + (avCharWidth / 2), y + yOf, + (mpos * avCharWidth) + (avCharWidth / 2), y + (yOf * 2)); } } @@ -473,6 +470,7 @@ public class ScalePanel extends Panel implements MouseMotionListener, int res; if (av.getShowHiddenMarkers()) { + int widthx = 1 + endx - startx; for (int i = 0; i < av.getColumnSelection().getHiddenColumns() .size(); i++) { @@ -485,21 +483,14 @@ public class ScalePanel extends Panel implements MouseMotionListener, continue; } - gg.fillPolygon(new int[] { res * avcharWidth - avcharHeight / 4, - res * avcharWidth + avcharHeight / 4, res * avcharWidth }, - new int[] { y - avcharHeight / 2, y - avcharHeight / 2, - y + 8 }, 3); - + gg.fillPolygon(new int[] { + -1 + res * avCharWidth - avcharHeight / 4, + -1 + res * avCharWidth + avcharHeight / 4, + -1 + res * avCharWidth }, + new int[] { y, y, y + 2 * yOf }, 3); } } - - if (reveal != null && reveal[0] > startx && reveal[0] < endx) - { - gg.drawString(MessageManager.getString("label.reveal_columns"), - reveal[0] * avcharWidth, 0); - } } - } } diff --git a/src/jalview/appletgui/SeqCanvas.java b/src/jalview/appletgui/SeqCanvas.java index 024fdc7..22849f1 100755 --- a/src/jalview/appletgui/SeqCanvas.java +++ b/src/jalview/appletgui/SeqCanvas.java @@ -24,6 +24,8 @@ import jalview.datamodel.AlignmentI; import jalview.datamodel.SearchResults; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; +import jalview.renderer.ScaleRenderer; +import jalview.renderer.ScaleRenderer.ScaleMark; import jalview.viewmodel.AlignmentViewport; import java.awt.Color; @@ -90,26 +92,30 @@ public class SeqCanvas extends Panel private void drawNorthScale(Graphics g, int startx, int endx, int ypos) { - int scalestartx = startx - startx % 10 + 10; - + updateViewport(); g.setColor(Color.black); - - // NORTH SCALE - for (int i = scalestartx; i < endx; i += 10) + for (ScaleMark mark : new ScaleRenderer().calculateMarks(av, startx, + endx)) { - int value = i; - if (av.hasHiddenColumns()) + int mpos = mark.column; // (i - startx - 1) + if (mpos < 0) { - value = av.getColumnSelection().adjustForHiddenColumns(value); + continue; } + String mstring = mark.text; - g.drawString(String.valueOf(value), (i - startx - 1) * avcharWidth, - ypos - (avcharHeight / 2)); - - g.drawLine(((i - startx - 1) * avcharWidth) + (avcharWidth / 2), - (ypos + 2) - (avcharHeight / 2), - ((i - startx - 1) * avcharWidth) + (avcharWidth / 2), - ypos - 2); + if (mark.major) + { + if (mstring != null) + { + g.drawString(mstring, mpos * avcharWidth, ypos + - (avcharHeight / 2)); + } + g.drawLine((mpos * avcharWidth) + (avcharWidth / 2), (ypos + 2) + - (avcharHeight / 2), (mpos * avcharWidth) + + (avcharWidth / 2), + ypos - 2); + } } } diff --git a/src/jalview/gui/ScalePanel.java b/src/jalview/gui/ScalePanel.java index 2165b2c..e231c6f 100755 --- a/src/jalview/gui/ScalePanel.java +++ b/src/jalview/gui/ScalePanel.java @@ -23,6 +23,8 @@ package jalview.gui; import jalview.datamodel.ColumnSelection; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; +import jalview.renderer.ScaleRenderer; +import jalview.renderer.ScaleRenderer.ScaleMark; import jalview.util.MessageManager; import java.awt.Color; @@ -497,7 +499,8 @@ public class ScalePanel extends JPanel implements MouseMotionListener, int widthx = 1 + endx - startx; FontMetrics fm = gg.getFontMetrics(av.getFont()); - int y = avCharHeight, yOf = fm.getDescent(); + int y = avCharHeight; + int yOf = fm.getDescent(); y -= yOf; if (av.hasHiddenColumns()) { @@ -522,7 +525,6 @@ public class ScalePanel extends JPanel implements MouseMotionListener, -1 + res * avCharWidth - avCharHeight / 4, -1 + res * avCharWidth + avCharHeight / 4, -1 + res * avCharWidth }, new int[] { y, y, y + 2 * yOf }, 3); - } } } @@ -530,14 +532,14 @@ public class ScalePanel extends JPanel implements MouseMotionListener, gg.setColor(Color.black); int maxX = 0; - List marks = jalview.renderer.ScaleRenderer.calculateMarks( - av, startx, endx); + List marks = new ScaleRenderer().calculateMarks(av, startx, + endx); - for (Object[] mark : marks) + for (ScaleMark mark : marks) { - boolean major = Boolean.valueOf((Boolean) mark[0]); - int mpos = ((Integer) mark[1]).intValue(); // (i - startx - 1) - String mstring = (String) mark[2]; + boolean major = mark.major; + int mpos = mark.column; // (i - startx - 1) + String mstring = mark.text; if (mstring != null) { if (mpos * avCharWidth > maxX) @@ -557,15 +559,6 @@ public class ScalePanel extends JPanel implements MouseMotionListener, (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); - } - } - } } diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index 2f7cd76..760ece0 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -24,6 +24,8 @@ import jalview.datamodel.AlignmentI; import jalview.datamodel.SearchResults; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; +import jalview.renderer.ScaleRenderer; +import jalview.renderer.ScaleRenderer.ScaleMark; import java.awt.BasicStroke; import java.awt.BorderLayout; @@ -122,17 +124,17 @@ public class SeqCanvas extends JComponent private void drawNorthScale(Graphics g, int startx, int endx, int ypos) { updateViewport(); - for (Object[] mark : jalview.renderer.ScaleRenderer.calculateMarks(av, - startx, endx)) + for (ScaleMark mark : new ScaleRenderer().calculateMarks(av, startx, + endx)) { - int mpos = ((Integer) mark[1]).intValue(); // (i - startx - 1) + int mpos = mark.column; // (i - startx - 1) if (mpos < 0) { continue; } - String mstring = (String) mark[2]; + String mstring = mark.text; - if (Boolean.valueOf((Boolean) mark[0])) + if (mark.major) { if (mstring != null) { diff --git a/src/jalview/renderer/ScaleRenderer.java b/src/jalview/renderer/ScaleRenderer.java index 7f1e074..164c7c7 100644 --- a/src/jalview/renderer/ScaleRenderer.java +++ b/src/jalview/renderer/ScaleRenderer.java @@ -34,6 +34,22 @@ import java.util.List; */ public class ScaleRenderer { + public class ScaleMark + { + public final boolean major; + + public final int column; + + public final String text; + + ScaleMark(boolean isMajor, int col, String txt) + { + major = isMajor; + column = col; + text = txt; + } + } + /** * calculate positions markers on the alignment ruler * @@ -42,15 +58,13 @@ public class ScaleRenderer * left-most column in visible view * @param endx * - right-most column in visible view - * @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. + * @return List of ScaleMark holding boolean: true/false for major/minor mark, + * marker position in alignment column coords, a String to be rendered + * at the position (or null) */ - public static List calculateMarks(AlignViewportI av, + public List calculateMarks(AlignViewportI av, int startx, int endx) { - new ArrayList(); - int scalestartx = (startx / 10) * 10; SequenceI refSeq = av.getAlignment().getSeqrep(); @@ -72,13 +86,12 @@ public class ScaleRenderer { scalestartx += 5; } - List marks = new ArrayList(); + List marks = new ArrayList(); String string; int 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) @@ -106,18 +119,12 @@ public class ScaleRenderer string = String.valueOf(refN) + refSeq.getCharAt(iadj); } } - amark[0] = Boolean.TRUE; - amark[1] = Integer.valueOf(i - startx - 1); - amark[2] = string; - + marks.add(new ScaleMark(true, i - startx - 1, string)); } else { - amark[0] = Boolean.FALSE; - amark[1] = Integer.valueOf(i - startx - 1); - amark[2] = null; + marks.add(new ScaleMark(false, i - startx - 1, null)); } - marks.add(amark); } return marks; } -- 1.7.10.2