X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAnnotationColourChooser.java;h=ad013f5bb1a90478c99967c3ce79a70c6c862b24;hb=27dc4596d13971e00f04578d469c5e3eb604757f;hp=d24409f804df8e17ba309ddd838762a1499fa999;hpb=2826ec08117a35c2b53fdc7729921a5087e54c1f;p=jalview.git diff --git a/src/jalview/gui/AnnotationColourChooser.java b/src/jalview/gui/AnnotationColourChooser.java index d24409f..ad013f5 100644 --- a/src/jalview/gui/AnnotationColourChooser.java +++ b/src/jalview/gui/AnnotationColourChooser.java @@ -24,6 +24,7 @@ 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; @@ -42,7 +43,6 @@ 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; @@ -53,34 +53,36 @@ import net.miginfocom.swing.MigLayout; @SuppressWarnings("serial") public class AnnotationColourChooser extends AnnotationRowFilter { - private static final int ONETHOUSAND = 1000; - private ColourSchemeI oldcs; private JButton defColours; private Hashtable oldgroupColours; - private JCheckBox currentColours = new JCheckBox(); + 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(); + protected static final int MIN_WIDTH = 500; + + protected static final int MIN_HEIGHT = 240; + public AnnotationColourChooser(AlignViewport av, final AlignmentPanel ap) { 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.cs != null) + if (sg.getColourScheme() != null) { - oldgroupColours.put(sg, sg.cs); + oldgroupColours.put(sg, sg.getColourScheme()); } } } @@ -90,7 +92,7 @@ public class AnnotationColourChooser extends AnnotationRowFilter Desktop.addInternalFrame(frame, MessageManager.getString("label.colour_by_annotation"), 520, 215); - + frame.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT)); addSliderChangeListener(); addSliderMouseListeners(); @@ -106,8 +108,8 @@ public class AnnotationColourChooser extends AnnotationRowFilter if (oldcs instanceof AnnotationColourGradient) { AnnotationColourGradient acg = (AnnotationColourGradient) oldcs; - currentColours.setSelected(acg.isPredefinedColours() - || acg.getBaseColour() != null); + useOriginalColours.setSelected( + acg.isPredefinedColours() || acg.getBaseColour() != null); if (!acg.isPredefinedColours() && acg.getBaseColour() == null) { minColour.setBackground(acg.getMinColour()); @@ -116,9 +118,9 @@ public class AnnotationColourChooser extends AnnotationRowFilter seqAssociated.setSelected(acg.isSeqAssociated()); } - Vector annotItems = getAnnotationItems(seqAssociated - .isSelected()); - annotations = new JComboBox(annotItems); + Vector annotItems = getAnnotationItems( + seqAssociated.isSelected()); + annotations = new JComboBox<>(annotItems); populateThresholdComboBox(threshold); @@ -139,12 +141,12 @@ public class AnnotationColourChooser extends AnnotationRowFilter getThreshold().setSelectedIndex(2); break; default: - throw new Error( - MessageManager - .getString("error.implementation_error_dont_know_about_threshold_setting")); + throw new Error(MessageManager.getString( + "error.implementation_error_dont_know_about_threshold_setting")); } thresholdIsMin.setSelected(acg.isThresholdIsMinMax()); - thresholdValue.setText("" + acg.getAnnotationThreshold()); + thresholdValue + .setText(String.valueOf(acg.getAnnotationThreshold())); } jbInit(); @@ -171,7 +173,7 @@ public class AnnotationColourChooser extends AnnotationRowFilter { if (minColour.isEnabled()) { - minColour_actionPerformed(); + showColourChooser(minColour, "label.select_colour_minimum_value"); } } }); @@ -186,7 +188,7 @@ public class AnnotationColourChooser extends AnnotationRowFilter { if (maxColour.isEnabled()) { - maxColour_actionPerformed(); + showColourChooser(maxColour, "label.select_colour_maximum_value"); } } }); @@ -206,22 +208,22 @@ public class AnnotationColourChooser extends AnnotationRowFilter } }); - currentColours.setFont(JvSwingUtils.getLabelFont()); - currentColours.setOpaque(false); - currentColours.setText(MessageManager - .getString("label.use_original_colours")); - currentColours.addActionListener(new ActionListener() + useOriginalColours.setFont(JvSwingUtils.getLabelFont()); + useOriginalColours.setOpaque(false); + useOriginalColours.setText( + MessageManager.getString("label.use_original_colours")); + useOriginalColours.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - currentColours_actionPerformed(); + originalColours_actionPerformed(); } }); thresholdIsMin.setBackground(Color.white); thresholdIsMin.setFont(JvSwingUtils.getLabelFont()); - thresholdIsMin.setText(MessageManager - .getString("label.threshold_minmax")); + thresholdIsMin + .setText(MessageManager.getString("label.threshold_minmax")); thresholdIsMin.addActionListener(new ActionListener() { @Override @@ -232,8 +234,8 @@ public class AnnotationColourChooser extends AnnotationRowFilter }); seqAssociated.setBackground(Color.white); seqAssociated.setFont(JvSwingUtils.getLabelFont()); - seqAssociated.setText(MessageManager - .getString("label.per_sequence_only")); + seqAssociated + .setText(MessageManager.getString("label.per_sequence_only")); seqAssociated.addActionListener(new ActionListener() { @@ -255,7 +257,7 @@ public class AnnotationColourChooser extends AnnotationRowFilter jPanel1.add(cancel); jPanel2.add(annotations, "grow, wrap"); jPanel2.add(seqAssociated); - jPanel2.add(currentColours); + jPanel2.add(useOriginalColours); JPanel colpanel = new JPanel(new FlowLayout()); colpanel.setBackground(Color.white); colpanel.add(minColour); @@ -279,48 +281,39 @@ public class AnnotationColourChooser extends AnnotationRowFilter private void setDefaultMinMax() { - minColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", - Color.orange)); - maxColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", - Color.red)); + minColour.setBackground( + Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", Color.orange)); + maxColour.setBackground( + 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) { for (SequenceGroup sg : ap.av.getAlignment().getGroups()) { - sg.cs = oldgroupColours.get(sg); + sg.setColourScheme(oldgroupColours.get(sg)); } } } @@ -330,26 +323,28 @@ public class AnnotationColourChooser extends AnnotationRowFilter { if (slider.isEnabled()) { - if (currentColours.isSelected() - && !(av.getGlobalColourScheme() instanceof AnnotationColourGradient)) + if (useOriginalColours.isSelected() && !(av + .getGlobalColourScheme() instanceof AnnotationColourGradient)) { updateView(); } - getCurrentAnnotation().threshold.value = slider.getValue() / 1000f; + getCurrentAnnotation().threshold.value = getSliderValue(); propagateSeqAssociatedThreshold(updateAllAnnotation, getCurrentAnnotation()); - ap.paintAlignment(false); + ap.paintAlignment(false, false); } } - public void currentColours_actionPerformed() + public void originalColours_actionPerformed() { - if (currentColours.isSelected()) + boolean selected = useOriginalColours.isSelected(); + if (selected) { reset(); } - maxColour.setEnabled(!currentColours.isSelected()); - minColour.setEnabled(!currentColours.isSelected()); + maxColour.setEnabled(!selected); + minColour.setEnabled(!selected); + thresholdIsMin.setEnabled(!selected); updateView(); } @@ -362,16 +357,18 @@ public class AnnotationColourChooser extends AnnotationRowFilter return; } - setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[annmap[annotations - .getSelectedIndex()]]); + setCurrentAnnotation( + av.getAlignment().getAlignmentAnnotation()[annmap[annotations + .getSelectedIndex()]]); - int selectedThresholdItem = getSelectedThresholdItem(getThreshold() - .getSelectedIndex()); + int selectedThresholdItem = getSelectedThresholdItem( + getThreshold().getSelectedIndex()); slider.setEnabled(true); thresholdValue.setEnabled(true); - thresholdIsMin.setEnabled(true); + thresholdIsMin.setEnabled(!useOriginalColours.isSelected()); + final AlignmentAnnotation currentAnnotation = getCurrentAnnotation(); if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD) { slider.setEnabled(false); @@ -380,43 +377,36 @@ 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, - "Threshold", Color.black)); + 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, int selectedThresholdOption) + protected void colorAlignmentContaining(AlignmentAnnotation currentAnn, + int selectedThresholdOption) { - + AnnotationColourGradient acg = null; - if (currentColours.isSelected()) + if (useOriginalColours.isSelected()) { acg = new AnnotationColourGradient(currentAnn, av.getGlobalColourScheme(), selectedThresholdOption); @@ -428,44 +418,35 @@ public class AnnotationColourChooser extends AnnotationRowFilter selectedThresholdOption); } acg.setSeqAssociated(seqAssociated.isSelected()); - + if (currentAnn.graphMin == 0f && currentAnn.graphMax == 0f) { acg.setPredefinedColours(true); } - + acg.setThresholdIsMinMax(thresholdIsMin.isSelected()); - - av.setGlobalColourScheme(acg); - + + this.ap.alignFrame.changeColour(acg); + if (av.getAlignment().getGroups() != null) { - + for (SequenceGroup sg : ap.av.getAlignment().getGroups()) { if (sg.cs == null) { continue; } - - if (currentColours.isSelected()) - { - sg.cs = new AnnotationColourGradient(currentAnn, sg.cs, - selectedThresholdOption); - ((AnnotationColourGradient) sg.cs).setSeqAssociated(seqAssociated - .isSelected()); - } - else - { - sg.cs = 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); + } }