X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAnnotationColourChooser.java;h=60ad75d4f78f5904cb4745fe285e605c676ef8d0;hb=16d109024847af92482237e43f99b82fd997451a;hp=3c6fd88f79386b5534cf2c0900c5e76924bfafa6;hpb=c03d2649512cdc491a46dda1d1370273241b5253;p=jalview.git diff --git a/src/jalview/gui/AnnotationColourChooser.java b/src/jalview/gui/AnnotationColourChooser.java index 3c6fd88..60ad75d 100644 --- a/src/jalview/gui/AnnotationColourChooser.java +++ b/src/jalview/gui/AnnotationColourChooser.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2) - * Copyright (C) 2014 The Jalview Authors + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * @@ -21,6 +21,8 @@ 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; @@ -35,9 +37,11 @@ import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.Hashtable; +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; @@ -49,31 +53,25 @@ import net.miginfocom.swing.MigLayout; @SuppressWarnings("serial") public class AnnotationColourChooser extends AnnotationRowFilter { + private static final int ONETHOUSAND = 1000; - ColourSchemeI oldcs; + private ColourSchemeI oldcs; - Hashtable oldgroupColours; + private JButton defColours; - /** - * enabled if the user is dragging the slider - try to keep updates to a - * minimun - */ + private Hashtable oldgroupColours; - JComboBox annotations; + private JCheckBox useOriginalColours = new JCheckBox(); - JButton defColours = new JButton(); + private JPanel minColour = new JPanel(); - JButton ok = new JButton(); + private JPanel maxColour = new JPanel(); - JButton cancel = new JButton(); + private JCheckBox thresholdIsMin = new JCheckBox(); - JPanel jPanel1 = new JPanel(); + protected static final int MIN_WIDTH = 500; - JPanel jPanel2 = new JPanel(); - - BorderLayout borderLayout1 = new BorderLayout(); - - private JComboBox threshold = new JComboBox(); + protected static final int MIN_HEIGHT = 240; public AnnotationColourChooser(AlignViewport av, final AlignmentPanel ap) { @@ -81,12 +79,12 @@ public class AnnotationColourChooser extends AnnotationRowFilter 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()); } } } @@ -96,7 +94,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(); @@ -112,8 +110,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()); @@ -122,15 +120,17 @@ public class AnnotationColourChooser extends AnnotationRowFilter seqAssociated.setSelected(acg.isSeqAssociated()); } - annotations = new JComboBox( - getAnnotationItems(seqAssociated.isSelected())); + Vector annotItems = getAnnotationItems( + seqAssociated.isSelected()); + annotations = new JComboBox<>(annotItems); populateThresholdComboBox(threshold); if (oldcs instanceof AnnotationColourGradient) { AnnotationColourGradient acg = (AnnotationColourGradient) oldcs; - annotations.setSelectedItem(acg.getAnnotation()); + String label = getAnnotationMenuLabel(acg.getAnnotation()); + annotations.setSelectedItem(label); switch (acg.getAboveThreshold()) { case AnnotationColourGradient.NO_THRESHOLD: @@ -143,18 +143,14 @@ public class AnnotationColourChooser extends AnnotationRowFilter getThreshold().setSelectedIndex(2); break; default: - throw new Error(MessageManager.getString("error.implementation_error_dont_know_about_thereshold_setting")); + throw new Error(MessageManager.getString( + "error.implementation_error_dont_know_about_threshold_setting")); } - thresholdIsMin.setSelected(acg.thresholdIsMinMax); + thresholdIsMin.setSelected(acg.isThresholdIsMinMax()); thresholdValue.setText("" + acg.getAnnotationThreshold()); } - try - { - jbInit(); - } catch (Exception ex) - { - } + jbInit(); adjusting = false; updateView(); @@ -162,19 +158,11 @@ public class AnnotationColourChooser extends AnnotationRowFilter frame.pack(); } - public AnnotationColourChooser() + @Override + protected void jbInit() { - try - { - jbInit(); - } catch (Exception ex) - { - ex.printStackTrace(); - } - } + super.jbInit(); - private void jbInit() throws Exception - { minColour.setFont(JvSwingUtils.getLabelFont()); minColour.setBorder(BorderFactory.createEtchedBorder()); minColour.setPreferredSize(new Dimension(40, 20)); @@ -205,26 +193,8 @@ public class AnnotationColourChooser extends AnnotationRowFilter } } }); - ok.setOpaque(false); - ok.setText(MessageManager.getString("action.ok")); - ok.addActionListener(new ActionListener() - { - @Override - public void actionPerformed(ActionEvent e) - { - ok_actionPerformed(e); - } - }); - cancel.setOpaque(false); - cancel.setText(MessageManager.getString("action.cancel")); - cancel.addActionListener(new ActionListener() - { - @Override - public void actionPerformed(ActionEvent e) - { - cancel_actionPerformed(e); - } - }); + + defColours = new JButton(); defColours.setOpaque(false); defColours.setText(MessageManager.getString("action.set_defaults")); defColours.setToolTipText(MessageManager @@ -235,81 +205,51 @@ public class AnnotationColourChooser extends AnnotationRowFilter @Override public void actionPerformed(ActionEvent arg0) { - resetColours_actionPerformed(arg0); + resetColours_actionPerformed(); } }); - annotations.addActionListener(new ActionListener() - { - @Override - public void actionPerformed(ActionEvent e) - { - annotations_actionPerformed(e); - } - }); - getThreshold().addActionListener(new ActionListener() - { - @Override - public void actionPerformed(ActionEvent e) - { - threshold_actionPerformed(e); - } - }); - thresholdValue.addActionListener(new ActionListener() - { - @Override - public void actionPerformed(ActionEvent e) - { - thresholdValue_actionPerformed(e); - } - }); - slider.setPaintLabels(false); - slider.setPaintTicks(true); - slider.setBackground(Color.white); - slider.setEnabled(false); - slider.setOpaque(false); - slider.setPreferredSize(new Dimension(100, 32)); - thresholdValue.setEnabled(false); - thresholdValue.setColumns(7); - 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(e); + 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 public void actionPerformed(ActionEvent actionEvent) { - thresholdIsMin_actionPerformed(actionEvent); + thresholdIsMin_actionPerformed(); } }); 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() { @Override public void actionPerformed(ActionEvent arg0) { - seqAssociated_actionPerformed(arg0, annotations, seqAssociated); + seqAssociated_actionPerformed(annotations); } }); - this.setLayout(borderLayout1); + this.setLayout(new BorderLayout()); + JPanel jPanel1 = new JPanel(); + JPanel jPanel2 = new JPanel(); jPanel2.setLayout(new MigLayout("", "[left][center][right]", "[][][]")); jPanel1.setBackground(Color.white); jPanel2.setBackground(Color.white); @@ -318,7 +258,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); @@ -334,7 +274,7 @@ public class AnnotationColourChooser extends AnnotationRowFilter this.validate(); } - protected void resetColours_actionPerformed(ActionEvent arg0) + protected void resetColours_actionPerformed() { setDefaultMinMax(); updateView(); @@ -342,16 +282,17 @@ 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() { Color col = JColorChooser.showDialog(this, - MessageManager.getString("label.select_colour_minimum_value"), minColour.getBackground()); + MessageManager.getString("label.select_colour_minimum_value"), + minColour.getBackground()); if (col != null) { minColour.setBackground(col); @@ -363,7 +304,8 @@ public class AnnotationColourChooser extends AnnotationRowFilter public void maxColour_actionPerformed() { Color col = JColorChooser.showDialog(this, - MessageManager.getString("label.select_colour_maximum_value"), maxColour.getBackground()); + MessageManager.getString("label.select_colour_maximum_value"), + maxColour.getBackground()); if (col != null) { maxColour.setBackground(col); @@ -372,53 +314,47 @@ public class AnnotationColourChooser extends AnnotationRowFilter updateView(); } + @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)); } } } + @Override public void valueChanged(boolean updateAllAnnotation) { if (slider.isEnabled()) { - if (currentColours.isSelected() - && !(av.getGlobalColourScheme() instanceof AnnotationColourGradient)) + if (useOriginalColours.isSelected() && !(av + .getGlobalColourScheme() instanceof AnnotationColourGradient)) { updateView(); } getCurrentAnnotation().threshold.value = slider.getValue() / 1000f; propagateSeqAssociatedThreshold(updateAllAnnotation, getCurrentAnnotation()); - ap.paintAlignment(false); + ap.paintAlignment(false, false); } } - public JComboBox getThreshold() - { - return threshold; - } - - public void setThreshold(JComboBox threshold) - { - this.threshold = threshold; - } - - public void currentColours_actionPerformed(ActionEvent e) + 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(); } @@ -431,15 +367,16 @@ 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()); if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD) { @@ -451,33 +388,81 @@ public class AnnotationColourChooser extends AnnotationRowFilter else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD && getCurrentAnnotation().threshold == null) { - getCurrentAnnotation() - .setThreshold(new jalview.datamodel.GraphLine( - (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f, - "Threshold", Color.black)); + getCurrentAnnotation().setThreshold(new GraphLine( + (getCurrentAnnotation().graphMax + - getCurrentAnnotation().graphMin) / 2f, + "Threshold", Color.black)); } if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD) { adjusting = true; - float range = getCurrentAnnotation().graphMax * 1000 - - getCurrentAnnotation().graphMin * 1000; - - slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000)); - slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000)); - slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000)); + 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)); slider.setEnabled(true); thresholdValue.setEnabled(true); adjusting = false; } - colorAlignmContaining(getCurrentAnnotation(), selectedThresholdItem); + colorAlignmentContaining(getCurrentAnnotation(), selectedThresholdItem); ap.alignmentChanged(); - // ensure all associated views (overviews, structures, etc) are notified of - // updated colours. - ap.paintAlignment(true); } + protected void colorAlignmentContaining(AlignmentAnnotation currentAnn, + int selectedThresholdOption) + { + + AnnotationColourGradient acg = null; + if (useOriginalColours.isSelected()) + { + acg = new AnnotationColourGradient(currentAnn, + av.getGlobalColourScheme(), selectedThresholdOption); + } + else + { + acg = new AnnotationColourGradient(currentAnn, + minColour.getBackground(), maxColour.getBackground(), + selectedThresholdOption); + } + acg.setSeqAssociated(seqAssociated.isSelected()); + + if (currentAnn.graphMin == 0f && currentAnn.graphMax == 0f) + { + acg.setPredefinedColours(true); + } + + acg.setThresholdIsMinMax(thresholdIsMin.isSelected()); + + this.ap.alignFrame.changeColour(acg); + + if (av.getAlignment().getGroups() != null) + { + + for (SequenceGroup sg : ap.av.getAlignment().getGroups()) + { + if (sg.cs == null) + { + continue; + } + sg.setColourScheme( + acg.getInstance(av, sg)); + } + } + } + + @Override + protected void sliderDragReleased() + { + super.sliderDragReleased(); + ap.paintAlignment(true, true); + } }