import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
+import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Vector;
-import java.util.concurrent.Callable;
import javax.swing.ButtonGroup;
import javax.swing.JCheckBoxMenuItem;
import jalview.datamodel.AlignmentOrder;
import jalview.datamodel.AlignmentView;
import jalview.datamodel.ColumnSelection;
+import jalview.datamodel.ContactMatrixI;
import jalview.datamodel.HiddenColumns;
import jalview.datamodel.PDBEntry;
import jalview.datamodel.SeqCigar;
import jalview.io.NewickFile;
import jalview.io.ScoreMatrixFile;
import jalview.io.TCoffeeScoreFile;
+import jalview.io.exceptions.ImageOutputException;
import jalview.io.vcf.VCFLoader;
import jalview.jbgui.GAlignFrame;
import jalview.project.Jalview2XML;
import jalview.util.ImageMaker.TYPE;
import jalview.util.MessageManager;
import jalview.util.Platform;
+import jalview.util.imagemaker.BitmapImageSizing;
import jalview.viewmodel.AlignmentViewport;
import jalview.viewmodel.ViewportRanges;
import jalview.ws.DBRefFetcher;
@Override
public void setProgressBar(String message, long id)
{
- progressBar.setProgressBar(message, id);
+ if (!Platform.isHeadless() && progressBar != null)
+ progressBar.setProgressBar(message, id);
}
@Override
public void registerHandler(final long id,
final IProgressIndicatorHandler handler)
{
- progressBar.registerHandler(id, handler);
+ if (progressBar != null)
+ progressBar.registerHandler(id, handler);
}
/**
@Override
public boolean operationInProgress()
{
- return progressBar.operationInProgress();
+ return progressBar == null ? false : progressBar.operationInProgress();
}
/**
*/
public void saveAlignment(String file, FileFormatI format)
{
+ saveAlignment(file, format, false);
+ }
+
+ public void saveAlignment(String file, FileFormatI format, boolean stdout)
+ {
lastSaveSuccessful = true;
- lastFilenameSaved = file;
+ if (!stdout)
+ {
+ lastFilenameSaved = file;
+ }
lastFormatSaved = format;
if (FileFormat.Jalview.equals(format))
shortName = shortName
.substring(shortName.lastIndexOf(File.separatorChar) + 1);
}
+ // TODO deal with stdout=true
lastSaveSuccessful = new Jalview2XML().saveAlignment(this, file,
shortName);
}
AlignExportSettingsI options = new AlignExportSettingsAdapter(false);
- Callable<Void> cancelAction = () -> {
+ Runnable cancelAction = () -> {
lastSaveSuccessful = false;
- return null;
};
- Callable<Void> outputAction = () -> {
+ Runnable outputAction = () -> {
// todo defer this to inside formatSequences (or later)
AlignmentExportData exportData = viewport.getAlignExportData(options);
String output = new FormatAdapter(alignPanel, options)
else
{
// create backupfiles object and get new temp filename destination
- boolean doBackup = BackupFiles.getEnabled();
+ boolean doBackup = BackupFiles.getEnabled() && !stdout;
BackupFiles backupfiles = null;
if (doBackup)
{
String tempFilePath = doBackup ? backupfiles.getTempFilePath()
: file;
Console.trace("ALIGNFRAME setting PrintWriter");
- PrintWriter out = new PrintWriter(new FileWriter(tempFilePath));
+ PrintWriter out = stdout
+ ? new PrintWriter(new OutputStreamWriter(System.out))
+ : new PrintWriter(new FileWriter(tempFilePath));
if (backupfiles != null)
{
}
out.print(output);
+ out.flush();
Console.trace("ALIGNFRAME about to close file");
out.close();
Console.trace("ALIGNFRAME closed file");
- AlignFrame.this.setTitle(file);
- statusBar.setText(MessageManager.formatMessage(
- "label.successfully_saved_to_file_in_format", new Object[]
- { fileName, format.getName() }));
+ AlignFrame.this.setTitle(stdout ? "STDOUT" : file);
+ if (stdout)
+ {
+ statusBar.setText(MessageManager.formatMessage(
+ "label.successfully_printed_to_stdout_in_format",
+ new Object[]
+ { format.getName() }));
+ }
+ else
+ {
+ statusBar.setText(MessageManager.formatMessage(
+ "label.successfully_saved_to_file_in_format",
+ new Object[]
+ { fileName, format.getName() }));
+ }
lastSaveSuccessful = true;
} catch (IOException e)
{
AlignFrame.this.getViewport().setSavedUpToDate(true);
}
}
- return null;
};
/*
{
try
{
- outputAction.call();
+ outputAction.run();
} catch (Exception e)
{
// TODO Auto-generated catch block
FileFormatI fileFormat = FileFormats.getInstance()
.forName(fileFormatName);
AlignExportSettingsI options = new AlignExportSettingsAdapter(false);
- Callable<Void> outputAction = () -> {
+ Runnable outputAction = () -> {
// todo defer this to inside formatSequences (or later)
AlignmentExportData exportData = viewport.getAlignExportData(options);
CutAndPasteTransfer cap = new CutAndPasteTransfer();
oom);
cap.dispose();
}
- return null;
};
/*
{
try
{
- outputAction.call();
+ outputAction.run();
} catch (Exception e)
{
e.printStackTrace();
protected void htmlMenuItem_actionPerformed(ActionEvent e)
{
HtmlSvgOutput htmlSVG = new HtmlSvgOutput(alignPanel);
- htmlSVG.exportHTML(null);
+ try
+ {
+ htmlSVG.exportHTML(null);
+ } catch (ImageOutputException x)
+ {
+ // report problem to console and raise dialog
+ }
}
@Override
public void bioJSMenuItem_actionPerformed(ActionEvent e)
{
BioJsHTMLOutput bjs = new BioJsHTMLOutput(alignPanel);
- bjs.exportHTML(null);
+ try
+ {
+ bjs.exportHTML(null);
+ } catch (ImageOutputException x)
+ {
+ // report problem to console and raise dialog
+ }
}
public void createImageMap(File file, String image)
{
- alignPanel.makePNGImageMap(file, image);
+ try
+ {
+ alignPanel.makePNGImageMap(file, image);
+ } catch (ImageOutputException x)
+ {
+ // report problem to console and raise dialog
+ }
+ }
+
+ @Override
+ public void createPNG_actionPerformed(ActionEvent e)
+ {
+ try
+ {
+ createPNG(null);
+ } catch (ImageOutputException ioex)
+ {
+ // raise dialog, and report via console
+ }
+ }
+
+ @Override
+ public void createEPS_actionPerformed(ActionEvent e)
+ {
+ try
+ {
+ createEPS(null);
+ } catch (ImageOutputException ioex)
+ {
+ // raise dialog, and report via console
+ }
+
+ }
+
+ @Override
+ public void createSVG_actionPerformed(ActionEvent e)
+ {
+ try
+ {
+ createSVG(null);
+ } catch (ImageOutputException ioex)
+ {
+ // raise dialog, and report via console
+ }
+
}
/**
*
* @param f
*/
- @Override
- public void createPNG(File f)
+ public void createPNG(File f) throws ImageOutputException
{
- alignPanel.makeAlignmentImage(TYPE.PNG, f);
+ createPNG(f, null, BitmapImageSizing.nullBitmapImageSizing());
+ }
+
+ public void createPNG(File f, String renderer, BitmapImageSizing userBis)
+ throws ImageOutputException
+ {
+ alignPanel.makeAlignmentImage(TYPE.PNG, f, renderer, userBis);
}
/**
*
* @param f
*/
- @Override
- public void createEPS(File f)
+ public void createEPS(File f) throws ImageOutputException
+ {
+ createEPS(f, null);
+ }
+
+ public void createEPS(File f, String renderer) throws ImageOutputException
{
- alignPanel.makeAlignmentImage(TYPE.EPS, f);
+ alignPanel.makeAlignmentImage(TYPE.EPS, f, renderer);
}
/**
*
* @param f
*/
- @Override
- public void createSVG(File f)
+ public void createSVG(File f) throws ImageOutputException
+ {
+ createSVG(f, null);
+ }
+
+ public void createSVG(File f, String renderer) throws ImageOutputException
{
- alignPanel.makeAlignmentImage(TYPE.SVG, f);
+ alignPanel.makeAlignmentImage(TYPE.SVG, f, renderer);
}
@Override
String choice = chooser.getSelectedFile().getPath();
Cache.setProperty("LAST_DIRECTORY", choice);
loadJalviewDataFile(chooser.getSelectedFile(), null, null, null);
- return null;
});
chooser.showOpenDialog(this);
.intValue();
}
}
- alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
- // was
- // duplicated
- // earlier
+ // annotation was duplicated earlier
+ alignment.addAnnotation(sequences[i].getAnnotation()[a]);
+ // take care of contact matrix too
+ ContactMatrixI cm = sequences[i]
+ .getContactMatrixFor(sequences[i].getAnnotation()[a]);
+ if (cm != null)
+ {
+ alignment.addContactListFor(sequences[i].getAnnotation()[a],
+ cm);
+ }
+
alignment.setAnnotationIndex(sequences[i].getAnnotation()[a],
a);
}
return;
}
- Callable okAction = () -> {
+ Runnable okAction = () -> {
SequenceI[] cut = sg.getSequences()
.toArray(new SequenceI[sg.getSize()]);
{
}
}
- return null;
};
/*
{
try
{
- okAction.call();
+ okAction.run();
} catch (Exception e)
{
e.printStackTrace();
{
viewport.invertColumnSelection();
alignPanel.paintAlignment(true, false);
+ PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
viewport.sendSelection();
}
viewport.setGatherViewsHere(true);
}
tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
+
return newap;
}
}
/**
- * DOCUMENT ME!
+ * Opens an Overview panel for the alignment, unless one is open already
*
* @param e
- * DOCUMENT ME!
*/
@Override
public void overviewMenuItem_actionPerformed(ActionEvent e)
{
+ boolean showHiddenRegions = Cache
+ .getDefault(Preferences.SHOW_OV_HIDDEN_AT_START, false);
+ openOverviewPanel(showHiddenRegions);
+ }
+
+ public OverviewPanel openOverviewPanel(boolean showHidden)
+ {
if (alignPanel.overviewPanel != null)
{
- return;
+ return alignPanel.overviewPanel;
}
-
JInternalFrame frame = new JInternalFrame();
- final OverviewPanel overview = new OverviewPanel(alignPanel);
+ final OverviewPanel overview = new OverviewPanel(alignPanel, frame,
+ showHidden);
frame.setContentPane(overview);
- Desktop.addInternalFrame(frame, MessageManager
- .formatMessage("label.overview_params", new Object[]
- { this.getTitle() }), true, frame.getWidth(), frame.getHeight(),
- true, true);
+ Desktop.addInternalFrame(frame, "", true, frame.getWidth(),
+ frame.getHeight(), true, true);
frame.setFrameIcon(null);
frame.pack();
frame.setLayer(JLayeredPane.PALETTE_LAYER);
+ final AlignmentPanel thePanel = this.alignPanel;
frame.addInternalFrameListener(
new javax.swing.event.InternalFrameAdapter()
{
javax.swing.event.InternalFrameEvent evt)
{
overview.dispose();
- alignPanel.setOverviewPanel(null);
+ thePanel.setOverviewPanel(null);
}
});
if (getKeyListeners().length > 0)
}
alignPanel.setOverviewPanel(overview);
+ alignPanel.setOverviewTitle(this);
+
+ return overview;
}
@Override
.getString("label.possible_problem_with_tree_file"),
JvOptionPane.WARNING_MESSAGE);
}
- return null;
});
chooser.showOpenDialog(this);
}
return tp;
}
+ public void showContactMapTree(AlignmentAnnotation aa, ContactMatrixI cm)
+ {
+ int x = 4, y = 5;
+ int w = 400, h = 500;
+
+ try
+ {
+ NewickFile fin = new NewickFile(
+ new FileParse(cm.getNewick(), DataSourceType.PASTE));
+ String title = aa.label + " " + cm.getTreeMethod() + " tree"
+ + (aa.sequenceRef != null
+ ? (" for " + aa.sequenceRef.getDisplayId(false))
+ : "");
+
+ showColumnWiseTree(fin, aa, title, w, h, x, y);
+ } catch (Throwable xx)
+ {
+ Console.error("Unexpected exception showing tree for contact matrix",
+ xx);
+ }
+ }
+
+ public TreePanel showColumnWiseTree(NewickFile nf, AlignmentAnnotation aa,
+ String treeTitle, int w, int h, int x, int y)
+ {
+ try
+ {
+ nf.parse();
+ if (nf.getTree() == null)
+ {
+ return null;
+ }
+ TreePanel tp = new TreePanel(alignPanel, nf, aa, treeTitle);
+
+ tp.setSize(w, h);
+
+ if (x > 0 && y > 0)
+ {
+ tp.setLocation(x, y);
+ }
+
+ Desktop.addInternalFrame(tp, treeTitle, w, h);
+ return tp;
+ } catch (Throwable xx)
+ {
+ Console.error("Unexpected exception showing tree for contact matrix",
+ xx);
+ }
+ return null;
+ }
+
private boolean buildingMenu = false;
/**
{
if (index > -1)
{
+ /*
+ * update current Overview window title (if there is one)
+ * to add view name "Original" if necessary
+ */
+ alignPanel.setOverviewTitle(this);
+
+ /*
+ * switch panels and set Overview title (if there is one
+ * because it was opened automatically)
+ */
alignPanel = alignPanels.get(index);
+ alignPanel.setOverviewTitle(this);
+
viewport = alignPanel.av;
avc.setViewportAndAlignmentPanel(viewport, alignPanel);
setMenusFromViewport(viewport);
* update non-sequence-related annotations
*/
@Override
- protected void setAnnotationsVisibility(boolean visible,
+ public void setAnnotationsVisibility(boolean visible,
boolean forSequences, boolean forAlignment)
{
AlignmentAnnotation[] anns = alignPanel.getAlignment()
| ActionEvent.CTRL_MASK)) != 0);
}
+ @Override
+ protected void copyHighlightedColumns_actionPerformed(
+ ActionEvent actionEvent)
+ {
+ avc.copyHighlightedRegionsToClipboard();
+ }
+
/**
* Rebuilds the Colour menu, including any user-defined colours which have
* been loaded either on startup or during the session
Cache.setProperty("LAST_DIRECTORY", choice);
SequenceI[] seqs = viewport.getAlignment().getSequencesArray();
new VCFLoader(choice).loadVCF(seqs, us);
- return null;
});
chooser.showOpenDialog(null);
{
return lastFeatureSettingsBounds;
}
+
}
class PrintThread extends Thread