Merge branch 'develop' into Jalview-BH/JAL-3026-JAL-3063-JAXB
[jalview.git] / src / jalview / gui / FeatureSettings.java
index 27676d5..a6f4a84 100644 (file)
@@ -98,7 +98,6 @@ import javax.swing.ToolTipManager;
 import javax.swing.border.Border;
 import javax.swing.event.ChangeEvent;
 import javax.swing.event.ChangeListener;
-import javax.swing.plaf.TableUI;
 import javax.swing.table.AbstractTableModel;
 import javax.swing.table.TableCellEditor;
 import javax.swing.table.TableCellRenderer;
@@ -209,6 +208,33 @@ public class FeatureSettings extends JPanel
 
     table = new JTable()
     {
+       
+//     @Override
+//     public void repaint() {
+//       System.out.println("FS repaint");
+//       super.repaint();
+//       
+//     }
+//     
+//     @Override
+//        public void repaint(long tm, int x, int y, int width, int height) {
+//       System.out.println("FS repaint " + x  + " " + y + " " + width + " " + height);
+//       super.repaint(tm, x, y, width, height);
+//       
+//     }
+//     @Override
+//     public void invalidate() {
+//             if (isValid())
+//               System.out.println("FS invalidating ");
+//            super.invalidate();
+//     }
+//     
+//     @Override
+//     public void validate() {
+//            System.out.println("FS validating "  + isValid());
+//            super.validate();
+//     }
+
       @Override
       public String getToolTipText(MouseEvent e)
       {
@@ -231,7 +257,8 @@ public class FeatureSettings extends JPanel
           FeatureMatcherSet o = (FeatureMatcherSet) table.getValueAt(row,
                   column);
           tip = o.isEmpty()
-                  ? MessageManager.getString("label.filters_tooltip")
+                  ? MessageManager
+                          .getString("label.configure_feature_tooltip")
                   : o.toString();
           break;
         default:
@@ -266,18 +293,18 @@ public class FeatureSettings extends JPanel
     table.getTableHeader().setFont(new Font("Verdana", Font.PLAIN, 12));
     ToolTipManager.sharedInstance().registerComponent(table);
 
-    table.setDefaultEditor(FeatureColour.class, new ColorEditor(this));
+    table.setDefaultEditor(FeatureColour.class, new ColorEditor());
     table.setDefaultRenderer(FeatureColour.class, new ColorRenderer());
 
-    table.setDefaultEditor(FeatureMatcherSet.class, new FilterEditor(this));
+    table.setDefaultEditor(FeatureMatcherSet.class, new FilterEditor());
     table.setDefaultRenderer(FeatureMatcherSet.class, new FilterRenderer());
     
     TableColumn colourColumn = new TableColumn(COLOUR_COLUMN, 75,
-            new ColorRenderer(), new ColorEditor(this));
+            new ColorRenderer(), new ColorEditor());
     table.addColumn(colourColumn);
 
     TableColumn filterColumn = new TableColumn(FILTER_COLUMN, 75,
-            new FilterRenderer(), new FilterEditor(this));
+            new FilterRenderer(), new FilterEditor());
     table.addColumn(filterColumn);
 
     table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
@@ -416,44 +443,13 @@ public class FeatureSettings extends JPanel
   protected void showPopupMenu(final int rowSelected, final String type,
           final Object typeCol, final Point pt)
   {
-    final FeatureColourI featureColour = (FeatureColourI) typeCol;
-
     JPopupMenu men = new JPopupMenu(MessageManager
             .formatMessage("label.settings_for_param", new String[]
             { type }));
-    JMenuItem scr = new JMenuItem(
-            MessageManager.getString("label.sort_by_score"));
-    men.add(scr);
-    final FeatureSettings me = this;
-    scr.addActionListener(new ActionListener()
-    {
-
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        me.af.avc
-                .sortAlignmentByFeatureScore(Arrays.asList(new String[]
-                { type }));
-      }
-    });
-    JMenuItem dens = new JMenuItem(
-            MessageManager.getString("label.sort_by_density"));
-    dens.addActionListener(new ActionListener()
-    {
-
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        me.af.avc
-                .sortAlignmentByFeatureDensity(Arrays.asList(new String[]
-                { type }));
-      }
-    });
-    men.add(dens);
+    final FeatureColourI featureColour = (FeatureColourI) typeCol;
 
     /*
-     * variable colour options include colour by label, by score,
-     * by selected attribute text, or attribute value
+     * menu option to select (or deselect) variable colour
      */
     final JCheckBoxMenuItem variableColourCB = new JCheckBoxMenuItem(
             MessageManager.getString("label.variable_colour"));
@@ -478,7 +474,7 @@ public class FeatureSettings extends JPanel
             /*
              * toggle simple colour to variable colour - show dialog
              */
-            FeatureTypeSettings fc = new FeatureTypeSettings(me.fr, type);
+            FeatureTypeSettings fc = new FeatureTypeSettings(fr, type);
             fc.addActionListener(this);
           }
           else
@@ -495,12 +491,13 @@ public class FeatureSettings extends JPanel
                 table.setValueAt(new FeatureColour(c), rowSelected,
                         COLOUR_COLUMN);
                 table.validate();
-                me.updateFeatureRenderer(
+                updateFeatureRenderer(
                         ((FeatureTableModel) table.getModel()).getData(),
                         false);
               }
             };
-            JalviewColourChooser.showColourChooser(me, title, featureColour.getMaxColour(), listener);
+            JalviewColourChooser.showColourChooser(FeatureSettings.this, title,
+               featureColour.getMaxColour(), listener);
           }
         }
         else    
@@ -514,12 +511,41 @@ public class FeatureSettings extends JPanel
             FeatureColourI fci = fr.getFeatureColours().get(type);
             table.setValueAt(fci, rowSelected, COLOUR_COLUMN);
             // BH 2018 setting a table value does not invalidate it.
-            System.out.println("FeatureSettings is valied" + table.isValid());
-//            table.validate();
+//                 System.out.println("FeatureSettings is valied" + table.isValid());
+//                 table.validate();
           }
         }
       }
     });
+    
+    men.addSeparator();
+
+    JMenuItem scr = new JMenuItem(
+            MessageManager.getString("label.sort_by_score"));
+    men.add(scr);
+    scr.addActionListener(new ActionListener()
+    {
+
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        af.avc.sortAlignmentByFeatureScore(Arrays.asList(new String[]
+                { type }));
+      }
+    });
+    JMenuItem dens = new JMenuItem(
+            MessageManager.getString("label.sort_by_density"));
+    dens.addActionListener(new ActionListener()
+    {
+
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        af.avc.sortAlignmentByFeatureDensity(Arrays.asList(new String[]
+                { type }));
+      }
+    });
+    men.add(dens);
 
     JMenuItem selCols = new JMenuItem(
             MessageManager.getString("label.select_columns_containing"));
@@ -1482,7 +1508,7 @@ public class FeatureSettings extends JPanel
     private String[] columnNames = {
         MessageManager.getString("label.feature_type"),
         MessageManager.getString("action.colour"),
-        MessageManager.getString("label.filter"),
+        MessageManager.getString("label.configuration"),
         MessageManager.getString("label.show") };
 
     private Object[][] data;
@@ -1682,11 +1708,10 @@ public class FeatureSettings extends JPanel
     renderGraduatedColor(comp, gcol, w, h);
   }
 
-  class ColorEditor extends AbstractCellEditor
+  @SuppressWarnings("serial")
+class ColorEditor extends AbstractCellEditor
           implements TableCellEditor, ActionListener
   {
-    FeatureSettings me;
-
     FeatureColourI currentColor;
 
     FeatureTypeSettings chooser;
@@ -1699,9 +1724,8 @@ public class FeatureSettings extends JPanel
 
     int rowSelected = 0;
 
-    public ColorEditor(FeatureSettings fs)
+    public ColorEditor()
     {
-      this.me = fs;
       // Set up the editor (from the table's point of view),
       // which is a button.
       // This button brings up the color chooser dialog,
@@ -1733,7 +1757,7 @@ public class FeatureSettings extends JPanel
             public void colourSelected(Color c)
             {
               currentColor = new FeatureColour(c);
-              me.table.setValueAt(currentColor, rowSelected, COLOUR_COLUMN);
+              table.setValueAt(currentColor, rowSelected, COLOUR_COLUMN);
               fireEditingStopped();
             }
                        @Override
@@ -1749,7 +1773,7 @@ public class FeatureSettings extends JPanel
           /*
            * variable colour and filters dialog
            */
-          chooser = new FeatureTypeSettings(me.fr, type);
+          chooser = new FeatureTypeSettings(fr, type);
           if (!Jalview.isJS())
           {
             chooser.setRequestFocusEnabled(true);
@@ -1767,7 +1791,7 @@ public class FeatureSettings extends JPanel
          * update table data without triggering updateFeatureRenderer
          */
         currentColor = fr.getFeatureColours().get(type);
-        FeatureMatcherSetI currentFilter = me.fr.getFeatureFilter(type);
+        FeatureMatcherSetI currentFilter = fr.getFeatureFilter(type);
         if (currentFilter == null)
         {
           currentFilter = new FeatureMatcherSet();
@@ -1776,13 +1800,26 @@ public class FeatureSettings extends JPanel
                 .getData()[rowSelected];
         data[COLOUR_COLUMN] = currentColor;
         data[FILTER_COLUMN] = currentFilter;
-
         fireEditingStopped();
-        me.table.validate();
+        // SwingJS needs an explicit repaint() here, 
+        // rather than relying upon no validation having
+        // occurred since the stopEditing call was made.
+        // Its laying out has not been stopped by the modal frame
+        table.validate();
+        table.repaint();
       }
     }
 
-    // Implement the one CellEditor method that AbstractCellEditor doesn't.
+    /**
+     * Override allows access to this method from anonymous inner classes 
+     */
+    @Override
+       protected void fireEditingStopped() 
+    {
+           super.fireEditingStopped();
+       }
+
+       // Implement the one CellEditor method that AbstractCellEditor doesn't.
     @Override
     public Object getCellEditorValue()
     {
@@ -1796,9 +1833,9 @@ public class FeatureSettings extends JPanel
     {
       currentColor = (FeatureColourI) value;
       this.rowSelected = row;
-      type = me.table.getValueAt(row, TYPE_COLUMN).toString();
+      type = table.getValueAt(row, TYPE_COLUMN).toString();
       button.setOpaque(true);
-      button.setBackground(me.getBackground());
+      button.setBackground(FeatureSettings.this.getBackground());
       if (!currentColor.isSimpleColour())
       {
         JLabel btn = new JLabel();
@@ -1824,10 +1861,10 @@ public class FeatureSettings extends JPanel
    * as display text). On click in the cell, opens the Feature Display Settings
    * dialog at the Filters tab.
    */
-  class FilterEditor extends AbstractCellEditor
+  @SuppressWarnings("serial")
+class FilterEditor extends AbstractCellEditor
           implements TableCellEditor, ActionListener
   {
-    FeatureSettings me;
 
     FeatureMatcherSetI currentFilter;
 
@@ -1841,9 +1878,8 @@ public class FeatureSettings extends JPanel
 
     int rowSelected = 0;
 
-    public FilterEditor(FeatureSettings me)
+    public FilterEditor()
     {
-      this.me = me;
       button = new JButton();
       button.setActionCommand(EDIT);
       button.addActionListener(this);
@@ -1858,7 +1894,7 @@ public class FeatureSettings extends JPanel
     {
       if (button == e.getSource())
       {
-        FeatureTypeSettings chooser = new FeatureTypeSettings(me.fr, type);
+        FeatureTypeSettings chooser = new FeatureTypeSettings(fr, type);
         chooser.addActionListener(this);
         chooser.setRequestFocusEnabled(true);
         chooser.requestFocus();
@@ -1880,17 +1916,23 @@ public class FeatureSettings extends JPanel
          * update table data without triggering updateFeatureRenderer
          */
         FeatureColourI currentColor = fr.getFeatureColours().get(type);
-        currentFilter = me.fr.getFeatureFilter(type);
+        currentFilter = fr.getFeatureFilter(type);
         if (currentFilter == null)
         {
           currentFilter = new FeatureMatcherSet();
         }
+        
         Object[] data = ((FeatureTableModel) table.getModel())
                 .getData()[rowSelected];
         data[COLOUR_COLUMN] = currentColor;
         data[FILTER_COLUMN] = currentFilter;
         fireEditingStopped();
-        me.table.validate();
+        // SwingJS needs an explicit repaint() here, 
+        // rather than relying upon no validation having
+        // occurred since the stopEditing call was made.
+        // Its laying out has not been stopped by the modal frame
+        table.validate();
+        table.repaint();
       }
     }
 
@@ -1906,9 +1948,9 @@ public class FeatureSettings extends JPanel
     {
       currentFilter = (FeatureMatcherSetI) value;
       this.rowSelected = row;
-      type = me.table.getValueAt(row, TYPE_COLUMN).toString();
+      type = table.getValueAt(row, TYPE_COLUMN).toString();
       button.setOpaque(true);
-      button.setBackground(me.getBackground());
+      button.setBackground(FeatureSettings.this.getBackground());
       button.setText(currentFilter.toString());
       button.setIcon(null);
       return button;