import java.io.PrintWriter;
import java.util.List;
+import javax.swing.JScrollBar;
+
/**
* The main panel of an AlignFrame, containing holders for the IdPanel,
* SeqPanel, AnnotationLabels (a JPanel), and AnnotationPanel.
hscroll.addAdjustmentListener(this);
vscroll.addAdjustmentListener(this);
+
addComponentListener(new ComponentAdapter()
{
@Override
public void componentResized(ComponentEvent evt)
{
+ System.out.println("AlignmentPanel resized " + evt);
// reset the viewport ranges when the alignment panel is resized
// in particular, this initialises the end residue value when Jalview
// is initialised
/ av.getCharHeight();
ranges.setViewportWidth(widthInRes);
- ranges.setViewportHeight(heightInSeq);
ViewportRanges.sTest += "AP.resize chht=" + av.getCharHeight()
+ "canvHt=" + getSeqPanel().seqCanvas.getHeight() + " "
+ heightInSeq + "\n";
+ ranges.setViewportHeight(heightInSeq);
}
}
}
@Override
+ public void setBounds(int x, int y, int width, int height)
+ {
+ System.out.println("?AlignmentPanel.setBounds " + this.getX() + " "
+ + this.getY() + " " + this.getWidth() + " " + getHeight() + " "
+ + x + " " + y + " " + width + " " + height);
+ // BH 2020.03.23 when the Desktop changes its progress bar it re-lays out
+ // all
+ // its
+ // children, for unclear reasons. Maybe because they could be tiled?
+ if (x == this.getX() && y == this.getY() && width == this.getWidth()
+ && height == this.getHeight())
+ {
+ return;
+ }
+ System.out.println("!AlignmentPanel.setBounds " + this.getX() + " "
+ + this.getY() + " " + this.getWidth() + " " + getHeight() + " "
+ + x + " " + y + " " + width + " " + height);
+ super.setBounds(x, y, width, height);
+ }
+
+ // @Override
+ // public void reshape(int x, int y, int width, int height)
+ // {
+ // // BH 2020.03.23 when the Desktop changes its progress bar it relays out
+ // all its
+ // // children, for unclear reasons. Maybe because they could be tiled?
+ // if (x == this.getX() && y == this.getY() && width == this.getWidth()
+ // && height == this.getHeight())
+ // {
+ // return;
+ // }
+ //
+ // System.out.println("AlignmentPanel.reshape " + this.getX() + " "
+ // + this.getY() + " " + this.getWidth() + " " + getHeight() + " "
+ // + x
+ // + " " + y + " " + width + " " + height);
+ // super.reshape(x, y, width, height);
+ // }
+
+ @Override
public AlignViewportI getAlignViewport()
{
return av;
* visible column to scroll to
* @param y
* visible row to scroll to
+ *
+ * @return true if scrollbars will fire property changes
*
*/
- public void setScrollValues(int xpos, int ypos)
+ public boolean setScrollValues(int xpos, int ypos)
{
int x = xpos;
int y = ypos;
if (av == null || av.getAlignment() == null)
{
- return;
+ return false;
}
if (av.getWrapAlignment())
{
- setScrollingForWrappedPanel(x);
+ return setScrollingForWrappedPanel(x);
}
- else
+ int width = av.getAlignment().getVisibleWidth();
+ int height = av.getAlignment().getHeight();
+
+ hextent = getSeqPanel().seqCanvas.getWidth() / av.getCharWidth();
+ vextent = getSeqPanel().seqCanvas.getHeight() / av.getCharHeight();
+
+ if (hextent > width)
{
- int width = av.getAlignment().getVisibleWidth();
- int height = av.getAlignment().getHeight();
+ hextent = width;
+ }
- hextent = getSeqPanel().seqCanvas.getWidth() / av.getCharWidth();
- vextent = getSeqPanel().seqCanvas.getHeight() / av.getCharHeight();
+ if (vextent > height)
+ {
+ vextent = height;
+ }
- if (hextent > width)
- {
- hextent = width;
- }
+ if ((hextent + x) > width)
+ {
+ x = width - hextent;
+ }
- if (vextent > height)
- {
- vextent = height;
- }
+ if ((vextent + y) > height)
+ {
+ y = height - vextent;
+ }
- if ((hextent + x) > width)
- {
- x = width - hextent;
- }
+ if (y < 0)
+ {
+ y = 0;
+ }
- if ((vextent + y) > height)
- {
- y = height - vextent;
- }
+ if (x < 0)
+ {
+ x = 0;
+ }
- if (y < 0)
- {
- y = 0;
- }
+ // update the scroll values and return true if they changed
- if (x < 0)
- {
- x = 0;
- }
+ return (setIfChanged(hscroll, x, hextent, 0, width)
+ + setIfChanged(vscroll, y, vextent, 0, height) != 0);
- // update the scroll values
- hscroll.setValues(x, hextent, 0, width);
- vscroll.setValues(y, vextent, 0, height);
+ }
+
+ /**
+ * Update a horizontal or vertical scrollbar and indicate if it is actually changed
+ * (and so will be firing an AdjustmentChangedEvent)
+ * @param sb
+ * @param val
+ * @param extent
+ * @param min
+ * @praam max
+ * @return 1 if JScrollBar is changed; 0 if not
+ */
+ private int setIfChanged(JScrollBar sb, int val, int extent, int min,
+ int max)
+ {
+ if (sb.getValue() == val && sb.getModel().getExtent() == extent
+ && sb.getMinimum() == min && sb.getMaximum() == max)
+ {
+ return 0;
}
+ sb.setValues(val, extent, min, max);
+ return 1;
}
/**
return;
}
- ViewportRanges.sTest += "AP.valChanged chht=" + av.getCharHeight()
- + "canvHt=" + getSeqPanel().seqCanvas.getHeight() + " "
+ ViewportRanges.sTest += "AP.adjvalChanged chht=" + av.getCharHeight()
+ + "canvHt=" + getSeqPanel().seqCanvas.getHeight() + " newHt="
+ height + "\n";
ranges.setViewportStartAndHeight(y, height);
}
}
+ @Override
+ public void invalidate()
+ {
+ System.out.println("AlignmentPanel invalidate");
+ super.invalidate();
+ }
+
+ @Override
+ public void validate()
+ {
+ System.out.println("AlignmentPanel validate");
+ super.validate();
+ }
+
/**
* DOCUMENT ME!
*
public void paintComponent(Graphics g)
{
+ System.out.println("AlignmentPanel paintComponent");
+
invalidate(); // needed so that the id width adjuster works correctly
Dimension d = getIdPanel().getIdCanvas().getPreferredSize();
* though I still think this call should be elsewhere.
*/
ViewportRanges ranges = av.getRanges();
- setScrollValues(ranges.getStartRes(), ranges.getStartSeq());
+ if (!setScrollValues(ranges.getStartRes(), ranges.getStartSeq()))
+ {
+ // super.paintComponent(g);
+ }
super.paintComponent(g);
}
* @param topLeftColumn
* the column position at top left (0..)
*/
- private void setScrollingForWrappedPanel(int topLeftColumn)
+ private boolean setScrollingForWrappedPanel(int topLeftColumn)
{
ViewportRanges ranges = av.getRanges();
int scrollPosition = ranges.getWrappedScrollPosition(topLeftColumn);
* so we add extent (1) to the maxScroll value
*/
vscroll.setUnitIncrement(1);
- vscroll.setValues(scrollPosition, 1, 0, maxScroll + 1);
+ return (setIfChanged(vscroll, scrollPosition, 1, 0,
+ maxScroll + 1) != 0);
}
/**
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Toolkit;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintStream;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
{
Thread.currentThread().setName("SeqCanvasTest Setup " + ++nTest);
+ Cache.loadProperties("test/jalview/io/testProps.jvprops");
Cache.initLogger();
Jalview.setSynchronous(true);
}
@Test(groups = "Functional")
public void testCalculateWrappedGeometry_fromScrolled()
{
- flushEvents();
+ // debugOut("12]", new Runnable()
+ // {
+ //
+ // @Override
+ // public void run()
+ // {
+ //
+ // String s = Arrays
+ // .toString(new NullPointerException().getStackTrace())
+ // .replace(',', '\n') + "\n\n";
+ //
+ // System.err.println(s);
+ //
+ // }
+ //
+ // });
+ //
ViewportRanges.sTest = "";
Thread.currentThread().setName("SeqCanvasTest fromScrolled " + ++nTest);
AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
"examples/uniref50.fa", DataSourceType.FILE);
+ // note that this frame is unpacked, with w = h = 0;
AlignViewport av = af.getViewport();
AlignmentI al = av.getAlignment();
assertEquals(al.getWidth(), 157);
assertEquals(al.getHeight(), 15);
+ String s = "";
+ s += "flushing events";
flushEvents();
+ s += "events flushed";
av.getRanges().setStartEndSeq(0, 3);
- String s = "";
s += " SC1 " + av.getRanges() + " " + ViewportRanges.sTest;
av.setShowAnnotation(false);
av.setScaleAboveWrapped(true);
testee.calculateWrappedGeometry(canvasWidth, canvasHeight);
int repeatingHeight = (int) PA.getValue(testee,
"wrappedRepeatHeightPx");
- assertEquals(av.getRanges().getEndSeq(), 0, "endSeq should be 3 " + s); // unchanged
+ assertEquals(av.getRanges().getEndSeq(), 3, "endSeq should be 3 " + s); // unchanged
assertEquals(repeatingHeight, charHeight * (2 + al.getHeight()));
}
+ /**
+ * Let me know when the output indicates the specified message.
+ *
+ * @param msg
+ * @param r
+ */
+ private void debugOut(String msg, Runnable r)
+ {
+ int len = msg.length();
+ int c0 = msg.charAt(0);
+ boolean[] recording = new boolean[1];
+ System.setOut(new PrintStream(new OutputStream()
+ {
+
+ StringBuffer out = new StringBuffer();
+
+ @Override
+ public void write(int b) throws IOException
+ {
+
+ if (recording[0])
+ {
+ out.append((char) b);
+ if (out.length() == len)
+ {
+ if (out.toString().equals(msg))
+ {
+ r.run();
+ }
+ recording[0] = false;
+ out.setLength(0);
+ }
+ }
+ else if (b == c0)
+ {
+ out.append((char) b);
+ recording[0] = true;
+ }
+ }
+
+ }));
+
+ // TODO Auto-generated method stub
+
+ }
+
private static void flushEvents()
{
((sun.awt.SunToolkit) Toolkit.getDefaultToolkit()).flushPendingEvents();