JAL-4047 - proof of concept for JAL-4048 - display columns of info in sequence ID...
[jalview.git] / src / jalview / gui / IdCanvas.java
index c94dee0..e284bbe 100755 (executable)
@@ -36,6 +36,9 @@ import javax.swing.JPanel;
 import jalview.datamodel.SequenceI;
 import jalview.viewmodel.ViewportListenerI;
 import jalview.viewmodel.ViewportRanges;
+import jalview.viewmodel.seqfeatures.IdColumn;
+import jalview.viewmodel.seqfeatures.IdColumns;
+import jalview.viewmodel.seqfeatures.IdColumns.ColumnCell;
 
 /**
  * DOCUMENT ME!
@@ -308,7 +311,16 @@ public class IdCanvas extends JPanel implements ViewportListenerI
     }
 
     // Now draw the id strings
-    int panelWidth = getWidth();
+    int fullPanelWidth = getWidth();
+
+    IdColumns id_cols = alignViewport.getIdColumns();
+    List<IdColumn> visible = id_cols.getVisible();
+    /**
+     * width of an idColumn
+     */
+    int colWid = 20;
+    int panelWidth = Math.max(fullPanelWidth / 2,
+            fullPanelWidth - (colWid * visible.size()));
     int xPos = 0;
 
     // Now draw the id strings
@@ -320,7 +332,6 @@ public class IdCanvas extends JPanel implements ViewportListenerI
       {
         continue;
       }
-
       if (hasHiddenRows || alignViewport.isDisplayReferenceSeq())
       {
         g.setFont(getHiddenFont(sequence, alignViewport));
@@ -364,6 +375,32 @@ public class IdCanvas extends JPanel implements ViewportListenerI
               (((i - startSeq) * charHeight) + charHeight)
                       - (charHeight / 5));
 
+      if (visible != null && visible.size() > 0)
+      {
+        xPos = panelWidth + 2;
+        for (IdColumn col : visible)
+        {
+          ColumnCell col_cell = id_cols.getCellFor(sequence, col);
+          if (col_cell == null)
+          {
+            g.setColor(Color.gray);
+            g.fillRect(xPos, (i - startSeq) * charHeight, xPos + colWid - 4,
+                    charHeight);
+          }
+          else
+          {
+            g.setColor(col_cell.bg);
+            g.fillRect(xPos, (i - startSeq) * charHeight, xPos + colWid - 4,
+                    charHeight);
+            g.setColor(col_cell.fg);
+            g.drawString(col_cell.label, xPos,
+                    (((i - startSeq) * charHeight) + charHeight)
+                            - (charHeight / 5));
+          }
+          xPos += colWid;
+          g.setColor(currentTextColor);
+        }
+      }
       if (hasHiddenRows && av.getShowHiddenMarkers())
       {
         drawMarker(g, alignViewport, i, startSeq, 0);