package jalview.appletgui;
import jalview.datamodel.ColumnSelection;
+import jalview.datamodel.HiddenColumns;
import jalview.datamodel.SequenceGroup;
+import jalview.renderer.ScaleRenderer;
+import jalview.renderer.ScaleRenderer.ScaleMark;
import jalview.util.MessageManager;
+import jalview.viewmodel.ViewportListenerI;
+import jalview.viewmodel.ViewportRanges;
import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
+import java.beans.PropertyChangeEvent;
+import java.util.Iterator;
+import java.util.List;
-public class ScalePanel extends Panel implements MouseMotionListener,
- MouseListener
+public class ScalePanel extends Panel
+ implements MouseMotionListener, MouseListener, ViewportListenerI
{
protected int offy = 4;
addMouseListener(this);
addMouseMotionListener(this);
+ av.getRanges().addPropertyChangeListener(this);
}
@Override
public void mousePressed(MouseEvent evt)
{
- int x = (evt.getX() / av.getCharWidth()) + av.getStartRes();
+ int x = (evt.getX() / av.getCharWidth()) + av.getRanges().getStartRes();
final int res;
if (av.hasHiddenColumns())
{
- res = av.getColumnSelection().adjustForHiddenColumns(x);
+ res = av.getAlignment().getHiddenColumns().visibleToAbsoluteColumn(x);
}
else
{
min = res;
max = res;
- if ((evt.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK)
+ if ((evt.getModifiersEx()
+ & InputEvent.BUTTON3_DOWN_MASK) == InputEvent.BUTTON3_DOWN_MASK)
{
rightMouseButtonPressed(evt, res);
}
sg.setStartRes(min);
sg.setEndRes(max);
}
- ap.paintAlignment(true);
+ ap.paintAlignment(false, false);
av.sendSelection();
}
{
av.showColumn(reveal[0]);
reveal = null;
- ap.paintAlignment(true);
- if (ap.overviewPanel != null)
- {
- ap.overviewPanel.updateOverviewImage();
- }
+ ap.paintAlignment(true, true);
av.sendSelection();
}
});
pop.add(item);
- if (av.getColumnSelection().hasManyHiddenColumns())
+ if (av.getAlignment().getHiddenColumns()
+ .hasMultiHiddenColumnRegions())
{
item = new MenuItem(MessageManager.getString("action.reveal_all"));
item.addActionListener(new ActionListener()
{
av.showAllHiddenColumns();
reveal = null;
- ap.paintAlignment(true);
- if (ap.overviewPanel != null)
- {
- ap.overviewPanel.updateOverviewImage();
- }
+ ap.paintAlignment(true, true);
av.sendSelection();
}
});
public void actionPerformed(ActionEvent e)
{
av.hideColumns(res, res);
- if (av.getSelectionGroup() != null
- && av.getSelectionGroup().getSize() == av
- .getAlignment().getHeight())
+ if (av.getSelectionGroup() != null && av.getSelectionGroup()
+ .getSize() == av.getAlignment().getHeight())
{
av.setSelectionGroup(null);
}
- ap.paintAlignment(true);
- if (ap.overviewPanel != null)
- {
- ap.overviewPanel.updateOverviewImage();
- }
+ ap.paintAlignment(true, true);
av.sendSelection();
}
});
{
mouseDragging = false;
- int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();
+ int res = (evt.getX() / av.getCharWidth())
+ + av.getRanges().getStartRes();
if (res > av.getAlignment().getWidth())
{
if (av.hasHiddenColumns())
{
- res = av.getColumnSelection().adjustForHiddenColumns(res);
+ res = av.getAlignment().getHiddenColumns()
+ .visibleToAbsoluteColumn(res);
}
if (!stretchingGroup)
{
- ap.paintAlignment(false);
+ ap.paintAlignment(false, false);
return;
}
}
stretchingGroup = false;
- ap.paintAlignment(false);
+ ap.paintAlignment(false, false);
av.sendSelection();
}
+ /**
+ * Action on dragging the mouse in the scale panel is to expand or shrink the
+ * selection group range (including any hidden columns that it spans)
+ *
+ * @param evt
+ */
@Override
public void mouseDragged(MouseEvent evt)
{
mouseDragging = true;
+ ColumnSelection cs = av.getColumnSelection();
- int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();
- if (res < 0)
- {
- res = 0;
- }
-
- if (av.hasHiddenColumns())
- {
- res = av.getColumnSelection().adjustForHiddenColumns(res);
- }
-
- if (res > av.getAlignment().getWidth())
- {
- res = av.getAlignment().getWidth() - 1;
- }
-
- if (res < min)
- {
- min = res;
- }
-
- if (res > max)
- {
- max = res;
- }
+ int res = (evt.getX() / av.getCharWidth())
+ + av.getRanges().getStartRes();
+ res = Math.max(0, res);
+ res = av.getAlignment().getHiddenColumns().visibleToAbsoluteColumn(res);
+ res = Math.min(res, av.getAlignment().getWidth() - 1);
+ min = Math.min(res, min);
+ max = Math.max(res, max);
SequenceGroup sg = av.getSelectionGroup();
-
if (sg != null)
{
stretchingGroup = true;
-
- if (!av.getColumnSelection().contains(res))
- {
- av.getColumnSelection().addElement(res);
- }
-
- if (res > sg.getStartRes())
- {
- sg.setEndRes(res);
- }
- if (res < sg.getStartRes())
- {
- sg.setStartRes(res);
- }
-
- int col;
- for (int i = min; i <= max; i++)
- {
- col = av.getColumnSelection().adjustForHiddenColumns(i);
-
- if ((col < sg.getStartRes()) || (col > sg.getEndRes()))
- {
- av.getColumnSelection().removeElement(col);
- }
- else
- {
- av.getColumnSelection().addElement(col);
- }
- }
-
- ap.paintAlignment(false);
+ cs.stretchGroup(res, sg, min, max);
+ ap.paintAlignment(false, false);
}
}
return;
}
- int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();
+ int res = (evt.getX() / av.getCharWidth())
+ + av.getRanges().getStartRes();
- res = av.getColumnSelection().adjustForHiddenColumns(res);
-
- reveal = null;
- for (int[] region : av.getColumnSelection().getHiddenColumns())
- {
- if (res + 1 == region[0] || res - 1 == region[1])
- {
- reveal = region;
- break;
- }
- }
+ reveal = av.getAlignment().getHiddenColumns()
+ .getRegionWithEdgeAtRes(res);
repaint();
}
@Override
public void paint(Graphics g)
{
- drawScale(g, av.getStartRes(), av.getEndRes(), getSize().width,
- getSize().height);
+ /*
+ * shouldn't get called in wrapped mode as the scale above is
+ * drawn instead by SeqCanvas.drawNorthScale
+ */
+ if (!av.getWrapAlignment())
+ {
+ drawScale(g, av.getRanges().getStartRes(), av.getRanges().getEndRes(),
+ getSize().width, getSize().height);
+ }
}
// scalewidth will normally be screenwidth,
// Fill the selected columns
ColumnSelection cs = av.getColumnSelection();
- gg.setColor(new Color(220, 0, 0));
- int avcharWidth = av.getCharWidth(), avcharHeight = av.getCharHeight();
- for (int sel : cs.getSelected())
+ HiddenColumns hidden = av.getAlignment().getHiddenColumns();
+ int avCharWidth = av.getCharWidth();
+ int avcharHeight = av.getCharHeight();
+ if (cs != null)
{
- // TODO: JAL-2001 - provide a fast method to list visible selected in a
- // given range
- if (av.hasHiddenColumns())
+ gg.setColor(new Color(220, 0, 0));
+ boolean hasHiddenColumns = hidden.hasHiddenColumns();
+ for (int sel : cs.getSelected())
{
- sel = av.getColumnSelection().findColumnPosition(sel);
- }
+ // TODO: JAL-2001 - provide a fast method to list visible selected in a
+ // given range
+ if (hasHiddenColumns)
+ {
+ if (hidden.isVisible(sel))
+ {
+ sel = hidden.absoluteToVisibleColumn(sel);
+ }
+ else
+ {
+ continue;
+ }
+ }
- if ((sel >= startx) && (sel <= endx))
- {
- gg.fillRect((sel - startx) * avcharWidth, 0, avcharWidth,
- getSize().height);
+ if ((sel >= startx) && (sel <= endx))
+ {
+ gg.fillRect((sel - startx) * avCharWidth, 0, avCharWidth,
+ getSize().height);
+ }
}
}
// Draw the scale numbers
gg.setColor(Color.black);
- int scalestartx = (startx / 10) * 10;
-
- FontMetrics fm = gg.getFontMetrics(av.getFont());
- int y = avcharHeight - fm.getDescent();
-
- if ((scalestartx % 10) == 0)
- {
- scalestartx += 5;
- }
-
- String string;
int maxX = 0;
+ List<ScaleMark> marks = new ScaleRenderer().calculateMarks(av, startx,
+ endx);
- for (int i = scalestartx; i < endx; i += 5)
+ FontMetrics fm = gg.getFontMetrics(av.getFont());
+ int y = avcharHeight;
+ int yOf = fm.getDescent();
+ y -= yOf;
+ for (ScaleMark mark : marks)
{
- if ((i % 10) == 0)
+ boolean major = mark.major;
+ int mpos = mark.column; // (i - startx - 1)
+ String mstring = mark.text;
+ if (mstring != null)
{
- string = String.valueOf(av.getColumnSelection()
- .adjustForHiddenColumns(i));
- if ((i - startx - 1) * avcharWidth > maxX)
+ if (mpos * avCharWidth > maxX)
{
- gg.drawString(string, (i - startx - 1) * avcharWidth, y);
- maxX = (i - startx + 1) * avcharWidth + fm.stringWidth(string);
+ gg.drawString(mstring, mpos * avCharWidth, y);
+ maxX = (mpos + 2) * avCharWidth + fm.stringWidth(mstring);
}
-
- gg.drawLine(((i - startx - 1) * avcharWidth) + (avcharWidth / 2),
- y + 2,
- ((i - startx - 1) * avcharWidth) + (avcharWidth / 2), y
- + (fm.getDescent() * 2));
-
+ }
+ if (major)
+ {
+ gg.drawLine((mpos * avCharWidth) + (avCharWidth / 2), y + 2,
+ (mpos * avCharWidth) + (avCharWidth / 2), y + (yOf * 2));
}
else
{
- gg.drawLine(((i - startx - 1) * avcharWidth) + (avcharWidth / 2), y
- + fm.getDescent(), ((i - startx - 1) * avcharWidth)
- + (avcharWidth / 2), y + (fm.getDescent() * 2));
+ gg.drawLine((mpos * avCharWidth) + (avCharWidth / 2), y + yOf,
+ (mpos * avCharWidth) + (avCharWidth / 2), y + (yOf * 2));
}
}
int res;
if (av.getShowHiddenMarkers())
{
- for (int i = 0; i < av.getColumnSelection().getHiddenColumns()
- .size(); i++)
+ int widthx = 1 + endx - startx;
+ Iterator<Integer> it = hidden.getStartRegionIterator(startx,
+ startx + widthx + 1);
+ while (it.hasNext())
{
-
- res = av.getColumnSelection().findHiddenRegionPosition(i)
- - startx;
-
- if (res < 0 || res > endx - scalestartx)
- {
- continue;
- }
-
- gg.fillPolygon(new int[] { res * avcharWidth - avcharHeight / 4,
- res * avcharWidth + avcharHeight / 4, res * avcharWidth },
- new int[] { y - avcharHeight / 2, y - avcharHeight / 2,
- y + 8 }, 3);
-
+ res = it.next() - startx;
+
+ gg.fillPolygon(
+ new int[]
+ { -1 + res * avCharWidth - avcharHeight / 4,
+ -1 + res * avCharWidth + avcharHeight / 4,
+ -1 + res * avCharWidth },
+ new int[]
+ { y, y, y + 2 * yOf }, 3);
}
}
-
- if (reveal != null && reveal[0] > startx && reveal[0] < endx)
- {
- gg.drawString(MessageManager.getString("label.reveal_columns"),
- reveal[0] * avcharWidth, 0);
- }
}
+ }
+ @Override
+ public void propertyChange(PropertyChangeEvent evt)
+ {
+ // Respond to viewport change events (e.g. alignment panel was scrolled)
+ // Both scrolling and resizing change viewport ranges: scrolling changes
+ // both start and end points, but resize only changes end values.
+ // Here we only want to fastpaint on a scroll, with resize using a normal
+ // paint, so scroll events are identified as changes to the horizontal or
+ // vertical start value.
+ if (evt.getPropertyName().equals(ViewportRanges.STARTRES)
+ || evt.getPropertyName().equals(ViewportRanges.STARTRESANDSEQ)
+ || evt.getPropertyName().equals(ViewportRanges.MOVE_VIEWPORT))
+ {
+ // scroll event, repaint panel
+ repaint();
+ }
}
}