import jalview.schemes.ColourSchemeI;
import java.awt.Color;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
*/
public class SequenceGroup implements AnnotatedCollectionI
{
+ // TODO ideally this event notification functionality should be separated into
+ // a
+ // subclass of ViewportProperties similarly to ViewportRanges. Done here as
+ // quick fix for JAL-2665
+ public static final String SEQ_GROUP_CHANGED = "Sequence group changed";
+
+ protected PropertyChangeSupport changeSupport = new PropertyChangeSupport(
+ this);
+
+ public void addPropertyChangeListener(PropertyChangeListener listener)
+ {
+ changeSupport.addPropertyChangeListener(listener);
+ }
+
+ public void removePropertyChangeListener(PropertyChangeListener listener)
+ {
+ changeSupport.removePropertyChangeListener(listener);
+ }
+ // end of event notification functionality initialisation
+
String groupName;
String description;
{
if (s != null && !sequences.contains(s))
{
+ List<SequenceI> before = sequences;
sequences.add(s);
+ changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before,
+ sequences);
}
if (recalc)
{
synchronized (sequences)
{
+ List<SequenceI> before = sequences;
sequences.remove(s);
+ changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before,
+ sequences);
if (recalc)
{
*/
public void setStartRes(int i)
{
+ int before = startRes;
startRes = i;
+ changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before, startRes);
}
/**
*/
public void setEndRes(int i)
{
+ int before = endRes;
endRes = i;
+ changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before, endRes);
}
/**
{
synchronized (sequences)
{
+ List<SequenceI> before = sequences;
sequences.clear();
+ changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before,
+ sequences);
}
}
public void paintComponent(Graphics g)
{
updateViewport();
- BufferedImage lcimg = img; // take reference since other threads may null
+
+ // img is a cached version of the last view we drew
+ // selectImage will hold any selection we have
+ // lcimg is a local *copy* of img which we'll draw selectImage on top of
+
+ if (img == null)
+ {
+ setupImage();
+ }
+ if (img == null)
+ {
+ return;
+ }
+ BufferedImage lcimg = new BufferedImage(img.getWidth(), img.getHeight(),
+ img.getType());
+ Graphics2D g2d = lcimg.createGraphics();
+ g2d.drawImage(img, 0, 0, null);
+ g2d.dispose();
+
+
+ // BufferedImage lcimg = img; // take reference since other threads may null
// img and call later.
super.paintComponent(g);
{
Graphics2D g2 = (Graphics2D) lcimg.getGraphics();
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC));
- // g.drawImage(lcimg, 0, 0, this);
// overlay selection group on lcimg
if (selectImage != null)
return;
}
- lcimg = setupImage(lcimg);
- // img = lcimg;
+ /* lcimg = setupImage(lcimg);
if (lcimg == null)
{
return;
- }
+ }*/
if (av.antiAlias)
{
}
Graphics2D g2 = (Graphics2D) lcimg.getGraphics();
- // g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC));
- // g.drawImage(lcimg, 0, 0, this); // scrolling only works with g not g2???
// overlay selection group on lcimg
if (selectImage != null)
g2.drawImage(selectImage, 0, 0, this);
}
g.drawImage(lcimg, 0, 0, this);
- // g.drawImage(selectImage, 0, 0, this);
}
- private BufferedImage setupImage(BufferedImage lcimg)
+ private void paintSeqGroup()
+ {
+ fastPaint = true;
+ repaint();
+ }
+
+ private void setupImage()
{
// this draws the whole of the alignment
imgWidth = getWidth();
if ((imgWidth < 1) || (imgHeight < 1))
{
- return null;
+ return;
}
- if (lcimg == null || imgWidth != lcimg.getWidth()
- || imgHeight != lcimg.getHeight())
- {
+
try
{
- lcimg = img = new BufferedImage(imgWidth, imgHeight,
+ img = new BufferedImage(imgWidth, imgHeight,
BufferedImage.TYPE_INT_ARGB); // ARGB so alpha compositing works
gg = (Graphics2D) img.getGraphics();
gg.setFont(av.getFont());
System.err.println("SeqCanvas OutOfMemory Redraw Error.\n" + er);
new OOMWarning("Creating alignment image for display", er);
- return null;
+ return;
}
- }
- return lcimg;
+
}
private BufferedImage setupSelectionImage()
try
{
- lcimg = new BufferedImage(imgWidth, imgHeight,
+ lcimg = new BufferedImage(width, height,
BufferedImage.TYPE_INT_ARGB); // ARGB so alpha compositing works
} catch (OutOfMemoryError er)
{
// ///////////////////////////////////
// Now outline any areas if necessary
// ///////////////////////////////////
- // SequenceGroup group = av.getSelectionGroup();
SequenceGroup group = null;
int groupIndex = -1;
int visWidth = (endRes - startRes + 1) * charWidth;
- // if ((group == null) && (av.getAlignment().getGroups().size() > 0))
if (av.getAlignment().getGroups().size() > 0)
{
group = av.getAlignment().getGroups().get(0);
oldY = sy;
inGroup = true;
- /*if (group == av.getSelectionGroup())
- {
- g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT,
- BasicStroke.JOIN_ROUND, 3f, new float[] { 5f, 3f },
- 0f));
- g.setColor(Color.RED);
- }
- else
- {*/
- g.setStroke(new BasicStroke());
- g.setColor(group.getOutlineColour());
- // }
+ g.setStroke(new BasicStroke());
+ g.setColor(group.getOutlineColour());
}
}
else
{
String eventName = evt.getPropertyName();
- if (av.getWrapAlignment())
+ if (eventName.equals(SequenceGroup.SEQ_GROUP_CHANGED))
+ {
+ paintSeqGroup();
+ }
+ else if (av.getWrapAlignment())
{
if (eventName.equals(ViewportRanges.STARTRES))
{