From: Charles Ofoegbu Date: Fri, 23 Jan 2015 10:37:09 +0000 (+0000) Subject: JAL-1553 fixed null pointer exception thrown in SeqCanvas and ScalePanel of jalview... X-Git-Tag: Jalview_2_9~107^2~1 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=6ff627c729ffdea1bbf658a463e3e993aad493bb;p=jalview.git JAL-1553 fixed null pointer exception thrown in SeqCanvas and ScalePanel of jalview applet while attempting to redraw the panels when hidden columns no longer exists --- diff --git a/src/jalview/appletgui/ScalePanel.java b/src/jalview/appletgui/ScalePanel.java index 60d89aa..bc5b3e7 100755 --- a/src/jalview/appletgui/ScalePanel.java +++ b/src/jalview/appletgui/ScalePanel.java @@ -20,12 +20,23 @@ */ package jalview.appletgui; -import java.awt.*; -import java.awt.event.*; - -import jalview.datamodel.*; +import jalview.datamodel.ColumnSelection; +import jalview.datamodel.SequenceGroup; import jalview.util.MessageManager; +import java.awt.Color; +import java.awt.FontMetrics; +import java.awt.Graphics; +import java.awt.MenuItem; +import java.awt.Panel; +import java.awt.PopupMenu; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.InputEvent; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; + public class ScalePanel extends Panel implements MouseMotionListener, MouseListener { @@ -323,6 +334,8 @@ public class ScalePanel extends Panel implements MouseMotionListener, res = av.getColumnSelection().adjustForHiddenColumns(res); reveal = null; + if (av.getColumnSelection().getHiddenColumns() != null) + { for (int i = 0; i < av.getColumnSelection().getHiddenColumns().size(); i++) { int[] region = (int[]) av.getColumnSelection().getHiddenColumns() @@ -333,6 +346,7 @@ public class ScalePanel extends Panel implements MouseMotionListener, break; } } + } repaint(); } @@ -407,18 +421,18 @@ public class ScalePanel extends Panel implements MouseMotionListener, } gg.drawLine( - (int) (((i - startx - 1) * av.charWidth) + (av.charWidth / 2)), + ((i - startx - 1) * av.charWidth) + (av.charWidth / 2), y + 2, - (int) (((i - startx - 1) * av.charWidth) + (av.charWidth / 2)), + ((i - startx - 1) * av.charWidth) + (av.charWidth / 2), y + (fm.getDescent() * 2)); } else { gg.drawLine( - (int) (((i - startx - 1) * av.charWidth) + (av.charWidth / 2)), + ((i - startx - 1) * av.charWidth) + (av.charWidth / 2), y + fm.getDescent(), - (int) (((i - startx - 1) * av.charWidth) + (av.charWidth / 2)), + ((i - startx - 1) * av.charWidth) + (av.charWidth / 2), y + (fm.getDescent() * 2)); } } @@ -427,7 +441,8 @@ public class ScalePanel extends Panel implements MouseMotionListener, { gg.setColor(Color.blue); int res; - if (av.getShowHiddenMarkers()) + if (av.getColumnSelection().getHiddenColumns() != null + && av.getShowHiddenMarkers()) { for (int i = 0; i < av.getColumnSelection().getHiddenColumns() .size(); i++) diff --git a/src/jalview/appletgui/SeqCanvas.java b/src/jalview/appletgui/SeqCanvas.java index 53cca3c..4b3cd1c 100755 --- a/src/jalview/appletgui/SeqCanvas.java +++ b/src/jalview/appletgui/SeqCanvas.java @@ -20,9 +20,16 @@ */ package jalview.appletgui; -import java.awt.*; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.SearchResults; +import jalview.datamodel.SequenceGroup; +import jalview.datamodel.SequenceI; -import jalview.datamodel.*; +import java.awt.Color; +import java.awt.FontMetrics; +import java.awt.Graphics; +import java.awt.Image; +import java.awt.Panel; public class SeqCanvas extends Panel { @@ -510,18 +517,27 @@ public class SeqCanvas extends Panel void drawPanel(Graphics g1, int startRes, int endRes, int startSeq, int endSeq, int offset) { + + if (!av.hasHiddenColumns()) { draw(g1, startRes, endRes, startSeq, endSeq, offset); } else { - java.util.Vector regions = av.getColumnSelection().getHiddenColumns(); + + int screenY = 0; int blockStart = startRes; int blockEnd = endRes; + if (av.getColumnSelection() != null + && av.getColumnSelection().getHiddenColumns() != null) + { + java.util.Vector regions = av.getColumnSelection() + .getHiddenColumns(); + for (int i = 0; i < regions.size(); i++) { int[] region = (int[]) regions.elementAt(i); @@ -552,7 +568,7 @@ public class SeqCanvas extends Panel screenY += blockEnd - blockStart + 1; blockStart = hideEnd + 1; } - + } if (screenY <= (endRes - startRes)) { blockEnd = blockStart + (endRes - startRes) - screenY; @@ -646,7 +662,7 @@ public class SeqCanvas extends Panel if ((group == null) && (av.getAlignment().getGroups().size() > 0)) { - group = (SequenceGroup) av.getAlignment().getGroups().get(0); + group = av.getAlignment().getGroups().get(0); groupIndex = 0; } @@ -803,7 +819,7 @@ public class SeqCanvas extends Panel break; } - group = (SequenceGroup) av.getAlignment().getGroups() + group = av.getAlignment().getGroups() .get(groupIndex); } while (groupIndex < av.getAlignment().getGroups().size());