From: gmungoc Date: Fri, 5 Feb 2016 14:56:13 +0000 (+0000) Subject: JAL-2006 scale even very small score ranges to a usable threshold slider X-Git-Tag: Release_2_10_0~316^2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=9885d5229311c88fc0ac67da9afb08f01269858b;p=jalview.git JAL-2006 scale even very small score ranges to a usable threshold slider --- diff --git a/src/jalview/gui/FeatureColourChooser.java b/src/jalview/gui/FeatureColourChooser.java index 625cccc..064d58b 100644 --- a/src/jalview/gui/FeatureColourChooser.java +++ b/src/jalview/gui/FeatureColourChooser.java @@ -76,9 +76,11 @@ public class FeatureColourChooser extends JalviewDialog boolean adjusting = false; - private float min; + final private float min; - private float max; + final private float max; + + final private float scaleFactor; String type = null; @@ -93,25 +95,28 @@ public class FeatureColourChooser extends JalviewDialog this.fr = frender; this.type = type; ap = fr.ap; - initDialogFrame(this, true, block, "Graduated Feature Colour for " - + type, 480, 185); + String title = MessageManager.formatMessage( + "label.graduated_color_for_params", new String[] { type }); + initDialogFrame(this, true, block, title, 480, 185); // frame.setLayer(JLayeredPane.PALETTE_LAYER); // Desktop.addInternalFrame(frame, "Graduated Feature Colour for "+type, // 480, 145); slider.addChangeListener(new ChangeListener() { + @Override public void stateChanged(ChangeEvent evt) { if (!adjusting) { - thresholdValue.setText(((float) slider.getValue() / 1000f) + ""); + thresholdValue.setText((slider.getValue() / scaleFactor) + ""); valueChanged(); } } }); slider.addMouseListener(new MouseAdapter() { + @Override public void mouseReleased(MouseEvent evt) { if (ap != null) @@ -125,6 +130,14 @@ public class FeatureColourChooser extends JalviewDialog float mm[] = ((float[][]) fr.getMinMax().get(type))[0]; min = mm[0]; max = mm[1]; + + /* + * ensure scale factor allows a scaled range with + * 10 integer divisions ('ticks'); if we have got here, + * we should expect that max != min + */ + scaleFactor = (max == min) ? 1f : 100f / (max - min); + oldcs = fr.getFeatureColours().get(type); if (oldcs instanceof GraduatedColor) { @@ -182,17 +195,6 @@ public class FeatureColourChooser extends JalviewDialog waitForInput(); } - public FeatureColourChooser() - { - try - { - jbInit(); - } catch (Exception ex) - { - ex.printStackTrace(); - } - } - private void jbInit() throws Exception { @@ -202,6 +204,7 @@ public class FeatureColourChooser extends JalviewDialog minColour.setToolTipText(MessageManager.getString("label.min_colour")); minColour.addMouseListener(new MouseAdapter() { + @Override public void mousePressed(MouseEvent e) { if (minColour.isEnabled()) @@ -216,6 +219,7 @@ public class FeatureColourChooser extends JalviewDialog maxColour.setToolTipText(MessageManager.getString("label.max_colour")); maxColour.addMouseListener(new MouseAdapter() { + @Override public void mousePressed(MouseEvent e) { if (maxColour.isEnabled()) @@ -235,6 +239,7 @@ public class FeatureColourChooser extends JalviewDialog jPanel2.setBackground(Color.white); threshold.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { threshold_actionPerformed(e); @@ -251,6 +256,7 @@ public class FeatureColourChooser extends JalviewDialog jPanel3.setLayout(flowLayout2); thresholdValue.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { thresholdValue_actionPerformed(e); @@ -274,6 +280,7 @@ public class FeatureColourChooser extends JalviewDialog .getString("label.toggle_absolute_relative_display_threshold")); thresholdIsMin.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent actionEvent) { thresholdIsMin_actionPerformed(actionEvent); @@ -287,6 +294,7 @@ public class FeatureColourChooser extends JalviewDialog .getString("label.display_features_same_type_different_label_using_different_colour")); colourByLabel.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent actionEvent) { colourByLabel_actionPerformed(actionEvent); @@ -432,11 +440,11 @@ public class FeatureColourChooser extends JalviewDialog adjusting = true; acg.setThresh(threshline.value); - float range = max * 1000f - min * 1000f; + float range = (max - min) * scaleFactor; - slider.setMinimum((int) (min * 1000)); - slider.setMaximum((int) (max * 1000)); - slider.setValue((int) (threshline.value * 1000)); + slider.setMinimum((int) (min * scaleFactor)); + slider.setMaximum((int) (max * scaleFactor)); + slider.setValue((int) (threshline.value * scaleFactor)); thresholdValue.setText(threshline.value + ""); slider.setMajorTickSpacing((int) (range / 10f)); slider.setEnabled(true); @@ -488,6 +496,7 @@ public class FeatureColourChooser extends JalviewDialog ap.paintAlignment(false); } + @Override protected void raiseClosed() { if (this.colourEditor != null) @@ -496,11 +505,13 @@ public class FeatureColourChooser extends JalviewDialog } } + @Override public void okPressed() { changeColour(); } + @Override public void cancelPressed() { reset(); @@ -533,7 +544,7 @@ public class FeatureColourChooser extends JalviewDialog try { float f = Float.parseFloat(thresholdValue.getText()); - slider.setValue((int) (f * 1000)); + slider.setValue((int) (f * scaleFactor)); threshline.value = f; } catch (NumberFormatException ex) { @@ -542,7 +553,7 @@ public class FeatureColourChooser extends JalviewDialog public void valueChanged() { - threshline.value = (float) slider.getValue() / 1000f; + threshline.value = slider.getValue() / scaleFactor; cs.setThresh(threshline.value); changeColour(); ap.paintAlignment(false);