X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FOverviewPanel.java;h=9d0a55da93a501d6bc1eee4ecdd6632d8ab2baf2;hb=5010b95e8e250e744eefc5a1c976d70c044be32f;hp=5fbefb5b5c015a1ebf32c6a7f070173e0b003aba;hpb=236efa0d06562386ba9a5e44764143298e0306d2;p=jalview.git diff --git a/src/jalview/gui/OverviewPanel.java b/src/jalview/gui/OverviewPanel.java index 5fbefb5..9d0a55d 100755 --- a/src/jalview/gui/OverviewPanel.java +++ b/src/jalview/gui/OverviewPanel.java @@ -20,6 +20,8 @@ */ package jalview.gui; +import jalview.bin.Cache; +import jalview.renderer.OverviewRenderer; import jalview.util.MessageManager; import jalview.util.Platform; import jalview.viewmodel.OverviewDimensions; @@ -38,8 +40,10 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionAdapter; import java.beans.PropertyChangeEvent; +import java.beans.PropertyVetoException; import javax.swing.JCheckBoxMenuItem; +import javax.swing.JInternalFrame; import javax.swing.JPanel; import javax.swing.JPopupMenu; import javax.swing.SwingUtilities; @@ -51,8 +55,8 @@ import javax.swing.SwingUtilities; * @author $author$ * @version $Revision$ */ -public class OverviewPanel extends JPanel implements Runnable, - ViewportListenerI +public class OverviewPanel extends JPanel + implements Runnable, ViewportListenerI { private OverviewDimensions od; @@ -68,6 +72,8 @@ public class OverviewPanel extends JPanel implements Runnable, private boolean draggingBox = false; + private ProgressPanel progressPanel; + /** * Creates a new OverviewPanel object. * @@ -79,30 +85,62 @@ public class OverviewPanel extends JPanel implements Runnable, this.av = alPanel.av; this.ap = alPanel; - od = new OverviewDimensionsShowHidden(av.getRanges(), - (av.isShowAnnotation() && av - .getAlignmentConservationAnnotation() != null)); - - setSize(od.getWidth(), od.getHeight()); + showHidden = Cache.getDefault(Preferences.SHOW_OV_HIDDEN_AT_START, + false); + if (showHidden) + { + od = new OverviewDimensionsShowHidden(av.getRanges(), + (av.isShowAnnotation() + && av.getAlignmentConservationAnnotation() != null)); + } + else + { + od = new OverviewDimensionsHideHidden(av.getRanges(), + (av.isShowAnnotation() + && av.getAlignmentConservationAnnotation() != null)); + } - oviewCanvas = new OverviewCanvas(od, av); setLayout(new BorderLayout()); + progressPanel = new ProgressPanel(OverviewRenderer.UPDATE, + MessageManager.getString("label.oview_calc"), getWidth()); + this.add(progressPanel, BorderLayout.SOUTH); + oviewCanvas = new OverviewCanvas(od, av, progressPanel); + add(oviewCanvas, BorderLayout.CENTER); av.getRanges().addPropertyChangeListener(this); + // without this the overview window does not size to fit the overview canvas + setPreferredSize(new Dimension(od.getWidth(), od.getHeight())); + addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent evt) { - if ((getWidth() != od.getWidth()) - || (getHeight() != (od.getHeight()))) + // Resize is called on the initial display of the overview. + // This code adjusts sizes to account for the progress bar if it has not + // already been accounted for, which triggers another resize call for + // the correct sizing, at which point the overview image is updated. + // (This avoids a double recalculation of the image.) + if (getWidth() == od.getWidth() && getHeight() == od.getHeight() + + progressPanel.getHeight()) { updateOverviewImage(); - setBoxPosition(); + } + else + { + if ((getWidth() > 0) && (getHeight() > 0)) + { + od.setWidth(getWidth()); + od.setHeight(getHeight() - progressPanel.getHeight()); + } + + setPreferredSize(new Dimension(od.getWidth(), + od.getHeight() + progressPanel.getHeight())); } } + }); addMouseMotionListener(new MouseMotionAdapter() @@ -110,22 +148,22 @@ public class OverviewPanel extends JPanel implements Runnable, @Override public void mouseDragged(MouseEvent evt) { - if (!SwingUtilities.isRightMouseButton(evt) - && !av.getWrapAlignment()) + if (!SwingUtilities.isRightMouseButton(evt)) { if (draggingBox) { - od.adjustViewportFromMouse(evt.getX(), - evt.getY(), av.getAlignment().getHiddenSequences(), + // set the mouse position as a fixed point in the box + // and drag relative to that position + od.adjustViewportFromMouse(evt.getX(), evt.getY(), + av.getAlignment().getHiddenSequences(), av.getAlignment().getHiddenColumns()); } else { - od.updateViewportFromMouse(evt.getX(), evt.getY(), av - .getAlignment().getHiddenSequences(), av.getAlignment() - .getHiddenColumns()); + od.updateViewportFromMouse(evt.getX(), evt.getY(), + av.getAlignment().getHiddenSequences(), + av.getAlignment().getHiddenColumns()); } - } } @@ -134,15 +172,21 @@ public class OverviewPanel extends JPanel implements Runnable, { if (od.isPositionInBox(evt.getX(), evt.getY())) { - // display drag cursor at mouse position - setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); + /* + * using HAND_CURSOR rather than DRAG_CURSOR + * as the latter is not supported on Mac + */ + getParent().setCursor( + Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } else { // reset cursor - setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + getParent().setCursor( + Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR)); } } + }); addMouseListener(new MouseAdapter() @@ -157,16 +201,23 @@ public class OverviewPanel extends JPanel implements Runnable, showPopupMenu(evt); } } - else if (!av.getWrapAlignment()) + else { + // don't do anything if the mouse press is in the overview's box + // (wait to see if it's a drag instead) + // otherwise update the viewport if (!od.isPositionInBox(evt.getX(), evt.getY())) { - // don't do anything if the mouse press is in the overview's box - // (wait to see if it's a drag instead) - // otherwise update the viewport + draggingBox = false; + + // display drag cursor at mouse position + setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); + od.updateViewportFromMouse(evt.getX(), evt.getY(), av.getAlignment().getHiddenSequences(), av.getAlignment().getHiddenColumns()); + getParent().setCursor( + Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } else { @@ -179,15 +230,6 @@ public class OverviewPanel extends JPanel implements Runnable, } @Override - public void mouseReleased(MouseEvent evt) - { - if (draggingBox) - { - draggingBox = false; - } - } - - @Override public void mouseClicked(MouseEvent evt) { if (SwingUtilities.isRightMouseButton(evt)) @@ -196,11 +238,13 @@ public class OverviewPanel extends JPanel implements Runnable, } } + @Override + public void mouseReleased(MouseEvent evt) + { + draggingBox = false; + } }); - - - updateOverviewImage(); } /* @@ -237,15 +281,15 @@ public class OverviewPanel extends JPanel implements Runnable, { showHidden = false; od = new OverviewDimensionsHideHidden(av.getRanges(), - (av.isShowAnnotation() && av - .getAlignmentConservationAnnotation() != null)); + (av.isShowAnnotation() + && av.getAlignmentConservationAnnotation() != null)); } else { showHidden = true; od = new OverviewDimensionsShowHidden(av.getRanges(), - (av.isShowAnnotation() && av - .getAlignmentConservationAnnotation() != null)); + (av.isShowAnnotation() + && av.getAlignmentConservationAnnotation() != null)); } oviewCanvas.resetOviewDims(od); updateOverviewImage(); @@ -257,13 +301,22 @@ public class OverviewPanel extends JPanel implements Runnable, */ public void updateOverviewImage() { + if (oviewCanvas == null) + { + /* + * panel has been disposed + */ + return; + } + if ((getWidth() > 0) && (getHeight() > 0)) { od.setWidth(getWidth()); - od.setHeight(getHeight()); + od.setHeight(getHeight() - progressPanel.getHeight()); } - setPreferredSize(new Dimension(od.getWidth(), od.getHeight())); + setPreferredSize(new Dimension(od.getWidth(), + od.getHeight() + progressPanel.getHeight())); if (oviewCanvas.restartDraw()) { @@ -274,16 +327,20 @@ public class OverviewPanel extends JPanel implements Runnable, thread.start(); repaint(); + } @Override public void run() { - oviewCanvas.draw(av.isShowSequenceFeatures(), - (av.isShowAnnotation() && av - .getAlignmentConservationAnnotation() != null), ap - .getSeqPanel().seqCanvas.getFeatureRenderer()); - setBoxPosition(); + if (oviewCanvas != null) + { + oviewCanvas.draw(av.isShowSequenceFeatures(), + (av.isShowAnnotation() + && av.getAlignmentConservationAnnotation() != null), + ap.getSeqPanel().seqCanvas.getFeatureRenderer()); + setBoxPosition(); + } } /** @@ -291,16 +348,68 @@ public class OverviewPanel extends JPanel implements Runnable, * changed * */ + private void setBoxPositionOnly() + { + if (od != null) + { + int oldX = od.getBoxX(); + int oldY = od.getBoxY(); + int oldWidth = od.getBoxWidth(); + int oldHeight = od.getBoxHeight(); + od.setBoxPosition(av.getAlignment().getHiddenSequences(), + av.getAlignment().getHiddenColumns()); + repaint(oldX - 1, oldY - 1, oldWidth + 2, oldHeight + 2); + repaint(od.getBoxX(), od.getBoxY(), od.getBoxWidth(), + od.getBoxHeight()); + } + } + private void setBoxPosition() { - od.setBoxPosition(av.getAlignment().getHiddenSequences(), av - .getAlignment().getHiddenColumns()); - repaint(); + if (od != null) + { + od.setBoxPosition(av.getAlignment().getHiddenSequences(), + av.getAlignment().getHiddenColumns()); + repaint(); + } } @Override public void propertyChange(PropertyChangeEvent evt) { - setBoxPosition(); + setBoxPositionOnly(); + } + + /** + * Removes this object as a property change listener, and nulls references + */ + protected void dispose() + { + try + { + if (av != null) + { + av.getRanges().removePropertyChangeListener(this); + } + + oviewCanvas.dispose(); + + /* + * close the parent frame (which also removes it from the + * Desktop Windows menu) + */ + ((JInternalFrame) SwingUtilities.getAncestorOfClass( + JInternalFrame.class, (this))).setClosed(true); + } catch (PropertyVetoException e) + { + // ignore + } finally + { + progressPanel = null; + av = null; + oviewCanvas = null; + ap = null; + od = null; + } } }