X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FScalePanel.java;h=d2c16931f3a95bbff81139331651f8c823a9b24d;hb=4d9ad51dc8a445c2f1fb02b997e13bd945fa8ad2;hp=3c6a4f146c0ba1f652efd462f55ecff3eb13cbeb;hpb=e2399fe0a610faf5dee11a68a8643c34e3ef2490;p=jalview.git diff --git a/src/jalview/appletgui/ScalePanel.java b/src/jalview/appletgui/ScalePanel.java index 3c6a4f1..d2c1693 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 @@ -406,61 +409,69 @@ 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(); - for (int sel : cs.getSelected()) + int avCharWidth = av.getCharWidth(); + int avcharHeight = av.getCharHeight(); + if (cs != null) { - if (av.hasHiddenColumns()) + gg.setColor(new Color(220, 0, 0)); + boolean hasHiddenColumns = cs.hasHiddenColumns(); + for (int sel : cs.getSelected()) { - sel = av.getColumnSelection().findColumnPosition(sel); - } + // TODO: JAL-2001 - provide a fast method to list visible selected in a + // given range + if (hasHiddenColumns) + { + if (cs.isVisible(sel)) + { + sel = cs.findColumnPosition(sel); + } + else + { + continue; + } + } - if ((sel >= startx) && (sel <= endx)) - { - gg.fillRect((sel - startx) * avcharWidth, 0, avcharWidth, - getSize().height); + if ((sel >= startx) && (sel <= endx)) + { + gg.fillRect((sel - startx) * avCharWidth, 0, avCharWidth, + getSize().height); + } } } // Draw the scale numbers gg.setColor(Color.black); - int scalestartx = (startx / 10) * 10; - - 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)); } } @@ -470,33 +481,25 @@ public class ScalePanel extends Panel implements MouseMotionListener, int res; if (av.getShowHiddenMarkers()) { - for (int i = 0; i < av.getColumnSelection().getHiddenColumns() - .size(); i++) + int widthx = 1 + endx - startx; + for (int i = 0; i < cs.getHiddenColumns().size(); i++) { - res = av.getColumnSelection().findHiddenRegionPosition(i) - - startx; + res = cs.findHiddenRegionPosition(i) - startx; - if (res < 0 || res > endx - scalestartx) + if (res < 0 || res > widthx) { 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); - } } - } }