JAL-2808 set (read-only) condition text field as disabled
[jalview.git] / src / jalview / gui / FeatureSettings.java
index 01c40d5..974b387 100644 (file)
@@ -120,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;
@@ -1417,6 +1419,7 @@ public class FeatureSettings extends JPanel
     filtersAsText = new JTextArea();
     filtersAsText.setLineWrap(true);
     filtersAsText.setWrapStyleWord(true);
+    filtersAsText.setEnabled(false); // for display only
     showFiltersPanel.add(filtersAsText);
 
     filtersPane.setLayout(new BorderLayout());
@@ -1486,8 +1489,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
@@ -1507,7 +1510,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);
 
     /*
@@ -1516,11 +1520,11 @@ 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++;
@@ -1539,18 +1543,18 @@ 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));
@@ -1593,13 +1597,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);
 
@@ -1667,22 +1671,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
@@ -1760,7 +1766,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);
   }
@@ -2134,7 +2141,7 @@ public class FeatureSettings extends JPanel
 
     if (gcol.isColourByAttribute())
     {
-      tx.append(gcol.getAttributeName());
+      tx.append(String.join(":", gcol.getAttributeName()));
     }
     else if (!gcol.isColourByLabel())
     {