X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Fjalview%2Fgui%2FScalePanel.java;h=aedb15790680f89c891aa79e49da177313936e54;hb=2303177fbc4c86e4a63c1e8efa8c8bc50516b6a5;hp=c70f3c16cc9c767676da378cfc0192537f6bdec5;hpb=d053a3c980cf4318b9a19a255f9fc870e74de989;p=jalview.git
diff --git a/src/jalview/gui/ScalePanel.java b/src/jalview/gui/ScalePanel.java
index c70f3c1..aedb157 100755
--- a/src/jalview/gui/ScalePanel.java
+++ b/src/jalview/gui/ScalePanel.java
@@ -1,27 +1,45 @@
/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
- * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
*
* This file is part of Jalview.
*
* Jalview is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
- *
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
* Jalview is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License along with Jalview. If not, see .
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
*/
package jalview.gui;
-import java.awt.*;
-import java.awt.event.*;
-import javax.swing.*;
-
-import jalview.datamodel.*;
+import jalview.datamodel.ColumnSelection;
+import jalview.datamodel.SequenceGroup;
+import jalview.datamodel.SequenceI;
+import jalview.util.MessageManager;
+
+import java.awt.Color;
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseMotionListener;
+
+import javax.swing.JMenuItem;
+import javax.swing.JPanel;
+import javax.swing.JPopupMenu;
+import javax.swing.ToolTipManager;
/**
* DOCUMENT ME!
@@ -65,6 +83,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
* @param evt
* DOCUMENT ME!
*/
+ @Override
public void mousePressed(MouseEvent evt)
{
int x = (evt.getX() / av.getCharWidth()) + av.getStartRes();
@@ -87,108 +106,138 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
min = res;
max = res;
- if (SwingUtilities.isRightMouseButton(evt))
+ if (evt.isPopupTrigger())
+ {
+ rightMouseButtonPressed(evt, res);
+ }
+ else
+ {
+ leftMouseButtonPressed(evt, res);
+ }
+ }
+
+ /**
+ * Handles right mouse button press. If pressed in a selected column, opens
+ * context menu for 'Hide Columns'. If pressed on a hidden columns marker,
+ * opens context menu for 'Reveal / Reveal All'. Else does nothing.
+ *
+ * @param evt
+ * @param res
+ */
+ protected void rightMouseButtonPressed(MouseEvent evt, final int res)
+ {
+ JPopupMenu pop = new JPopupMenu();
+ if (reveal != null)
{
- JPopupMenu pop = new JPopupMenu();
- if (reveal != null)
+ JMenuItem item = new JMenuItem(
+ MessageManager.getString("label.reveal"));
+ item.addActionListener(new ActionListener()
{
- JMenuItem item = new JMenuItem("Reveal");
- item.addActionListener(new ActionListener()
+ @Override
+ public void actionPerformed(ActionEvent e)
{
- public void actionPerformed(ActionEvent e)
+ av.showColumn(reveal[0]);
+ reveal = null;
+ ap.paintAlignment(true);
+ if (ap.overviewPanel != null)
{
- av.showColumn(reveal[0]);
- reveal = null;
- ap.paintAlignment(true);
- if (ap.overviewPanel != null)
- {
- ap.overviewPanel.updateOverviewImage();
- }
+ ap.overviewPanel.updateOverviewImage();
}
- });
- pop.add(item);
-
- if (av.getColumnSelection().getHiddenColumns().size() > 1)
- {
- item = new JMenuItem("Reveal All");
- item.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- av.showAllHiddenColumns();
- reveal = null;
- ap.paintAlignment(true);
- if (ap.overviewPanel != null)
- {
- ap.overviewPanel.updateOverviewImage();
- }
- }
- });
- pop.add(item);
+ av.sendSelection();
}
- pop.show(this, evt.getX(), evt.getY());
- }
- else if (av.getColumnSelection().contains(res))
+ });
+ pop.add(item);
+
+ if (av.getColumnSelection().hasHiddenColumns())
{
- JMenuItem item = new JMenuItem("Hide Columns");
+ item = new JMenuItem(MessageManager.getString("action.reveal_all"));
item.addActionListener(new ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
- av.hideColumns(res, res);
- if (av.getSelectionGroup() != null
- && av.getSelectionGroup().getSize() == av.getAlignment()
- .getHeight())
- {
- av.setSelectionGroup(null);
- }
-
+ av.showAllHiddenColumns();
+ reveal = null;
ap.paintAlignment(true);
if (ap.overviewPanel != null)
{
ap.overviewPanel.updateOverviewImage();
}
+ av.sendSelection();
}
});
pop.add(item);
- pop.show(this, evt.getX(), evt.getY());
}
+ pop.show(this, evt.getX(), evt.getY());
}
- else
- // LEFT MOUSE TO SELECT
+ else if (av.getColumnSelection().contains(res))
{
- if (!evt.isControlDown() && !evt.isShiftDown())
+ JMenuItem item = new JMenuItem(
+ MessageManager.getString("label.hide_columns"));
+ item.addActionListener(new ActionListener()
{
- av.getColumnSelection().clear();
- }
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ av.hideColumns(res, res);
+ if (av.getSelectionGroup() != null
+ && av.getSelectionGroup().getSize() == av.getAlignment()
+ .getHeight())
+ {
+ av.setSelectionGroup(null);
+ }
- av.getColumnSelection().addElement(res);
- SequenceGroup sg = new SequenceGroup();
- // try to be as quick as possible
- SequenceI[] iVec = av.getAlignment().getSequencesArray();
- for (int i = 0; i < iVec.length; i++)
- {
- sg.addSequence(iVec[i], false);
- iVec[i] = null;
- }
- iVec = null;
- sg.setStartRes(res);
- sg.setEndRes(res);
+ ap.paintAlignment(true);
+ if (ap.overviewPanel != null)
+ {
+ ap.overviewPanel.updateOverviewImage();
+ }
+ av.sendSelection();
+ }
+ });
+ pop.add(item);
+ pop.show(this, evt.getX(), evt.getY());
+ }
+ }
- if (evt.isShiftDown())
+ /**
+ * Handles left mouse button press
+ *
+ * @param evt
+ * @param res
+ */
+ protected void leftMouseButtonPressed(MouseEvent evt, final int res)
+ {
+ if (!evt.isControlDown() && !evt.isShiftDown())
+ {
+ av.getColumnSelection().clear();
+ }
+
+ av.getColumnSelection().addElement(res);
+ SequenceGroup sg = new SequenceGroup();
+ // try to be as quick as possible
+ SequenceI[] iVec = av.getAlignment().getSequencesArray();
+ for (int i = 0; i < iVec.length; i++)
+ {
+ sg.addSequence(iVec[i], false);
+ iVec[i] = null;
+ }
+ iVec = null;
+ sg.setStartRes(res);
+ sg.setEndRes(res);
+
+ if (evt.isShiftDown())
+ {
+ int min = Math.min(av.getColumnSelection().getMin(), res);
+ int max = Math.max(av.getColumnSelection().getMax(), res);
+ for (int i = min; i < max; i++)
{
- int min = Math.min(av.getColumnSelection().getMin(), res);
- int max = Math.max(av.getColumnSelection().getMax(), res);
- for (int i = min; i < max; i++)
- {
- av.getColumnSelection().addElement(i);
- }
- sg.setStartRes(min);
- sg.setEndRes(max);
+ av.getColumnSelection().addElement(i);
}
- av.setSelectionGroup(sg);
+ sg.setStartRes(min);
+ sg.setEndRes(max);
}
-
+ av.setSelectionGroup(sg);
ap.paintAlignment(false);
av.sendSelection();
}
@@ -199,6 +248,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
* @param evt
* DOCUMENT ME!
*/
+ @Override
public void mouseReleased(MouseEvent evt)
{
mouseDragging = false;
@@ -246,6 +296,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
* @param evt
* DOCUMENT ME!
*/
+ @Override
public void mouseDragged(MouseEvent evt)
{
mouseDragging = true;
@@ -315,26 +366,30 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
}
}
+ @Override
public void mouseEntered(MouseEvent evt)
{
if (mouseDragging)
{
- ap.seqPanel.scrollCanvas(null);
+ ap.getSeqPanel().scrollCanvas(null);
}
}
+ @Override
public void mouseExited(MouseEvent evt)
{
if (mouseDragging)
{
- ap.seqPanel.scrollCanvas(evt);
+ ap.getSeqPanel().scrollCanvas(evt);
}
}
+ @Override
public void mouseClicked(MouseEvent evt)
{
}
+ @Override
public void mouseMoved(MouseEvent evt)
{
if (!av.hasHiddenColumns())
@@ -347,24 +402,24 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
res = av.getColumnSelection().adjustForHiddenColumns(res);
reveal = null;
- for (int i = 0; i < av.getColumnSelection().getHiddenColumns().size(); i++)
+ if (av.getColumnSelection().getHiddenColumns() != null)
{
- int[] region = (int[]) av.getColumnSelection().getHiddenColumns()
- .elementAt(i);
- if (res + 1 == region[0] || res - 1 == region[1])
- {
- reveal = region;
- ToolTipManager.sharedInstance().registerComponent(this);
- this.setToolTipText("Reveal Hidden Columns with Right Mouse Button");
- break;
- }
- else
+ for (int[] region : av.getColumnSelection().getHiddenColumns())
{
- this.setToolTipText(null);
+ if (res + 1 == region[0] || res - 1 == region[1])
+ {
+ reveal = region;
+ ToolTipManager.sharedInstance().registerComponent(this);
+ this.setToolTipText(MessageManager
+ .getString("label.reveal_hidden_columns"));
+ break;
+ }
+ else
+ {
+ this.setToolTipText(null);
+ }
}
-
}
-
repaint();
}
@@ -376,6 +431,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
* @param g
* DOCUMENT ME!
*/
+ @Override
public void paintComponent(Graphics g)
{
drawScale(g, av.getStartRes(), av.getEndRes(), getWidth(), getHeight());
@@ -401,14 +457,18 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
// Fill the selected columns
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 i = 0; i < cs.size(); i++)
+ for (int sel : cs.getSelected())
{
- int sel = cs.columnAt(i);
+ // TODO: JAL-2001 - provide a fast method to list visible selected in a
+ // given range
+
if (av.hasHiddenColumns())
{
if (cs.isVisible(sel))
@@ -423,7 +483,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
if ((sel >= startx) && (sel <= endx))
{
- gg.fillRect((sel - startx) * av.charWidth, 0, av.charWidth,
+ gg.fillRect((sel - startx) * avCharWidth, 0, avCharWidth,
getHeight());
}
}
@@ -433,43 +493,82 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
int scalestartx = (startx / 10) * 10;
+ SequenceI refSeq = av.getAlignment().getSeqrep();
+ int refSp = 0, refEp = -1, refStart = 0, refEnd = -1, refStartI = 0, refEndI = -1;
+ if (refSeq != null)
+ {
+ // find bounds and set origin appopriately
+ // locate first visible position for this sequence
+ int[] refbounds = av.getColumnSelection()
+ .locateVisibleBoundsOfSequence(refSeq);
+
+ refSp = refbounds[0];
+ refEp = refbounds[1];
+ refStart = refbounds[2];
+ refEnd = refbounds[3];
+ refStartI = refbounds[4];
+ refEndI = refbounds[5];
+ scalestartx = refSp + ((scalestartx - refSp) / 10) * 10;
+ }
+
+
+ int widthx = 1 + endx - startx;
+
FontMetrics fm = gg.getFontMetrics(av.getFont());
- int y = av.charHeight - fm.getDescent();
+ int y = avCharHeight - fm.getDescent();
- if ((scalestartx % 10) == 0)
+ if (refSeq == null && scalestartx % 10 == 0)
{
scalestartx += 5;
}
String string;
- int maxX = 0;
-
+ int maxX = 0, refN, iadj;
+ // todo: add a 'reference origin column' to set column number relative to
for (int i = scalestartx; i < endx; i += 5)
{
- if ((i % 10) == 0)
+ if (((i - refSp) % 10) == 0)
{
- string = String.valueOf(av.getColumnSelection()
- .adjustForHiddenColumns(i));
- if ((i - startx - 1) * av.charWidth > maxX)
+ iadj = av.getColumnSelection().adjustForHiddenColumns(i) - 1;
+ if (refSeq == null)
{
- gg.drawString(string, (i - startx - 1) * av.charWidth, y);
- maxX = (i - startx + 1) * av.charWidth + fm.stringWidth(string);
+ string = String.valueOf(iadj + 1);
+ }
+ else
+ {
+ refN = refSeq.findPosition(iadj);
+ // TODO show bounds if position is a gap
+ // - ie L--R -> "1L|2R" for
+ // marker
+ if (iadj < refStartI)
+ {
+ string = String.valueOf(iadj - refStartI);
+ }
+ else if (iadj > refEndI)
+ {
+ string = "+" + String.valueOf(iadj - refEndI);
+ }
+ else
+ {
+ string = String.valueOf(refN) + refSeq.getCharAt(iadj);
+ }
+ }
+ if ((i - startx - 1) * avCharWidth > maxX)
+ {
+ gg.drawString(string, (i - startx - 1) * avCharWidth, y);
+ maxX = (i - startx + 1) * avCharWidth + fm.stringWidth(string);
}
- gg.drawLine(
- (int) (((i - startx - 1) * av.charWidth) + (av.charWidth / 2)),
+ gg.drawLine(((i - startx - 1) * avCharWidth) + (avCharWidth / 2),
y + 2,
- (int) (((i - startx - 1) * av.charWidth) + (av.charWidth / 2)),
- y + (fm.getDescent() * 2));
-
+ ((i - startx - 1) * avCharWidth) + (avCharWidth / 2), y
+ + (fm.getDescent() * 2));
}
else
{
- gg.drawLine(
- (int) (((i - startx - 1) * av.charWidth) + (av.charWidth / 2)),
- y + fm.getDescent(),
- (int) (((i - startx - 1) * av.charWidth) + (av.charWidth / 2)),
- y + (fm.getDescent() * 2));
+ gg.drawLine(((i - startx - 1) * avCharWidth) + (avCharWidth / 2), y
+ + fm.getDescent(), ((i - startx - 1) * avCharWidth)
+ + (avCharWidth / 2), y + (fm.getDescent() * 2));
}
}
@@ -477,33 +576,32 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
{
gg.setColor(Color.blue);
int res;
- if (av.getShowHiddenMarkers())
+ if (av.getShowHiddenMarkers()
+ && av.getColumnSelection().getHiddenColumns() != null)
{
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 * av.charWidth - av.charHeight / 4,
- res * av.charWidth + av.charHeight / 4, res * av.charWidth },
- new int[]
- { y - av.charHeight / 2, y - av.charHeight / 2, y + 8 },
- 3);
+ 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);
}
}
if (reveal != null && reveal[0] > startx && reveal[0] < endx)
{
- gg.drawString("Reveal Columns", reveal[0] * av.charWidth, 0);
+ gg.drawString(MessageManager.getString("label.reveal_columns"),
+ reveal[0] * avCharWidth, 0);
}
}