X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FOverviewPanel.java;h=62f8ca9fb31f8f6e50b58be7f51d81215b32d96b;hb=efc31b4a8d5cee63555586804a2b79c06bdb5a14;hp=244d884b50d4e2a08b87ba34757711d9a4d4fc93;hpb=9257b8510c7354cbd7e43a3fc2817978cc8e4ae9;p=jalview.git diff --git a/src/jalview/gui/OverviewPanel.java b/src/jalview/gui/OverviewPanel.java index 244d884..62f8ca9 100755 --- a/src/jalview/gui/OverviewPanel.java +++ b/src/jalview/gui/OverviewPanel.java @@ -21,305 +21,346 @@ package jalview.gui; import java.awt.*; import java.awt.event.*; import java.awt.image.*; + import javax.swing.*; -public class OverviewPanel - extends JPanel implements Runnable + +/** + * DOCUMENT ME! + * + * @author $author$ + * @version $Revision$ + */ +public class OverviewPanel extends JPanel implements Runnable { - BufferedImage miniMe; - AlignViewport av; - AlignmentPanel ap; - float scalew = 1f; - float scaleh = 1f; - int width; - int sequencesHeight; - int graphHeight = 30; - int boxX = -1; - int boxY = -1; - int boxWidth = -1; - int boxHeight = -1; - boolean resizing = false; - - public OverviewPanel(AlignmentPanel ap) - { - this.av = ap.av; - this.ap = ap; - setLayout(null); - - // scale the initial size of overviewpanel to shape of alignment - float initialScale = (float) av.alignment.getWidth() / - (float) av.alignment.getHeight(); - - if (av.alignment.getWidth() > av.alignment.getHeight()) + BufferedImage miniMe; + AlignViewport av; + AlignmentPanel ap; + float scalew = 1f; + float scaleh = 1f; + int width; + int sequencesHeight; + int graphHeight = 30; + int boxX = -1; + int boxY = -1; + int boxWidth = -1; + int boxHeight = -1; + boolean resizing = false; + + /** + * Creates a new OverviewPanel object. + * + * @param ap DOCUMENT ME! + */ + public OverviewPanel(AlignmentPanel ap) { - // wider - width = 400; - sequencesHeight = (int) (400f / initialScale); - } - else - { - // taller - width = (int) (400f * initialScale); - sequencesHeight = 300; - - if (width < 120) - { - width = 120; - } - } + this.av = ap.av; + this.ap = ap; + setLayout(null); - addComponentListener(new ComponentAdapter() - { - public void componentResized(ComponentEvent evt) - { - if ( (getWidth() != width) || - (getHeight() != (sequencesHeight + graphHeight))) + // scale the initial size of overviewpanel to shape of alignment + float initialScale = (float) av.alignment.getWidth() / (float) av.alignment.getHeight(); + + if (av.alignment.getWidth() > av.alignment.getHeight()) { - updateOverviewImage(); + // wider + width = 400; + sequencesHeight = (int) (400f / initialScale); + } + else + { + // taller + width = (int) (400f * initialScale); + sequencesHeight = 300; + + if (width < 120) + { + width = 120; + } } - } - }); - - addMouseMotionListener(new MouseMotionAdapter() - { - public void mouseDragged(MouseEvent evt) - { - doMouseDragged(evt); - } - }); - addMouseListener(new MouseAdapter() - { - public void mousePressed(MouseEvent evt) - { - doMousePressed(evt); - } - - public void mouseReleased(MouseEvent evt) - { - doMouseReleased(evt); - } - }); - - updateOverviewImage(); - } - - public void doMousePressed(MouseEvent evt) - { - boxX = evt.getX(); - boxY = evt.getY(); - - checkValid(); - repaint(); - } - - public void doMouseReleased(MouseEvent evt) - { - boxX = evt.getX(); - boxY = evt.getY(); - checkValid(); - - if (!resizing) - { - ap.setScrollValues( (int) (boxX / scalew / av.getCharWidth()), - (int) (boxY / scaleh / av.getCharHeight())); + addComponentListener(new ComponentAdapter() + { + public void componentResized(ComponentEvent evt) + { + if ((getWidth() != width) || + (getHeight() != (sequencesHeight + graphHeight))) + { + updateOverviewImage(); + } + } + }); + + addMouseMotionListener(new MouseMotionAdapter() + { + public void mouseDragged(MouseEvent evt) + { + doMouseDragged(evt); + } + }); + + addMouseListener(new MouseAdapter() + { + public void mousePressed(MouseEvent evt) + { + doMousePressed(evt); + } + + public void mouseReleased(MouseEvent evt) + { + doMouseReleased(evt); + } + }); + + updateOverviewImage(); } - } - public void doMouseDragged(MouseEvent evt) - { - boxX = evt.getX(); - boxY = evt.getY(); - checkValid(); - - if (!resizing) + /** + * DOCUMENT ME! + * + * @param evt DOCUMENT ME! + */ + public void doMousePressed(MouseEvent evt) { - ap.setScrollValues( (int) (boxX / scalew / av.getCharWidth()), - (int) (boxY / scaleh / av.getCharHeight())); - } - } + boxX = evt.getX(); + boxY = evt.getY(); - void checkValid() - { - if (boxY < 0) - { - boxY = 0; + checkValid(); + repaint(); } - if (boxY > (sequencesHeight - boxHeight)) + /** + * DOCUMENT ME! + * + * @param evt DOCUMENT ME! + */ + public void doMouseReleased(MouseEvent evt) { - boxY = sequencesHeight - boxHeight + 1; - } + boxX = evt.getX(); + boxY = evt.getY(); + checkValid(); - if (boxX < 0) - { - boxX = 0; + if (!resizing) + { + ap.setScrollValues((int) (boxX / scalew / av.getCharWidth()), + (int) (boxY / scaleh / av.getCharHeight())); + } } - if (boxX > (width - boxWidth)) + /** + * DOCUMENT ME! + * + * @param evt DOCUMENT ME! + */ + public void doMouseDragged(MouseEvent evt) { - boxX = width - boxWidth; - } - } + boxX = evt.getX(); + boxY = evt.getY(); + checkValid(); - public void updateOverviewImage() - { - if (resizing) - { - return; + if (!resizing) + { + ap.setScrollValues((int) (boxX / scalew / av.getCharWidth()), + (int) (boxY / scaleh / av.getCharHeight())); + } } - resizing = true; - - Thread thread = new Thread(this); - thread.start(); - repaint(); - } + /** + * DOCUMENT ME! + */ + void checkValid() + { + if (boxY < 0) + { + boxY = 0; + } - public void run() - { - miniMe = null; + if (boxY > (sequencesHeight - boxHeight)) + { + boxY = sequencesHeight - boxHeight + 1; + } - int alwidth = av.alignment.getWidth(); - int alheight = av.alignment.getHeight(); + if (boxX < 0) + { + boxX = 0; + } - if ( (getWidth() > 0) && (getHeight() > 0)) - { - width = getWidth(); - sequencesHeight = getHeight() - graphHeight; + if (boxX > (width - boxWidth)) + { + boxX = width - boxWidth; + } } - setPreferredSize(new Dimension(width, sequencesHeight + graphHeight)); - - int fullsizeWidth = alwidth * av.getCharWidth(); - int fullsizeHeight = alheight * av.getCharHeight(); + /** + * DOCUMENT ME! + */ + public void updateOverviewImage() + { + if (resizing) + { + return; + } - scalew = (float) width / (float) fullsizeWidth; - scaleh = (float) sequencesHeight / (float) fullsizeHeight; + resizing = true; - miniMe = new BufferedImage(width, sequencesHeight + graphHeight, - BufferedImage.TYPE_INT_RGB); + Thread thread = new Thread(this); + thread.start(); + repaint(); + } - Graphics mg = miniMe.getGraphics(); - BufferedImage consensus = new BufferedImage(fullsizeWidth, 60, - BufferedImage.TYPE_3BYTE_BGR); - 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); + /** + * DOCUMENT ME! + */ + public void run() + { + miniMe = null; - boolean oldRenderGaps = av.renderGaps; + int alwidth = av.alignment.getWidth(); + int alheight = av.alignment.getHeight(); - try - { - // 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++) - { - eSeq = 0; - eRes += maxSize; - - if (eRes > alwidth) + if ((getWidth() > 0) && (getHeight() > 0)) { - eRes = alwidth; + width = getWidth(); + sequencesHeight = getHeight() - graphHeight; } - for (int sSeq = 0, chunky = 0; sSeq < alheight; - sSeq += maxSize, chunky++) - { - eSeq += maxSize; + setPreferredSize(new Dimension(width, sequencesHeight + graphHeight)); - if (eSeq > alheight) - { - eSeq = alheight; - } + int fullsizeWidth = alwidth * av.getCharWidth(); + int fullsizeHeight = alheight * av.getCharHeight(); - blocky = 0; - blockx = (int) ( (float) sRes / (float) alwidth * width); + scalew = (float) width / (float) fullsizeWidth; + scaleh = (float) sequencesHeight / (float) fullsizeHeight; - block = new BufferedImage( (eRes - sRes) * av.charWidth, - (eSeq - sSeq) * av.charHeight, - BufferedImage.TYPE_3BYTE_BGR); - g = block.getGraphics(); + miniMe = new BufferedImage(width, sequencesHeight + graphHeight, + BufferedImage.TYPE_INT_RGB); - ap.seqPanel.seqCanvas.drawPanel(g, sRes, eRes, sSeq, eSeq, - sRes, sSeq, 0); + Graphics mg = miniMe.getGraphics(); + BufferedImage consensus = new BufferedImage(fullsizeWidth, 60, + BufferedImage.TYPE_3BYTE_BGR); + 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); - blockh = (int) ( (float) (eSeq - sSeq) / (float) alheight * - sequencesHeight) + - 1; - blockw = (int) ( (float) (eRes - sRes) / (float) alwidth * width) + - 1; + boolean oldRenderGaps = av.renderGaps; - blocky += (int) ( (float) sSeq / (float) alheight * sequencesHeight); + try + { + // 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++) + { + eSeq = 0; + eRes += maxSize; + + if (eRes > alwidth) + { + eRes = alwidth; + } + + for (int sSeq = 0, chunky = 0; sSeq < alheight; + sSeq += maxSize, chunky++) + { + eSeq += maxSize; + + if (eSeq > alheight) + { + eSeq = alheight; + } + + blocky = 0; + blockx = (int) ((float) sRes / (float) alwidth * width); + + 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); + + mg.drawImage(block, blockx, blocky, blockx + blockw, + blocky + blockh, 0, 0, block.getWidth(), + block.getHeight(), this); + + block = null; + } + } + } + catch (OutOfMemoryError error) + { + System.err.println( + "Out of memory when trying to calculate the overview window image!"); + } - mg.drawImage(block, blockx, blocky, blockx + blockw, - blocky + blockh, 0, 0, block.getWidth(), - block.getHeight(), this); + av.setRenderGaps(oldRenderGaps); + resizing = false; - block = null; - } - } - } - catch (OutOfMemoryError error) - { - System.err.println( - "Out of memory when trying to calculate the overview window image!"); + setBoxPosition(); } - av.setRenderGaps(oldRenderGaps); - resizing = false; - - setBoxPosition(); - } - - public void setBoxPosition() - { - boxX = (int) (av.getStartRes() * av.getCharWidth() * scalew); - boxY = (int) (av.getStartSeq() * av.getCharHeight() * scaleh); - boxWidth = (int) ( (av.getEndRes() - av.getStartRes() + 1) * - av.getCharWidth() * scalew); - boxHeight = (int) (av.getEndSeq() * av.getCharHeight() * scaleh) - - boxY; - repaint(); - } - - public void paintComponent(Graphics g) - { - g.setColor(Color.white); - g.fillRect(0, 0, getWidth(), getHeight()); - g.setColor(Color.black); - - if (resizing) + /** + * DOCUMENT ME! + */ + public void setBoxPosition() { - g.setFont(new Font("Verdana", Font.BOLD, 15)); - g.drawString("Recalculating", 5, sequencesHeight / 2); - g.drawString("Overview.....", 5, (sequencesHeight / 2) + 20); + boxX = (int) (av.getStartRes() * av.getCharWidth() * scalew); + boxY = (int) (av.getStartSeq() * av.getCharHeight() * scaleh); + boxWidth = (int) ((av.getEndRes() - av.getStartRes() + 1) * av.getCharWidth() * scalew); + boxHeight = (int) (av.getEndSeq() * av.getCharHeight() * scaleh) - + boxY; + repaint(); } - else + + /** + * DOCUMENT ME! + * + * @param g DOCUMENT ME! + */ + public void paintComponent(Graphics g) { - if (miniMe != null) - { - g.drawImage(miniMe, 0, 0, this); - } - - g.setColor(Color.red); - g.drawRect(boxX, boxY, boxWidth, boxHeight); - g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2); + g.setColor(Color.white); + g.fillRect(0, 0, getWidth(), getHeight()); + g.setColor(Color.black); + + if (resizing) + { + g.setFont(new Font("Verdana", Font.BOLD, 15)); + g.drawString("Recalculating", 5, sequencesHeight / 2); + g.drawString("Overview.....", 5, (sequencesHeight / 2) + 20); + } + else + { + if (miniMe != null) + { + g.drawImage(miniMe, 0, 0, this); + } + + g.setColor(Color.red); + g.drawRect(boxX, boxY, boxWidth, boxHeight); + g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2); + } } - } }