/*\r
-* Jalview - A Sequence Alignment Editor and Viewer\r
-* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
-*\r
-* This program is free software; you can redistribute it and/or\r
-* modify it under the terms of the GNU General Public License\r
-* as published by the Free Software Foundation; either version 2\r
-* of the License, or (at your option) any later version.\r
-*\r
-* This program is distributed in the hope that it will be useful,\r
-* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
-* GNU General Public License for more details.\r
-*\r
-* You should have received a copy of the GNU General Public License\r
-* along with this program; if not, write to the Free Software\r
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
-*/\r
-\r
+ * Jalview - A Sequence Alignment Editor and Viewer\r
+ * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
+ */\r
package jalview.gui;\r
\r
-import jalview.datamodel.*;\r
import java.awt.*;\r
import java.awt.event.*;\r
import javax.swing.*;\r
\r
-public class ScalePanel extends JPanel\r
-{\r
+import jalview.datamodel.*;\r
\r
+public class ScalePanel\r
+ extends JPanel\r
+{\r
protected int offy = 4;\r
- public int width;\r
-\r
+ public int width;\r
protected AlignViewport av;\r
AlignmentPanel ap;\r
-\r
boolean stretchingGroup = false;\r
\r
public ScalePanel(AlignViewport av, AlignmentPanel ap)\r
{\r
- this.av = av;\r
+ this.av = av;\r
this.ap = ap;\r
\r
addMouseListener(new MouseAdapter()\r
{\r
doMousePressed(evt);\r
}\r
+\r
public void mouseReleased(MouseEvent evt)\r
{\r
doMouseReleased(evt);\r
}\r
-\r
});\r
addMouseMotionListener(new MouseMotionAdapter()\r
{\r
doMouseDragged(evt);\r
}\r
});\r
-\r
}\r
\r
-\r
- public void doMousePressed(MouseEvent evt) {\r
+ public void doMousePressed(MouseEvent evt)\r
+ {\r
int x = evt.getX();\r
- int res = x/av.getCharWidth() + av.getStartRes();\r
+ int res = (x / av.getCharWidth()) + av.getStartRes();\r
SequenceGroup sg = null;\r
\r
if (av.getColumnSelection().contains(res))\r
+ {\r
av.getColumnSelection().removeElement(res);\r
+ }\r
else\r
{\r
av.getColumnSelection().addElement(res);\r
\r
sg = new SequenceGroup();\r
+\r
for (int i = 0; i < av.alignment.getSequences().size(); i++)\r
+ {\r
sg.addSequence(av.alignment.getSequenceAt(i));\r
+ }\r
\r
sg.setStartRes(res);\r
sg.setEndRes(res);\r
\r
ap.annotationPanel.addEditableColumn(res);\r
}\r
+\r
av.setSelectionGroup(sg);\r
ap.repaint();\r
}\r
\r
public void doMouseReleased(MouseEvent evt)\r
{\r
- if(!stretchingGroup)\r
+ if (!stretchingGroup)\r
+ {\r
return;\r
+ }\r
\r
int x = evt.getX();\r
- int res = x/av.getCharWidth() + av.getStartRes();\r
+ int res = (x / av.getCharWidth()) + av.getStartRes();\r
\r
- if (! av.getColumnSelection().contains(res))\r
- av.getColumnSelection().addElement(res);\r
+ if (!av.getColumnSelection().contains(res))\r
+ {\r
+ av.getColumnSelection().addElement(res);\r
+ }\r
\r
- SequenceGroup sg = av.getSelectionGroup();\r
+ SequenceGroup sg = av.getSelectionGroup();\r
\r
- if(res>sg.getStartRes())\r
- sg.setEndRes(res);\r
- else if(res<sg.getStartRes())\r
- sg.setStartRes(res);\r
+ if (res > sg.getStartRes())\r
+ {\r
+ sg.setEndRes(res);\r
+ }\r
+ else if (res < sg.getStartRes())\r
+ {\r
+ sg.setStartRes(res);\r
+ }\r
\r
- stretchingGroup = false;\r
- ap.repaint();\r
+ stretchingGroup = false;\r
+ ap.repaint();\r
}\r
\r
public void doMouseDragged(MouseEvent evt)\r
{\r
int x = evt.getX();\r
- int res = x/av.getCharWidth() + av.getStartRes();\r
+ int res = (x / av.getCharWidth()) + av.getStartRes();\r
\r
SequenceGroup sg = av.getSelectionGroup();\r
- if(sg!=null)\r
+\r
+ if (sg != null)\r
{\r
stretchingGroup = true;\r
+\r
if (res > sg.getStartRes())\r
+ {\r
sg.setEndRes(res);\r
+ }\r
else if (res < sg.getStartRes())\r
+ {\r
sg.setStartRes(res);\r
+ }\r
\r
- ap.annotationPanel.addEditableColumn(res);\r
+ ap.annotationPanel.addEditableColumn(res);\r
ap.repaint();\r
}\r
}\r
drawScale(g, av.getStartRes(), av.getEndRes(), getWidth(), getHeight());\r
}\r
\r
-// scalewidth will normally be screenwidth,\r
- public void drawScale(Graphics g, int startx, int endx, int width, int height)\r
+ // scalewidth will normally be screenwidth,\r
+ public void drawScale(Graphics g, int startx, int endx, int width,\r
+ int height)\r
{\r
- Graphics2D gg = (Graphics2D)g;\r
+ Graphics2D gg = (Graphics2D) g;\r
gg.setFont(av.getFont());\r
- gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);\r
+ gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,\r
+ RenderingHints.VALUE_ANTIALIAS_ON);\r
\r
//Fill in the background\r
gg.setColor(Color.white);\r
- gg.fillRect(0,0,width, height);\r
+ gg.fillRect(0, 0, width, height);\r
gg.setColor(Color.black);\r
\r
-\r
//Fill the selected columns\r
ColumnSelection cs = av.getColumnSelection();\r
- gg.setColor(new Color(220,0,0));\r
- for (int i=0; i<cs.size(); i++)\r
+ gg.setColor(new Color(220, 0, 0));\r
+\r
+ for (int i = 0; i < cs.size(); i++)\r
{\r
- int sel = cs.columnAt(i);\r
- if ( sel >= startx && sel <= endx)\r
- gg.fillRect((sel-startx)*av.charWidth,0,av.charWidth,getHeight());\r
- }\r
+ int sel = cs.columnAt(i);\r
\r
+ if ( (sel >= startx) && (sel <= endx))\r
+ {\r
+ gg.fillRect( (sel - startx) * av.charWidth, 0, av.charWidth,\r
+ getHeight());\r
+ }\r
+ }\r
\r
// Draw the scale numbers\r
gg.setColor(Color.black);\r
- int scalestartx = (startx/10) * 10;\r
+\r
+ int scalestartx = (startx / 10) * 10;\r
\r
FontMetrics fm = gg.getFontMetrics(av.getFont());\r
- int y = av.charHeight -fm.getDescent();\r
+ int y = av.charHeight - fm.getDescent();\r
\r
- if(scalestartx%10==0)\r
- scalestartx+=5;\r
+ if ( (scalestartx % 10) == 0)\r
+ {\r
+ scalestartx += 5;\r
+ }\r
\r
- for (int i=scalestartx;i < endx; i+= 5)\r
+ for (int i = scalestartx; i < endx; i += 5)\r
{\r
- if(i%10==0)\r
+ if ( (i % 10) == 0)\r
{\r
- gg.drawString(String.valueOf(i), (i - startx - 1) * av.charWidth, y);\r
- gg.drawLine( (int) ( (i - startx - 1) * av.charWidth + av.charWidth / 2),\r
- y+2,\r
- (int) ( (i - startx - 1) * av.charWidth + av.charWidth / 2),\r
- y+fm.getDescent()*2);\r
+ gg.drawString(String.valueOf(i),\r
+ (i - startx - 1) * av.charWidth, y);\r
+ gg.drawLine( (int) ( ( (i - startx - 1) * av.charWidth) +\r
+ (av.charWidth / 2)), y + 2,\r
+ (int) ( ( (i - startx - 1) * av.charWidth) +\r
+ (av.charWidth / 2)), y + (fm.getDescent() * 2));\r
}\r
else\r
- gg.drawLine( (int) ( (i - startx - 1) * av.charWidth + av.charWidth / 2),\r
- y+fm.getDescent(),\r
- (int) ( (i - startx - 1) * av.charWidth + av.charWidth / 2),\r
- y+fm.getDescent()*2);\r
-\r
-\r
+ {\r
+ gg.drawLine( (int) ( ( (i - startx - 1) * av.charWidth) +\r
+ (av.charWidth / 2)), y + fm.getDescent(),\r
+ (int) ( ( (i - startx - 1) * av.charWidth) +\r
+ (av.charWidth / 2)), y + (fm.getDescent() * 2));\r
+ }\r
}\r
}\r
-\r
-\r
}\r