Merge branch 'develop' into features/JAL-3010ontologyFeatureSettings
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 19 Sep 2018 14:26:17 +0000 (15:26 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 19 Sep 2018 14:26:17 +0000 (15:26 +0100)
Conflicts:
src/jalview/gui/FeatureSettings.java
src/jalview/gui/FeatureTypeSettings.java

1  2 
src/jalview/bin/Jalview.java
src/jalview/gui/AlignFrame.java
src/jalview/gui/FeatureSettings.java
src/jalview/gui/FeatureTypeSettings.java
src/jalview/gui/SequenceFetcher.java

Simple merge
Simple merge
@@@ -98,9 -91,7 +94,8 @@@ import javax.swing.JScrollPane
  import javax.swing.JSlider;
  import javax.swing.JTable;
  import javax.swing.ListSelectionModel;
 +import javax.swing.RowFilter;
  import javax.swing.SwingConstants;
- import javax.swing.SwingUtilities;
  import javax.swing.event.ChangeEvent;
  import javax.swing.event.ChangeListener;
  import javax.swing.table.AbstractTableModel;
@@@ -170,12 -152,12 +159,6 @@@ public class FeatureSettings extends JP
  
    int selectedRow = -1;
  
--  JButton fetchDAS = new JButton();
--
--  JButton saveDAS = new JButton();
--
--  JButton cancelDAS = new JButton();
--
    boolean resettingTable = false;
  
    /*
        ex.printStackTrace();
      }
  
 +    initTable();
 +
 +    scrollPane.setViewportView(table);
 +
-     dassourceBrowser = new DasSourceBrowser(this);
-     dasSettingsPane.add(dassourceBrowser, BorderLayout.CENTER);
 +    if (af.getViewport().isShowSequenceFeatures() || !fr.hasRenderOrder())
 +    {
 +      fr.findAllFeatures(true); // display everything!
 +    }
 +
 +    discoverAllFeatureData();
 +    final PropertyChangeListener change;
 +    final FeatureSettings fs = this;
 +    fr.addPropertyChangeListener(change = new PropertyChangeListener()
 +    {
 +      @Override
 +      public void propertyChange(PropertyChangeEvent evt)
 +      {
 +        if (!fs.resettingTable && !fs.handlingUpdate)
 +        {
 +          fs.handlingUpdate = true;
 +          fs.resetTable(null);
 +          // new groups may be added with new sequence feature types only
 +          fs.handlingUpdate = false;
 +        }
 +      }
 +    });
 +
 +    frame = new JInternalFrame();
 +    frame.setContentPane(this);
 +    if (Platform.isAMac())
 +    {
 +      Desktop.addInternalFrame(frame,
 +              MessageManager.getString("label.sequence_feature_settings"),
 +              600, 480);
 +    }
 +    else
 +    {
 +      Desktop.addInternalFrame(frame,
 +              MessageManager.getString("label.sequence_feature_settings"),
 +              600, 450);
 +    }
 +    frame.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT));
 +
 +    frame.addInternalFrameListener(
 +            new javax.swing.event.InternalFrameAdapter()
 +            {
 +              @Override
 +              public void internalFrameClosed(
 +                      javax.swing.event.InternalFrameEvent evt)
 +              {
 +                fr.removePropertyChangeListener(change);
-                 dassourceBrowser.fs = null;
 +              };
 +            });
 +    frame.setLayer(JLayeredPane.PALETTE_LAYER);
 +    inConstruction = false;
 +  }
 +
 +  /**
 +   * Constructs and configures the JTable which displays columns of data for
 +   * each feature type
 +   */
 +  protected void initTable()
 +  {
      table = new JTable()
      {
        @Override
      transparency.setMaximum(70);
      transparency.setToolTipText(
              MessageManager.getString("label.transparency_tip"));
-     fetchDAS.setText(MessageManager.getString("label.fetch_das_features"));
-     fetchDAS.addActionListener(new ActionListener()
-     {
-       @Override
-       public void actionPerformed(ActionEvent e)
-       {
-         fetchDAS_actionPerformed(e);
-       }
-     });
-     saveDAS.setText(MessageManager.getString("action.save_as_default"));
-     saveDAS.addActionListener(new ActionListener()
-     {
-       @Override
-       public void actionPerformed(ActionEvent e)
-       {
-         saveDAS_actionPerformed(e);
-       }
-     });
-     JPanel dasButtonPanel = new JPanel();
-     dasButtonPanel.setBorder(BorderFactory.createEtchedBorder());
-     dasSettingsPane.setBorder(null);
-     cancelDAS.setEnabled(false);
-     cancelDAS.setText(MessageManager.getString("action.cancel_fetch"));
-     cancelDAS.addActionListener(new ActionListener()
-     {
-       @Override
-       public void actionPerformed(ActionEvent e)
-       {
-         cancelDAS_actionPerformed(e);
-       }
-     });
  
 -    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);
      this.add(settingsPane);
    }
  
-   public void fetchDAS_actionPerformed(ActionEvent e)
-   {
-     fetchDAS.setEnabled(false);
-     cancelDAS.setEnabled(true);
-     dassourceBrowser.setGuiEnabled(false);
-     Vector<jalviewSourceI> selectedSources = dassourceBrowser
-             .getSelectedSources();
-     doDasFeatureFetch(selectedSources, true, true);
-   }
-   /**
-    * get the features from selectedSources for all or the current selection
-    * 
-    * @param selectedSources
-    * @param checkDbRefs
-    * @param promptFetchDbRefs
-    */
-   private void doDasFeatureFetch(List<jalviewSourceI> selectedSources,
-           boolean checkDbRefs, boolean promptFetchDbRefs)
-   {
-     SequenceI[] dataset, seqs;
-     int iSize;
-     AlignmentViewport vp = af.getViewport();
-     if (vp.getSelectionGroup() != null
-             && vp.getSelectionGroup().getSize() > 0)
-     {
-       iSize = vp.getSelectionGroup().getSize();
-       dataset = new SequenceI[iSize];
-       seqs = vp.getSelectionGroup().getSequencesInOrder(vp.getAlignment());
-     }
-     else
-     {
-       iSize = vp.getAlignment().getHeight();
-       seqs = vp.getAlignment().getSequencesArray();
-     }
-     dataset = new SequenceI[iSize];
-     for (int i = 0; i < iSize; i++)
-     {
-       dataset[i] = seqs[i].getDatasetSequence();
-     }
-     cancelDAS.setEnabled(true);
-     dasFeatureFetcher = new jalview.ws.DasSequenceFeatureFetcher(dataset,
-             this, selectedSources, checkDbRefs, promptFetchDbRefs);
-     af.getViewport().setShowSequenceFeatures(true);
-     af.showSeqFeatures.setSelected(true);
-   }
-   /**
-    * blocking call to initialise the das source browser
-    */
-   public void initDasSources()
-   {
-     dassourceBrowser.initDasSources();
-   }
-   /**
-    * examine the current list of das sources and return any matching the given
-    * nicknames in sources
-    * 
-    * @param sources
-    *          Vector of Strings to resolve to DAS source nicknames.
-    * @return sources that are present in source list.
-    */
-   public List<jalviewSourceI> resolveSourceNicknames(Vector<String> sources)
-   {
-     return dassourceBrowser.sourceRegistry.resolveSourceNicknames(sources);
-   }
-   /**
-    * get currently selected das sources. ensure you have called initDasSources
-    * before calling this.
-    * 
-    * @return vector of selected das source nicknames
-    */
-   public Vector<jalviewSourceI> getSelectedSources()
-   {
-     return dassourceBrowser.getSelectedSources();
-   }
-   /**
-    * properly initialise DAS fetcher and then initiate a new thread to fetch
-    * features from the named sources (rather than any turned on by default)
-    * 
-    * @param sources
-    * @param block
-    *          if true then runs in same thread, otherwise passes to the Swing
-    *          executor
-    */
-   public void fetchDasFeatures(Vector<String> sources, boolean block)
-   {
-     initDasSources();
-     List<jalviewSourceI> resolved = dassourceBrowser.sourceRegistry
-             .resolveSourceNicknames(sources);
-     if (resolved.size() == 0)
-     {
-       resolved = dassourceBrowser.getSelectedSources();
-     }
-     if (resolved.size() > 0)
-     {
-       final List<jalviewSourceI> dassources = resolved;
-       fetchDAS.setEnabled(false);
-       // cancelDAS.setEnabled(true); doDasFetch does this.
-       Runnable fetcher = new Runnable()
-       {
-         @Override
-         public void run()
-         {
-           doDasFeatureFetch(dassources, true, false);
-         }
-       };
-       if (block)
-       {
-         fetcher.run();
-       }
-       else
-       {
-         SwingUtilities.invokeLater(fetcher);
-       }
-     }
-   }
-   public void saveDAS_actionPerformed(ActionEvent e)
-   {
-     dassourceBrowser
-             .saveProperties(jalview.bin.Cache.applicationProperties);
-   }
-   public void complete()
-   {
-     fetchDAS.setEnabled(true);
-     cancelDAS.setEnabled(false);
-     dassourceBrowser.setGuiEnabled(true);
-   }
-   public void cancelDAS_actionPerformed(ActionEvent e)
-   {
-     if (dasFeatureFetcher != null)
-     {
-       dasFeatureFetcher.cancel();
-     }
-     complete();
-   }
-   public void noDasSourceActive()
-   {
-     complete();
-     JvOptionPane.showInternalConfirmDialog(Desktop.desktop,
-             MessageManager.getString("label.no_das_sources_selected_warn"),
-             MessageManager.getString("label.no_das_sources_selected_title"),
-             JvOptionPane.DEFAULT_OPTION, JvOptionPane.INFORMATION_MESSAGE);
-   }
 +  /**
 +   * 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
    // ///////////////////////////////////////////////////////////////////////
        updateFeatureRenderer(data);
      }
  
 +    /**
 +     * Sets the visibility of any feature types which are sub-types of the type
 +     * in the given row of the table
 +     * 
 +     * @param row
 +     * @param value
 +     */
 +    protected void setSubtypesVisibility(int row, Boolean value)
 +    {
 +      String type = (String) data[row][TYPE_COLUMN];
 +      OntologyI so = SequenceOntologyFactory.getInstance();
 +
 +      for (int r = 0; r < data.length; r++)
 +      {
 +        if (r != row)
 +        {
 +          String type2 = (String) data[r][TYPE_COLUMN];
 +          if (so.isA(type2, type))
 +          {
 +            data[r][SHOW_COLUMN] = value;
 +            fireTableCellUpdated(r, SHOW_COLUMN);
 +          }
 +        }
 +      }
 +    }
    }
  
    class ColorRenderer extends JLabel implements TableCellRenderer
          {
            // bring up graduated chooser.
            chooser = new FeatureTypeSettings(me.fr, type);
 -          /**
 -           * @j2sNative
 -           */
 -          {
 -            chooser.setRequestFocusEnabled(true);
 -            chooser.requestFocus();
 -          }
 +          chooser.setRequestFocusEnabled(true);
 +          chooser.requestFocus();
            chooser.addActionListener(this);
-           chooser.showTab(true);
+           // Make the renderer reappear.
+           fireEditingStopped();
          }
-         // Make the renderer reappear.
-         fireEditingStopped();
        }
        else
        {
@@@ -205,27 -204,8 +210,22 @@@ public class FeatureTypeSettings extend
     */
    private List<FeatureMatcherI> filters;
  
-   // set white normally, black to debug layout
-   private Color debugBorderColour = Color.white;
    private JPanel chooseFiltersPanel;
  
-   private JTabbedPane tabbedPane;
 +  /*
 +   * feature types present in Feature Renderer which are
 +   * sub-types of the one this editor is acting on
 +   */
 +  private final List<String> subTypes;
 +
 +  /*
 +   * if true, filter or colour settings are also applied to 
 +   * any feature sub-types in the Sequence Ontology
 +   */
 +  private boolean applyFiltersToSubtypes;
 +
 +  private boolean applyColourToSubtypes;
 +
    /**
     * Constructor
     * 
    private JPanel initialiseColoursPanel()
    {
      JPanel colourByPanel = new JPanel();
+     colourByPanel.setBackground(Color.white);
      colourByPanel.setLayout(new BoxLayout(colourByPanel, BoxLayout.Y_AXIS));
+     JvSwingUtils.createTitledBorder(colourByPanel,
+             MessageManager.getString("action.colour"), true);
  
      /*
 +     * option to apply colour to sub-types as well (if there are any)
 +     */
 +    if (!subTypes.isEmpty())
 +    {
 +      applyColourToSubtypes = false;
 +      colourByPanel.add(initSubtypesPanel(false));
 +    }
 +
 +    /*
       * simple colour radio button and colour picker
       */
      JPanel simpleColourPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
     */
    private JPanel initialiseAndOrPanel()
    {
 -    JPanel andOrPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
 +    JPanel andOrPanel = new JPanel(new BorderLayout());
      andOrPanel.setBackground(Color.white);
-     JPanel panel1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
-     andOrPanel.add(panel1, BorderLayout.WEST);
-     panel1.setBackground(Color.white);
-     panel1.setBorder(BorderFactory.createLineBorder(debugBorderColour));
++//<<<<<<< HEAD
++//    JPanel panel1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
++//    andOrPanel.add(panel1, BorderLayout.WEST);
++//    panel1.setBackground(Color.white);
++//    panel1.setBorder(BorderFactory.createLineBorder(debugBorderColour));
++//=======
++//>>>>>>> refs/heads/develop
      andFilters = new JRadioButton(MessageManager.getString("label.and"));
      orFilters = new JRadioButton(MessageManager.getString("label.or"));
      ActionListener actionListener = new ActionListener()
      andOr.add(andFilters);
      andOr.add(orFilters);
      andFilters.setSelected(true);
-     panel1.add(
+     andOrPanel.add(
              new JLabel(MessageManager.getString("label.join_conditions")));
-     panel1.add(andFilters);
-     panel1.add(orFilters);
+     andOrPanel.add(andFilters);
+     andOrPanel.add(orFilters);
 +
      return andOrPanel;
    }
  
Simple merge