*/
package jalview.gui;
+import jalview.analysis.AlignSeq;
import jalview.analysis.AlignmentUtils;
import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.SequenceI;
import jalview.io.FileFormat;
import jalview.io.FormatAdapter;
+import jalview.util.Comparison;
import jalview.util.MessageManager;
+import jalview.util.Platform;
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.ToolTipManager;
/**
- * DOCUMENT ME!
- *
- * @author $author$
- * @version $Revision$
+ * The panel that holds the labels for alignment annotations, providing
+ * tooltips, context menus, drag to reorder rows, and drag to adjust panel
+ * height
*/
public class AnnotationLabels extends JPanel
implements MouseListener, MouseMotionListener, ActionListener
{
+ // width in pixels within which height adjuster arrows are shown and active
+ private static final int HEIGHT_ADJUSTER_WIDTH = 50;
+
private static final Pattern LEFT_ANGLE_BRACKET_PATTERN = Pattern
.compile("<");
- String TOGGLE_LABELSCALE = MessageManager
+ private static final Font font = new Font("Arial", Font.PLAIN, 11);
+
+ private static final String TOGGLE_LABELSCALE = MessageManager
.getString("label.scale_label_to_column");
- String ADDNEW = MessageManager.getString("label.add_new_row");
+ private static final String ADDNEW = MessageManager
+ .getString("label.add_new_row");
- String EDITNAME = MessageManager
+ private static final String EDITNAME = MessageManager
.getString("label.edit_label_description");
- String HIDE = MessageManager.getString("label.hide_row");
+ private static final String HIDE = MessageManager
+ .getString("label.hide_row");
- String DELETE = MessageManager.getString("label.delete_row");
+ private static final String DELETE = MessageManager
+ .getString("label.delete_row");
- String SHOWALL = MessageManager.getString("label.show_all_hidden_rows");
+ private static final String SHOWALL = MessageManager
+ .getString("label.show_all_hidden_rows");
- String OUTPUT_TEXT = MessageManager.getString("label.export_annotation");
+ private static final String OUTPUT_TEXT = MessageManager
+ .getString("label.export_annotation");
- String COPYCONS_SEQ = MessageManager
+ private static final String COPYCONS_SEQ = MessageManager
.getString("label.copy_consensus_sequence");
- boolean resizePanel = false;
+ private static Image adjusterImage;
- Image image;
+ private static int adjusterImageHeight;
- AlignmentPanel ap;
+ private final boolean debugRedraw = false;
- AlignViewport av;
+ private AlignmentPanel ap;
- boolean resizing = false;
+ AlignViewport av;
- MouseEvent dragEvent;
+ private MouseEvent dragEvent;
- int oldY;
+ private int oldY;
- int selectedRow;
+ private int selectedRow;
private int scrollOffset = 0;
- Font font = new Font("Arial", Font.PLAIN, 11);
-
private boolean hasHiddenRows;
+ private boolean resizePanel = false;
+
/**
- * Creates a new AnnotationLabels object.
+ * Creates a new AnnotationLabels object
*
* @param ap
- * DOCUMENT ME!
*/
public AnnotationLabels(AlignmentPanel ap)
{
av = ap.av;
ToolTipManager.sharedInstance().registerComponent(this);
+ if (adjusterImage == null)
+ {
+ loadAdjusterImage();
+ }
+
+ addMouseListener(this);
+ addMouseMotionListener(this);
+ addMouseWheelListener(ap.getAnnotationPanel());
+ }
+
+ public AnnotationLabels(AlignViewport av)
+ {
+ this.av = av;
+ }
+
+ /**
+ * Loads the gif for the panel height adjustment
+ */
+ protected void loadAdjusterImage()
+ {
java.net.URL url = getClass().getResource("/images/idwidth.gif");
Image temp = null;
if (url != null)
{
- temp = java.awt.Toolkit.getDefaultToolkit().createImage(url);
+ temp = Toolkit.getDefaultToolkit().createImage(url);
}
try
Graphics2D g = (Graphics2D) bi.getGraphics();
g.rotate(Math.toRadians(90));
g.drawImage(temp, 0, -bi.getWidth(this), this);
- image = bi;
-
- addMouseListener(this);
- addMouseMotionListener(this);
- addMouseWheelListener(ap.getAnnotationPanel());
- }
-
- public AnnotationLabels(AlignViewport av)
- {
- this.av = av;
+ adjusterImage = bi;
+ adjusterImageHeight = bi.getHeight();
}
/**
}
/**
- * DOCUMENT ME!
+ * Reorders annotation rows after a drag of a label
*
* @param evt
- * DOCUMENT ME!
*/
@Override
public void mouseReleased(MouseEvent evt)
getSelectedRow(evt.getY() - getScrollOffset());
int end = selectedRow;
+ /*
+ * if dragging to resize instead, start == end
+ */
if (start != end)
{
// Swap these annotations
}
/**
- * DOCUMENT ME!
- *
- * @param evt
- * DOCUMENT ME!
- */
- @Override
- public void mouseEntered(MouseEvent evt)
- {
- if (evt.getY() < 10)
- {
- resizePanel = true;
- repaint();
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param evt
- * DOCUMENT ME!
+ * Removes the height adjuster image on leaving the panel, unless currently
+ * dragging it
*/
@Override
public void mouseExited(MouseEvent evt)
{
- if (dragEvent == null)
+ if (resizePanel && dragEvent == null)
{
resizePanel = false;
repaint();
}
/**
- * DOCUMENT ME!
+ * A mouse drag may be either an adjustment of the panel height (if flag
+ * resizePanel is set on), or a reordering of the annotation rows. The former
+ * is dealt with by this method, the latter in mouseReleased.
*
* @param evt
- * DOCUMENT ME!
*/
@Override
public void mouseDragged(MouseEvent evt)
}
/**
- * DOCUMENT ME!
+ * Updates the tooltip as the mouse moves over the labels
*
* @param evt
- * DOCUMENT ME!
*/
@Override
public void mouseMoved(MouseEvent evt)
{
- resizePanel = evt.getY() < 10;
+ showOrHideAdjuster(evt);
getSelectedRow(evt.getY() - getScrollOffset());
}
}
+ /**
+ * Shows the height adjuster image if the mouse moves into the top left
+ * region, or hides it if the mouse leaves the regio
+ *
+ * @param evt
+ */
+ protected void showOrHideAdjuster(MouseEvent evt)
+ {
+ boolean was = resizePanel;
+ resizePanel = evt.getY() < adjusterImageHeight && evt.getX() < HEIGHT_ADJUSTER_WIDTH;
+ if (resizePanel != was)
+ {
+ repaint();
+ }
+ }
+
@Override
public void mouseClicked(MouseEvent evt)
{
// process modifiers
SequenceGroup sg = ap.av.getSelectionGroup();
if (sg == null || sg == aa[selectedRow].groupRef
- || !(jalview.util.Platform.isControlDown(evt)
- || evt.isShiftDown()))
+ || !(Platform.isControlDown(evt) || evt.isShiftDown()))
{
- if (jalview.util.Platform.isControlDown(evt)
- || evt.isShiftDown())
+ if (Platform.isControlDown(evt) || evt.isShiftDown())
{
// clone a new selection group from the associated group
ap.av.setSelectionGroup(
// we make a copy rather than edit the current selection if no
// modifiers pressed
// see Enhancement JAL-1557
- if (!(jalview.util.Platform.isControlDown(evt)
- || evt.isShiftDown()))
+ if (!(Platform.isControlDown(evt) || evt.isShiftDown()))
{
sg = new SequenceGroup(sg);
sg.clear();
}
else
{
- if (jalview.util.Platform.isControlDown(evt))
+ if (Platform.isControlDown(evt))
{
sg.addOrRemove(aa[selectedRow].sequenceRef, true);
}
if (dseqs[0] == null)
{
dseqs[0] = new Sequence(sq);
- dseqs[0].setSequence(jalview.analysis.AlignSeq.extractGaps(
- jalview.util.Comparison.GapChars, sq.getSequenceAsString()));
+ dseqs[0].setSequence(AlignSeq.extractGaps(Comparison.GapChars,
+ sq.getSequenceAsString()));
sq.setDatasetSequence(dseqs[0]);
}
drawComponent(g, false, width);
}
- private final boolean debugRedraw = false;
-
/**
* Draw the full set of annotation Labels for the alignment at the given
* cursor
if (resizePanel)
{
- g.drawImage(image, 2, 0 - getScrollOffset(), this);
+ g.drawImage(adjusterImage, 2, 0 - getScrollOffset(), this);
}
else if (dragEvent != null && aa != null)
{
{
return scrollOffset;
}
+
+ @Override
+ public void mouseEntered(MouseEvent e)
+ {
+ }
}