Merge branch 'features/JAL-3010ontologyFeatureSettings' into
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 12 Feb 2019 11:28:07 +0000 (11:28 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 12 Feb 2019 11:28:07 +0000 (11:28 +0000)
merge/JAL-3187_JAL-3010

Conflicts:
resources/lang/Messages.properties
resources/lang/Messages_es.properties
src/jalview/gui/FeatureSettings.java
src/jalview/gui/FeatureTypeSettings.java

1  2 
resources/lang/Messages.properties
resources/lang/Messages_es.properties
src/jalview/gui/AlignFrame.java
src/jalview/gui/CrossRefAction.java
src/jalview/gui/FeatureSettings.java
src/jalview/gui/FeatureTypeSettings.java
test/jalview/gui/AlignFrameTest.java

@@@ -1359,5 -1364,7 +1360,9 @@@ label.most_bound_molecules = Most Boun
  label.most_polymer_residues = Most Polymer Residues
  label.cached_structures = Cached Structures
  label.free_text_search = Free Text Search
 +label.configuration = Configuration
 +label.configure_feature_tooltip = Click to configure variable colour or filters
+ label.summary_view = Summary View
+ label.summary_view_tip = Show only top level ontology terms
+ label.apply_to_subtypes = Apply changes also to sub-types of ''{0}''
 -label.apply_also_to = Apply also to:
++label.apply_also_to = Apply also to:
@@@ -1360,5 -1365,7 +1361,9 @@@ label.most_bound_molecules = Más Molécu
  label.most_polymer_residues = Más Residuos de Polímeros
  label.cached_structures = Estructuras en Caché
  label.free_text_search = Búsqueda de texto libre
 +label.configuration = Configuración
 +label.configure_feature_tooltip = Haga clic para configurar el color o los filtros
+ label.summary_view = Vista Resumida
+ label.summary_view_tip = Mostrar solo términos de ontología de nivel mayor
+ label.apply_to_subtypes = Aplicar cambios también a subtipos de ''{0}''
 -label.apply_also_to = Aplicar también a:
++label.apply_also_to = Aplicar también a:
Simple merge
Simple merge
@@@ -31,6 -31,10 +32,7 @@@ import jalview.datamodel.ontology.Ontol
  import jalview.gui.Help.HelpId;
  import jalview.io.JalviewFileChooser;
  import jalview.io.JalviewFileView;
+ import jalview.io.gff.SequenceOntologyFactory;
 -import jalview.schemabinding.version2.Filter;
 -import jalview.schemabinding.version2.JalviewUserColours;
 -import jalview.schemabinding.version2.MatcherSet;
  import jalview.schemes.FeatureColour;
  import jalview.util.MessageManager;
  import jalview.util.Platform;
@@@ -99,11 -102,7 +104,12 @@@ import javax.swing.table.AbstractTableM
  import javax.swing.table.TableCellEditor;
  import javax.swing.table.TableCellRenderer;
  import javax.swing.table.TableColumn;
+ import javax.swing.table.TableRowSorter;
 +import javax.xml.bind.JAXBContext;
 +import javax.xml.bind.JAXBElement;
 +import javax.xml.bind.Marshaller;
 +import javax.xml.stream.XMLInputFactory;
 +import javax.xml.stream.XMLStreamReader;
  
  public class FeatureSettings extends JPanel
          implements FeatureSettingsControllerI
      });
      men.add(dens);
  
++    // fixme is Variable Colour in popup menu or not
+     /*
+      * variable colour options include colour by label, by score,
+      * by selected attribute text, or attribute value
+      */
+     final JCheckBoxMenuItem mxcol = new JCheckBoxMenuItem(
+             MessageManager.getString("label.variable_colour"));
+     mxcol.setSelected(!featureColour.isSimpleColour());
+     men.add(mxcol);
+     mxcol.addActionListener(new ActionListener()
+     {
+       JColorChooser colorChooser;
+       @Override
+       public void actionPerformed(ActionEvent e)
+       {
+         if (e.getSource() == mxcol)
+         {
+           if (featureColour.isSimpleColour())
+           {
+             FeatureTypeSettings fc = new FeatureTypeSettings(me.fr, type);
+             fc.addActionListener(this);
+           }
+           else
+           {
+             // bring up simple color chooser
+             colorChooser = new JColorChooser();
+             String title = MessageManager
+                     .getString("label.select_colour");
+             JDialog dialog = JColorChooser.createDialog(me,
+                     title, true, // modal
+                     colorChooser, this, // OK button handler
+                     null); // no CANCEL button handler
+             colorChooser.setColor(featureColour.getMaxColour());
+             dialog.setVisible(true);
+           }
+         }
+         else
+         {
+           if (e.getSource() instanceof FeatureTypeSettings)
+           {
+             /*
+              * update after OK in feature colour dialog; the updated
+              * colour will have already been set in the FeatureRenderer
+              */
+             FeatureColourI fci = fr.getFeatureColours().get(type);
+             table.setValueAt(fci, rowSelected, 1);
+             table.validate();
+           }
+           else
+           {
+             // probably the color chooser!
+             table.setValueAt(new FeatureColour(colorChooser.getColor()),
+                     rowSelected, 1);
+             table.validate();
+             me.updateFeatureRenderer(
+                     ((FeatureTableModel) table.getModel()).getData(),
+                     false);
+           }
+         }
+       }
+     });
      JMenuItem selCols = new JMenuItem(
              MessageManager.getString("label.select_columns_containing"));
      selCols.addActionListener(new ActionListener()
      transparency.setToolTipText(
              MessageManager.getString("label.transparency_tip"));
  
 +    boolean nucleotide = af.getViewport().getAlignment().isNucleotide();
 +    showComplement = new JCheckBox(
 +            "Show " + (nucleotide ? "protein" : "CDS") + " features");
 +    showComplement.setSelected(af.getViewport().isShowComplementFeatures());
 +    showComplement.addActionListener(new ActionListener()
 +    {
 +      @Override
 +      public void actionPerformed(ActionEvent e)
 +      {
 +        af.getViewport()
 +                .setShowComplementFeatures(showComplement.isSelected());
 +        refreshDisplay();
 +      }
 +    });
 +
-     JPanel transPanel = new JPanel(new GridLayout(1, 2));
-     bigPanel.add(transPanel, BorderLayout.SOUTH);
+     JPanel lowerPanel = new JPanel(new GridLayout(1, 2));
+     bigPanel.add(lowerPanel, BorderLayout.SOUTH);
  
      JPanel transbuttons = new JPanel(new GridLayout(5, 1));
      transbuttons.add(optimizeOrder);
      transbuttons.add(sortByScore);
      transbuttons.add(sortByDens);
      transbuttons.add(help);
 -    JPanel transPanel = new JPanel(new GridLayout(3, 1));
 -    transPanel.add(summaryView);
 -    transPanel.add(new JLabel(" Colour transparency" + ":"));
 -    transPanel.add(transparency);
 -    lowerPanel.add(transPanel);
 +
 +    boolean hasComplement = af.getViewport().getCodingComplement() != null;
 +    JPanel transPanelLeft = new JPanel(
-             new GridLayout(hasComplement ? 2 : 1, 1));
++            new GridLayout(hasComplement ? 4 : 3, 1));
++    transPanelLeft.add(summaryView);
++    transPanelLeft.add(new JLabel(" Colour transparency" + ":"));
 +    transPanelLeft.add(transparency);
 +    if (hasComplement)
 +    {
 +      transPanelLeft.add(showComplement);
 +    }
-     transPanel.add(transPanelLeft);
-     transPanel.add(transbuttons);
++    lowerPanel.add(transPanelLeft);
+     lowerPanel.add(transbuttons);
  
      JPanel buttonPanel = new JPanel();
      buttonPanel.add(ok);
    }
  
    /**
 +   * Repaints alignment, structure and overview (if shown). If there is a
 +   * complementary view which is showing this view's features, then also
 +   * repaints that.
 +   */
 +  void refreshDisplay()
 +  {
 +    af.alignPanel.paintAlignment(true, true);
 +    AlignViewportI complement = af.getViewport().getCodingComplement();
 +    if (complement != null && complement.isShowComplementFeatures())
 +    {
 +      AlignFrame af2 = Desktop.getAlignFrameFor(complement);
 +      af2.alignPanel.paintAlignment(true, true);
 +    }
 +  }
 +
++  /**
+    * Reorders features by 'dragging' selectedRow to 'newRow'
+    * 
+    * @param newRow
+    */
+   protected void dragRow(int newRow)
+   {
+     if (summaryView.isSelected())
+     {
+       // no drag while in summary view
+       return;
+     }
+     if (newRow != selectedRow && selectedRow != -1 && newRow != -1)
+     {
+       /*
+        * reposition 'selectedRow' to 'newRow' (the dragged to location)
+        * this could be more than one row away for a very fast drag action
+        * so just swap it with adjacent rows until we get it there
+        */
+       Object[][] data = ((FeatureTableModel) table.getModel())
+               .getData();
+       int direction = newRow < selectedRow ? -1 : 1;
+       for (int i = selectedRow; i != newRow; i += direction)
+       {
+         Object[] temp = data[i];
+         data[i] = data[i + direction];
+         data[i + direction] = temp;
+       }
+       updateFeatureRenderer(data);
+       table.repaint();
+       selectedRow = newRow;
+     }
+   }
+   protected void refreshTable()
+   {
+     Object[][] data = ((FeatureTableModel) table.getModel()).getData();
+     for (Object[] row : data)
+     {
+       String type = (String) row[TYPE_COLUMN];
+       FeatureColourI colour = fr.getFeatureColours().get(type);
+       FeatureMatcherSetI filter = fr.getFeatureFilter(type);
+       if (filter == null)
+       {
+         filter = new FeatureMatcherSet();
+       }
+       row[COLOUR_COLUMN] = colour;
+       row[FILTER_COLUMN] = filter;
+     }
+     repaint();
+   }
    // ///////////////////////////////////////////////////////////////////////
    // http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
    // ///////////////////////////////////////////////////////////////////////
@@@ -866,10 -944,18 +945,18 @@@ public class FeatureTypeSettings extend
      FeatureColourI acg = makeColourFromInputs();
  
      /*
-      * save the colour, and repaint stuff
+      * save the colour, and set on subtypes if selected
       */
      fr.setColour(featureType, acg);
+     if (applyColourToSubtypes)
+     {
+       for (String child : subTypes)
+       {
+         fr.setColour(child, acg);
+       }
+     }
+     refreshFeatureSettings();
 -    ap.paintAlignment(updateStructsAndOverview, updateStructsAndOverview);
 +    refreshDisplay(updateStructsAndOverview);
  
      updateColoursTab();
    }
    @Override
    public void cancelPressed()
    {
-     fr.setColour(featureType, originalColour);
-     fr.setFeatureFilter(featureType, originalFilter);
+     restoreOriginalColours();
+     restoreOriginalFilters();
 -    ap.paintAlignment(true, true);
 +    refreshDisplay(true);
    }
  
+   protected void restoreOriginalFilters()
+   {
+     for (Entry<String, FeatureMatcherSetI> entry : originalFilters
+             .entrySet())
+     {
+       fr.setFeatureFilter(entry.getKey(), entry.getValue());
+     }
+   }
+   protected void restoreOriginalColours()
+   {
+     for (Entry<String, FeatureColourI> entry : originalColours.entrySet())
+     {
+       fr.setColour(entry.getKey(), entry.getValue());
+     }
+   }
    /**
     * Action on text entry of a threshold value
     */
       * (note this might now be an empty filter with no conditions)
       */
      fr.setFeatureFilter(featureType, combined.isEmpty() ? null : combined);
++
+     if (applyFiltersToSubtypes)
+     {
+       for (String child : subTypes)
+       {
+         fr.setFeatureFilter(child, combined.isEmpty() ? null : combined);
+       }
+     }
+     refreshFeatureSettings();
 -    ap.paintAlignment(true, true);
 +    refreshDisplay(true);
  
      updateFiltersTab();
    }
Simple merge