X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FScalePanel.java;h=2165b2c143f42c6813751a822c9b9e3c42b3f53f;hb=f931c557266d95b3f4ab5b64bd108123c90e85ab;hp=b2c9a126e0dc3d06bda13f14051b1ea2924193cc;hpb=e2399fe0a610faf5dee11a68a8643c34e3ef2490;p=jalview.git diff --git a/src/jalview/gui/ScalePanel.java b/src/jalview/gui/ScalePanel.java index b2c9a12..2165b2c 100755 --- a/src/jalview/gui/ScalePanel.java +++ b/src/jalview/gui/ScalePanel.java @@ -35,25 +35,22 @@ import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; +import java.util.List; import javax.swing.JMenuItem; import javax.swing.JPanel; import javax.swing.JPopupMenu; -import javax.swing.SwingUtilities; import javax.swing.ToolTipManager; /** - * DOCUMENT ME! - * - * @author $author$ - * @version $Revision$ + * The panel containing the sequence ruler (when not in wrapped mode), and + * supports a range of mouse operations to select, hide or reveal columns. */ public class ScalePanel extends JPanel implements MouseMotionListener, MouseListener { protected int offy = 4; - /** DOCUMENT ME!! */ public int width; protected AlignViewport av; @@ -62,13 +59,26 @@ public class ScalePanel extends JPanel implements MouseMotionListener, boolean stretchingGroup = false; - int min; // used by mouseDragged to see if user + /* + * min, max hold the extent of a mouse drag action + */ + int min; - int max; // used by mouseDragged to see if user + int max; boolean mouseDragging = false; - // wants to delete columns + /* + * holds a hidden column range when the mouse is over an adjacent column + */ + int[] reveal; + + /** + * Constructor + * + * @param av + * @param ap + */ public ScalePanel(AlignViewport av, AlignmentPanel ap) { this.av = av; @@ -107,7 +117,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, min = res; max = res; - if (SwingUtilities.isRightMouseButton(evt)) + if (evt.isPopupTrigger()) { rightMouseButtonPressed(evt, res); } @@ -393,6 +403,8 @@ public class ScalePanel extends JPanel implements MouseMotionListener, @Override public void mouseMoved(MouseEvent evt) { + this.setToolTipText(null); + reveal = null; if (!av.hasHiddenColumns()) { return; @@ -402,7 +414,6 @@ public class ScalePanel extends JPanel implements MouseMotionListener, res = av.getColumnSelection().adjustForHiddenColumns(res); - reveal = null; if (av.getColumnSelection().getHiddenColumns() != null) { for (int[] region : av.getColumnSelection().getHiddenColumns()) @@ -415,17 +426,11 @@ public class ScalePanel extends JPanel implements MouseMotionListener, .getString("label.reveal_hidden_columns")); break; } - else - { - this.setToolTipText(null); - } } } repaint(); } - int[] reveal; - /** * DOCUMENT ME! * @@ -460,13 +465,15 @@ public class ScalePanel extends JPanel implements MouseMotionListener, ColumnSelection cs = av.getColumnSelection(); int avCharWidth = av.getCharWidth(), avCharHeight = av.getCharHeight(); - int s; if (cs != null) { gg.setColor(new Color(220, 0, 0)); for (int sel : cs.getSelected()) { + // TODO: JAL-2001 - provide a fast method to list visible selected in a + // given range + if (av.hasHiddenColumns()) { if (cs.isVisible(sel)) @@ -486,49 +493,15 @@ public class ScalePanel extends JPanel 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; - - for (int i = scalestartx; i < endx; i += 5) - { - if ((i % 10) == 0) - { - string = String.valueOf(av.getColumnSelection() - .adjustForHiddenColumns(i)); - if ((i - startx - 1) * avCharWidth > maxX) - { - gg.drawString(string, (i - startx - 1) * avCharWidth, y); - maxX = (i - startx + 1) * avCharWidth + fm.stringWidth(string); - } - - gg.drawLine(((i - startx - 1) * avCharWidth) + (avCharWidth / 2), - y + 2, - ((i - startx - 1) * avCharWidth) + (avCharWidth / 2), y - + (fm.getDescent() * 2)); - } - else - { - gg.drawLine(((i - startx - 1) * avCharWidth) + (avCharWidth / 2), y - + fm.getDescent(), ((i - startx - 1) * avCharWidth) - + (avCharWidth / 2), y + (fm.getDescent() * 2)); - } - } - + int y = avCharHeight, yOf = fm.getDescent(); + y -= yOf; if (av.hasHiddenColumns()) { + // draw any hidden column markers gg.setColor(Color.blue); int res; if (av.getShowHiddenMarkers() @@ -537,23 +510,55 @@ public class ScalePanel extends JPanel implements MouseMotionListener, for (int i = 0; i < av.getColumnSelection().getHiddenColumns() .size(); i++) { - res = av.getColumnSelection().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); } } + } + // Draw the scale numbers + gg.setColor(Color.black); + int maxX = 0; + List marks = jalview.renderer.ScaleRenderer.calculateMarks( + av, startx, endx); + + 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"), @@ -562,4 +567,5 @@ public class ScalePanel extends JPanel implements MouseMotionListener, } } + }