Merge branch 'feature/JAL-3063JAXB' into Jalview-BH/JAL-3026-JAL-3063-JAXB
authorJim Procter <jprocter@issues.jalview.org>
Wed, 17 Oct 2018 15:52:01 +0000 (16:52 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Wed, 17 Oct 2018 15:52:01 +0000 (16:52 +0100)
22 files changed:
1  2 
.classpath
README
build.xml
src/jalview/analysis/Conservation.java
src/jalview/bin/Jalview.java
src/jalview/gui/AlignFrame.java
src/jalview/gui/AlignViewport.java
src/jalview/gui/AlignmentPanel.java
src/jalview/gui/AnnotationPanel.java
src/jalview/gui/Desktop.java
src/jalview/gui/FeatureSettings.java
src/jalview/gui/Jalview2XML.java
src/jalview/gui/PCAPanel.java
src/jalview/gui/SeqCanvas.java
src/jalview/gui/TreeCanvas.java
src/jalview/gui/TreePanel.java
src/jalview/gui/UserDefinedColours.java
src/jalview/gui/WsParamSetManager.java
src/jalview/io/FileFormat.java
src/jalview/io/FileLoader.java
src/jalview/io/JalviewFileChooser.java
src/jalview/jbgui/GDesktop.java

diff --cc .classpath
Simple merge
diff --cc README
Simple merge
diff --cc build.xml
Simple merge
Simple merge
@@@ -1230,73 -1147,82 +1230,78 @@@ public class AlignFrame extends GAlignF
      if (FileFormat.Jalview.equals(format))
      {
        String shortName = title;
 -
 -      if (shortName.indexOf(java.io.File.separatorChar) > -1)
 +      if (shortName.indexOf(File.separatorChar) > -1)
        {
          shortName = shortName.substring(
 -                shortName.lastIndexOf(java.io.File.separatorChar) + 1);
 +                shortName.lastIndexOf(File.separatorChar) + 1);
        }
-       lastSaveSuccessful = new Jalview2XML().saveAlignment(this, file,
 -
 -      success = new jalview.project.Jalview2XML().saveAlignment(this, file,
++      lastSaveSuccessful = new jalview.project.Jalview2XML().saveAlignment(this, file,
                shortName);
 -
++      
+       statusBar.setText(MessageManager.formatMessage(
+               "label.successfully_saved_to_file_in_format", new Object[]
+               { fileName, format }));
 -
++      
 +      return;
      }
 -    else
 +
 +    AlignExportSettingsI options = new AlignExportSettingsAdapter(false);
 +    RunResponse cancelAction = new RunResponse(JvOptionPane.CANCEL_OPTION)
      {
 -      AlignmentExportData exportData = getAlignmentForExport(format,
 -              viewport, null);
 -      if (exportData.getSettings().isCancelled())
 -      {
 -        return false;
 -      }
 -      FormatAdapter f = new FormatAdapter(alignPanel,
 -              exportData.getSettings());
 -      String output = f.formatSequences(format, exportData.getAlignment(), // class
 -                                                                           // cast
 -                                                                           // exceptions
 -                                                                           // will
 -              // occur in the distant future
 -              exportData.getOmitHidden(), exportData.getStartEndPostions(),
 -              f.getCacheSuffixDefault(format),
 -              viewport.getAlignment().getHiddenColumns());
 -
 -      if (output == null)
 +      @Override
 +      public void run()
        {
 -        success = false;
 +        lastSaveSuccessful = false;
        }
 -      else
 +    };
 +    RunResponse outputAction = new RunResponse(JvOptionPane.OK_OPTION)
 +    {
 +      @Override
 +      public void run()
        {
 -        try
 +        // todo defer this to inside formatSequences (or later)
 +        AlignmentExportData exportData = viewport
 +                .getAlignExportData(options);
 +        String output = new FormatAdapter(alignPanel, options)
 +                .formatSequences(format, exportData.getAlignment(),
 +                        exportData.getOmitHidden(),
 +                        exportData.getStartEndPostions(),
 +                        viewport.getAlignment().getHiddenColumns());
 +        if (output == null)
          {
 -          PrintWriter out = new PrintWriter(new FileWriter(file));
 -
 -          out.print(output);
 -          out.close();
 -          this.setTitle(file);
 -          statusBar.setText(MessageManager.formatMessage(
 -                  "label.successfully_saved_to_file_in_format", new Object[]
 -                  { fileName, format.getName() }));
 -        } catch (Exception ex)
 +          lastSaveSuccessful = false;
 +        }
 +        else
          {
 -          success = false;
 -          ex.printStackTrace();
 +          try
 +          {
 +            PrintWriter out = new PrintWriter(new FileWriter(file));
 +            out.print(output);
 +            out.close();
 +            AlignFrame.this.setTitle(file);
 +            setStatus(MessageManager.formatMessage(
 +                    "label.successfully_saved_to_file_in_format",
 +                    new Object[]
 +                    { fileName, format.getName() }));
 +          } catch (Exception ex)
 +          {
 +            lastSaveSuccessful = false;
 +            ex.printStackTrace();
 +          }
          }
        }
 -    }
 -
 -    if (!success)
 -    {
 -      JvOptionPane.showInternalMessageDialog(this, MessageManager
 -              .formatMessage("label.couldnt_save_file", new Object[]
 -              { fileName }),
 -              MessageManager.getString("label.error_saving_file"),
 -              JvOptionPane.WARNING_MESSAGE);
 -    }
 +    };
  
 -    return success;
 -  }
 -
 -  private void warningMessage(String warning, String title)
 -  {
 -    if (new jalview.util.Platform().isHeadless())
 +    /*
 +     * show dialog with export options if applicable; else just do it
 +     */
 +    if (AlignExportOptions.isNeeded(viewport, format))
      {
 -      System.err.println("Warning: " + title + "\nWarning: " + warning);
 -
 +      AlignExportOptions choices = new AlignExportOptions(
 +              alignPanel.getAlignViewport(), format, options);
 +      choices.setResponseAction(outputAction);
 +      choices.setResponseAction(cancelAction);
 +      choices.showDialog();
      }
      else
      {
Simple merge
@@@ -38,9 -36,7 +38,8 @@@ import jalview.math.AlignmentDimension
  import jalview.schemes.ResidueProperties;
  import jalview.structure.StructureSelectionManager;
  import jalview.util.Comparison;
 +import jalview.util.ImageMaker;
  import jalview.util.MessageManager;
- import jalview.util.Platform;
  import jalview.viewmodel.ViewportListenerI;
  import jalview.viewmodel.ViewportRanges;
  
Simple merge
@@@ -1636,18 -1599,21 +1637,19 @@@ public class Desktop extends jalview.jb
    }
  
    /**
 -   * DOCUMENT ME!
 -   * 
 -   * @param e
 -   *          DOCUMENT ME!
 +   * Prompts the user to choose a file and then saves the Jalview state as a
 +   * Jalview project file
     */
    @Override
-   public void saveState_actionPerformed()
+   public void saveState_actionPerformed(boolean asCastor)
    {
-     JalviewFileChooser chooser = new JalviewFileChooser("jvp",
+     JalviewFileChooser chooser = new JalviewFileChooser(
+             asCastor ? "jvp" : "jvx",
              "Jalview Project");
  
      chooser.setFileView(new JalviewFileView());
      chooser.setDialogTitle(MessageManager.getString("label.save_state"));
--
++    // TODO: JAL-3048 Dialog runner refactoring here
      int value = chooser.showSaveDialog(this);
  
      if (value == JalviewFileChooser.APPROVE_OPTION)
    }
  
    /**
 -   * DOCUMENT ME!
 -   * 
 -   * @param e
 -   *          DOCUMENT ME!
 +   * Prompts the user to choose a file and loads in as a Jalview project file
     */
    @Override
-   public void loadState_actionPerformed()
+   public void loadState_actionPerformed(boolean asCastor)
    {
++    // TODO: GET RID OF .JVX BEFORE RELEASE JIM!
+     final String[] suffix = asCastor ? new String[] { "jvp", "jar" }
+             : new String[]
+             { "jvx" };
+     final String[] desc = asCastor
+             ? new String[]
+             { "Jalview Project", "Jalview Project (old)" }
+             : new String[]
+             { "Jalview Project" };
      JalviewFileChooser chooser = new JalviewFileChooser(
-             Cache.getProperty("LAST_DIRECTORY"), new String[]
-             { "jvp", "jar" },
-             new String[]
-             { "Jalview Project", "Jalview Project (old)" },
+             Cache.getProperty("LAST_DIRECTORY"), suffix,
+             desc,
              "Jalview Project");
      chooser.setFileView(new JalviewFileView());
      chooser.setDialogTitle(MessageManager.getString("label.restore_state"));
@@@ -30,12 -28,8 +30,9 @@@ import jalview.datamodel.features.Featu
  import jalview.datamodel.features.FeatureMatcherSet;
  import jalview.datamodel.features.FeatureMatcherSetI;
  import jalview.gui.Help.HelpId;
 +import jalview.gui.JalviewColourChooser.ColourChooserListener;
  import jalview.io.JalviewFileChooser;
  import jalview.io.JalviewFileView;
- 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;
Simple merge
Simple merge
@@@ -355,19 -351,19 +355,20 @@@ public class SeqCanvas extends JPanel i
    @Override
    public void paintComponent(Graphics g)
    {
 -    super.paintComponent(g);    
 -    
 +    super.paintComponent(g);
 +
      int charHeight = av.getCharHeight();
      int charWidth = av.getCharWidth();
 -    
 +
      ViewportRanges ranges = av.getRanges();
 -    
 +
      int width = getWidth();
      int height = getHeight();
 -    
 +
      width -= (width % charWidth);
      height -= (height % charHeight);
 +
+     
      if ((img != null) && (fastPaint
              || (getVisibleRect().width != g.getClipBounds().width)
              || (getVisibleRect().height != g.getClipBounds().height)))
@@@ -57,7 -56,7 +57,6 @@@ import java.util.Hashtable
  import java.util.List;
  import java.util.Vector;
  
--import javax.swing.JColorChooser;
  import javax.swing.JPanel;
  import javax.swing.JScrollPane;
  import javax.swing.SwingUtilities;
@@@ -125,7 -126,7 +125,8 @@@ public class TreePanel extends GTreePan
  
    public AlignmentViewport getViewPort()
    {
-     return treeCanvas.av;
++    // @Mungo - Why don't we return our own viewport ???
+     return getTreeCanvas().getViewport();
    }
  
    void initTreePanel(AlignmentPanel ap, String type, String modelName,
    void buildAssociatedViewMenu()
    {
      AlignmentPanel[] aps = PaintRefresher
 -            .getAssociatedPanels(getViewport().getSequenceSetId());
 +            .getAssociatedPanels(av.getSequenceSetId());
-     if (aps.length == 1 && treeCanvas.ap == aps[0])
+     if (aps.length == 1 && getTreeCanvas().getAssociatedPanel() == aps[0])
      {
        associateLeavesMenu.setVisible(false);
        return;
      for (i = 0; i < iSize; i++)
      {
        final AlignmentPanel ap = aps[i];
-       item = new JRadioButtonMenuItem(ap.av.viewName, ap == treeCanvas.ap);
 -      item = new JRadioButtonMenuItem(ap.av.getViewName(), ap == getTreeCanvas().getAssociatedPanel());
++      item = new JRadioButtonMenuItem(ap.av.getViewName(),
++              ap == treeCanvas.getAssociatedPanel());
        buttonGroup.add(item);
        item.addActionListener(new ActionListener()
        {
          @Override
          public void actionPerformed(ActionEvent evt)
          {
 -          getTreeCanvas().applyToAllViews = false;
 -          getTreeCanvas().setAssociatedPanel(ap);
 -          getTreeCanvas().setViewport(ap.av);
 +          treeCanvas.applyToAllViews = false;
-           treeCanvas.ap = ap;
-           treeCanvas.av = ap.av;
++          treeCanvas.setAssociatedPanel(ap);
++          treeCanvas.setViewport(ap.av);
            PaintRefresher.Register(thisTreePanel, ap.av.getSequenceSetId());
          }
        });
        else
        {
          ScoreModelI sm = ScoreModels.getInstance()
-                 .getScoreModel(scoreModelName, treeCanvas.ap);
 -                .getScoreModel(scoreModelName, getTreeCanvas().getAssociatedPanel());
++                .getScoreModel(scoreModelName,
++                        treeCanvas.getAssociatedPanel());
          TreeBuilder njtree = treeType.equals(TreeBuilder.NEIGHBOUR_JOINING)
 -                ? new NJTree(getViewport(), sm, similarityParams)
 -                : new AverageDistanceTree(getViewport(), sm, similarityParams);
 +                ? new NJTree(av, sm, similarityParams)
 +                : new AverageDistanceTree(av, sm, similarityParams);
          tree = new TreeModel(njtree);
          showDistances(true);
        }
      }
      else
      {
-       treeCanvas.ap.alignFrame
-               .addHistoryItem(sortAlignmentIn(treeCanvas.ap));
 -      getTreeCanvas().getAssociatedPanel().alignFrame
 -              .addHistoryItem(sortAlignmentIn(getTreeCanvas().getAssociatedPanel()));
++      treeCanvas.getAssociatedPanel().alignFrame
++              .addHistoryItem(
++                      sortAlignmentIn(treeCanvas.getAssociatedPanel()));
      }
  
    }
      return ttl;
    }
  
 +  /**
 +   * Builds an EPS image and writes it to the specified file.
 +   * 
 +   * @param outFile
 +   * @param textOption
 +   *          true for Text character rendering, false for Lineart
 +   */
 +  protected void writeEpsFile(File outFile, boolean textOption)
 +  {
 +    try
 +    {
 +      int width = treeCanvas.getWidth();
 +      int height = treeCanvas.getHeight();
 +
 +      FileOutputStream out = new FileOutputStream(
 +              outFile);
 +      EpsGraphics2D pg = new EpsGraphics2D("Tree", out, 0, 0, width,
 +              height);
 +      pg.setAccurateTextMode(!textOption);
 +      treeCanvas.draw(pg, width, height);
 +
 +      pg.flush();
 +      pg.close();
 +    } catch (Exception ex)
 +    {
 +      System.err.println("Error writing tree as EPS");
 +      ex.printStackTrace();
 +    }
 +  }
++  
+   public AlignViewport getViewport()
+   {
+     return av;
+   }
+   public void setViewport(AlignViewport av)
+   {
+     this.av = av;
+   }
+   public TreeCanvas getTreeCanvas()
+   {
+     return treeCanvas;
+   }
  }
Simple merge
Simple merge
@@@ -309,85 -277,82 +309,127 @@@ public class JalviewFileChooser extend
      }
      return null;
    }
 -
++  
+   File ourselectedFile = null;
+   @Override
+   public File getSelectedFile()
+   {
+     File selfile = super.getSelectedFile();
+     if (selfile == null && ourselectedFile != null)
+     {
+       return ourselectedFile;
+     }
+     return selfile;
+   }
  
 -  @Override
 -  public int showSaveDialog(Component parent) throws HeadlessException
 +  Component saveparent;
 +  RunResponse overwriteCheck = new RunResponse(
 +          JalviewFileChooser.APPROVE_OPTION)
    {
 -    this.setAccessory(null);
 -
 -    setDialogType(SAVE_DIALOG);
 -
 -    this.setSelectedFile(null);
 -    int ret = showDialog(parent, MessageManager.getString("action.save"));
 +    @Override
 +    public void run()
 +    {
+     ourselectedFile = getSelectedFile();
+     if (getSelectedFile() == null)
+     {
+       // Workaround for Java 9,10 on OSX - no selected file, but there is a
+       // filename typed in
+       try
+       {
+         String filename = ((BasicFileChooserUI) getUI()).getFileName();
+         if (filename != null && filename.length() > 0)
+         {
+           ourselectedFile = new File(getCurrentDirectory(), filename);
+         }
+       } catch (Throwable x)
+       {
+         System.err.println(
+                 "Unexpected exception when trying to get filename.");
+         x.printStackTrace();
+       }
+     }
+     if (ourselectedFile == null)
+     {
 -      return JalviewFileChooser.CANCEL_OPTION;
++      returned = new Response(JalviewFileChooser.CANCEL_OPTION);
++      return;
+     }
 -    if (getFileFilter() instanceof JalviewFileFilter)
 -    {
 -      JalviewFileFilter jvf = (JalviewFileFilter) getFileFilter();
 +      // JBP Note - this code was executed regardless of 'SAVE' being pressed
 +      // need to see if there were side effects
 +      if (getFileFilter() instanceof JalviewFileFilter)
 +      {
 +        JalviewFileFilter jvf = (JalviewFileFilter) getFileFilter();
  
 -      if (!jvf.accept(ourselectedFile))
 +        if (!jvf.accept(getSelectedFile()))
 +        {
 +          String withExtension = getSelectedFile() + "."
 +                  + jvf.getAcceptableExtension();
 +          setSelectedFile(new File(withExtension));
 +        }
 +      }
 +      // All good, so we continue to save
 +      returned = new Response(JalviewFileChooser.APPROVE_OPTION);
 +
 +      // TODO: ENSURE THAT FILES SAVED WITH A ':' IN THE NAME ARE REFUSED AND THE
 +      // USER PROMPTED FOR A NEW FILENAME
 +      /**
 +       * @j2sNative
 +       */
        {
 -        String withExtension = getSelectedFile().getName() + "."
 -                + jvf.getAcceptableExtension();
 -        ourselectedFile = (new File(getCurrentDirectory(), withExtension));
 -        setSelectedFile(ourselectedFile);
 +        if (getSelectedFile().exists())
 +        {
 +          // JAL-3048 - may not need to raise this for browser saves
 +
 +          // yes/no cancel
 +          int confirm = JvOptionPane.showConfirmDialog(saveparent,
 +                  MessageManager.getString("label.overwrite_existing_file"),
 +                  MessageManager.getString("label.file_already_exists"),
 +                  JvOptionPane.YES_NO_OPTION);
 +
 +          if (confirm != JvOptionPane.YES_OPTION)
 +          {
 +            returned = new Response(JalviewFileChooser.CANCEL_OPTION);
 +          }
 +        }
        }
 +    };
 +  };
 +
 +  @Override
 +  public int showSaveDialog(Component parent) throws HeadlessException
 +  {
 +    this.setAccessory(null);
 +
 +    /*
 +     * Save dialog is opened until user picks a file format 
 +     */
 +    if (!runner.isRegistered(overwriteCheck))
 +    {
 +      // first call for this instance
 +      runner.firstResponse(overwriteCheck);
      }
 -    // TODO: ENSURE THAT FILES SAVED WITH A ':' IN THE NAME ARE REFUSED AND THE
 -    // USER PROMPTED FOR A NEW FILENAME
 -    if ((ret == JalviewFileChooser.APPROVE_OPTION)
 -            && ourselectedFile.exists())
 +    else
      {
 -      int confirm = JvOptionPane.showConfirmDialog(parent,
 -              MessageManager.getString("label.overwrite_existing_file"),
 -              MessageManager.getString("label.file_already_exists"),
 -              JvOptionPane.YES_NO_OPTION);
 -
 -      if (confirm != JvOptionPane.YES_OPTION)
 -      {
 -        ret = JalviewFileChooser.CANCEL_OPTION;
 -      }
 +      // reset response flags
 +      runner.resetResponses();
      }
  
 -    return ret;
 +    setDialogType(SAVE_DIALOG);
++    
++    // Java 9,10,11 on OSX - clear selected file so name isn't auto populated
++    this.setSelectedFile(null);
++ 
 +    saveparent = parent;
 +
 +    int value = showDialog(parent, MessageManager.getString("action.save"));
 +    /**
 +     * @j2sNative
 +     */
 +    {
 +      runner.firstRun(value);
 +    }
 +    return value;
    }
  
    void recentListSelectionChanged(Object selection)
@@@ -441,12 -440,11 +459,15 @@@ public class GDesktop extends JFram
      desktopMenubar.add(windowMenu);
      FileMenu.add(inputMenu);
      FileMenu.add(inputSequence);
 -    FileMenu.addSeparator();
 -    FileMenu.add(saveState);
 +    if (!Jalview.isJS())
 +    {
 +      FileMenu.addSeparator();
 +      FileMenu.add(saveState);
 +      FileMenu.add(loadState);
 +    }
++
+     FileMenu.add(saveAsJaxb);
 -    FileMenu.add(loadState);
+     FileMenu.add(loadAsJaxb);
      FileMenu.addSeparator();
      FileMenu.add(quit);
      HelpMenu.add(aboutMenuItem);