X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAnnotationLabels.java;h=445ee11e675f90e28f11df608866c9507070161d;hb=refs%2Fheads%2Ffeatures%2Fhmmer_statistics;hp=8b9168a510dea05f74da076bfcfb3fdb915ce544;hpb=3705d44c1e45abab9180067ed1e2862b9dea65d1;p=jalview.git diff --git a/src/jalview/gui/AnnotationLabels.java b/src/jalview/gui/AnnotationLabels.java index 8b9168a..445ee11 100755 --- a/src/jalview/gui/AnnotationLabels.java +++ b/src/jalview/gui/AnnotationLabels.java @@ -27,6 +27,7 @@ import jalview.datamodel.Annotation; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; +import jalview.io.FileFormat; import jalview.io.FormatAdapter; import jalview.util.MessageManager; @@ -73,6 +74,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, private static final Pattern LEFT_ANGLE_BRACKET_PATTERN = Pattern .compile("<"); + String TOGGLE_LABELSCALE = MessageManager .getString("label.scale_label_to_column"); @@ -219,6 +221,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, AlignmentAnnotation[] aa = ap.av.getAlignment() .getAlignmentAnnotation(); + boolean fullRepaint = false; if (evt.getActionCommand().equals(ADDNEW)) { AlignmentAnnotation newAnnotation = new AlignmentAnnotation(null, @@ -231,11 +234,16 @@ public class AnnotationLabels extends JPanel implements MouseListener, ap.av.getAlignment().addAnnotation(newAnnotation); ap.av.getAlignment().setAnnotationIndex(newAnnotation, 0); + fullRepaint = true; } else if (evt.getActionCommand().equals(EDITNAME)) { + String name = aa[selectedRow].label; editLabelDescription(aa[selectedRow]); - repaint(); + if (!name.equalsIgnoreCase(aa[selectedRow].label)) + { + fullRepaint = true; + } } else if (evt.getActionCommand().equals(HIDE)) { @@ -244,6 +252,8 @@ public class AnnotationLabels extends JPanel implements MouseListener, else if (evt.getActionCommand().equals(DELETE)) { ap.av.getAlignment().deleteAnnotation(aa[selectedRow]); + ap.av.getCalcManager().removeWorkerForAnnotation(aa[selectedRow]); + fullRepaint = true; } else if (evt.getActionCommand().equals(SHOWALL)) { @@ -254,6 +264,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, aa[i].visible = true; } } + fullRepaint = true; } else if (evt.getActionCommand().equals(OUTPUT_TEXT)) { @@ -282,21 +293,11 @@ public class AnnotationLabels extends JPanel implements MouseListener, aa[selectedRow].scaleColLabel = !aa[selectedRow].scaleColLabel; } - refresh(); + ap.refresh(fullRepaint); } /** - * Redraw sensibly. - */ - protected void refresh() - { - ap.validateAnnotationDimensions(false); - ap.addNotify(); - ap.repaint(); - } - - /** * DOCUMENT ME! * * @param e @@ -304,6 +305,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, */ boolean editLabelDescription(AlignmentAnnotation annotation) { + // TODO i18n EditNameDialog dialog = new EditNameDialog(annotation.label, annotation.description, " Annotation Name ", "Annotation Description ", "Edit Annotation Name/Description", @@ -331,12 +333,20 @@ public class AnnotationLabels extends JPanel implements MouseListener, { getSelectedRow(evt.getY() - getScrollOffset()); oldY = evt.getY(); - if (!evt.isPopupTrigger()) + if (evt.isPopupTrigger()) { - return; + showPopupMenu(evt); } + } + + /** + * Build and show the Pop-up menu at the right-click mouse position + * + * @param evt + */ + void showPopupMenu(MouseEvent evt) + { evt.consume(); - // handle popup menu event final AlignmentAnnotation[] aa = ap.av.getAlignment() .getAlignmentAnnotation(); @@ -389,7 +399,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, // ann.visible = false; // } // } - refresh(); + ap.refresh(true); } }); pop.add(hideType); @@ -412,7 +422,8 @@ public class AnnotationLabels extends JPanel implements MouseListener, if (selectedRow < aa.length) { final String label = aa[selectedRow].label; - if (!aa[selectedRow].autoCalculated) + if (!(aa[selectedRow].autoCalculated + || label.indexOf("Information Content") > -1)) { if (aa[selectedRow].graph == AlignmentAnnotation.NO_GRAPH) { @@ -427,14 +438,18 @@ public class AnnotationLabels extends JPanel implements MouseListener, } else if (label.indexOf("Consensus") > -1) { + + pop.addSeparator(); // av and sequencegroup need to implement same interface for + final AlignmentAnnotation aaa = aa[selectedRow]; + final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem( - MessageManager.getString("label.ignore_gaps_consensus"), + MessageManager.getString("label.ignore_gaps_consensus"), (aa[selectedRow].groupRef != null) ? aa[selectedRow].groupRef .getIgnoreGapsConsensus() : ap.av .isIgnoreGapsConsensus()); - final AlignmentAnnotation aaa = aa[selectedRow]; + cbmi.addActionListener(new ActionListener() { @Override @@ -451,6 +466,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, { ap.av.setIgnoreGapsConsensus(cbmi.getState(), ap); } + ap.alignmentChanged(); } }); pop.add(cbmi); @@ -592,9 +608,180 @@ public class AnnotationLabels extends JPanel implements MouseListener, consclipbrd.addActionListener(this); pop.add(consclipbrd); } + else if (label.indexOf("Information Content") > -1) // TODO create labels + // in message resource + // for these + { + pop.addSeparator(); + final AlignmentAnnotation aaa = aa[selectedRow]; + + final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem( + "Ignore Below Background Frequency", + (aa[selectedRow].groupRef != null) + ? aa[selectedRow].groupRef + .getIgnoreBelowBackground() + : ap.av.isIgnoreBelowBackground()); + + cbmi.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + if (aaa.groupRef != null) + { + // TODO: pass on reference to ap so the view can be updated. + aaa.groupRef.setIgnoreBelowBackground(cbmi.getState()); + ap.getAnnotationPanel() + .paint(ap.getAnnotationPanel().getGraphics()); + } + else + { + ap.av.setIgnoreBelowBackground(cbmi.getState(), ap); + } + ap.alignmentChanged(); + } + }); + pop.add(cbmi); + if (aaa.groupRef != null) + { + final JCheckBoxMenuItem chist = new JCheckBoxMenuItem( + MessageManager.getString("label.show_group_histogram"), + aa[selectedRow].groupRef.isShowInformationHistogram()); + chist.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + // TODO: pass on reference + // to ap + // so the + // view + // can be + // updated. + aaa.groupRef.setShowInformationHistogram(chist.getState()); + ap.repaint(); + // ap.annotationPanel.paint(ap.annotationPanel.getGraphics()); + } + }); + pop.add(chist); + final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem( + MessageManager.getString("label.show_group_logo"), + aa[selectedRow].groupRef.isShowHMMSequenceLogo()); + cprofl.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + // TODO: pass on reference + // to ap + // so the + // view + // can be + // updated. + aaa.groupRef.setshowHMMSequenceLogo(cprofl.getState()); + ap.repaint(); + // ap.annotationPanel.paint(ap.annotationPanel.getGraphics()); + } + }); + pop.add(cprofl); + final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem( + MessageManager.getString("label.normalise_group_logo"), + aa[selectedRow].groupRef.isNormaliseHMMSequenceLogo()); + cproflnorm.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + + // TODO: pass on reference + // to ap + // so the + // view + // can be + // updated. + aaa.groupRef + .setNormaliseHMMSequenceLogo(cproflnorm.getState()); + // automatically enable logo display if we're clicked + aaa.groupRef.setshowHMMSequenceLogo(true); + ap.repaint(); + // ap.annotationPanel.paint(ap.annotationPanel.getGraphics()); + } + }); + pop.add(cproflnorm); + } + else + { + final JCheckBoxMenuItem chist = new JCheckBoxMenuItem( + MessageManager.getString("label.show_histogram"), + av.isShowInformationHistogram()); + chist.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + // TODO: pass on reference + // to ap + // so the + // view + // can be + // updated. + av.setShowInformationHistogram(chist.getState()); + ap.alignFrame.setMenusForViewport(); + ap.repaint(); + // ap.annotationPanel.paint(ap.annotationPanel.getGraphics()); + } + }); + pop.add(chist); + final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem( + MessageManager.getString("label.show_logo"), + av.isShowHMMSequenceLogo()); + cprof.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + // TODO: pass on reference + // to ap + // so the + // view + // can be + // updated. + av.setShowHMMSequenceLogo(cprof.getState()); + ap.alignFrame.setMenusForViewport(); + ap.repaint(); + // ap.annotationPanel.paint(ap.annotationPanel.getGraphics()); + } + }); + pop.add(cprof); + final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem( + MessageManager.getString("label.normalise_logo"), + av.isNormaliseHMMSequenceLogo()); + cprofnorm.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + // TODO: pass on reference + // to ap + // so the + // view + // can be + // updated. + av.setShowHMMSequenceLogo(true); + av.setNormaliseHMMSequenceLogo(cprofnorm.getState()); + ap.alignFrame.setMenusForViewport(); + ap.repaint(); + // ap.annotationPanel.paint(ap.annotationPanel.getGraphics()); + } + }); + pop.add(cprofnorm); + } + final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ); + consclipbrd.addActionListener(this); + pop.add(consclipbrd); + } } pop.show(this, evt.getX(), evt.getY()); - } /** @@ -606,6 +793,12 @@ public class AnnotationLabels extends JPanel implements MouseListener, @Override public void mouseReleased(MouseEvent evt) { + if (evt.isPopupTrigger()) + { + showPopupMenu(evt); + return; + } + int start = selectedRow; getSelectedRow(evt.getY() - getScrollOffset()); int end = selectedRow; @@ -802,8 +995,45 @@ public class AnnotationLabels extends JPanel implements MouseListener, // todo: make the ap scroll to the selection - not necessary, first // click highlights/scrolls, second selects ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null); - ap.av.setSelectionGroup(// new SequenceGroup( - aa[selectedRow].groupRef); // ); + // process modifiers + SequenceGroup sg = ap.av.getSelectionGroup(); + if (sg == null + || sg == aa[selectedRow].groupRef + || !(jalview.util.Platform.isControlDown(evt) || evt + .isShiftDown())) + { + if (jalview.util.Platform.isControlDown(evt) + || evt.isShiftDown()) + { + // clone a new selection group from the associated group + ap.av.setSelectionGroup(new SequenceGroup( + aa[selectedRow].groupRef)); + } + else + { + // set selection to the associated group so it can be edited + ap.av.setSelectionGroup(aa[selectedRow].groupRef); + } + } + else + { + // modify current selection with associated group + int remainToAdd = aa[selectedRow].groupRef.getSize(); + for (SequenceI sgs : aa[selectedRow].groupRef.getSequences()) + { + if (jalview.util.Platform.isControlDown(evt)) + { + sg.addOrRemove(sgs, --remainToAdd == 0); + } + else + { + // notionally, we should also add intermediate sequences from + // last added sequence ? + sg.addSequence(sgs, --remainToAdd == 0); + } + } + } + ap.paintAlignment(false); PaintRefresher.Refresh(ap, ap.av.getSequenceSetId()); ap.av.sendSelection(); @@ -862,9 +1092,9 @@ public class AnnotationLabels extends JPanel implements MouseListener, sg.addSequence(aa[selectedRow].sequenceRef, false); } ap.av.setSelectionGroup(sg); - ap.av.sendSelection(); ap.paintAlignment(false); PaintRefresher.Refresh(ap, ap.av.getSequenceSetId()); + ap.av.sendSelection(); } } @@ -895,19 +1125,21 @@ public class AnnotationLabels extends JPanel implements MouseListener, Alignment ds = new Alignment(dseqs); if (av.hasHiddenColumns()) { - omitHidden = av.getColumnSelection().getVisibleSequenceStrings(0, + omitHidden = av.getAlignment().getHiddenColumns() + .getVisibleSequenceStrings(0, sq.getLength(), seqs); } int[] alignmentStartEnd = new int[] { 0, ds.getWidth() - 1 }; - List hiddenCols = av.getColumnSelection().getHiddenColumns(); + List hiddenCols = av.getAlignment().getHiddenColumns() + .getHiddenRegions(); if (hiddenCols != null) { alignmentStartEnd = av.getAlignment().getVisibleStartAndEndIndex( hiddenCols); } - String output = new FormatAdapter().formatSequences("Fasta", seqs, - omitHidden, alignmentStartEnd); + String output = new FormatAdapter().formatSequences(FileFormat.Fasta, + seqs, omitHidden, alignmentStartEnd); Toolkit.getDefaultToolkit().getSystemClipboard() .setContents(new StringSelection(output), Desktop.instance); @@ -915,8 +1147,9 @@ public class AnnotationLabels extends JPanel implements MouseListener, ArrayList hiddenColumns = null; if (av.hasHiddenColumns()) { - hiddenColumns = new ArrayList(); - for (int[] region : av.getColumnSelection().getHiddenColumns()) + hiddenColumns = new ArrayList<>(); + for (int[] region : av.getAlignment().getHiddenColumns() + .getHiddenRegions()) { hiddenColumns.add(new int[] { region[0], region[1] }); }