simplification of FeatureSettings inner classes
authorhansonr <hansonr@STO24954W.ad.stolaf.edu>
Wed, 9 Jan 2019 05:38:31 +0000 (23:38 -0600)
committerhansonr <hansonr@STO24954W.ad.stolaf.edu>
Wed, 9 Jan 2019 05:38:31 +0000 (23:38 -0600)
No need here for additional private inner variables that cover outer
class's versions of the same thing. No need for a pointer to the outer
class, as "me" is already the "this" of the other class.

Added necessary JTable.repaint() to fix the problem that "stopping"
editing was relying upon the invalidation to be maintained throughout
the modal dialog, but JavaScript cannot keep the thread from doing its
repaints. So in JavaScript, while the modal dialog is loading, the
validate sequence from stopping editing fires. Thus, when the editing
dialog closes, it is already validated for the previous value, and we
need to explicitly repaint the table to see the update.

src/jalview/gui/FeatureSettings.java

index 27676d5..93b5f31 100644 (file)
@@ -209,6 +209,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)
       {
@@ -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);
@@ -1682,10 +1709,11 @@ 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;
+//    FeatureSettings me;
 
     FeatureColourI currentColor;
 
@@ -1699,9 +1727,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 +1760,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 +1776,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 +1794,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,9 +1803,13 @@ 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();
       }
     }
 
@@ -1796,9 +1827,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(getBackground());
       if (!currentColor.isSimpleColour())
       {
         JLabel btn = new JLabel();
@@ -1824,10 +1855,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 +1872,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 +1888,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 +1910,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 +1942,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(getBackground());
       button.setText(currentFilter.toString());
       button.setIcon(null);
       return button;