import jalview.datamodel.ColumnSelection;
import jalview.datamodel.SequenceGroup;
+import jalview.renderer.ScaleRenderer;
+import jalview.renderer.ScaleRenderer.ScaleMark;
import jalview.util.MessageManager;
import java.awt.Color;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
+import java.util.List;
public class ScalePanel extends Panel implements MouseMotionListener,
MouseListener
// Fill the selected columns
ColumnSelection cs = av.getColumnSelection();
gg.setColor(new Color(220, 0, 0));
- int avcharWidth = av.getCharWidth(), avcharHeight = av.getCharHeight();
+ int avCharWidth = av.getCharWidth();
+ int avcharHeight = av.getCharHeight();
for (int sel : cs.getSelected())
{
// TODO: JAL-2001 - provide a fast method to list visible selected in a
if ((sel >= startx) && (sel <= endx))
{
- gg.fillRect((sel - startx) * avcharWidth, 0, avcharWidth,
+ gg.fillRect((sel - startx) * avCharWidth, 0, avCharWidth,
getSize().height);
}
}
// Draw the scale numbers
gg.setColor(Color.black);
- int scalestartx = (startx / 10) * 10;
- int widthx = 1 + endx - startx;
-
- 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())
{
+ int widthx = 1 + endx - startx;
for (int i = 0; i < av.getColumnSelection().getHiddenColumns()
.size(); i++)
{
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);
-
+ 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);
- }
}
-
}
}
import jalview.datamodel.SearchResults;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
+import jalview.renderer.ScaleRenderer;
+import jalview.renderer.ScaleRenderer.ScaleMark;
import jalview.viewmodel.AlignmentViewport;
import java.awt.Color;
private void drawNorthScale(Graphics g, int startx, int endx, int ypos)
{
- int scalestartx = startx - startx % 10 + 10;
-
+ updateViewport();
g.setColor(Color.black);
-
- // NORTH SCALE
- for (int i = scalestartx; i < endx; i += 10)
+ for (ScaleMark mark : new ScaleRenderer().calculateMarks(av, startx,
+ endx))
{
- int value = i;
- if (av.hasHiddenColumns())
+ int mpos = mark.column; // (i - startx - 1)
+ if (mpos < 0)
{
- value = av.getColumnSelection().adjustForHiddenColumns(value);
+ continue;
}
+ String mstring = mark.text;
- g.drawString(String.valueOf(value), (i - startx - 1) * avcharWidth,
- ypos - (avcharHeight / 2));
-
- g.drawLine(((i - startx - 1) * avcharWidth) + (avcharWidth / 2),
- (ypos + 2) - (avcharHeight / 2),
- ((i - startx - 1) * avcharWidth) + (avcharWidth / 2),
- ypos - 2);
+ if (mark.major)
+ {
+ if (mstring != null)
+ {
+ g.drawString(mstring, mpos * avcharWidth, ypos
+ - (avcharHeight / 2));
+ }
+ g.drawLine((mpos * avcharWidth) + (avcharWidth / 2), (ypos + 2)
+ - (avcharHeight / 2), (mpos * avcharWidth)
+ + (avcharWidth / 2),
+ ypos - 2);
+ }
}
}
import jalview.datamodel.ColumnSelection;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
+import jalview.renderer.ScaleRenderer;
+import jalview.renderer.ScaleRenderer.ScaleMark;
import jalview.util.MessageManager;
import java.awt.Color;
int widthx = 1 + endx - startx;
FontMetrics fm = gg.getFontMetrics(av.getFont());
- int y = avCharHeight, yOf = fm.getDescent();
+ int y = avCharHeight;
+ int yOf = fm.getDescent();
y -= yOf;
if (av.hasHiddenColumns())
{
-1 + res * avCharWidth - avCharHeight / 4,
-1 + res * avCharWidth + avCharHeight / 4,
-1 + res * avCharWidth }, new int[] { y, y, y + 2 * yOf }, 3);
-
}
}
}
gg.setColor(Color.black);
int maxX = 0;
- List<Object[]> marks = jalview.renderer.ScaleRenderer.calculateMarks(
- av, startx, endx);
+ List<ScaleMark> marks = new ScaleRenderer().calculateMarks(av, startx,
+ endx);
- for (Object[] mark : marks)
+ for (ScaleMark mark : marks)
{
- boolean major = Boolean.valueOf((Boolean) mark[0]);
- int mpos = ((Integer) mark[1]).intValue(); // (i - startx - 1)
- String mstring = (String) mark[2];
+ boolean major = mark.major;
+ int mpos = mark.column; // (i - startx - 1)
+ String mstring = mark.text;
if (mstring != null)
{
if (mpos * avCharWidth > maxX)
(mpos * avCharWidth) + (avCharWidth / 2), y + (yOf * 2));
}
}
- if (av.hasHiddenColumns())
- {
- if (reveal != null && reveal[0] > startx && reveal[0] < endx)
- {
- gg.drawString(MessageManager.getString("label.reveal_columns"),
- reveal[0] * avCharWidth, 0);
- }
- }
-
}
}
import jalview.datamodel.SearchResults;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
+import jalview.renderer.ScaleRenderer;
+import jalview.renderer.ScaleRenderer.ScaleMark;
import java.awt.BasicStroke;
import java.awt.BorderLayout;
private void drawNorthScale(Graphics g, int startx, int endx, int ypos)
{
updateViewport();
- for (Object[] mark : jalview.renderer.ScaleRenderer.calculateMarks(av,
- startx, endx))
+ for (ScaleMark mark : new ScaleRenderer().calculateMarks(av, startx,
+ endx))
{
- int mpos = ((Integer) mark[1]).intValue(); // (i - startx - 1)
+ int mpos = mark.column; // (i - startx - 1)
if (mpos < 0)
{
continue;
}
- String mstring = (String) mark[2];
+ String mstring = mark.text;
- if (Boolean.valueOf((Boolean) mark[0]))
+ if (mark.major)
{
if (mstring != null)
{
*/
public class ScaleRenderer
{
+ public class ScaleMark
+ {
+ public final boolean major;
+
+ public final int column;
+
+ public final String text;
+
+ ScaleMark(boolean isMajor, int col, String txt)
+ {
+ major = isMajor;
+ column = col;
+ text = txt;
+ }
+ }
+
/**
* calculate positions markers on the alignment ruler
*
* left-most column in visible view
* @param endx
* - right-most column in visible view
- * @return List { Object { .. } } Boolean: true/false for major/minor mark,
- * Integer: marker position in alignment column coords, String: null
- * or a String to be rendered at the position.
+ * @return List of ScaleMark holding boolean: true/false for major/minor mark,
+ * marker position in alignment column coords, a String to be rendered
+ * at the position (or null)
*/
- public static List<Object[]> calculateMarks(AlignViewportI av,
+ public List<ScaleMark> calculateMarks(AlignViewportI av,
int startx, int endx)
{
- new ArrayList<Object[]>();
-
int scalestartx = (startx / 10) * 10;
SequenceI refSeq = av.getAlignment().getSeqrep();
{
scalestartx += 5;
}
- List<Object[]> marks = new ArrayList<Object[]>();
+ List<ScaleMark> marks = new ArrayList<ScaleMark>();
String string;
int refN, iadj;
// todo: add a 'reference origin column' to set column number relative to
for (int i = scalestartx; i < endx; i += 5)
{
- Object[] amark = new Object[3];
if (((i - refSp) % 10) == 0)
{
if (refSeq == null)
string = String.valueOf(refN) + refSeq.getCharAt(iadj);
}
}
- amark[0] = Boolean.TRUE;
- amark[1] = Integer.valueOf(i - startx - 1);
- amark[2] = string;
-
+ marks.add(new ScaleMark(true, i - startx - 1, string));
}
else
{
- amark[0] = Boolean.FALSE;
- amark[1] = Integer.valueOf(i - startx - 1);
- amark[2] = null;
+ marks.add(new ScaleMark(false, i - startx - 1, null));
}
- marks.add(amark);
}
return marks;
}