import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.geom.AffineTransform;
-import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import jalview.analysis.AlignSeq;
import jalview.analysis.AlignmentUtils;
-import jalview.bin.Console;
+import jalview.bin.Cache;
+import jalview.bin.Jalview;
import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.Annotation;
import jalview.datamodel.ContactMatrixI;
+import jalview.datamodel.GroupSet;
import jalview.datamodel.HiddenColumns;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
-import jalview.io.DataSourceType;
import jalview.io.FileFormat;
import jalview.io.FormatAdapter;
-import jalview.io.NewickFile;
import jalview.util.Comparison;
import jalview.util.MessageManager;
import jalview.util.Platform;
-import jalview.ws.datamodel.alphafold.PAEContactMatrix;
/**
* The panel that holds the labels for alignment annotations, providing
private static final String COPYCONS_SEQ = MessageManager
.getString("label.copy_consensus_sequence");
+ private static final String ADJUST_ANNOTATION_LABELS_WIDTH_PREF = "ADJUST_ANNOTATION_LABELS_WIDTH";
+
private final boolean debugRedraw = false;
private AlignmentPanel ap;
*/
public AnnotationLabels(AlignmentPanel ap)
{
-
this.ap = ap;
av = ap.av;
ToolTipManager.sharedInstance().registerComponent(this);
ap.av.getAlignment().setAnnotationIndex(annotation, 0);
}
ap.refresh(true);
- return null;
});
}
consclipbrd.addActionListener(this);
pop.add(consclipbrd);
}
- if (aa[selectedRow].graph == AlignmentAnnotation.CONTACT_MAP
- && PAEContactMatrix.PAEMATRIX
- .equals(aa[selectedRow].getCalcId()))
+
+ addColourOrFilterByOptions(ap, aa[selectedRow], pop);
+
+ if (aa[selectedRow].graph == AlignmentAnnotation.CONTACT_MAP)
+ {
+ addContactMatrixOptions(ap, aa[selectedRow], pop);
+ // Set/adjust threshold for grouping ?
+ // colour alignment by this [type]
+ // select/hide columns by this row
+
+ }
+ }
+
+ pop.show(this, evt.getX(), evt.getY());
+ }
+
+ static void addColourOrFilterByOptions(final AlignmentPanel ap,
+ final AlignmentAnnotation alignmentAnnotation,
+ final JPopupMenu pop)
+ {
+ JMenuItem item;
+ item = new JMenuItem(
+ MessageManager.getString("label.colour_by_annotation"));
+ item.addActionListener(new ActionListener()
+ {
+
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ AnnotationColourChooser.displayFor(ap.av, ap, alignmentAnnotation,
+ false);
+ };
+ });
+ pop.add(item);
+ if (alignmentAnnotation.sequenceRef != null)
+ {
+ item = new JMenuItem(
+ MessageManager.getString("label.colour_by_annotation") + " ("
+ + MessageManager.getString("label.per_seq") + ")");
+ item.addActionListener(new ActionListener()
{
- final PAEContactMatrix cm = (PAEContactMatrix) av
- .getContactMatrix(aa[selectedRow]);
- if (cm != null && cm.hasTree())
+ @Override
+ public void actionPerformed(ActionEvent e)
{
- item = new JMenuItem("Show Tree for Matrix");
- item.addActionListener(new ActionListener()
- {
+ AnnotationColourChooser.displayFor(ap.av, ap, alignmentAnnotation,
+ true);
+ };
+ });
+ pop.add(item);
+ }
+ item = new JMenuItem(
+ MessageManager.getString("action.select_by_annotation"));
+ item.addActionListener(new ActionListener()
+ {
- @Override
- public void actionPerformed(ActionEvent e)
- {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ AnnotationColumnChooser.displayFor(ap.av, ap, alignmentAnnotation);
+ };
+ });
+ pop.add(item);
+ }
- ap.alignFrame.showContactMapTree(aa[selectedRow], cm);
+ static void addContactMatrixOptions(final AlignmentPanel ap,
+ final AlignmentAnnotation alignmentAnnotation,
+ final JPopupMenu pop)
+ {
- }
- });
- pop.addSeparator();
- pop.add(item);
- }
+ final ContactMatrixI cm = ap.av.getContactMatrix(alignmentAnnotation);
+ JMenuItem item;
+ if (cm != null)
+ {
+ pop.addSeparator();
+
+ if (cm.hasGroups())
+ {
+ JCheckBoxMenuItem chitem = new JCheckBoxMenuItem(
+ MessageManager.getString("action.show_groups_on_matrix"));
+ chitem.setToolTipText(MessageManager
+ .getString("action.show_groups_on_matrix_tooltip"));
+ boolean showGroups = alignmentAnnotation
+ .isShowGroupsForContactMatrix();
+ final AlignmentAnnotation sel_row = alignmentAnnotation;
+ chitem.setState(showGroups);
+ chitem.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ sel_row.setShowGroupsForContactMatrix(chitem.getState());
+ ap.getAnnotationPanel()
+ .paint(ap.getAnnotationPanel().getGraphics());
+ }
+ });
+ pop.add(chitem);
+ }
+ if (cm.hasTree())
+ {
+ item = new JMenuItem(
+ MessageManager.getString("action.show_tree_for_matrix"));
+ item.setToolTipText(MessageManager
+ .getString("action.show_tree_for_matrix_tooltip"));
+ item.addActionListener(new ActionListener()
+ {
+
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+
+ ap.alignFrame.showContactMapTree(alignmentAnnotation, cm);
+
+ }
+ });
+ pop.add(item);
+ }
+ else
+ {
+ item = new JMenuItem(
+ MessageManager.getString("action.cluster_matrix"));
+ item.setToolTipText(
+ MessageManager.getString("action.cluster_matrix_tooltip"));
+ item.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ new Thread(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ final long progBar;
+ ap.alignFrame.setProgressBar(
+ MessageManager.formatMessage(
+ "action.clustering_matrix_for",
+ cm.getAnnotDescr(), 5f),
+ progBar = System.currentTimeMillis());
+ cm.setGroupSet(GroupSet.makeGroups(cm, 5f, true));
+ ap.alignFrame.showContactMapTree(alignmentAnnotation, cm);
+ ap.alignFrame.setProgressBar(null, progBar);
+ }
+ }).start();
+ }
+ });
+ pop.add(item);
}
}
- pop.show(this, evt.getX(), evt.getY());
}
/**
* @param width
* Width for scaling labels
*/
- public void drawComponent(Graphics g, boolean clip, int width)
+ public void drawComponent(Graphics g, boolean clip, int givenWidth)
{
+ int width = givenWidth;
+ IdwidthAdjuster iwa = ap.idwidthAdjuster;
+ if ((Cache.getDefault(ADJUST_ANNOTATION_LABELS_WIDTH_PREF, true)
+ || Jalview.isHeadlessMode()) && !iwa.manuallyAdjusted())
+ {
+ Graphics2D g2d = (Graphics2D) g;
+ Graphics dummy = g2d.create();
+ int annotationIdWidth = drawLabels(dummy, clip, width, false);
+ Dimension d = ap.calculateDefaultAlignmentIdWidth();
+ int alignmentIdWidth = d.width;
+ if (!iwa.manuallyAdjusted())
+ {
+ // If no manual adjustment to ID column with has been made then adjust
+ // width match widest of alignment or annotation id widths
+ width = Math.max(alignmentIdWidth, annotationIdWidth);
+ }
+ else if (annotationIdWidth > givenWidth
+ && annotationIdWidth > alignmentIdWidth)
+ {
+ // otherwise if the annotation id width has become larger than the
+ // current id width, increase
+ width = annotationIdWidth;
+ }
+ // set the width if it's changed
+ if (width != ap.av.getIdWidth())
+ {
+ iwa.setWidth(width);
+ ap.validateAnnotationDimensions(false);
+ }
+ }
+ drawLabels(g, clip, width, true);
+ }
+
+ /**
+ * Render the full set of annotation Labels for the alignment at the given
+ * cursor. If actuallyDraw is false then no actual drawing will occur, but the
+ * widest label width will be returned.
+ *
+ * @param g
+ * Graphics2D instance (needed for font scaling)
+ * @param clip
+ * - true indicates that only current visible area needs to be
+ * rendered
+ * @param width
+ * Width for scaling labels
+ */
+ public int drawLabels(Graphics g, boolean clip, int width,
+ boolean actuallyDraw)
+ {
+ int actualWidth = 0;
if (av.getFont().getSize() < 10)
{
g.setFont(font);
}
FontMetrics fm = g.getFontMetrics(g.getFont());
- g.setColor(Color.white);
- g.fillRect(0, 0, getWidth(), getHeight());
+ if (actuallyDraw)
+ {
+ g.setColor(Color.white);
+ g.fillRect(0, 0, getWidth(), getHeight());
+ }
- g.translate(0, getScrollOffset());
- g.setColor(Color.black);
+ if (actuallyDraw)
+ {
+ g.translate(0, getScrollOffset());
+ g.setColor(Color.black);
+ }
SequenceI lastSeqRef = null;
String lastLabel = null;
AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
continue;
}
}
- g.setColor(Color.black);
-
+ if (actuallyDraw)
+ {
+ g.setColor(Color.black);
+ }
offset = -aa[i].height / 2;
if (aa[i].hasText)
vertBar = true;
}
}
- x = width - fm.stringWidth(label) - 3;
+
+ int labelWidth = fm.stringWidth(label) + 3;
+ x = width - labelWidth;
if (aa[i].graphGroup > -1)
{
{
if (aa[gg].graphGroup == aa[i].graphGroup)
{
- x = width - fm.stringWidth(aa[gg].label) - 3;
- g.drawString(aa[gg].label, x, y - graphExtras);
-
- if (aa[gg]._linecolour != null)
+ labelWidth = fm.stringWidth(aa[gg].label) + 3;
+ x = width - labelWidth;
+ if (actuallyDraw)
{
+ g.drawString(aa[gg].label, x, y - graphExtras);
- g.setColor(aa[gg]._linecolour);
- g.drawLine(x, y - graphExtras + 3,
- x + fm.stringWidth(aa[gg].label),
- y - graphExtras + 3);
- }
+ if (aa[gg]._linecolour != null)
+ {
- g.setColor(Color.black);
+ g.setColor(aa[gg]._linecolour);
+ g.drawLine(x, y - graphExtras + 3,
+ x + fm.stringWidth(aa[gg].label),
+ y - graphExtras + 3);
+ }
+
+ g.setColor(Color.black);
+ }
graphExtras += fontHeight + 8;
}
}
}
else
{
- if (vertBar)
+ if (actuallyDraw)
{
- g.drawLine(width - 3, y + offset - fontHeight, width - 3,
- (int) (y - 1.5 * aa[i].height - offset - fontHeight));
- // g.drawLine(20, y + offset, x - 20, y + offset);
+ if (vertBar)
+ {
+ g.drawLine(width - 3, y + offset - fontHeight, width - 3,
+ (int) (y - 1.5 * aa[i].height - offset - fontHeight));
+ // g.drawLine(20, y + offset, x - 20, y + offset);
+ }
+ g.drawString(label, x, y + offset);
}
- g.drawString(label, x, y + offset);
}
lastSeqRef = aa[i].sequenceRef;
+
+ if (labelWidth > actualWidth)
+ {
+ actualWidth = labelWidth;
+ }
}
}
if (!resizePanel && dragEvent != null && aa != null)
{
- g.setColor(Color.lightGray);
- g.drawString(
- (aa[selectedRow].sequenceRef == null ? ""
- : aa[selectedRow].sequenceRef.getName())
- + aa[selectedRow].label,
- dragEvent.getX(), dragEvent.getY() - getScrollOffset());
+ if (actuallyDraw)
+ {
+ g.setColor(Color.lightGray);
+ g.drawString(
+ (aa[selectedRow].sequenceRef == null ? ""
+ : aa[selectedRow].sequenceRef.getName())
+ + aa[selectedRow].label,
+ dragEvent.getX(), dragEvent.getY() - getScrollOffset());
+ }
}
if (!av.getWrapAlignment() && ((aa == null) || (aa.length < 1)))
{
- g.drawString(MessageManager.getString("label.right_click"), 2, 8);
- g.drawString(MessageManager.getString("label.to_add_annotation"), 2,
- 18);
+ if (actuallyDraw)
+ {
+ g.drawString(MessageManager.getString("label.right_click"), 2, 8);
+ g.drawString(MessageManager.getString("label.to_add_annotation"), 2,
+ 18);
+ }
}
+
+ return actualWidth;
}
public int getScrollOffset()