X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fgui%2FAnnotationColourChooser.java;h=965770ce5a7bbc4f7a57821d2f365b94ca089951;hb=0ebbad305e982eeda562a1842362dc415c36cc8d;hp=4e9a26d4e2b35078b550f20443d71eae53a590c1;hpb=57738a1f3c19b1c3a00bd3ac5108f8cd0af32f99;p=jalview.git diff --git a/src/jalview/gui/AnnotationColourChooser.java b/src/jalview/gui/AnnotationColourChooser.java index 4e9a26d..965770c 100644 --- a/src/jalview/gui/AnnotationColourChooser.java +++ b/src/jalview/gui/AnnotationColourChooser.java @@ -20,15 +20,6 @@ */ package jalview.gui; -import jalview.bin.Cache; -import jalview.datamodel.AlignmentAnnotation; -import jalview.datamodel.GraphLine; -import jalview.datamodel.SequenceGroup; -import jalview.gui.JalviewColourChooser.ColourChooserListener; -import jalview.schemes.AnnotationColourGradient; -import jalview.schemes.ColourSchemeI; -import jalview.util.MessageManager; - import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; @@ -48,6 +39,15 @@ import javax.swing.JInternalFrame; import javax.swing.JLayeredPane; import javax.swing.JPanel; +import jalview.bin.Cache; +import jalview.datamodel.AlignmentAnnotation; +import jalview.datamodel.Annotation; +import jalview.datamodel.GraphLine; +import jalview.datamodel.SequenceGroup; +import jalview.gui.JalviewColourChooser.ColourChooserListener; +import jalview.schemes.AnnotationColourGradient; +import jalview.schemes.ColourSchemeI; +import jalview.util.MessageManager; import net.miginfocom.swing.MigLayout; @SuppressWarnings("serial") @@ -73,6 +73,12 @@ public class AnnotationColourChooser extends AnnotationRowFilter public AnnotationColourChooser(AlignViewport av, final AlignmentPanel ap) { + this(av, ap, null); + } + + public AnnotationColourChooser(AlignViewport av, final AlignmentPanel ap, + AnnotationColourGradient initSettings) + { super(av, ap); oldcs = av.getGlobalColourScheme(); if (av.getAlignment().getGroups() != null) @@ -87,6 +93,7 @@ public class AnnotationColourChooser extends AnnotationRowFilter } } frame = new JInternalFrame(); + frame.setFrameIcon(null); frame.setContentPane(this); frame.setLayer(JLayeredPane.PALETTE_LAYER); Desktop.addInternalFrame(frame, @@ -105,9 +112,29 @@ public class AnnotationColourChooser extends AnnotationRowFilter setDefaultMinMax(); adjusting = true; - if (oldcs instanceof AnnotationColourGradient) + if (oldcs instanceof AnnotationColourGradient && initSettings == null) + { + // init from oldcs + initialiseFrom((AnnotationColourGradient) oldcs); + } + else + { + // use initial colour gradient - if any.. + initialiseFrom(initSettings); + } + + jbInit(); + adjusting = false; + + updateView(); + frame.invalidate(); + frame.pack(); + } + + private void initialiseFrom(AnnotationColourGradient acg) + { + if (acg != null) { - AnnotationColourGradient acg = (AnnotationColourGradient) oldcs; useOriginalColours.setSelected( acg.isPredefinedColours() || acg.getBaseColour() != null); if (!acg.isPredefinedColours() && acg.getBaseColour() == null) @@ -124,10 +151,15 @@ public class AnnotationColourChooser extends AnnotationRowFilter populateThresholdComboBox(threshold); - if (oldcs instanceof AnnotationColourGradient) + if (acg != null) { - AnnotationColourGradient acg = (AnnotationColourGradient) oldcs; String label = getAnnotationMenuLabel(acg.getAnnotation()); + // TODO: workaround below shouldn't be necessary - there's a bug in + // getAnnotationMenuLabel! + if (acg.isSeqAssociated()) + { + label = acg.getAnnotation().label; + } annotations.setSelectedItem(label); switch (acg.getAboveThreshold()) { @@ -147,13 +179,6 @@ public class AnnotationColourChooser extends AnnotationRowFilter thresholdIsMin.setSelected(acg.isThresholdIsMinMax()); thresholdValue.setText(String.valueOf(acg.getAnnotationThreshold())); } - - jbInit(); - adjusting = false; - - updateView(); - frame.invalidate(); - frame.pack(); } @Override @@ -356,9 +381,10 @@ public class AnnotationColourChooser extends AnnotationRowFilter return; } + int selIndex = annotations.getSelectedIndex(); + int annIndex = annmap[selIndex]; setCurrentAnnotation( - av.getAlignment().getAlignmentAnnotation()[annmap[annotations - .getSelectedIndex()]]); + av.getAlignment().getAlignmentAnnotation()[annIndex]); int selectedThresholdItem = getSelectedThresholdItem( getThreshold().getSelectedIndex()); @@ -447,4 +473,41 @@ public class AnnotationColourChooser extends AnnotationRowFilter super.sliderDragReleased(); ap.paintAlignment(true, true); } + + /** + * construct and display a colourchooser for a given annotation row + * + * @param av + * @param ap + * @param alignmentAnnotation + * @param perseq + * - when true, enable per-sequence if alignment annotation is per + * sequence + */ + public static void displayFor(AlignViewport av, AlignmentPanel ap, + AlignmentAnnotation alignmentAnnotation, boolean perSeq) + { + ColourSchemeI global = av.getGlobalColourScheme(); + AnnotationColourGradient newCS = new AnnotationColourGradient( + alignmentAnnotation, global, + alignmentAnnotation.threshold != null + ? AnnotationColourGradient.ABOVE_THRESHOLD + : AnnotationColourGradient.NO_THRESHOLD); + if (alignmentAnnotation.sequenceRef != null) + { + newCS.setSeqAssociated(perSeq); + } + for (int i = 0; i < alignmentAnnotation.annotations.length; i++) + { + Annotation ann = alignmentAnnotation.annotations[i]; + if (ann != null && ann.colour != null + && !ann.colour.equals(Color.white)) + { + newCS.setPredefinedColours(true); + break; + } + } + AnnotationColourChooser achooser = new AnnotationColourChooser(av, ap, + newCS); + } }