X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FOverviewPanel.java;h=92451041b77ca2b784d38dd55d9e331c4ad67e72;hb=74d5ca6390288f6cd6cb445cccc728802806a29a;hp=1785e70d18243bbb4c30f7675f92bf9c2b97326d;hpb=f5d6c0018555b2c453c2c0354c84cd5d2d81e3b9;p=jalview.git diff --git a/src/jalview/gui/OverviewPanel.java b/src/jalview/gui/OverviewPanel.java index 1785e70..9245104 100755 --- a/src/jalview/gui/OverviewPanel.java +++ b/src/jalview/gui/OverviewPanel.java @@ -20,6 +20,8 @@ */ package jalview.gui; +import jalview.api.AlignViewportI; +import jalview.api.AlignmentViewPanel; import jalview.bin.Cache; import jalview.renderer.OverviewRenderer; import jalview.util.MessageManager; @@ -61,11 +63,11 @@ public class OverviewPanel extends JPanel { protected OverviewDimensions od; - private OverviewCanvas oviewCanvas; + OverviewCanvas canvas; - protected AlignViewport av; + protected AlignViewportI av; - private AlignmentPanel ap; + AlignmentViewPanel ap; protected JCheckBoxMenuItem displayToggle; @@ -75,73 +77,46 @@ public class OverviewPanel extends JPanel protected ProgressPanel progressPanel; + private Dimension dim; + + private boolean showProgress = !Platform.isJS(); // Jalview.getInstance().getShowStatus() + /** * Creates a new OverviewPanel object. * * @param alPanel * The alignment panel which is shown in the overview panel */ - public OverviewPanel(AlignmentPanel alPanel) + public OverviewPanel(AlignmentViewPanel alPanel, Dimension dim) { - this.av = alPanel.av; + this.av = alPanel.getAlignViewport(); this.ap = alPanel; + this.dim = dim; showHidden = Cache.getDefault(Preferences.SHOW_OV_HIDDEN_AT_START, - true); - if (showHidden) - { - od = new OverviewDimensionsShowHidden(av.getRanges(), - (av.isShowAnnotation() - && av.getAlignmentConservationAnnotation() != null)); - } - else - { - od = new OverviewDimensionsHideHidden(av.getRanges(), - (av.isShowAnnotation() - && av.getAlignmentConservationAnnotation() != null)); - } - + false); + createOverviewDimensions(); 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); + if (showProgress) // BH 2019 + { + add(progressPanel, BorderLayout.SOUTH); + } + canvas = new OverviewCanvas(this, od, av, + showProgress ? progressPanel : null); + canvas.setPreferredSize(canvas.getSize()); + add(canvas, 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) { - // 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(); - } - else - { - if ((getWidth() > 0) && (getHeight() > 0)) - { - od.setWidth(getWidth()); - od.setHeight(getHeight() - progressPanel.getHeight()); - } - - setPreferredSize(new Dimension(od.getWidth(), - od.getHeight() + progressPanel.getHeight())); - } + resizePanel(); } - }); addMouseMotionListener(new MouseMotionAdapter() @@ -171,20 +146,20 @@ public class OverviewPanel extends JPanel @Override public void mouseMoved(MouseEvent evt) { - if (!draggingBox) - // don't bother changing the cursor if we're dragging the box - // as we can't have moved inside or out of the box in that case + if (od.isPositionInBox(evt.getX(), evt.getY())) { - if (od.isPositionInBox(evt.getX(), evt.getY())) - { - // display drag cursor at mouse position - setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); - } - else - { - // reset cursor - setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_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 + getParent().setCursor( + Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR)); } } }); @@ -194,37 +169,37 @@ public class OverviewPanel extends JPanel @Override public void mousePressed(MouseEvent evt) { + if (Platform.isWinRightButton(evt)) + { + showPopupMenu(evt); + return; + } if (SwingUtilities.isRightMouseButton(evt)) { - if (!Platform.isAMacAndNotJS()) - { - // BH - MAC L&F here - forces popup and cancels any drag operation - showPopupMenu(evt); - } + return; } - 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 - if (!od.isPositionInBox(evt.getX(), evt.getY())) - { - draggingBox = false; + draggingBox = false; - // display drag cursor at mouse position - setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); + // display drag cursor at mouse position + setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); - od.updateViewportFromMouse(evt.getX(), evt.getY(), - av.getAlignment().getHiddenSequences(), - av.getAlignment().getHiddenColumns()); - } - else - { - draggingBox = true; - od.setDragPoint(evt.getX(), evt.getY(), - av.getAlignment().getHiddenSequences(), - av.getAlignment().getHiddenColumns()); - } + od.updateViewportFromMouse(evt.getX(), evt.getY(), + av.getAlignment().getHiddenSequences(), + av.getAlignment().getHiddenColumns()); + getParent().setCursor( + Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + } + else + { + draggingBox = true; + od.setDragPoint(evt.getX(), evt.getY(), + av.getAlignment().getHiddenSequences(), + av.getAlignment().getHiddenColumns()); } } @@ -242,19 +217,63 @@ public class OverviewPanel extends JPanel { draggingBox = false; } - }); + } - /* - * Javascript does not call componentResized on initial display, - * so do the update here - */ - boolean doUpdate = /** @j2sNative true || */ false; - if (doUpdate) - updateOverviewImage(); + protected void resizePanel() + { + int ph = (progressPanel.getParent() == null ? 0 + : progressPanel.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() + ph) + { + if (canvas.lastMiniMe == null) + { + updateOverviewImage(); + } + } + else + { + int w = getWidth(); + int h = getHeight(); + if ((w > 0) && (h > 0)) + { + if (dim != null) + { + dim.setSize(w, h - ph); + } + od.setWidth(w); + od.setHeight(h - ph); + updateOverviewImage(); + } + } } - /* + /** + * Create the appropriate type of OverViewDimensions, with the desired size. + */ + private void createOverviewDimensions() + { + boolean showAnnotation = (av.isShowAnnotation() + && av.getAlignmentConservationAnnotation() != null); + if (showHidden) + { + od = new OverviewDimensionsShowHidden(av.getRanges(), showAnnotation, + dim); + } + else + { + od = new OverviewDimensionsHideHidden(av.getRanges(), showAnnotation, + dim); + } + + } + + /** * Displays the popup menu and acts on user input */ protected void showPopupMenu(MouseEvent e) @@ -279,36 +298,38 @@ public class OverviewPanel extends JPanel popup.show(this, e.getX(), e.getY()); } - /* - * Toggle overview display between showing hidden columns and hiding hidden columns + /** + * Toggle overview display between showing hidden columns and hiding hidden + * columns */ protected void toggleHiddenColumns() { - if (showHidden) - { - showHidden = false; - od = new OverviewDimensionsHideHidden(av.getRanges(), - (av.isShowAnnotation() - && av.getAlignmentConservationAnnotation() != null)); - } - else - { - showHidden = true; - od = new OverviewDimensionsShowHidden(av.getRanges(), - (av.isShowAnnotation() - && av.getAlignmentConservationAnnotation() != null)); - } - oviewCanvas.resetOviewDims(od); + showHidden = !showHidden; + createOverviewDimensions(); + canvas.resetOviewDims(od); updateOverviewImage(); setBoxPosition(); } /** - * Updates the overview image when the related alignment panel is updated + * Updates the overview image when the related alignment panel is updated. + * + * Cases: + * + * AlignFrame.setFeatureGroupState + * + * AlignmentPanel.paintAlignment(true,...) (117 references) + * + * OverviewPanel..componentResized() OverviewPanel.toggleHiddenColumns() + * + * PopupMenu for action.reveal_sequences, action.reveal_all + * + * SliderPanel.mouseReleased() + * */ public void updateOverviewImage() { - if (oviewCanvas == null) + if (canvas == null) { /* * panel has been disposed @@ -316,37 +337,36 @@ public class OverviewPanel extends JPanel return; } + int ph = (progressPanel.getParent() == null ? 0 + : progressPanel.getHeight()); + if ((getWidth() > 0) && (getHeight() > 0)) { od.setWidth(getWidth()); - od.setHeight(getHeight() - progressPanel.getHeight()); + od.setHeight(getHeight() - ph); } - - setPreferredSize(new Dimension(od.getWidth(), - od.getHeight() + progressPanel.getHeight())); - if (oviewCanvas.restartDraw()) + setPreferredSize(new Dimension(od.getWidth(), od.getHeight() + ph)); + + if (canvas.restartDraw()) { return; } Thread thread = new Thread(this); thread.start(); - repaint(); - - } @Override public void run() { - if (oviewCanvas != null) + if (canvas != null) { - oviewCanvas.draw(av.isShowSequenceFeatures(), + setBoxPosition(); + canvas.draw(av.isShowSequenceFeatures(), (av.isShowAnnotation() && av.getAlignmentConservationAnnotation() != null), - ap.getSeqPanel().seqCanvas.getFeatureRenderer()); - setBoxPosition(); + ap.getFeatureRenderer()); } } @@ -359,6 +379,7 @@ public class OverviewPanel extends JPanel { if (od != null) { + od.updateBox(); int oldX = od.getBoxX(); int oldY = od.getBoxY(); int oldWidth = od.getBoxWidth(); @@ -399,14 +420,15 @@ public class OverviewPanel extends JPanel av.getRanges().removePropertyChangeListener(this); } - oviewCanvas.dispose(); + canvas.dispose(); /* * close the parent frame (which also removes it from the * Desktop Windows menu) */ - ((JInternalFrame) SwingUtilities.getAncestorOfClass( - JInternalFrame.class, (this))).setClosed(true); + ((JInternalFrame) SwingUtilities + .getAncestorOfClass(JInternalFrame.class, (this))) + .setClosed(true); } catch (PropertyVetoException e) { // ignore @@ -414,7 +436,7 @@ public class OverviewPanel extends JPanel { progressPanel = null; av = null; - oviewCanvas = null; + canvas = null; ap = null; od = null; }