X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fgui%2FOverviewPanel.java;h=5694c3d719ddc3f31ee3b1c68f7a59c9fa3aa3e5;hb=a83adb45bdf9554e270921b4baad94defd314b36;hp=567a1213f4b583c634b1429f76c7de952157fcc1;hpb=75aceeffea6e41f77a85ce6732780e760db739e5;p=jalview.git diff --git a/src/jalview/gui/OverviewPanel.java b/src/jalview/gui/OverviewPanel.java index 567a121..5694c3d 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; @@ -32,8 +34,6 @@ import jalview.viewmodel.ViewportListenerI; import java.awt.BorderLayout; import java.awt.Cursor; import java.awt.Dimension; -import java.awt.Image; -import java.awt.Point; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ComponentAdapter; @@ -44,7 +44,6 @@ import java.awt.event.MouseMotionAdapter; import java.beans.PropertyChangeEvent; import java.beans.PropertyVetoException; -import javax.swing.ImageIcon; import javax.swing.JCheckBoxMenuItem; import javax.swing.JInternalFrame; import javax.swing.JPanel; @@ -58,28 +57,29 @@ import javax.swing.SwingUtilities; * @author $author$ * @version $Revision$ */ +@SuppressWarnings("serial") public class OverviewPanel extends JPanel implements Runnable, ViewportListenerI { - protected Image dragImage = new ImageIcon( - getClass().getResource("/images/dragcursor.png")) - .getImage(); + protected OverviewDimensions od; - private OverviewDimensions od; + OverviewCanvas canvas; - private OverviewCanvas oviewCanvas; + protected AlignViewportI av; - private AlignViewport av; + AlignmentViewPanel ap; - private AlignmentPanel ap; + protected JCheckBoxMenuItem displayToggle; - private JCheckBoxMenuItem displayToggle; + protected boolean showHidden = true; - private boolean showHidden = true; + protected boolean draggingBox = false; - private boolean draggingBox = false; + protected ProgressPanel progressPanel; - private ProgressPanel progressPanel; + private Dimension dim; + + private boolean showProgress = !Platform.isJS(); // Jalview.getInstance().getShowStatus() /** * Creates a new OverviewPanel object. @@ -87,81 +87,40 @@ public class OverviewPanel extends JPanel * @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())); - - // set up custom cursor for use on Mac... - Point hotSpot = new Point(16, 16); - String cursorName = "Custom drag cursor"; - - Cursor tempCursor; - if (Platform.isAMac()) - { - tempCursor = getToolkit().createCustomCursor(dragImage, hotSpot, - cursorName); - } - else - { - tempCursor = Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR); - } - final Cursor dragCursor = tempCursor; - + // BH - no,no! - This does not include the progressPanel! + // BH the problem was that OverviewCanvas.setPreferredSize() had not been set. + // 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(); } }); @@ -195,14 +154,18 @@ public class OverviewPanel extends JPanel { if (od.isPositionInBox(evt.getX(), evt.getY())) { - // display drag cursor at mouse position - getParent().setCursor(dragCursor); + /* + * 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.DEFAULT_CURSOR)); + Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR)); } } @@ -213,32 +176,38 @@ public class OverviewPanel extends JPanel @Override public void mousePressed(MouseEvent evt) { + + if (Platform.isWinRightButton(evt)) + { + showPopupMenu(evt); + return; + } if (SwingUtilities.isRightMouseButton(evt)) { - if (!Platform.isAMac()) - { - showPopupMenu(evt); - } + return; + } + // 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; + + // 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 { - // 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; - 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()); - } + draggingBox = true; + od.setDragPoint(evt.getX(), evt.getY(), + av.getAlignment().getHiddenSequences(), + av.getAlignment().getHiddenColumns()); } } @@ -249,26 +218,87 @@ public class OverviewPanel extends JPanel { showPopupMenu(evt); } - // click in box should also reset the cursor - else if (od.isPositionInBox(evt.getX(), evt.getY())) - { - // display drag cursor at mouse position - getParent().setCursor(dragCursor); - } - else + } + + @Override + public void mouseReleased(MouseEvent evt) + { + draggingBox = false; + } + + }); + + // /* + // * Javascript does not call componentResized on initial display, + // * so do the update here + // */ + // if (Platform.isJS()) + // { + // 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) { - // reset cursor - getParent().setCursor( - Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + dim.setSize(w, h - ph); } + od.setWidth(w); + od.setHeight(h - ph); + updateOverviewImage(); } - }); + // BH 2019.07.29 this is unnecessary -- it is what layout managers are + // for: + // setPreferredSize(new Dimension(od.getWidth(), od.getHeight() + + // ph)); + } + } + + /** + * 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 */ - private void showPopupMenu(MouseEvent e) + protected void showPopupMenu(MouseEvent e) { JPopupMenu popup = new JPopupMenu(); ActionListener menuListener = new ActionListener() @@ -293,33 +323,34 @@ public class OverviewPanel extends JPanel /* * Toggle overview display between showing hidden columns and hiding hidden columns */ - private void toggleHiddenColumns() + 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 @@ -327,37 +358,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()); } } @@ -370,6 +400,7 @@ public class OverviewPanel extends JPanel { if (od != null) { + od.updateBox(); int oldX = od.getBoxX(); int oldY = od.getBoxY(); int oldWidth = od.getBoxWidth(); @@ -410,14 +441,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 @@ -425,7 +457,7 @@ public class OverviewPanel extends JPanel { progressPanel = null; av = null; - oviewCanvas = null; + canvas = null; ap = null; od = null; }