{\r
Vector selected = new Vector();\r
\r
+ //Vector of int [] {startCol, endCol}\r
+ Vector hiddenColumns;\r
+\r
/**\r
* DOCUMENT ME!\r
*\r
return min;\r
}\r
\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public Vector asVector()\r
- {\r
- return selected;\r
- }\r
\r
/**\r
* DOCUMENT ME!\r
}\r
}\r
}\r
+\r
+ /**\r
+ * This Method is used to return all the HiddenColumn regions\r
+ * less than the given index.\r
+ * @param end int\r
+ * @return Vector\r
+ */\r
+ public Vector getHiddenColumns()\r
+ {\r
+ return hiddenColumns;\r
+ }\r
+\r
+ public int adjustForHiddenColumns(int column)\r
+ {\r
+ int result = column;\r
+ if (hiddenColumns != null)\r
+ {\r
+ for (int i = 0; i < hiddenColumns.size(); i++)\r
+ {\r
+ int[] region = (int[]) hiddenColumns.elementAt(i);\r
+ if (result >= region[0])\r
+ {\r
+ result += region[1] - region[0] + 1;\r
+ }\r
+ }\r
+ }\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * Use this method to find out where a visible column is in the alignment\r
+ * when hidden columns exist\r
+ * @param hiddenColumn int\r
+ * @return int\r
+ */\r
+ public int findColumnPosition(int hiddenColumn)\r
+ {\r
+ int result = hiddenColumn;\r
+ if (hiddenColumns != null)\r
+ {\r
+ int index = 0;\r
+ int gaps = 0;\r
+ do\r
+ {\r
+ int[] region = (int[]) hiddenColumns.elementAt(index);\r
+ if (hiddenColumn > region[1])\r
+ {\r
+ result -= region[1]+1-region[0];\r
+ }\r
+ index++;\r
+ }\r
+ while (index < hiddenColumns.size());\r
+\r
+ result -= gaps;\r
+ }\r
+\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * Use this method to determine where the next hiddenRegion starts\r
+ */\r
+ public int findHiddenRegionPosition(int hiddenRegion)\r
+ {\r
+ int result = 0;\r
+ if (hiddenColumns != null)\r
+ {\r
+ int index = 0;\r
+ int gaps = 0;\r
+ do\r
+ {\r
+ int[] region = (int[]) hiddenColumns.elementAt(index);\r
+ if(hiddenRegion==0)\r
+ {\r
+ return region[0];\r
+ }\r
+\r
+ gaps += region[1] +1 - region[0];\r
+ result = region[1] +1;\r
+ index++;\r
+ }\r
+ while(index < hiddenRegion+1);\r
+\r
+ result -= gaps;\r
+ }\r
+\r
+ return result;\r
+ }\r
+\r
+\r
+\r
+ public void hideColumns(int res, AlignViewport av)\r
+ {\r
+ if(hiddenColumns==null)\r
+ hiddenColumns = new Vector();\r
+\r
+ // First find out range of columns to hide\r
+ int min = res, max = res+1;\r
+ while( contains(min) )\r
+ { removeElement(min); min --; }\r
+\r
+ while( contains(max) )\r
+ { removeElement(max); max ++; }\r
+\r
+ min++; max--;\r
+\r
+ boolean added = false;\r
+ for(int i=0; i<hiddenColumns.size(); i++)\r
+ {\r
+ int [] region = (int[])hiddenColumns.elementAt(i);\r
+ if( max < region[0])\r
+ {\r
+ hiddenColumns.insertElementAt(new int[]{min, max}, i);\r
+ added = true;\r
+ break;\r
+ }\r
+ }\r
+\r
+ if(!added)\r
+ hiddenColumns.addElement(new int[]{min, max});\r
+\r
+\r
+ av.setSelectionGroup(null);\r
+ av.hasHiddenColumns = true;\r
+ }\r
+\r
+ public void revealHiddenColumns(int res, AlignViewport av)\r
+ {\r
+ for(int i=0; i<hiddenColumns.size(); i++)\r
+ {\r
+ int [] region = (int[])hiddenColumns.elementAt(i);\r
+ if( res == region[0])\r
+ {\r
+ hiddenColumns.remove(region);\r
+ break;\r
+ }\r
+ }\r
+\r
+\r
+ if(hiddenColumns.size()<1)\r
+ av.hasHiddenColumns = false;\r
+ }\r
+\r
}\r
* @author $author$\r
* @version $Revision$\r
*/\r
-public class ScalePanel extends JPanel\r
+public class ScalePanel extends JPanel implements MouseMotionListener, MouseListener\r
{\r
protected int offy = 4;\r
\r
this.av = av;\r
this.ap = ap;\r
\r
- addMouseListener(new MouseAdapter()\r
- {\r
- public void mousePressed(MouseEvent evt)\r
- {\r
- doMousePressed(evt);\r
- }\r
-\r
- public void mouseReleased(MouseEvent evt)\r
- {\r
- doMouseReleased(evt);\r
- }\r
- });\r
- addMouseMotionListener(new MouseMotionAdapter()\r
- {\r
- public void mouseDragged(MouseEvent evt)\r
- {\r
- doMouseDragged(evt);\r
- }\r
- });\r
+ addMouseListener(this);\r
+ addMouseMotionListener(this);\r
}\r
\r
/**\r
*\r
* @param evt DOCUMENT ME!\r
*/\r
- public void doMousePressed(MouseEvent evt)\r
+ public void mousePressed(MouseEvent evt)\r
{\r
- int x = evt.getX();\r
- int res = (x / av.getCharWidth()) + av.getStartRes();\r
- SequenceGroup sg = null;\r
+ int x = (evt.getX() / av.getCharWidth()) + av.getStartRes();\r
+ final int res;\r
+\r
+ if(av.hasHiddenColumns)\r
+ res = av.getColumnSelection().adjustForHiddenColumns(x);\r
+ else\r
+ res = x;\r
\r
min = res;\r
max = res;\r
\r
+ if(reveal != null)\r
+ {\r
+ av.getColumnSelection().revealHiddenColumns(reveal[0], av);\r
+ reveal = null;\r
+ return;\r
+ }\r
+\r
if (av.getColumnSelection().contains(res))\r
{\r
+ if( SwingUtilities.isRightMouseButton(evt))\r
+ {\r
+ JPopupMenu pop = new JPopupMenu();\r
+ JMenuItem item = new JMenuItem("Hide Columns");\r
+ item.addActionListener(new ActionListener()\r
+ {\r
+ public void actionPerformed(ActionEvent e)\r
+ {\r
+ av.getColumnSelection().hideColumns(res, av);\r
+ }\r
+ });\r
+ pop.add(item);\r
+ pop.show(this, evt.getX(), evt.getY());\r
+\r
+ }\r
+ else\r
+ {\r
av.getColumnSelection().removeElement(res);\r
ap.annotationPanel.removeEditableColumn(res);\r
+ }\r
}\r
else\r
{\r
av.getColumnSelection().addElement(res);\r
- sg = new SequenceGroup();\r
+ SequenceGroup sg = new SequenceGroup();\r
\r
for (int i = 0; i < av.alignment.getSequences().size(); i++)\r
{\r
\r
sg.setStartRes(res);\r
sg.setEndRes(res);\r
+ av.setSelectionGroup(sg);\r
}\r
\r
- av.setSelectionGroup(sg);\r
+\r
ap.repaint();\r
}\r
\r
*\r
* @param evt DOCUMENT ME!\r
*/\r
- public void doMouseReleased(MouseEvent evt)\r
+ public void mouseReleased(MouseEvent evt)\r
{\r
- int x = evt.getX();\r
- int res = (x / av.getCharWidth()) + av.getStartRes();\r
+ int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();\r
+\r
+ if(av.hasHiddenColumns)\r
+ res = av.getColumnSelection().adjustForHiddenColumns(res);\r
\r
if (av.getColumnSelection() != null)\r
{\r
*\r
* @param evt DOCUMENT ME!\r
*/\r
- public void doMouseDragged(MouseEvent evt)\r
+ public void mouseDragged(MouseEvent evt)\r
{\r
- int x = evt.getX();\r
- int res = (x / av.getCharWidth()) + av.getStartRes();\r
+ int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();\r
+\r
+ if(av.hasHiddenColumns)\r
+ res = av.getColumnSelection().adjustForHiddenColumns(res);\r
\r
if (res < min)\r
{\r
}\r
}\r
\r
+ public void mouseEntered(MouseEvent evt){}\r
+ public void mouseExited(MouseEvent evt){}\r
+ public void mouseClicked(MouseEvent evt){}\r
+\r
+ public void mouseMoved(MouseEvent evt)\r
+ {\r
+ if(!av.hasHiddenColumns)\r
+ return;\r
+\r
+ int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();\r
+\r
+ res = av.getColumnSelection().adjustForHiddenColumns(res);\r
+\r
+ reveal = null;\r
+ for(int i=0; i<av.getColumnSelection().getHiddenColumns().size(); i++)\r
+ {\r
+ int [] region = (int[])av.getColumnSelection().getHiddenColumns().elementAt(i);\r
+ if(res+1==region[0] || res-1==region[1])\r
+ {\r
+ reveal = region;\r
+ break;\r
+ }\r
+ }\r
+\r
+ repaint();\r
+ }\r
+\r
+ int [] reveal;\r
+\r
/**\r
* DOCUMENT ME!\r
*\r
for (int i = 0; i < cs.size(); i++)\r
{\r
int sel = cs.columnAt(i);\r
+ if(av.hasHiddenColumns)\r
+ sel = av.getColumnSelection().findColumnPosition(sel);\r
\r
if ((sel >= startx) && (sel <= endx))\r
{\r
{\r
if ((i % 10) == 0)\r
{\r
- gg.drawString(String.valueOf(i),\r
+ gg.drawString(String.valueOf(av.getColumnSelection().adjustForHiddenColumns(i)),\r
(i - startx - 1) * av.charWidth, y);\r
gg.drawLine((int) (((i - startx - 1) * av.charWidth) +\r
(av.charWidth / 2)), y + 2,\r
(av.charWidth / 2)), y + (fm.getDescent() * 2));\r
}\r
}\r
+\r
+ if (av.hasHiddenColumns)\r
+ {\r
+ gg.setColor(Color.blue);\r
+ int res;\r
+ for (int i = 0; i < av.getColumnSelection().getHiddenColumns().size(); i++)\r
+ {\r
+ res = av.getColumnSelection().findHiddenRegionPosition( i )-startx;\r
+\r
+ gg.fillPolygon(new int[] { res*av.charWidth - 4,\r
+ res*av.charWidth + 4,\r
+ res*av.charWidth },\r
+ new int[]\r
+ {\r
+ y-av.charHeight/2 , y-av.charHeight/2 ,\r
+ y + 8\r
+ }, 3);\r
+\r
+ }\r
+\r
+ if (reveal != null && reveal[0] > startx && reveal[0] < endx)\r
+ {\r
+ gg.drawString("Reveal Columns", reveal[0] * av.charWidth, 0);\r
+ }\r
+ }\r
+\r
+\r
}\r
}\r