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;
-
- 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++)
{
res = av.getColumnSelection().findHiddenRegionPosition(i)
- startx;
- if (res < 0 || res > endx - scalestartx)
+ if (res < 0 || res > widthx)
{
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);
- }
}
-
}
}