JAL-2835 spike updated with latest
[jalview.git] / src / jalview / gui / FeatureSettings.java
index 4e4d2cb..ed98830 100644 (file)
@@ -53,6 +53,7 @@ import java.awt.FlowLayout;
 import java.awt.Font;
 import java.awt.Graphics;
 import java.awt.GridLayout;
+import java.awt.LayoutManager;
 import java.awt.Rectangle;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
@@ -119,6 +120,8 @@ import javax.swing.table.TableCellRenderer;
 public class FeatureSettings extends JPanel
         implements FeatureSettingsControllerI
 {
+  private static final String COLON = ":";
+
   private static final int MIN_WIDTH = 400;
 
   private static final int MIN_HEIGHT = 400;
@@ -199,6 +202,9 @@ public class FeatureSettings extends JPanel
 
   private JTextArea filtersAsText;
 
+  // set white normally, black to debug layout
+  private Color debugBorderColour = Color.white;
+
   /**
    * Constructor
    * 
@@ -1371,6 +1377,7 @@ public class FeatureSettings extends JPanel
      */
     JPanel andOrPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
     andOrPanel.setBackground(Color.white);
+    andOrPanel.setBorder(BorderFactory.createLineBorder(debugBorderColour));
     andFilters = new JRadioButton("And");
     orFilters = new JRadioButton("Or");
     ActionListener actionListener = new ActionListener()
@@ -1397,8 +1404,9 @@ public class FeatureSettings extends JPanel
      * panel with filters - populated by refreshFiltersDisplay
      */
     chooseFiltersPanel = new JPanel();
-    chooseFiltersPanel.setLayout(new BoxLayout(chooseFiltersPanel,
-            BoxLayout.Y_AXIS));
+    LayoutManager box = new BoxLayout(chooseFiltersPanel,
+            BoxLayout.Y_AXIS);
+    chooseFiltersPanel.setLayout(box);
     filtersPanel.add(chooseFiltersPanel);
 
     /*
@@ -1454,12 +1462,12 @@ public class FeatureSettings extends JPanel
     }
     if (!found)
     {
-      filteredFeatureChoice // todo i18n
-              .addItem("No filterable feature attributes known");
+      filteredFeatureChoice.addItem(MessageManager
+              .getString("label.no_feature_attributes"));
+      filteredFeatureChoice.setEnabled(false);
     }
 
     filteredFeatureChoice.addItemListener(listener);
-
   }
 
   /**
@@ -1480,8 +1488,8 @@ public class FeatureSettings extends JPanel
      * look up attributes known for feature type
      */
     String selectedType = (String) filteredFeatureChoice.getSelectedItem();
-    List<String> attNames = FeatureAttributes.getInstance().getAttributes(
-            selectedType);
+    List<String[]> attNames = FeatureAttributes.getInstance()
+            .getAttributes(selectedType);
 
     /*
      * if this feature type has filters set, load them first
@@ -1501,7 +1509,8 @@ public class FeatureSettings extends JPanel
     /*
      * and an empty filter for the user to populate (add)
      */
-    KeyedMatcherI noFilter = new KeyedMatcher("", Condition.values()[0], "");
+    KeyedMatcherI noFilter = new KeyedMatcher(Condition.values()[0], "",
+            (String) null);
     filters.add(noFilter);
 
     /*
@@ -1510,14 +1519,16 @@ public class FeatureSettings extends JPanel
     int filterIndex = 0;
     for (KeyedMatcherI filter : filters)
     {
-      String key = filter.getKey();
+      String[] attName = filter.getKey();
       Condition condition = filter.getMatcher()
               .getCondition();
       String pattern = filter.getMatcher().getPattern();
-      JPanel row = addFilter(key, attNames, condition, pattern, filterIndex);
+      JPanel row = addFilter(attName, attNames, condition, pattern, filterIndex);
+      row.setBorder(BorderFactory.createLineBorder(debugBorderColour));
       chooseFiltersPanel.add(row);
       filterIndex++;
     }
+    // chooseFiltersPanel.add(Box.createVerticalGlue());
 
     filtersPane.validate();
     filtersPane.repaint();
@@ -1531,27 +1542,24 @@ public class FeatureSettings extends JPanel
    * <li>a text field for input of a match pattern</li>
    * <li>optionally, a 'remove' button</li>
    * </ul>
-   * If attribute, condition or pattern are not null, they are set as defaults
-   * for the input fields. The 'remove' button is added unless the pattern is
-   * null or empty (incomplete filter condition).
+   * If attribute, condition or pattern are not null, they are set as defaults for
+   * the input fields. The 'remove' button is added unless the pattern is null or
+   * empty (incomplete filter condition).
    * 
-   * @param attribute
+   * @param attName
    * @param attNames
    * @param cond
    * @param pattern
    * @param filterIndex
    * @return
    */
-  protected JPanel addFilter(String attribute, List<String> attNames,
+  protected JPanel addFilter(String[] attName, List<String[]> attNames,
           Condition cond, String pattern, int filterIndex)
   {
     JPanel filterRow = new JPanel(new FlowLayout(FlowLayout.LEFT));
     filterRow.setBackground(Color.white);
 
     /*
-     * inputs for attribute, condition, pattern
-     */
-    /*
      * drop-down choice of attribute, with description as a tooltip 
      * if we can obtain it
      */
@@ -1588,13 +1596,13 @@ public class FeatureSettings extends JPanel
       }
     };
 
-    if ("".equals(attribute))
+    if (attName == null) // the 'add a condition' row
     {
       attCombo.setSelectedItem(null);
     }
     else
     {
-      attCombo.setSelectedItem(attribute);
+      attCombo.setSelectedItem(String.join(COLON, attName));
     }
     attCombo.addItemListener(itemListener);
 
@@ -1634,7 +1642,7 @@ public class FeatureSettings extends JPanel
      */
     if (pattern != null && pattern.trim().length() > 0)
     {
-      // todo: gif for - button
+      // todo: gif for button drawing '-' or 'x'
       JButton removeCondition = new BasicArrowButton(SwingConstants.WEST);
       removeCondition.setToolTipText(MessageManager
               .getString("label.delete_row"));
@@ -1662,22 +1670,24 @@ public class FeatureSettings extends JPanel
    * @param attNames
    */
   protected JComboBox<String> populateAttributesDropdown(
-          String featureType, List<String> attNames)
+          String featureType, List<String[]> attNames)
   {
+    List<String> displayNames = new ArrayList<>();
     List<String> tooltips = new ArrayList<>();
     FeatureAttributes fa = FeatureAttributes.getInstance();
-    for (String attName : attNames)
+    for (String[] attName : attNames)
     {
       String desc = fa.getDescription(featureType, attName);
       if (desc != null && desc.length() > MAX_TOOLTIP_LENGTH)
       {
         desc = desc.substring(0, MAX_TOOLTIP_LENGTH) + "...";
       }
+      displayNames.add(String.join(COLON, attName));
       tooltips.add(desc == null ? "" : desc);
     }
 
     JComboBox<String> attCombo = JvSwingUtils.buildComboWithTooltips(
-            attNames, tooltips);
+            displayNames, tooltips);
     if (attNames.isEmpty())
     {
       attCombo.setToolTipText(MessageManager
@@ -1755,7 +1765,8 @@ public class FeatureSettings extends JPanel
     String attName = (String) attCombo.getSelectedItem();
     Condition cond = (Condition) condCombo.getSelectedItem();
     String pattern = valueField.getText();
-    KeyedMatcherI km = new KeyedMatcher(attName, cond, pattern);
+    KeyedMatcherI km = new KeyedMatcher(cond, pattern,
+            attName.split(COLON));
 
     filters.set(filterIndex, km);
   }
@@ -2129,7 +2140,7 @@ public class FeatureSettings extends JPanel
 
     if (gcol.isColourByAttribute())
     {
-      tx.append(gcol.getAttributeName());
+      tx.append(String.join(":", gcol.getAttributeName()));
     }
     else if (!gcol.isColourByLabel())
     {