Merge branch 'JAL-3048dialogRunner2' into Jalview-BH/JAL-3026-JAL-3063-JAXB
[jalview.git] / src / jalview / gui / FeatureSettings.java
index b82cf86..27676d5 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;
@@ -293,8 +292,7 @@ public class FeatureSettings extends JPanel
         if (evt.isPopupTrigger())
         {
           Object colour = table.getValueAt(selectedRow, COLOUR_COLUMN);
-          popupSort(selectedRow, type, colour, fr.getMinMax(), evt.getX(),
-                  evt.getY());
+          showPopupMenu(selectedRow, type, colour, evt.getPoint());
         }
         else if (evt.getClickCount() == 2)
         {
@@ -315,8 +313,7 @@ public class FeatureSettings extends JPanel
         {
           String type = (String) table.getValueAt(selectedRow, TYPE_COLUMN);
           Object colour = table.getValueAt(selectedRow, COLOUR_COLUMN);
-          popupSort(selectedRow, type, colour, fr.getMinMax(), evt.getX(),
-                  evt.getY());
+          showPopupMenu(selectedRow, type, colour, evt.getPoint());
         }
       }
     });
@@ -344,7 +341,7 @@ public class FeatureSettings extends JPanel
             data[i + direction] = temp;
           }
           updateFeatureRenderer(data);
-          repaintTable();
+          table.repaint();
           selectedRow = newRow;
         }
       }
@@ -407,9 +404,17 @@ public class FeatureSettings extends JPanel
     inConstruction = false;
   }
 
-  protected void popupSort(final int rowSelected, final String type,
-          final Object typeCol, final Map<String, float[][]> minmax, int x,
-          int y)
+       /**
+        * Constructs and shows a popup menu of possible actions on the selected row and
+        * feature type
+        * 
+        * @param rowSelected
+        * @param type
+        * @param typeCol
+        * @param pt
+        */
+  protected void showPopupMenu(final int rowSelected, final String type,
+          final Object typeCol, final Point pt)
   {
     final FeatureColourI featureColour = (FeatureColourI) typeCol;
 
@@ -430,7 +435,6 @@ public class FeatureSettings extends JPanel
                 .sortAlignmentByFeatureScore(Arrays.asList(new String[]
                 { type }));
       }
-
     });
     JMenuItem dens = new JMenuItem(
             MessageManager.getString("label.sort_by_density"));
@@ -444,7 +448,6 @@ public class FeatureSettings extends JPanel
                 .sortAlignmentByFeatureDensity(Arrays.asList(new String[]
                 { type }));
       }
-
     });
     men.add(dens);
 
@@ -468,6 +471,8 @@ public class FeatureSettings extends JPanel
       {
         if (e.getSource() == variableColourCB)
         {
+          men.setVisible(true); // BH 2018 for JavaScript because this is a checkbox
+          men.setVisible(false); // BH 2018 for JavaScript because this is a checkbox
           if (featureColour.isSimpleColour())
           {
             /*
@@ -481,7 +486,7 @@ public class FeatureSettings extends JPanel
             /*
              * toggle variable to simple colour - show colour chooser
              */
-            String title = MessageManager.getString("label.select_colour");
+            String title = MessageManager.formatMessage("label.select_colour_for", type);
             ColourChooserListener listener = new ColourChooserListener()
             {
               @Override
@@ -498,7 +503,8 @@ public class FeatureSettings extends JPanel
             JalviewColourChooser.showColourChooser(me, title, featureColour.getMaxColour(), listener);
           }
         }
-        else    {
+        else    
+        {
           if (e.getSource() instanceof FeatureTypeSettings)
           {
             /*
@@ -507,11 +513,12 @@ public class FeatureSettings extends JPanel
              */
             FeatureColourI fci = fr.getFeatureColours().get(type);
             table.setValueAt(fci, rowSelected, COLOUR_COLUMN);
-            table.validate();
+            // BH 2018 setting a table value does not invalidate it.
+            System.out.println("FeatureSettings is valied" + table.isValid());
+//            table.validate();
           }
         }
       }
-
     });
 
     JMenuItem selCols = new JMenuItem(
@@ -560,7 +567,7 @@ public class FeatureSettings extends JPanel
     men.add(clearCols);
     men.add(hideCols);
     men.add(hideOtherCols);
-    men.show(table, x, y);
+    men.show(table, pt.x, pt.y);
   }
 
   @Override
@@ -894,13 +901,15 @@ public class FeatureSettings extends JPanel
     chooser.setDialogTitle(
             MessageManager.getString("label.load_feature_colours"));
     chooser.setToolTipText(MessageManager.getString("action.load"));
-    chooser.response(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);
   }
 
@@ -965,7 +974,7 @@ public class FeatureSettings extends JPanel
                 .getData();
         ensureOrder(data);
         updateFeatureRenderer(data, false);
-        repaintTable();
+        table.repaint();
       }
     } catch (Exception ex)
     {
@@ -1079,7 +1088,7 @@ public class FeatureSettings extends JPanel
       data[i][SHOW_COLUMN] = !(Boolean) data[i][SHOW_COLUMN];
     }
     updateFeatureRenderer(data, true);
-    repaintTable();
+    table.repaint();
   }
 
   public void orderByAvWidth()
@@ -1142,28 +1151,7 @@ public class FeatureSettings extends JPanel
     }
 
     updateFeatureRenderer(data, false);
-    repaintTable();
-  }
-
-  /**
-   * Repaints the table using alternative code for Java and J2S
-   */
-  private void repaintTable() 
-  {
-       // BH 2018
-       // Here is a needed intervention
-       // because generally we don't "repaint"
-       // the table. We re-create the HTML divs
-       // that is associated with it. A better
-       // way to do this would be to fire a property change.
-       @SuppressWarnings("unused")
-       TableUI ui = table.getUI();
-       /**
-        * @j2sNative ui.repaintTable$();
-        */
-       {
-         table.repaint();
-       }
+    table.repaint();
   }
 
   public void close()
@@ -1738,7 +1726,7 @@ public class FeatureSettings extends JPanel
           /*
            * simple colour chooser
            */
-          String ttl = MessageManager.getString("label.select_colour");
+          String ttl = MessageManager.formatMessage("label.select_colour_for", type);
           ColourChooserListener listener = new ColourChooserListener() 
           {
             @Override
@@ -2005,7 +1993,8 @@ class FeatureIcon implements Icon
         g.fillRect(s1, 0, e1 - s1, height);
       }
       g.setColor(gcol.getMaxColour());
-      g.fillRect(0, e1, width - e1, height);
+//      g.fillRect(0, e1, width - e1, height);  // BH 2018
+      g.fillRect(e1, 0, width - e1, height);
     }
   }
 }