graduated feature schemes (with visual indication of thresholding)
[jalview.git] / src / jalview / gui / FeatureSettings.java
index def0a09..1bb4adc 100755 (executable)
@@ -1381,6 +1381,8 @@ public class FeatureSettings extends JPanel
     public ColorRenderer()
     {
       setOpaque(true); // MUST do this for background to show up.
+      setHorizontalTextPosition(SwingConstants.CENTER);
+      setVerticalTextPosition(SwingConstants.CENTER);
     }
 
     public Component getTableCellRendererComponent(JTable table,
@@ -1462,22 +1464,28 @@ public class FeatureSettings extends JPanel
   public static void renderGraduatedColor(JLabel comp, GraduatedColor gcol,
           int w, int h)
   {
-
+    boolean thr=false;
     String tt = "";
     String tx = "";
     if (gcol.getThreshType() == AnnotationColourGradient.ABOVE_THRESHOLD)
     {
-      tx += "> ";
+      thr=true;
+      tx += ">";
       tt += "Thresholded (Above " + gcol.getThresh() + ") ";
     }
     if (gcol.getThreshType() == AnnotationColourGradient.BELOW_THRESHOLD)
     {
-      tx += "< ";
+      thr=true;
+      tx += "<";
       tt += "Thresholded (Below " + gcol.getThresh() + ") ";
     }
     if (gcol.isColourByLabel())
     {
       tt = "Coloured by label text. " + tt;
+      if (thr)
+      {
+        tx+=" ";
+      }
       tx += "Label";
       comp.setIcon(null);
     }
@@ -1486,13 +1494,14 @@ public class FeatureSettings extends JPanel
       Color newColor = gcol.getMaxColor();
       comp.setBackground(newColor);
       // System.err.println("Width is " + w / 2);
-      Icon ficon = new FeatureIcon(gcol, comp.getBackground(), w / 2, h);
+      Icon ficon = new FeatureIcon(gcol, comp.getBackground(), w, h, thr);
       comp.setIcon(ficon);
       // tt+="RGB value: Max (" + newColor.getRed() + ", "
       // + newColor.getGreen() + ", " + newColor.getBlue()
       // + ")\nMin (" + minCol.getRed() + ", " + minCol.getGreen()
       // + ", " + minCol.getBlue() + ")");
     }
+    comp.setHorizontalAlignment(SwingConstants.CENTER);
     comp.setText(tx);
     if (tt.length() > 0)
     {
@@ -1513,15 +1522,26 @@ class FeatureIcon implements Icon
   GraduatedColor gcol;
 
   Color backg;
-
+  boolean midspace=false;
   int width = 50, height = 20;
+  int s1,e1; // start and end of midpoint band for thresholded symbol
+  Color mpcolour = Color.white;
 
-  FeatureIcon(GraduatedColor gfc, Color bg, int w, int h)
+  FeatureIcon(GraduatedColor gfc, Color bg, int w, int h, boolean mspace)
   {
     gcol = gfc;
     backg = bg;
     width = w;
     height = h;
+    midspace = mspace;
+    if (midspace)
+    {
+      s1=width/3;
+      e1=s1*2;
+    } else {
+      s1 = width/2;
+      e1 = s1;
+    }
   }
 
   public int getIconWidth()
@@ -1558,7 +1578,14 @@ class FeatureIcon implements Icon
     {
       Color minCol = gcol.getMinColor();
       g.setColor(minCol);
-      g.fillRect(0, 0, width, height);
+      g.fillRect(0, 0, s1, height);
+      if (midspace)
+      {
+        g.setColor(Color.white);
+        g.fillRect(s1,0,e1-s1, height);
+      }
+      g.setColor(gcol.getMaxColor());
+      g.fillRect(0,e1, width-e1,  height);
     }
   }
 }