X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FScalePanel.java;h=e49eb17b822f8543028d097c8a543cf0d6564346;hb=5929445a0af66d200677bf23b26f4bdbab2e4c0c;hp=e25a4bbdbe1eb05fd9aa5f11525ae9de859a1d68;hpb=1ecf6419aba86993b3c223bf5ec0fa79427baf85;p=jalview.git diff --git a/src/jalview/gui/ScalePanel.java b/src/jalview/gui/ScalePanel.java index e25a4bb..e49eb17 100755 --- a/src/jalview/gui/ScalePanel.java +++ b/src/jalview/gui/ScalePanel.java @@ -1,52 +1,195 @@ package jalview.gui; +import jalview.datamodel.*; import java.awt.*; import java.awt.event.*; - import javax.swing.*; public class ScalePanel extends JPanel { - protected ScaleCanvas scaleCanvas; - - protected int offy; + protected int offy = 4; public int width; protected AlignViewport av; + AlignmentPanel ap; - public ScalePanel(AlignViewport av) { + boolean stretchingGroup = false; + + public ScalePanel(AlignViewport av, AlignmentPanel ap) + { this.av = av; + this.ap = ap; - scaleCanvas = new ScaleCanvas(av); - setLayout(new BorderLayout()); - add(scaleCanvas, BorderLayout.CENTER); addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent evt) { doMousePressed(evt); } + public void mouseReleased(MouseEvent evt) + { + doMouseReleased(evt); + } + + }); + addMouseMotionListener(new MouseMotionAdapter() + { + public void mouseDragged(MouseEvent evt) + { + doMouseDragged(evt); + } }); - } - public Dimension getMinimumSize() { - return scaleCanvas.getMinimumSize(); } - public Dimension getPreferredSize() { - return scaleCanvas.getPreferredSize(); - } public void doMousePressed(MouseEvent evt) { int x = evt.getX(); - int res = x/(int)av.getCharWidth() + av.getStartRes(); + int res = x/av.getCharWidth() + av.getStartRes(); + SequenceGroup sg = null; - if (! av.getColumnSelection().contains(res)) - av.getColumnSelection().addElement(res); - else + if (av.getColumnSelection().contains(res)) av.getColumnSelection().removeElement(res); + else + { + av.getColumnSelection().addElement(res); + + sg = new SequenceGroup(); + for (int i = 0; i < av.alignment.getSequences().size(); i++) + sg.addSequence(av.alignment.getSequenceAt(i)); + + sg.setStartRes(res); + sg.setEndRes(res); + + ap.annotationPanel.addEditableColumn(res); + } + av.setSelectionGroup(sg); + ap.repaint(); + } + + public void doMouseReleased(MouseEvent evt) + { + if(!stretchingGroup) + return; + + int x = evt.getX(); + int res = x/av.getCharWidth() + av.getStartRes(); + + if (! av.getColumnSelection().contains(res)) + av.getColumnSelection().addElement(res); + + SequenceGroup sg = av.getSelectionGroup(); + + if(res>sg.getStartRes()) + sg.setEndRes(res); + else if(res sg.getStartRes()) + sg.setEndRes(res); + else if (res < sg.getStartRes()) + sg.setStartRes(res); + + ap.annotationPanel.addEditableColumn(res); + ap.repaint(); + } + } + + public void paintComponent(Graphics g) + { + drawScale(g, av.getStartRes(), av.getEndRes(), getWidth()); + } + +// scalewidth will normally be screenwidth, + public void drawScale(Graphics g, int startx, int endx, int scaleWidth) + { + Graphics2D gg = (Graphics2D)g; + gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON); + int charWidth = av.getCharWidth(); + + gg.setFont(av.getFont()); + + //Fill in the background + + gg.setColor(Color.white); + gg.fillRect(0,0,scaleWidth, getHeight()); + + int resWidth = endx - startx + 1; + + // We want roughly one tick every 50 pixels + + double rough = scaleWidth/50.0; + + double roughtick = resWidth/rough; + + int digits = (int)(Math.log(roughtick)/Math.log(10)); + int num = (int)(roughtick/Math.pow(10,digits)); + + if (roughtick>5) + num = 10; + else + num = 5; + + // else + // num = 2; + + // System.out.println("Dig " + digits + " " + rough + " " + roughtick + " " + getWidth() + " " + num); + + int space = (int)(num * Math.pow(10,digits)); - repaint(); + //Set the text font + + gg.setColor(Color.black); + + + int scalestartx = 0; + if(space>0) + scalestartx = startx - startx%space + space; + + + //Fill the selected columns + ColumnSelection cs = av.getColumnSelection(); + int width = charWidth; + if (width == 0) + width = 1; + + gg.setColor(new Color(220,0,0)); + for (int i=0; i