X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAnnotationColourChooser.java;h=965770ce5a7bbc4f7a57821d2f365b94ca089951;hb=0ebbad305e982eeda562a1842362dc415c36cc8d;hp=f0887915c40ce6b8f833613767dbcf2b9d9b6f26;hpb=3d0101179759ef157b088ea135423cd909512d9f;p=jalview.git diff --git a/src/jalview/gui/AnnotationColourChooser.java b/src/jalview/gui/AnnotationColourChooser.java index f088791..965770c 100644 --- a/src/jalview/gui/AnnotationColourChooser.java +++ b/src/jalview/gui/AnnotationColourChooser.java @@ -20,14 +20,6 @@ */ package jalview.gui; -import jalview.bin.Cache; -import jalview.datamodel.AlignmentAnnotation; -import jalview.datamodel.GraphLine; -import jalview.datamodel.SequenceGroup; -import jalview.schemes.AnnotationColourGradient; -import jalview.schemes.ColourSchemeI; -import jalview.util.MessageManager; - import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; @@ -42,19 +34,25 @@ import java.util.Vector; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JCheckBox; -import javax.swing.JColorChooser; import javax.swing.JComboBox; 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") public class AnnotationColourChooser extends AnnotationRowFilter { - private static final int ONETHOUSAND = 1000; - private ColourSchemeI oldcs; private JButton defColours; @@ -63,9 +61,9 @@ public class AnnotationColourChooser extends AnnotationRowFilter private JCheckBox useOriginalColours = new JCheckBox(); - private JPanel minColour = new JPanel(); + JPanel minColour = new JPanel(); - private JPanel maxColour = new JPanel(); + JPanel maxColour = new JPanel(); private JCheckBox thresholdIsMin = new JCheckBox(); @@ -75,11 +73,17 @@ 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) { - oldgroupColours = new Hashtable(); + oldgroupColours = new Hashtable<>(); for (SequenceGroup sg : ap.av.getAlignment().getGroups()) { if (sg.getColourScheme() != null) @@ -89,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, @@ -107,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) @@ -122,14 +147,19 @@ public class AnnotationColourChooser extends AnnotationRowFilter } Vector annotItems = getAnnotationItems( seqAssociated.isSelected()); - annotations = new JComboBox(annotItems); + annotations = new JComboBox<>(annotItems); 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,15 +177,8 @@ public class AnnotationColourChooser extends AnnotationRowFilter "error.implementation_error_dont_know_about_threshold_setting")); } thresholdIsMin.setSelected(acg.isThresholdIsMinMax()); - thresholdValue.setText("" + acg.getAnnotationThreshold()); + thresholdValue.setText(String.valueOf(acg.getAnnotationThreshold())); } - - jbInit(); - adjusting = false; - - updateView(); - frame.invalidate(); - frame.pack(); } @Override @@ -174,7 +197,7 @@ public class AnnotationColourChooser extends AnnotationRowFilter { if (minColour.isEnabled()) { - minColour_actionPerformed(); + showColourChooser(minColour, "label.select_colour_minimum_value"); } } }); @@ -189,7 +212,7 @@ public class AnnotationColourChooser extends AnnotationRowFilter { if (maxColour.isEnabled()) { - maxColour_actionPerformed(); + showColourChooser(maxColour, "label.select_colour_maximum_value"); } } }); @@ -288,36 +311,27 @@ public class AnnotationColourChooser extends AnnotationRowFilter Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", Color.red)); } - public void minColour_actionPerformed() + protected void showColourChooser(JPanel colourPanel, String titleKey) { - Color col = JColorChooser.showDialog(this, - MessageManager.getString("label.select_colour_minimum_value"), - minColour.getBackground()); - if (col != null) + String ttl = MessageManager.getString(titleKey); + ColourChooserListener listener = new ColourChooserListener() { - minColour.setBackground(col); - } - minColour.repaint(); - updateView(); - } - - public void maxColour_actionPerformed() - { - Color col = JColorChooser.showDialog(this, - MessageManager.getString("label.select_colour_maximum_value"), - maxColour.getBackground()); - if (col != null) - { - maxColour.setBackground(col); - } - maxColour.repaint(); - updateView(); + @Override + public void colourSelected(Color c) + { + colourPanel.setBackground(c); + colourPanel.repaint(); + updateView(); + } + }; + JalviewColourChooser.showColourChooser(Desktop.getDesktop(), ttl, + colourPanel.getBackground(), listener); } @Override public void reset() { - av.setGlobalColourScheme(oldcs); + this.ap.alignFrame.changeColour(oldcs); if (av.getAlignment().getGroups() != null) { @@ -338,10 +352,10 @@ public class AnnotationColourChooser extends AnnotationRowFilter { updateView(); } - getCurrentAnnotation().threshold.value = slider.getValue() / 1000f; + getCurrentAnnotation().threshold.value = getSliderValue(); propagateSeqAssociatedThreshold(updateAllAnnotation, getCurrentAnnotation()); - ap.paintAlignment(false); + ap.paintAlignment(false, false); } } @@ -367,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()); @@ -378,6 +393,7 @@ public class AnnotationColourChooser extends AnnotationRowFilter thresholdValue.setEnabled(true); thresholdIsMin.setEnabled(!useOriginalColours.isSelected()); + final AlignmentAnnotation currentAnnotation = getCurrentAnnotation(); if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD) { slider.setEnabled(false); @@ -386,41 +402,31 @@ public class AnnotationColourChooser extends AnnotationRowFilter thresholdIsMin.setEnabled(false); } else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD - && getCurrentAnnotation().threshold == null) + && currentAnnotation.threshold == null) { - getCurrentAnnotation().setThreshold(new GraphLine( - (getCurrentAnnotation().graphMax - - getCurrentAnnotation().graphMin) / 2f, + currentAnnotation.setThreshold(new GraphLine( + (currentAnnotation.graphMax - currentAnnotation.graphMin) + / 2f, "Threshold", Color.black)); } if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD) { adjusting = true; - float range = getCurrentAnnotation().graphMax * ONETHOUSAND - - getCurrentAnnotation().graphMin * ONETHOUSAND; - - slider.setMinimum( - (int) (getCurrentAnnotation().graphMin * ONETHOUSAND)); - slider.setMaximum( - (int) (getCurrentAnnotation().graphMax * ONETHOUSAND)); - slider.setValue( - (int) (getCurrentAnnotation().threshold.value * ONETHOUSAND)); - thresholdValue.setText(getCurrentAnnotation().threshold.value + ""); - slider.setMajorTickSpacing((int) (range / 10f)); + setSliderModel(currentAnnotation.graphMin, currentAnnotation.graphMax, + currentAnnotation.threshold.value); slider.setEnabled(true); + + setThresholdValueText(); thresholdValue.setEnabled(true); adjusting = false; } - colorAlignmentContaining(getCurrentAnnotation(), selectedThresholdItem); + colorAlignmentContaining(currentAnnotation, selectedThresholdItem); ap.alignmentChanged(); - // ensure all associated views (overviews, structures, etc) are notified of - // updated colours. - ap.paintAlignment(true); } - protected boolean colorAlignmentContaining(AlignmentAnnotation currentAnn, + protected void colorAlignmentContaining(AlignmentAnnotation currentAnn, int selectedThresholdOption) { @@ -445,7 +451,7 @@ public class AnnotationColourChooser extends AnnotationRowFilter acg.setThresholdIsMinMax(thresholdIsMin.isSelected()); - av.setGlobalColourScheme(acg); + this.ap.alignFrame.changeColour(acg); if (av.getAlignment().getGroups() != null) { @@ -456,25 +462,52 @@ public class AnnotationColourChooser extends AnnotationRowFilter { continue; } - - if (useOriginalColours.isSelected()) - { - sg.setColourScheme(new AnnotationColourGradient(currentAnn, - sg.getColourScheme(), selectedThresholdOption)); - ((AnnotationColourGradient) sg.cs) - .setSeqAssociated(seqAssociated.isSelected()); - } - else - { - sg.setColourScheme(new AnnotationColourGradient(currentAnn, - minColour.getBackground(), maxColour.getBackground(), - selectedThresholdOption)); - ((AnnotationColourGradient) sg.cs) - .setSeqAssociated(seqAssociated.isSelected()); - } + sg.setColourScheme(acg.getInstance(av, sg)); } } - return false; } + @Override + protected void sliderDragReleased() + { + 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); + } }