From: kiramt Date: Tue, 25 Apr 2017 12:26:21 +0000 (+0100) Subject: JAL-2388 Updated applet to show/hide hidden regions in overview X-Git-Tag: Release_2_10_2~3^2~92^2~12 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=af00f89579328012da26b151996997b1735265b4;p=jalview.git JAL-2388 Updated applet to show/hide hidden regions in overview --- diff --git a/src/jalview/appletgui/OverviewCanvas.java b/src/jalview/appletgui/OverviewCanvas.java index 2fbdeab..ffba5b9 100644 --- a/src/jalview/appletgui/OverviewCanvas.java +++ b/src/jalview/appletgui/OverviewCanvas.java @@ -20,7 +20,7 @@ */ package jalview.appletgui; -import jalview.datamodel.SequenceI; +import jalview.renderer.OverviewRenderer; import jalview.renderer.seqfeatures.FeatureColourFinder; import jalview.viewmodel.OverviewDimensions; @@ -52,7 +52,7 @@ public class OverviewCanvas extends JComponent // main visible SeqCanvas private SequenceRenderer sr; - private FeatureRenderer fr; + private jalview.renderer.seqfeatures.FeatureRenderer fr; private Frame nullFrame; @@ -69,12 +69,23 @@ public class OverviewCanvas extends JComponent sr.graphics = nullFrame.getGraphics(); sr.renderGaps = false; sr.forOverview = true; - fr = new FeatureRenderer(av); + fr = new jalview.renderer.seqfeatures.FeatureRenderer(av); } - /* - * Signals to drawing code that the associated alignment viewport - * has changed and a redraw will be required + /** + * Update the overview dimensions object used by the canvas (e.g. if we change + * from showing hidden columns to hiding them or vice versa) + * + * @param overviewDims + */ + public void resetOviewDims(OverviewDimensions overviewDims) + { + od = overviewDims; + } + + /** + * Signals to drawing code that the associated alignment viewport has changed + * and a redraw will be required */ public boolean restartDraw() { @@ -93,49 +104,42 @@ public class OverviewCanvas extends JComponent } public void draw(boolean showSequenceFeatures, boolean showAnnotation, - AlignmentPanel ap) + FeatureRenderer transferRenderer) { miniMe = null; - if (av.isShowSequenceFeatures()) + if (showSequenceFeatures) { - fr.transferSettings(ap.seqPanel.seqCanvas.getFeatureRenderer()); + fr.transferSettings(transferRenderer); } + FeatureColourFinder finder = new FeatureColourFinder(fr); setPreferredSize(new Dimension(od.getWidth(), od.getHeight())); + OverviewRenderer or = new OverviewRenderer(sr, finder, od); miniMe = nullFrame.createImage(od.getWidth(), od.getHeight()); offscreen = nullFrame.createImage(od.getWidth(), od.getHeight()); - Graphics mg = miniMe.getGraphics(); - - int alwidth = av.getAlignment().getWidth(); - int alheight = av.getAlignment().getAbsoluteHeight(); - float sampleCol = alwidth / (float) od.getWidth(); - float sampleRow = alheight / (float) od.getSequencesHeight(); + miniMe = or.draw(od.getRows(av.getAlignment()), + od.getColumns(av.getAlignment().getHiddenColumns())); - buildImage(sampleRow, sampleCol, mg); + Graphics mg = miniMe.getGraphics(); // check for conservation annotation to make sure overview works for DNA too if (showAnnotation) { - for (int col = 0; col < od.getWidth() && !restart; col++) - { - mg.translate(col, od.getSequencesHeight()); - ap.annotationPanel.renderer.drawGraph(mg, - av.getAlignmentConservationAnnotation(), - av.getAlignmentConservationAnnotation().annotations, - (int) (sampleCol) + 1, od.getGraphHeight(), - (int) (col * sampleCol), (int) (col * sampleCol) + 1); - mg.translate(-col, -od.getSequencesHeight()); - } + mg.translate(0, od.getSequencesHeight()); + or.drawGraph(mg, av.getAlignmentConservationAnnotation(), + av.getCharWidth(), od.getGraphHeight(), + od.getColumns(av.getAlignment().getHiddenColumns())); + mg.translate(0, -od.getSequencesHeight()); } System.gc(); if (restart) { restart = false; - draw(showSequenceFeatures, showAnnotation, ap); + draw(showSequenceFeatures, showAnnotation, transferRenderer); } else { @@ -143,95 +147,6 @@ public class OverviewCanvas extends JComponent } } - /* - * Build the overview panel image - */ - private void buildImage(float sampleRow, float sampleCol, Graphics mg) - { - int lastcol = 0; - int lastrow = 0; - int xstart = 0; - int ystart = 0; - Color color = Color.yellow; - int sameRow = 0; - int sameCol = 0; - - SequenceI seq = null; - FeatureColourFinder finder = new FeatureColourFinder(fr); - - final boolean hasHiddenCols = av.hasHiddenColumns(); - boolean hiddenRow = false; - - for (int row = 0; row < od.getSequencesHeight() && !restart; row++) - { - if ((int) (row * sampleRow) == lastrow) - { - sameRow++; - } - else - { - // get the sequence which would be at alignment index 'lastrow' if no - // rows were hidden, and determine whether it is hidden or not - hiddenRow = av.getAlignment().isHidden(lastrow); - seq = av.getAlignment().getSequenceAtAbsoluteIndex(lastrow); - - for (int col = 0; col < od.getWidth(); col++) - { - if ((int) (col * sampleCol) == lastcol - && (int) (row * sampleRow) == lastrow) - { - sameCol++; - } - else - { - lastcol = (int) (col * sampleCol); - - color = getColumnColourFromSequence(seq, hiddenRow, - hasHiddenCols, lastcol, finder); - - mg.setColor(color); - if (sameCol == 1 && sameRow == 1) - { - mg.drawLine(xstart, ystart, xstart, ystart); - } - else - { - mg.fillRect(xstart, ystart, sameCol, sameRow); - } - - xstart = col; - sameCol = 1; - } - } - lastrow = (int) (row * sampleRow); - ystart = row; - sameRow = 1; - } - } - } - - /* - * Find the colour of a sequence at a specified column position - */ - private Color getColumnColourFromSequence( - jalview.datamodel.SequenceI seq, boolean hiddenRow, - boolean hasHiddenCols, int lastcol, FeatureColourFinder finder) - { - Color color = Color.white; - if (seq.getLength() > lastcol) - { - color = sr.getResidueColour(seq, lastcol, finder); - } - - if (hiddenRow - || (hasHiddenCols && !av.getAlignment().getHiddenColumns() - .isVisible(lastcol))) - { - color = color.darker().darker(); - } - return color; - } - @Override public void update(Graphics g) { diff --git a/src/jalview/appletgui/OverviewPanel.java b/src/jalview/appletgui/OverviewPanel.java index 5a13c26..cf72daf 100755 --- a/src/jalview/appletgui/OverviewPanel.java +++ b/src/jalview/appletgui/OverviewPanel.java @@ -20,21 +20,31 @@ */ package jalview.appletgui; +import jalview.util.MessageManager; +import jalview.util.Platform; +import jalview.viewmodel.OverviewDimensions; +import jalview.viewmodel.OverviewDimensionsAllVisible; import jalview.viewmodel.OverviewDimensionsWithHidden; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.Panel; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; +import javax.swing.JMenuItem; +import javax.swing.JPopupMenu; +import javax.swing.SwingUtilities; + public class OverviewPanel extends Panel implements Runnable, MouseMotionListener, MouseListener { - private OverviewDimensionsWithHidden od; + private OverviewDimensions od; private OverviewCanvas oviewCanvas; @@ -42,6 +52,8 @@ public class OverviewPanel extends Panel implements Runnable, private AlignmentPanel ap; + private boolean showHidden = true; + private boolean updateRunning = false; public OverviewPanel(AlignmentPanel alPanel) @@ -93,6 +105,10 @@ public class OverviewPanel extends Panel implements Runnable, @Override public void mouseClicked(MouseEvent evt) { + if (SwingUtilities.isRightMouseButton(evt)) + { + showPopupMenu(evt); + } } @Override @@ -120,10 +136,20 @@ public class OverviewPanel extends Panel implements Runnable, private void mouseAction(MouseEvent evt) { - od.updateViewportFromMouse(evt.getX(), evt.getY(), av.getAlignment() - .getHiddenSequences(), av.getAlignment().getHiddenColumns()); - ap.setScrollValues(od.getScrollCol(), od.getScrollRow()); - ap.paintAlignment(false); + if (SwingUtilities.isRightMouseButton(evt)) + { + if (!Platform.isAMac()) + { + showPopupMenu(evt); + } + } + else + { + od.updateViewportFromMouse(evt.getX(), evt.getY(), av.getAlignment() + .getHiddenSequences(), av.getAlignment().getHiddenColumns()); + ap.setScrollValues(od.getScrollCol(), od.getScrollRow()); + ap.paintAlignment(false); + } } /** @@ -159,7 +185,8 @@ public class OverviewPanel extends Panel implements Runnable, { oviewCanvas.draw(av.isShowSequenceFeatures(), (av.isShowAnnotation() && av - .getAlignmentConservationAnnotation() != null), ap); + .getAlignmentConservationAnnotation() != null), + ap.seqPanel.seqCanvas.getFeatureRenderer()); setBoxPosition(); } @@ -175,4 +202,49 @@ public class OverviewPanel extends Panel implements Runnable, .getAlignment().getHiddenColumns()); repaint(); } + + /* + * Displays the popup menu and acts on user input + */ + private void showPopupMenu(MouseEvent e) + { + JPopupMenu popup = new JPopupMenu(); + ActionListener menuListener = new ActionListener() + { + @Override + public void actionPerformed(ActionEvent event) + { + // switch on/off the hidden columns view + toggleHiddenColumns(); + } + }; + JMenuItem item = new JMenuItem( + MessageManager.getString("label.togglehidden")); + popup.add(item); + item.addActionListener(menuListener); + popup.show(this, e.getX(), e.getY()); + } + + /* + * Toggle overview display between showing hidden columns and hiding hidden columns + */ + private void toggleHiddenColumns() + { + if (showHidden) + { + showHidden = false; + od = new OverviewDimensionsAllVisible(av.getRanges(), + (av.isShowAnnotation() && av + .getAlignmentConservationAnnotation() != null)); + } + else + { + showHidden = true; + od = new OverviewDimensionsWithHidden(av.getRanges(), + (av.isShowAnnotation() && av + .getAlignmentConservationAnnotation() != null)); + } + oviewCanvas.resetOviewDims(od); + updateOverviewImage(); + } } diff --git a/src/jalview/gui/OverviewCanvas.java b/src/jalview/gui/OverviewCanvas.java index 90181f8..920547f 100644 --- a/src/jalview/gui/OverviewCanvas.java +++ b/src/jalview/gui/OverviewCanvas.java @@ -21,6 +21,7 @@ package jalview.gui; import jalview.api.AlignViewportI; +import jalview.renderer.OverviewRenderer; import jalview.renderer.seqfeatures.FeatureColourFinder; import jalview.viewmodel.OverviewDimensions; diff --git a/src/jalview/gui/OverviewRenderer.java b/src/jalview/renderer/OverviewRenderer.java similarity index 97% rename from src/jalview/gui/OverviewRenderer.java rename to src/jalview/renderer/OverviewRenderer.java index 62b8601..75b8198 100644 --- a/src/jalview/gui/OverviewRenderer.java +++ b/src/jalview/renderer/OverviewRenderer.java @@ -18,7 +18,7 @@ * along with Jalview. If not, see . * The Jalview Authors are detailed in the 'AUTHORS' file. */ -package jalview.gui; +package jalview.renderer; import jalview.api.AlignmentColsCollectionI; import jalview.api.AlignmentRowsCollectionI; @@ -36,7 +36,7 @@ public class OverviewRenderer { private FeatureColourFinder finder; - private SequenceRenderer sr; + private jalview.api.SequenceRenderer sr; // image to render on private BufferedImage miniMe; @@ -47,7 +47,7 @@ public class OverviewRenderer // raw number of pixels to allocate to each row private float pixelsPerSeq; - public OverviewRenderer(SequenceRenderer seqRenderer, + public OverviewRenderer(jalview.api.SequenceRenderer seqRenderer, FeatureColourFinder colfinder, OverviewDimensions od) { sr = seqRenderer;