simplification of FeatureSettings inner classes
[jalview.git] / src / jalview / gui / FeatureSettings.java
index ea0d914..93b5f31 100644 (file)
@@ -36,7 +36,6 @@ import jalview.io.JalviewFileView;
 import jalview.schemes.FeatureColour;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
-import jalview.util.dialogrunner.RunResponse;
 import jalview.viewmodel.seqfeatures.FeatureRendererModel.FeatureSettingsBean;
 import jalview.xml.binding.jalview.JalviewUserColours;
 import jalview.xml.binding.jalview.JalviewUserColours.Colour;
@@ -210,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)
       {
@@ -267,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);
@@ -902,13 +928,15 @@ public class FeatureSettings extends JPanel
     chooser.setDialogTitle(
             MessageManager.getString("label.load_feature_colours"));
     chooser.setToolTipText(MessageManager.getString("action.load"));
-    chooser.addResponse(new RunResponse(JalviewFileChooser.APPROVE_OPTION){
-
-               @Override
-               public void run() {
-                     File file = chooser.getSelectedFile();
-                     load(file);
-               }});
+    chooser.setResponseHandler(0, new Runnable()
+    {
+         @Override
+         public void run() 
+         {
+           File file = chooser.getSelectedFile();
+               load(file);
+         }
+       });
     chooser.showOpenDialog(this);
   }
 
@@ -1681,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;
 
@@ -1698,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,
@@ -1732,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
@@ -1748,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);
@@ -1766,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();
@@ -1775,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();
       }
     }
 
@@ -1795,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();
@@ -1823,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;
 
@@ -1840,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);
@@ -1857,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();
@@ -1879,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();
       }
     }
 
@@ -1905,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;