private int id;
+ private DataSourceType protocol ;
+
/**
* Creates a new AlignFrame object with specific width and height.
*
* format of file
*/
+ @Deprecated
public void setFileName(String file, FileFormatI format)
{
fileName = file;
}
/**
+ *
+ * @param fileName
+ * @param file from SwingJS; may contain bytes -- for reload
+ * @param protocol from SwingJS; may be RELATIVE_URL
+ * @param format
+ */
+ public void setFile(String fileName, File file, DataSourceType protocol, FileFormatI format)
+ {
+ this.fileName = fileName;
+ this.fileObject = file;
+ this.protocol = protocol;
+ setFileFormat(format);
+ reload.setEnabled(true);
+ }
+
+ /**
* JavaScript will have this, maybe others. More dependable than a file name
* and maintains a reference to the actual bytes loaded.
*
@Override
public void reload_actionPerformed(ActionEvent e)
{
- if (fileName == null)
+ if (fileName == null && fileObject == null)
{
return;
}
Desktop.getInstance().closeAssociatedWindows();
FileLoader loader = new FileLoader();
- DataSourceType protocol = fileName.startsWith("http:")
- ? DataSourceType.URL
- : DataSourceType.FILE;
- loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
+// DataSourceType protocol = fileName.startsWith("http:")
+// ? DataSourceType.URL
+// : DataSourceType.FILE;
+ loader.LoadFile(viewport, (fileObject == null ? fileName : fileObject), protocol, currentFileFormat);
}
else
{
if (fileObject == null)
{
-
- DataSourceType protocol = (fileName.startsWith("http:")
- ? DataSourceType.URL
- : DataSourceType.FILE);
newframe = loader.LoadFileWaitTillLoaded(fileName, protocol,
currentFileFormat);
}
} catch (Exception ex)
{
}
+ } else {
+ updateAll(null);
}
}
};
{
if (avc.deleteGroups())
{
- PaintRefresher.Refresh(this, viewport.getSequenceSetId());
- alignPanel.updateAnnotation();
+ updateAll(viewport.getSequenceSetId());
+ }
+ }
+
+ private void updateAll(String id)
+ {
+ if (id == null)
+ {
+ // this will force a non-fast repaint of both the IdPanel and SeqPanel
+ alignPanel.getIdPanel().getIdCanvas().setNoFastPaint();
+ alignPanel.getSeqPanel().seqCanvas.setNoFastPaint();
+ alignPanel.repaint();
+ }
+ else
+ {
+ // original version
+ PaintRefresher.Refresh(this, id);
alignPanel.paintAlignment(true, true);
}
+ alignPanel.updateAnnotation();
}
/**
for (int i = 0; i < files.size(); i++)
{
// BH 2018
- Object file = files.get(i);
- String fileName = file.toString();
+ Object fileObj = files.get(i);
+ String fileName = fileObj.toString();
String pdbfn = "";
- DataSourceType protocol = (file instanceof File
+ DataSourceType protocol = (fileObj instanceof File
? DataSourceType.FILE
: FormatAdapter.checkProtocol(fileName));
if (protocol == DataSourceType.FILE)
{
- File fl;
- if (file instanceof File)
+ File file;
+ if (fileObj instanceof File)
{
- fl = (File) file;
- Platform.cacheFileData(fl);
+ file = (File) fileObj;
+ Platform.cacheFileData(file);
}
else
{
- fl = new File(fileName);
+ file = new File(fileName);
}
- pdbfn = fl.getName();
+ pdbfn = file.getName();
}
else if (protocol == DataSourceType.URL)
{
FileFormatI type;
try
{
- type = new IdentifyFile().identify(file, protocol);
+ type = new IdentifyFile().identify(fileObj, protocol);
} catch (Exception ex)
{
type = null;
}
if (type != null && type.isStructureFile())
{
- filesmatched.add(new Object[] { file, protocol, mtch });
+ filesmatched.add(new Object[] { fileObj, protocol, mtch });
continue;
}
}
// File wasn't named like one of the sequences or wasn't a PDB
// file.
- filesnotmatched.add(file);
+ filesnotmatched.add(fileObj);
}
}
int assocfiles = 0;
*/
public AlignmentPanel(AlignFrame af, final AlignViewport av)
{
+ setName("AligmentPanel");
// setBackground(Color.white); // BH 2019
alignFrame = af;
this.av = av;
// System.out.println("seqpan dim = " + getSeqPanel().getSize());
// System.out.println("seqcan dim = " + getSeqPanel().seqCanvas.getSize());
- // BH not added to anything yet! repaint();
+ repaint();
}
/**
if (updateOverview)
{
alignFrame.repaint();
-
if (overviewPanel != null)
{
overviewPanel.updateOverviewImage();
}
} else {
+ invalidate(); // needed so that the id width adjuster works correctly
repaint();
}
}
@Override
public void paintComponent(Graphics g)
{
+ // BH OUCH!
invalidate(); // needed so that the id width adjuster works correctly
Dimension d = getIdPanel().getIdCanvas().getPreferredSize();
*/
public AnnotationPanel(AlignmentPanel ap)
{
+ setName("AnnotationPanel");
ToolTipManager.sharedInstance().registerComponent(this);
ToolTipManager.sharedInstance().setInitialDelay(0);
ToolTipManager.sharedInstance().setDismissDelay(10000);
@Override
public void colourSelected(Color c)
{
- HiddenColumns hiddenColumns = av.getAlignment().getHiddenColumns();
+ HiddenColumns hiddenColumns = av.getAlignment()
+ .getHiddenColumns();
for (int index : av.getColumnSelection().getSelected())
{
if (hiddenColumns.isVisible(index))
}
fAnot[index].colour = c;
}
- }};
+ }
+ };
};
- JalviewColourChooser.showColourChooser(this,
- title, Color.black, listener);
+ JalviewColourChooser.showColourChooser(this, title, Color.black,
+ listener);
}
else
// HELIX, SHEET or STEM
}
if (dragMode == DragMode.Undefined)
- {
+ {
/*
* drag is diagonal - defer deciding whether to
* treat as up/down or left/right
*/
- return;
- }
-
+ return;
+ }
try
{
if (dragMode == DragMode.Resize)
int newHeight = Math.max(0, graphAnnotation.graphHeight + deltaY);
graphAnnotation.graphHeight = newHeight;
adjustPanelHeight();
+ setNoFastPaint();
ap.paintAlignment(false, false);
}
}
}
private volatile boolean imageFresh = false;
- private Rectangle visibleRect = new Rectangle(), clipBounds = new Rectangle();
+
+ private Rectangle visibleRect = new Rectangle(),
+ clipBounds = new Rectangle();
/**
* DOCUMENT ME!
@Override
public void paintComponent(Graphics g)
{
-
- // BH: note that this method is generally recommended to
- // call super.paintComponent(g). Otherwise, the children of this
- // component will not be rendered. That is not needed here
- // because AnnotationPanel does not have any children. It is
- // just a JPanel contained in a JViewPort.
+
+ // BH: note that this method is generally recommended to
+ // call super.paintComponent(g). Otherwise, the children of this
+ // component will not be rendered. That is not needed here
+ // because AnnotationPanel does not have any children. It is
+ // just a JPanel contained in a JViewPort.
computeVisibleRect(visibleRect);
-
+
g.setColor(Color.white);
g.fillRect(0, 0, visibleRect.width, visibleRect.height);
ViewportRanges ranges = av.getRanges();
-
-
-
- if (image != null)
+
+ if (allowFastPaint && image != null)
{
- // BH 2018 optimizing generation of new Rectangle().
- if (fastPaint || (visibleRect.width != (clipBounds = g.getClipBounds(clipBounds)).width)
- || (visibleRect.height != clipBounds.height))
+ // BH 2018 optimizing generation of new Rectangle().
+ if (fastPaint
+ || (visibleRect.width != (clipBounds = g
+ .getClipBounds(clipBounds)).width)
+ || (visibleRect.height != clipBounds.height))
{
- g.drawImage(image, 0, 0, this);
+ g.drawImage(image, 0, 0, this);
fastPaint = false;
return;
}
}
-
- imgWidth = (ranges.getEndRes() - ranges.getStartRes()
- + 1) * av.getCharWidth();
-
+
+ imgWidth = (ranges.getEndRes() - ranges.getStartRes() + 1)
+ * av.getCharWidth();
+
if (imgWidth < 1)
{
fastPaint = false;
gg.setColor(Color.white);
gg.fillRect(0, 0, imgWidth, image.getHeight());
imageFresh = true;
- } else {
- gg = (Graphics2D) image.getGraphics();
+ }
+ else
+ {
+ gg = (Graphics2D) image.getGraphics();
}
-
- drawComponent(gg, ranges.getStartRes(),
- av.getRanges().getEndRes() + 1);
+
+ drawComponent(gg, ranges.getStartRes(), av.getRanges().getEndRes() + 1);
gg.dispose();
imageFresh = false;
g.drawImage(image, 0, 0, this);
int sr = av.getRanges().getStartRes();
int er = av.getRanges().getEndRes() + 1;
int transX = 0;
-
- if (er == sr + 1) {
+
+ if (er == sr + 1)
+ {
fastPaint = false;
return;
}
gg.translate(-transX, 0);
gg.dispose();
-
+
fastPaint = true;
// Call repaint on alignment panel so that repaints from other alignment
private int[] bounds = new int[2];
+ private boolean allowFastPaint;
+
@Override
public int[] getVisibleVRange()
{
ap = null;
image = null;
fadedImage = null;
-// gg = null;
+ // gg = null;
_mwl = null;
/*
}
return annotationHeight;
}
+
+ /**
+ * Clears the flag that allows a 'fast paint' on the next repaint, so
+ * requiring a full repaint
+ */
+ public void setNoFastPaint()
+ {
+ allowFastPaint = false;
+ }
+
}
private Font idfont;
+ private boolean allowFastPaint;
+
/**
* Creates a new IdCanvas object.
*
g.setColor(Color.white);
g.fillRect(0, 0, getWidth(), getHeight());
- if (fastPaint)
+ if (allowFastPaint && fastPaint)
{
fastPaint = false;
g.drawImage(image, 0, 0, this);
*/
public void setNoFastPaint()
{
- fastPaint = false;
+ allowFastPaint = false;
}
}
*/
public class PaintRefresher
{
+ private static final int ALIGNMENT_CHANGED = 1 << 0;
+ private static final int VALIDATE_SEQUENCES = 1 << 1;
+
static Map<String, List<Component>> components = new HashMap<>();
/**
{
List<Component> comps = components.get(id);
+ int mode = (alignmentChanged ? ALIGNMENT_CHANGED : 0) | (validateSequences ? VALIDATE_SEQUENCES : 0);
if (comps == null)
{
return;
}
+ repaintComponents(source, mode, comps.toArray(new Component[comps.size()]));
+ }
- for (Component comp : comps)
+ public static void repaintComponents(Component source, int mode,
+ Component... comps)
+ {
+ for (int i = 0; i < comps.length; i++)
{
- if (comp == source)
+ Component comp = comps[i];
+ if (comp == null)
{
continue;
}
if (comp instanceof AlignmentPanel)
{
- if (validateSequences && source instanceof AlignmentPanel)
+ if ((mode & VALIDATE_SEQUENCES) != 0 && source instanceof AlignmentPanel)
{
validateSequences(((AlignmentPanel) source).av.getAlignment(),
((AlignmentPanel) comp).av.getAlignment());
}
- if (alignmentChanged)
+ if ((mode & ALIGNMENT_CHANGED) != 0)
{
((AlignmentPanel) comp).alignmentChanged();
}
return tmp.toArray(new AlignmentPanel[tmp.size()]);
}
+
}
private int availHeight;
+ private boolean allowFastPaint;
+
// Don't do this! Graphics handles are supposed to be transient
// private Graphics2D gg;
// Call repaint on alignment panel so that repaints from other alignment
// panel components can be aggregated. Otherwise performance of the
// overview window and others may be adversely affected.
- // System.out.println("SeqCanvas fastPaint() repaint() request...");
av.getAlignPanel().repaint();
} finally
{
{
return;
}
-
ViewportRanges ranges = av.getRanges();
int startRes = ranges.getStartRes();
int startSeq = ranges.getStartSeq();
// }
Rectangle vis, clip;
- if (img != null
- && (fastPaint
- || (vis = getVisibleRect()).width != (clip = g
- .getClipBounds()).width
- || vis.height != clip.height))
+ if (allowFastPaint && img != null
+ && (fastPaint || (vis = getVisibleRect()).width != (clip = g.getClipBounds()).width
+ || vis.height != clip.height))
{
g.drawImage(img, 0, 0, this);
drawSelectionGroup((Graphics2D) g, startRes, endRes, startSeq,
}
else
{
+ allowFastPaint = true;
// img is a cached version of the last view we drew.
// If we have no img or the size has changed, make a new one.
//
- ((int[]) evt.getOldValue())[0];
scrollY = ((int[]) evt.getNewValue())[1]
- ((int[]) evt.getOldValue())[1];
-
- // System.out.println("SC dx dy " + scrollX + " " + scrollY);
-
if (scrollX != 0 && scrollY != 0)
{
// all sorts of problems in JavaScript if this is commented out.
*/
public void setNoFastPaint()
{
- fastPaint = false;
+ allowFastPaint = false;
}
}
*/
public SeqPanel(AlignViewport viewport, AlignmentPanel alignPanel)
{
+ setName("SeqPanel");
seqARep = new SequenceAnnotationReport(true);
ToolTipManager.sharedInstance().registerComponent(this);
ToolTipManager.sharedInstance().setInitialDelay(0);
// add metadata and update ui
if (!(protocol == DataSourceType.PASTE))
{
- alignFrame.setFileName(file, format);
- alignFrame.setFileObject(selectedFile); // BH 2018 SwingJS
+ alignFrame.setFile(file, selectedFile, protocol, format);
}
if (proxyColourScheme != null)
{
import jalview.io.vamsas.Rangetype;
import jalview.project.Jalview2XML;
import jalview.util.MessageManager;
+import jalview.util.jarInputStreamProvider;
import jalview.viewmodel.AlignmentViewport;
+import java.io.File;
import java.io.IOException;
import java.util.Enumeration;
import java.util.HashMap;
// and
// mapValuesToString
fromxml.setSkipList(skipList);
- jalview.util.jarInputStreamProvider jprovider = new jalview.util.jarInputStreamProvider()
+ jarInputStreamProvider jprovider = new jarInputStreamProvider()
{
@Override
"Returning client input stream for Jalview from Vamsas Document.");
return new JarInputStream(cappdata.getClientInputStream());
}
+
+ @Override
+ public File getFile()
+ {
+ return null;
+ }
};
if (dojvsync)
{
fromxml.setSkipList(skipList);
fromxml.setObjectMappingTables(mapKeysToString(vobj2jv),
mapValuesToString(jv2vobj));
- jalview.util.jarInputStreamProvider jarstream = new jalview.util.jarInputStreamProvider()
+ jarInputStreamProvider jarstream = new jarInputStreamProvider()
{
@Override
"Returning user input stream for Jalview from Vamsas Document.");
return new JarInputStream(cappdata.getUserInputStream());
}
+
+ @Override
+ public File getFile()
+ {
+ return null;
+ }
};
if (dojvsync)
{
}
@Override
+ public File getFile()
+ {
+ return jarFile;
+ }
+
+ @Override
public String getFilename()
{
return file;
AlignFrame af = null, _af = null;
IdentityHashMap<AlignmentI, AlignmentI> importedDatasets = new IdentityHashMap<>();
Map<String, AlignFrame> gatherToThisFrame = new HashMap<>();
- final String file = jprovider.getFilename();
-
+ String fileName = jprovider.getFilename();
+ File file = jprovider.getFile();
List<AlignFrame> alignFrames = new ArrayList<>();
try
// Q: Do we have to load from the model, even if it
// does not have a viewport, could we discover that early on?
// Q: Do we need to load this object?
- _af = loadFromObject(model, file, true, jprovider);
+ _af = loadFromObject(model, fileName, file, true, jprovider);
// Platform.timeCheck("Jalview2XML.loadFromObject",
// Platform.TIME_MARK);
} catch (IOException ex)
{
ex.printStackTrace();
- errorMessage = "Couldn't locate Jalview XML file : " + file;
+ errorMessage = "Couldn't locate Jalview XML file : " + fileName;
System.err.println(
"Exception whilst loading jalview XML file : " + ex + "\n");
} catch (Exception ex)
*
* @param jalviewModel
* DOM
- * @param file
+ * @param fileName
* filename source string
+ * @param file
* @param loadTreesAndStructures
* when false only create Viewport
* @param jprovider
* data source provider
* @return alignment frame created from view stored in DOM
*/
- AlignFrame loadFromObject(JalviewModel jalviewModel, String file,
- boolean loadTreesAndStructures, jarInputStreamProvider jprovider)
+ AlignFrame loadFromObject(JalviewModel jalviewModel, String fileName,
+ File file, boolean loadTreesAndStructures, jarInputStreamProvider jprovider)
{
SequenceSet vamsasSet = jalviewModel.getVamsasModel().getSequenceSet().get(0);
List<Sequence> vamsasSeqs = vamsasSet.getSequence();
if (af == null)
{
- af = loadViewport(file, jseqs, hiddenSeqs, al, jalviewModel, view,
+ af = loadViewport(fileName, file, jseqs, hiddenSeqs, al, jalviewModel, view,
uniqueSeqSetId, viewId, autoAlan);
av = af.getViewport();
// note that this only retrieves the most recently accessed
}
}
- AlignFrame loadViewport(String fileName, List<JSeq> JSEQ,
+ AlignFrame loadViewport(String fileName, File file, List<JSeq> JSEQ,
List<SequenceI> hiddenSeqs, AlignmentI al, JalviewModel jm,
Viewport view, String uniqueSeqSetId, String viewId,
List<JvAnnotRow> autoAlan)
// }
;
af.alignPanel.setHoldRepaint(true);
- af.setFileName(fileName, FileFormat.Jalview);
+ af.setFile(fileName, file, null, FileFormat.Jalview);
af.setFileObject(jarFile); // BH 2019 JAL-3436
final AlignViewport viewport = af.getViewport();
viewportsAdded.clear();
- AlignFrame af = loadFromObject(jm, null, false, null);
+ AlignFrame af = loadFromObject(jm, null, null, false, null);
af.getAlignPanels().clear();
af.closeMenuItem_actionPerformed(true);
af.alignPanel.setHoldRepaint(false);
*/
package jalview.util;
+import java.io.File;
import java.io.IOException;
import java.util.jar.JarInputStream;
* with it
*/
String getFilename();
+
+ /**
+ * @return jarFile name if from SwingJS
+ */
+ File getFile();
}