From: amwaterhouse Date: Mon, 12 Sep 2005 12:23:09 +0000 (+0000) Subject: Overview subsamples alignment X-Git-Tag: Release_2_05b~50 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=8878681ec11f85c050248236a96ffbcaf2f0497b;hp=d7b15f85f8a1f1440e011116b5aa0d31306c217c;p=jalview.git Overview subsamples alignment --- diff --git a/src/jalview/appletgui/OverviewPanel.java b/src/jalview/appletgui/OverviewPanel.java index 3cd229d..7910f2d 100755 --- a/src/jalview/appletgui/OverviewPanel.java +++ b/src/jalview/appletgui/OverviewPanel.java @@ -32,11 +32,16 @@ public class OverviewPanel float scaleh = 1f; public int width, sequencesHeight; - int graphHeight = 30; + int graphHeight = 20; int boxX = -1, boxY = -1, boxWidth = -1, boxHeight = -1; boolean resizing = false; + // Can set different properties in this seqCanvas than + // main visible SeqCanvas + SeqCanvas overviewSeq; + + Frame nullFrame; public OverviewPanel(AlignmentPanel ap) @@ -47,14 +52,25 @@ public class OverviewPanel nullFrame = new Frame(); nullFrame.addNotify(); + overviewSeq = new SeqCanvas(av); + overviewSeq.isOverview = true; + overviewSeq.sr.renderGaps = false; + + // scale the initial size of overviewpanel to shape of alignment float initialScale = (float) av.alignment.getWidth() / (float) av.alignment.getHeight(); + + if(av.vconsensus==null) + graphHeight = 0; + if (av.alignment.getWidth() > av.alignment.getHeight()) { // wider width = 400; sequencesHeight = (int) (400f / initialScale); + if(sequencesHeight<40) + sequencesHeight = 40; } else { @@ -212,83 +228,36 @@ public class OverviewPanel miniMe = nullFrame.createImage(width, sequencesHeight + graphHeight); Graphics mg = miniMe.getGraphics(); - Image consensus = nullFrame.createImage(fullsizeWidth, 60); - Graphics g = consensus.getGraphics(); - ap.annotationPanel.drawGraph(g, av.conservation, fullsizeWidth, 60); - mg.drawImage(consensus, 0, sequencesHeight, width, - sequencesHeight + graphHeight, 0, 0, fullsizeWidth, 60, this); - - boolean oldRenderGaps = av.renderGaps; - try - { - // We'll have to draw the full size alignment in chunks, as an image of the - // whole alignment requires too much memory + float sampleCol = (float) alwidth / (float) width; + float sampleRow = (float) alheight / (float) sequencesHeight; - // Max size depends on the font size, the following is a - // guess at a size which works - int maxSize = 2000 / av.getFont().getSize(); - Image block; - int blockx = 0, blocky = 0, blockw = 0, blockh = 0, eRes = 0, eSeq = 0; - - av.setRenderGaps(false); - for (int sRes = 0, chunkx = 0; sRes < alwidth; sRes += maxSize, chunkx++) + for (int col = 0; col < width; col++) + { + for (int row = 0; row < sequencesHeight; row++) { - eSeq = 0; - eRes += maxSize; - if (eRes > alwidth) - { - eRes = alwidth; - } - - for (int sSeq = 0, chunky = 0; sSeq < alheight; sSeq += maxSize, chunky++) - { - if(resizeAgain) - break; - - eSeq += maxSize; - if (eSeq > alheight) - { - eSeq = alheight; - } - - blocky = 0; - blockx = (int) ( (float) sRes / (float) alwidth * width); - - block = nullFrame.createImage( (eRes - sRes) * av.charWidth, - (eSeq - sSeq) * av.charHeight); - g = block.getGraphics(); - - ap.seqPanel.seqCanvas.drawPanel(g, sRes, eRes, sSeq, eSeq, sRes, sSeq, - 0); - - blockh = (int) ( (float) (eSeq - sSeq) / (float) alheight * - sequencesHeight) + 1; - blockw = (int) ( (float) (eRes - sRes) / (float) alwidth * width) + 1; - - blocky += (int) ( (float) sSeq / (float) alheight * sequencesHeight); - - mg.drawImage(block, blockx, - blocky, - blockx + blockw, - blocky + blockh, - - 0, 0, block.getWidth(null), block.getHeight(null), this); - - block = null; - } + overviewSeq.drawPanel(mg, + (int) (col * sampleCol), + (int) (col * sampleCol), + (int) (row * sampleRow), + (int) (row * sampleRow) + 1, + (int) (col * sampleCol), + (int) (row * sampleRow), 0); + mg.translate(0, 1); + + if (av.conservation != null) + ap.annotationPanel.drawGraph(mg, av.conservation, + (int) (sampleCol) + 1, + graphHeight, + (int) (col * sampleCol), + (int) (col * sampleCol) + 1); } + mg.translate(0, -sequencesHeight); + mg.translate(1, 0); - } - catch (OutOfMemoryError error) - { - System.err.println( - "Out of memory when trying to calculate the overview window image!"); - } - + } System.gc(); - av.setRenderGaps(oldRenderGaps); resizing = false; setBoxPosition(); diff --git a/src/jalview/appletgui/SeqCanvas.java b/src/jalview/appletgui/SeqCanvas.java index 9e8f895..fd83309 100755 --- a/src/jalview/appletgui/SeqCanvas.java +++ b/src/jalview/appletgui/SeqCanvas.java @@ -43,6 +43,8 @@ public class SeqCanvas boolean fastPaint = false; + boolean isOverview = false; + public SeqCanvas(AlignViewport av) { this.av = av; @@ -203,6 +205,8 @@ public class SeqCanvas public void paint(Graphics g) { + sr.renderGaps(av.renderGaps); + if (fastPaint) { g.drawImage(img, 0, 0, this); @@ -408,7 +412,7 @@ public class SeqCanvas groupIndex = 0; } - if (group != null) + if (group != null && !isOverview) { do { diff --git a/src/jalview/gui/OverviewPanel.java b/src/jalview/gui/OverviewPanel.java index c80a830..7086a51 100755 --- a/src/jalview/gui/OverviewPanel.java +++ b/src/jalview/gui/OverviewPanel.java @@ -40,13 +40,17 @@ public class OverviewPanel extends JPanel implements Runnable float scaleh = 1f; int width; int sequencesHeight; - int graphHeight = 30; + int graphHeight = 20; int boxX = -1; int boxY = -1; int boxWidth = -1; int boxHeight = -1; boolean resizing = false; + // Can set different properties in this seqCanvas than + // main visible SeqCanvas + SeqCanvas overviewSeq; + /** * Creates a new OverviewPanel object. * @@ -58,14 +62,24 @@ public class OverviewPanel extends JPanel implements Runnable this.ap = ap; setLayout(null); + overviewSeq = new SeqCanvas(av); + overviewSeq.isOverview = true; + overviewSeq.sr.renderGaps = false; + // scale the initial size of overviewpanel to shape of alignment float initialScale = (float) av.alignment.getWidth() / (float) av.alignment.getHeight(); + if(av.vconsensus==null) + graphHeight = 0; + + if (av.alignment.getWidth() > av.alignment.getHeight()) { // wider width = 400; sequencesHeight = (int) (400f / initialScale); + if(sequencesHeight<40) + sequencesHeight = 40; } else { @@ -204,6 +218,7 @@ public class OverviewPanel extends JPanel implements Runnable width = getWidth(); sequencesHeight = getHeight() - graphHeight; } + setPreferredSize(new Dimension(width, sequencesHeight + graphHeight)); setBoxPosition(); @@ -238,117 +253,39 @@ public class OverviewPanel extends JPanel implements Runnable BufferedImage.TYPE_INT_RGB); - Graphics mg = miniMe.getGraphics(); - BufferedImage consensus; - Graphics cg; - Graphics g ; - - mg.setColor(Color.white); - mg.fillRect(0, 0, getWidth(), getHeight()); - mg.setColor(Color.black); - mg.setFont(new Font("Verdana", Font.BOLD, 15)); - mg.drawString("Recalculating", 5, sequencesHeight / 2); - mg.drawString("Overview.....", 5, (sequencesHeight / 2) + 20); - boolean oldRenderGaps = av.renderGaps; + float sampleCol = (float) alwidth / (float) width; + float sampleRow = (float) alheight / (float) sequencesHeight; - try + for (int col = 0; col < width; col++) { - // We'll have to draw the full size alignment in chunks, as an image of the - // whole alignment requires too much memory - // Max size depends on the font size, the following is a - // guess at a size which works - int maxSize = 2000 / av.getFont().getSize(); - BufferedImage block; - int blockx = 0; - int blocky = 0; - int blockw = 0; - int blockh = 0; - int eRes = 0; - int eSeq = 0; - - av.setRenderGaps(false); - - for (int sRes = 0, chunkx = 0; sRes < alwidth; - sRes += maxSize, chunkx++) - { - if(resizeAgain) - break; - - eSeq = 0; - eRes += maxSize; - - if (eRes > alwidth) - { - eRes = alwidth; - } - - for (int sSeq = 0, chunky = 0; sSeq < alheight; - sSeq += maxSize, chunky++) - { - if (resizeAgain) - break; - eSeq += maxSize; - - if (eSeq > alheight) - { - eSeq = alheight; - } - - blocky = 0; - blockx = (int) ((float) sRes / (float) alwidth * width); + for (int row = 0; row < sequencesHeight; row++) + { + overviewSeq.drawPanel(mg, + (int) (col * sampleCol), + (int) (col * sampleCol), + (int) (row * sampleRow), + (int) (row * sampleRow) + 1, + (int) (col * sampleCol), + (int) (row * sampleRow), 0); + mg.translate(0, 1); + + if (av.conservation != null) + ap.annotationPanel.drawGraph(mg, av.conservation, + (int) (sampleCol) + 1, + graphHeight, + (int) (col * sampleCol), + (int) (col * sampleCol) + 1); + + } + mg.translate(0, -sequencesHeight); + mg.translate(1, 0); - block = new BufferedImage((eRes - sRes) * av.charWidth, - (eSeq - sSeq) * av.charHeight, - BufferedImage.TYPE_3BYTE_BGR); - g = block.getGraphics(); - - ap.seqPanel.seqCanvas.drawPanel(g, sRes, eRes, sSeq, eSeq, - sRes, sSeq, 0); - - blockh = (int) ((float) (eSeq - sSeq) / (float) alheight * sequencesHeight) + - 1; - blockw = (int) ((float) (eRes - sRes) / (float) alwidth * width) + - 1; - - blocky += (int) ((float) sSeq / (float) alheight * sequencesHeight); - - if(av.conservation!=null) - { - consensus = new BufferedImage( (eRes - sRes) * av.charWidth, 60, - BufferedImage.TYPE_3BYTE_BGR); - cg = consensus.getGraphics(); - - ap.annotationPanel.drawGraph(cg, av.conservation, - (eRes - sRes) * av.charWidth, 60, sRes, eRes); - - mg.drawImage(consensus, blockx, sequencesHeight, blockx + blockw, - - sequencesHeight + graphHeight, 0, 0, - (eRes - sRes) * av.charWidth, 60, this); - } - - mg.drawImage(block, blockx, blocky, blockx + blockw, - blocky + blockh, 0, 0, block.getWidth(), - block.getHeight(), null); - - block = null; - repaint(); - } - - - } - } - catch (OutOfMemoryError error) - { - System.err.println( - "Out of memory when trying to calculate the overview window image!"); } System.gc(); - av.setRenderGaps(oldRenderGaps); resizing = false; setBoxPosition(); @@ -386,7 +323,7 @@ public class OverviewPanel extends JPanel implements Runnable */ public void paintComponent(Graphics g) { - if (miniMe != null) + if (miniMe != null && !resizing) { g.drawImage(miniMe, 0, 0, this); } @@ -400,6 +337,7 @@ public class OverviewPanel extends JPanel implements Runnable g.drawString("Overview.....", 5, (sequencesHeight / 2) + 20); } + g.setColor(Color.red); g.drawRect(boxX, boxY, boxWidth, boxHeight); g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2); diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index 9f1eb70..3cf7f9a 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -49,6 +49,8 @@ public class SeqCanvas extends JComponent int LABEL_WEST; int LABEL_EAST; + boolean isOverview = false; + /** * Creates a new SeqCanvas object. * @@ -254,6 +256,8 @@ public class SeqCanvas extends JComponent // Set this to false to force a full panel paint public void paintComponent(Graphics g) { + sr.renderGaps(av.renderGaps); + if ((img != null) && (fastPaint || (getWidth() != g.getClipBounds().width) || (getHeight() != g.getClipBounds().height))) @@ -276,11 +280,12 @@ public class SeqCanvas extends JComponent return; } + img = new BufferedImage(imgWidth, imgHeight, BufferedImage.TYPE_INT_RGB); gg = (Graphics2D) img.getGraphics(); gg.setFont(av.getFont()); - // gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, - // RenderingHints.VALUE_ANTIALIAS_ON); + gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); gg.setColor(Color.white); gg.fillRect(0, 0, imgWidth, imgHeight); @@ -453,7 +458,6 @@ public class SeqCanvas extends JComponent { Graphics2D g = (Graphics2D) g1; g.setFont(av.getFont()); - sr.renderGaps(av.renderGaps); SequenceI nextSeq; @@ -497,7 +501,7 @@ public class SeqCanvas extends JComponent } - if (group != null) + if (group != null && !isOverview) { do {