*/
package jalview.appletgui;
-import jalview.datamodel.SequenceI;
+import jalview.renderer.OverviewRenderer;
import jalview.renderer.seqfeatures.FeatureColourFinder;
import jalview.viewmodel.OverviewDimensions;
// main visible SeqCanvas
private SequenceRenderer sr;
- private FeatureRenderer fr;
+ private jalview.renderer.seqfeatures.FeatureRenderer fr;
private Frame nullFrame;
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()
{
}
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
{
}
}
- /*
- * 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)
{
*/
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;
private AlignmentPanel ap;
+ private boolean showHidden = true;
+
private boolean updateRunning = false;
public OverviewPanel(AlignmentPanel alPanel)
@Override
public void mouseClicked(MouseEvent evt)
{
+ if (SwingUtilities.isRightMouseButton(evt))
+ {
+ showPopupMenu(evt);
+ }
}
@Override
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);
+ }
}
/**
{
oviewCanvas.draw(av.isShowSequenceFeatures(),
(av.isShowAnnotation() && av
- .getAlignmentConservationAnnotation() != null), ap);
+ .getAlignmentConservationAnnotation() != null),
+ ap.seqPanel.seqCanvas.getFeatureRenderer());
setBoxPosition();
}
.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();
+ }
}