X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAnnotationLabels.java;h=b1a8aff6a863f3756989c1439747b8d3ef36ad01;hb=f0efe3029537bbbbe788e16eb85cb0af9c0fb81e;hp=4e181b3743c7cb6f4a16db82d87bb7ffcdc9d3ae;hpb=537da9c65518c52985308b67c499fe6a60a607ce;p=jalview.git diff --git a/src/jalview/gui/AnnotationLabels.java b/src/jalview/gui/AnnotationLabels.java index 4e181b3..b1a8aff 100755 --- a/src/jalview/gui/AnnotationLabels.java +++ b/src/jalview/gui/AnnotationLabels.java @@ -25,6 +25,7 @@ import jalview.analysis.AlignmentUtils; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.Annotation; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; @@ -33,6 +34,7 @@ import jalview.io.FormatAdapter; import jalview.util.Comparison; import jalview.util.MessageManager; import jalview.util.Platform; +import jalview.workers.InformationThread; import java.awt.Color; import java.awt.Cursor; @@ -41,8 +43,6 @@ import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Graphics2D; -import java.awt.Image; -import java.awt.MediaTracker; import java.awt.RenderingHints; import java.awt.Toolkit; import java.awt.datatransfer.StringSelection; @@ -52,10 +52,9 @@ import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.awt.geom.AffineTransform; -import java.awt.image.BufferedImage; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.Iterator; import java.util.regex.Pattern; import javax.swing.JCheckBoxMenuItem; @@ -73,9 +72,16 @@ import javax.swing.ToolTipManager; public class AnnotationLabels extends JPanel implements MouseListener, MouseMotionListener, ActionListener { - // width in pixels within which height adjuster arrows are shown and active + /** + * width in pixels within which height adjuster arrows are shown and active + */ private static final int HEIGHT_ADJUSTER_WIDTH = 50; + /** + * height in pixels for allowing height adjuster to be active + */ + private static int HEIGHT_ADJUSTER_HEIGHT = 10; + private static final Pattern LEFT_ANGLE_BRACKET_PATTERN = Pattern .compile("<"); @@ -105,10 +111,6 @@ public class AnnotationLabels extends JPanel private static final String COPYCONS_SEQ = MessageManager .getString("label.copy_consensus_sequence"); - private static Image adjusterImage; - - private static int adjusterImageHeight; - private final boolean debugRedraw = false; private AlignmentPanel ap; @@ -138,11 +140,6 @@ public class AnnotationLabels extends JPanel av = ap.av; ToolTipManager.sharedInstance().registerComponent(this); - if (adjusterImage == null) - { - loadAdjusterImage(); - } - addMouseListener(this); addMouseMotionListener(this); addMouseWheelListener(ap.getAnnotationPanel()); @@ -154,37 +151,6 @@ public class AnnotationLabels extends JPanel } /** - * 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 = Toolkit.getDefaultToolkit().createImage(url); - } - - try - { - MediaTracker mt = new MediaTracker(this); - mt.addImage(temp, 0); - mt.waitForID(0); - } catch (Exception ex) - { - } - - BufferedImage bi = new BufferedImage(temp.getHeight(this), - temp.getWidth(this), BufferedImage.TYPE_INT_RGB); - Graphics2D g = (Graphics2D) bi.getGraphics(); - g.rotate(Math.toRadians(90)); - g.drawImage(temp, 0, -bi.getWidth(this), this); - adjusterImage = bi; - adjusterImageHeight = bi.getHeight(); - } - - /** * DOCUMENT ME! * * @param y @@ -387,6 +353,10 @@ public class AnnotationLabels extends JPanel pop.show(this, evt.getX(), evt.getY()); return; } + + final AlignmentAnnotation ann = aa[selectedRow]; + final boolean isSequenceAnnotation = ann.sequenceRef != null; + item = new JMenuItem(EDITNAME); item.addActionListener(this); pop.add(item); @@ -396,9 +366,9 @@ public class AnnotationLabels extends JPanel // JAL-1264 hide all sequence-specific annotations of this type if (selectedRow < aa.length) { - if (aa[selectedRow].sequenceRef != null) + if (isSequenceAnnotation) { - final String label = aa[selectedRow].label; + final String label = ann.label; JMenuItem hideType = new JMenuItem(); String text = MessageManager.getString("label.hide_all") + " " + label; @@ -411,15 +381,6 @@ public class AnnotationLabels extends JPanel AlignmentUtils.showOrHideSequenceAnnotations( ap.av.getAlignment(), Collections.singleton(label), null, false, false); - // for (AlignmentAnnotation ann : ap.av.getAlignment() - // .getAlignmentAnnotation()) - // { - // if (ann.sequenceRef != null && ann.label != null - // && ann.label.equals(label)) - // { - // ann.visible = false; - // } - // } ap.refresh(true); } }); @@ -442,190 +403,317 @@ public class AnnotationLabels extends JPanel // property methods if (selectedRow < aa.length) { - final String label = aa[selectedRow].label; - if (!aa[selectedRow].autoCalculated) + final String label = ann.label; + if (!(ann.autoCalculated) + && !(InformationThread.HMM_CALC_ID.equals(ann.getCalcId()))) { - if (aa[selectedRow].graph == AlignmentAnnotation.NO_GRAPH) + if (ann.graph == AlignmentAnnotation.NO_GRAPH) { // display formatting settings for this row. pop.addSeparator(); // av and sequencegroup need to implement same interface for item = new JCheckBoxMenuItem(TOGGLE_LABELSCALE, - aa[selectedRow].scaleColLabel); + ann.scaleColLabel); item.addActionListener(this); pop.add(item); } } else if (label.indexOf("Consensus") > -1) { - pop.addSeparator(); - // av and sequencegroup need to implement same interface for - final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem( - 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() + addConsensusMenu(pop, ann); + } + else if (InformationThread.HMM_CALC_ID.equals(ann.getCalcId())) + { + addHmmerMenu(pop, ann); + } + } + pop.show(this, evt.getX(), evt.getY()); + } + + /** + * Adds context menu options for (alignment or group) Hmmer annotation + * + * @param pop + * @param ann + */ + protected void addHmmerMenu(JPopupMenu pop, final AlignmentAnnotation ann) + { + final boolean isGroupAnnotation = ann.groupRef != null; + pop.addSeparator(); + final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem( + MessageManager.getString( + "label.ignore_below_background_frequency"), + isGroupAnnotation + ? ann.groupRef + .isIgnoreBelowBackground() + : ap.av.isIgnoreBelowBackground()); + cbmi.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + if (isGroupAnnotation) { - @Override - public void actionPerformed(ActionEvent e) + if (!ann.groupRef.isUseInfoLetterHeight()) { - if (aaa.groupRef != null) - { - // TODO: pass on reference to ap so the view can be updated. - aaa.groupRef.setIgnoreGapsConsensus(cbmi.getState()); - ap.getAnnotationPanel() - .paint(ap.getAnnotationPanel().getGraphics()); - } - else - { - ap.av.setIgnoreGapsConsensus(cbmi.getState(), ap); - } - ap.alignmentChanged(); + ann.groupRef.setIgnoreBelowBackground(cbmi.getState()); + // todo and recompute group annotation } - }); - pop.add(cbmi); - // av and sequencegroup need to implement same interface for - if (aaa.groupRef != null) + } + else if (!ap.av.isInfoLetterHeight()) { - final JCheckBoxMenuItem chist = new JCheckBoxMenuItem( - MessageManager.getString("label.show_group_histogram"), - aa[selectedRow].groupRef.isShowConsensusHistogram()); - chist.addActionListener(new ActionListener() - { - @Override - public void actionPerformed(ActionEvent e) - { - // TODO: pass on reference - // to ap - // so the - // view - // can be - // updated. - aaa.groupRef.setShowConsensusHistogram(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.isShowSequenceLogo()); - cprofl.addActionListener(new ActionListener() - { - @Override - public void actionPerformed(ActionEvent e) - { - // TODO: pass on reference - // to ap - // so the - // view - // can be - // updated. - aaa.groupRef.setshowSequenceLogo(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.isNormaliseSequenceLogo()); - cproflnorm.addActionListener(new ActionListener() - { - @Override - public void actionPerformed(ActionEvent e) - { + ap.av.setIgnoreBelowBackground(cbmi.getState(), ap); + // todo and recompute annotation + } + ap.alignmentChanged(); // todo not like this + } + }); + pop.add(cbmi); + final JCheckBoxMenuItem letterHeight = new JCheckBoxMenuItem( + MessageManager.getString("label.use_info_for_height"), + isGroupAnnotation ? ann.groupRef.isUseInfoLetterHeight() + : ap.av.isInfoLetterHeight()); + letterHeight.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + if (isGroupAnnotation) + { + ann.groupRef.setInfoLetterHeight((letterHeight.getState())); + ann.groupRef.setIgnoreBelowBackground(true); + // todo and recompute group annotation + } + else + { + ap.av.setInfoLetterHeight(letterHeight.getState(), ap); + ap.av.setIgnoreBelowBackground(true, ap); + // todo and recompute annotation + } + ap.alignmentChanged(); + } + }); + pop.add(letterHeight); + if (isGroupAnnotation) + { + final JCheckBoxMenuItem chist = new JCheckBoxMenuItem( + MessageManager.getString("label.show_group_histogram"), + ann.groupRef.isShowInformationHistogram()); + chist.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + ann.groupRef.setShowInformationHistogram(chist.getState()); + ap.repaint(); + } + }); + pop.add(chist); + final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem( + MessageManager.getString("label.show_group_logo"), + ann.groupRef.isShowHMMSequenceLogo()); + cprofl.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + ann.groupRef.setShowHMMSequenceLogo(cprofl.getState()); + ap.repaint(); + } + }); + pop.add(cprofl); + final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem( + MessageManager.getString("label.normalise_group_logo"), + ann.groupRef.isNormaliseHMMSequenceLogo()); + cproflnorm.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + ann.groupRef + .setNormaliseHMMSequenceLogo(cproflnorm.getState()); + // automatically enable logo display if we're clicked + ann.groupRef.setShowHMMSequenceLogo(true); + ap.repaint(); + } + }); + 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) + { + av.setShowInformationHistogram(chist.getState()); + ap.repaint(); + } + }); + 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) + { + av.setShowHMMSequenceLogo(cprof.getState()); + ap.repaint(); + } + }); + 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) + { + av.setShowHMMSequenceLogo(true); + av.setNormaliseHMMSequenceLogo(cprofnorm.getState()); + ap.repaint(); + } + }); + pop.add(cprofnorm); + } + } - // TODO: pass on reference - // to ap - // so the - // view - // can be - // updated. - aaa.groupRef.setNormaliseSequenceLogo(cproflnorm.getState()); - // automatically enable logo display if we're clicked - aaa.groupRef.setshowSequenceLogo(true); - ap.repaint(); - // ap.annotationPanel.paint(ap.annotationPanel.getGraphics()); - } - }); - pop.add(cproflnorm); + /** + * Adds context menu options for (alignment or group) Consensus annotation + * + * @param pop + * @param ann + */ + protected void addConsensusMenu(JPopupMenu pop, + final AlignmentAnnotation ann) + { + final boolean isGroupAnnotation = ann.groupRef != null; + pop.addSeparator(); + + final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem( + MessageManager.getString("label.ignore_gaps_consensus"), + (ann.groupRef != null) + ? ann.groupRef.isIgnoreGapsConsensus() + : ap.av.isIgnoreGapsConsensus()); + cbmi.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + if (isGroupAnnotation) + { + ann.groupRef.setIgnoreGapsConsensus(cbmi.getState()); } else { - final JCheckBoxMenuItem chist = new JCheckBoxMenuItem( - MessageManager.getString("label.show_histogram"), - av.isShowConsensusHistogram()); - chist.addActionListener(new ActionListener() - { - @Override - public void actionPerformed(ActionEvent e) - { - // TODO: pass on reference - // to ap - // so the - // view - // can be - // updated. - av.setShowConsensusHistogram(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.isShowSequenceLogo()); - cprof.addActionListener(new ActionListener() - { - @Override - public void actionPerformed(ActionEvent e) - { - // TODO: pass on reference - // to ap - // so the - // view - // can be - // updated. - av.setShowSequenceLogo(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.isNormaliseSequenceLogo()); - cprofnorm.addActionListener(new ActionListener() - { - @Override - public void actionPerformed(ActionEvent e) - { - // TODO: pass on reference - // to ap - // so the - // view - // can be - // updated. - av.setShowSequenceLogo(true); - av.setNormaliseSequenceLogo(cprofnorm.getState()); - ap.alignFrame.setMenusForViewport(); - ap.repaint(); - // ap.annotationPanel.paint(ap.annotationPanel.getGraphics()); - } - }); - pop.add(cprofnorm); + ap.av.setIgnoreGapsConsensus(cbmi.getState(), ap); } - final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ); - consclipbrd.addActionListener(this); - pop.add(consclipbrd); + ap.alignmentChanged(); } + }); + pop.add(cbmi); + if (isGroupAnnotation) + { + /* + * group consensus options + */ + final JCheckBoxMenuItem chist = new JCheckBoxMenuItem( + MessageManager.getString("label.show_group_histogram"), + ann.groupRef.isShowConsensusHistogram()); + chist.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + ann.groupRef.setShowConsensusHistogram(chist.getState()); + ap.repaint(); + } + }); + pop.add(chist); + final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem( + MessageManager.getString("label.show_group_logo"), + ann.groupRef.isShowSequenceLogo()); + cprofl.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + ann.groupRef.setshowSequenceLogo(cprofl.getState()); + ap.repaint(); + } + }); + pop.add(cprofl); + final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem( + MessageManager.getString("label.normalise_group_logo"), + ann.groupRef.isNormaliseSequenceLogo()); + cproflnorm.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + ann.groupRef.setNormaliseSequenceLogo(cproflnorm.getState()); + // automatically enable logo display if we're clicked + ann.groupRef.setshowSequenceLogo(true); + ap.repaint(); + } + }); + pop.add(cproflnorm); } - pop.show(this, evt.getX(), evt.getY()); + else + { + /* + * alignment consensus options + */ + final JCheckBoxMenuItem chist = new JCheckBoxMenuItem( + MessageManager.getString("label.show_histogram"), + av.isShowConsensusHistogram()); + chist.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + av.setShowConsensusHistogram(chist.getState()); + ap.repaint(); + } + }); + pop.add(chist); + final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem( + MessageManager.getString("label.show_logo"), + av.isShowSequenceLogo()); + cprof.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + av.setShowSequenceLogo(cprof.getState()); + ap.repaint(); + } + }); + pop.add(cprof); + final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem( + MessageManager.getString("label.normalise_logo"), + av.isNormaliseSequenceLogo()); + cprofnorm.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + av.setShowSequenceLogo(true); + av.setNormaliseSequenceLogo(cprofnorm.getState()); + ap.repaint(); + } + }); + pop.add(cprofnorm); + } + final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ); + consclipbrd.addActionListener(this); + pop.add(consclipbrd); } /** @@ -816,7 +904,7 @@ public class AnnotationLabels extends JPanel protected void showOrHideAdjuster(MouseEvent evt) { boolean was = resizePanel; - resizePanel = evt.getY() < adjusterImageHeight && evt.getX() < HEIGHT_ADJUSTER_WIDTH; + resizePanel = evt.getY() < HEIGHT_ADJUSTER_HEIGHT && evt.getX() < HEIGHT_ADJUSTER_WIDTH; if (resizePanel != was) { @@ -939,7 +1027,6 @@ public class AnnotationLabels extends JPanel PaintRefresher.Refresh(ap, ap.av.getSequenceSetId()); ap.av.sendSelection(); } - } } return; @@ -968,8 +1055,9 @@ public class AnnotationLabels extends JPanel Alignment ds = new Alignment(dseqs); if (av.hasHiddenColumns()) { - omitHidden = av.getAlignment().getHiddenColumns() - .getVisibleSequenceStrings(0, sq.getLength(), seqs); + Iterator it = av.getAlignment().getHiddenColumns() + .getVisContigsIterator(0, sq.getLength(), false); + omitHidden = new String[] { sq.getSequenceStringFromIterator(it) }; } int[] alignmentStartEnd = new int[] { 0, ds.getWidth() - 1 }; @@ -985,12 +1073,12 @@ public class AnnotationLabels extends JPanel Toolkit.getDefaultToolkit().getSystemClipboard() .setContents(new StringSelection(output), Desktop.instance); - ArrayList hiddenColumns = null; + HiddenColumns hiddenColumns = null; if (av.hasHiddenColumns()) { - hiddenColumns = av.getAlignment().getHiddenColumns() - .getHiddenColumnsCopy(); + hiddenColumns = new HiddenColumns( + av.getAlignment().getHiddenColumns()); } Desktop.jalviewClipboard = new Object[] { seqs, ds, // what is the dataset @@ -1010,7 +1098,6 @@ public class AnnotationLabels extends JPanel @Override public void paintComponent(Graphics g) { - int width = getWidth(); if (width == 0) { @@ -1025,7 +1112,6 @@ public class AnnotationLabels extends JPanel } drawComponent(g2, true, width); - } /** @@ -1225,11 +1311,7 @@ public class AnnotationLabels extends JPanel } } - if (resizePanel) - { - // g.drawImage(adjusterImage, 2, 0 - getScrollOffset(), this); - } - else if (dragEvent != null && aa != null) + if (!resizePanel && dragEvent != null && aa != null) { g.setColor(Color.lightGray); g.drawString(aa[selectedRow].label, dragEvent.getX(),