X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FScalePanel.java;h=486b87a578c7b880c94369461b9ee0f0ad4c65c7;hb=eacce9627f059fc2f9e880c81d8d1bdfbe7fe5b3;hp=37cfcaf568ed7f03904f4e1c1ac67338d2cd2d2f;hpb=b6401ce0eeaf81c8a5ee8051d109fb581cb42eab;p=jalview.git diff --git a/src/jalview/gui/ScalePanel.java b/src/jalview/gui/ScalePanel.java index 37cfcaf..486b87a 100755 --- a/src/jalview/gui/ScalePanel.java +++ b/src/jalview/gui/ScalePanel.java @@ -1,190 +1,281 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer + * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ package jalview.gui; import jalview.datamodel.*; + import java.awt.*; import java.awt.event.*; + import javax.swing.*; + +/** + * DOCUMENT ME! + * + * @author $author$ + * @version $Revision$ + */ public class ScalePanel extends JPanel { - - protected int offy = 4; - public int width; - - protected AlignViewport av; - AlignmentPanel ap; - - boolean stretchingGroup = false; - - public ScalePanel(AlignViewport av, AlignmentPanel ap) - { - this.av = av; - this.ap = ap; - - addMouseListener(new MouseAdapter() - { - public void mousePressed(MouseEvent evt) - { - doMousePressed(evt); - } - public void mouseReleased(MouseEvent evt) - { - doMouseReleased(evt); - } - - }); - addMouseMotionListener(new MouseMotionAdapter() + protected int offy = 4; + + /** DOCUMENT ME!! */ + public int width; + protected AlignViewport av; + AlignmentPanel ap; + boolean stretchingGroup = false; + int min; //used by mouseDragged to see if user + int max; //used by mouseDragged to see if user + + // wants to delete columns + public ScalePanel(AlignViewport av, AlignmentPanel ap) { - public void mouseDragged(MouseEvent evt) - { - doMouseDragged(evt); - } - }); - - } - - - public void doMousePressed(MouseEvent evt) { - int x = evt.getX(); - int res = x/av.getCharWidth() + av.getStartRes(); - SequenceGroup sg = null; + this.av = av; + this.ap = ap; + + 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); + } + }); + } - if (av.getColumnSelection().contains(res)) - av.getColumnSelection().removeElement(res); - else + /** + * DOCUMENT ME! + * + * @param evt DOCUMENT ME! + */ + public void doMousePressed(MouseEvent evt) { - 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); + int x = evt.getX(); + int res = (x / av.getCharWidth()) + av.getStartRes(); + SequenceGroup sg = null; + + min = res; + max = res; + + if (av.getColumnSelection().contains(res)) + { + av.getColumnSelection().removeElement(res); + ap.annotationPanel.removeEditableColumn(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), false); + } + + sg.setStartRes(res); + sg.setEndRes(res); + } + + av.setSelectionGroup(sg); + ap.repaint(); } - av.setSelectionGroup(sg); - ap.RefreshPanels(); - } - - 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.RefreshPanels(); + int x = evt.getX(); + int res = (x / av.getCharWidth()) + av.getStartRes(); + + if (av.getColumnSelection() != null) + { + for (int i = 0; i < av.getColumnSelection().size(); i++) + { + ap.annotationPanel.addEditableColumn(av.getColumnSelection() + .columnAt(i)); + } + } + + if (!stretchingGroup) + { + ap.repaint(); + + return; + } + + SequenceGroup sg = av.getSelectionGroup(); + + if (res > sg.getStartRes()) + { + sg.setEndRes(res); + } + else if (res < sg.getStartRes()) + { + sg.setStartRes(res); + } + + stretchingGroup = false; + ap.repaint(); } - } - - public void paintComponent(Graphics g) - { - drawScale(g, av.getStartRes(), av.getEndRes(), getWidth()); - } - -// scalewidth will normally be screenwidth, - public void drawScale(Graphics gg, int startx, int endx, int scaleWidth) - { - 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)); - - //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