X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FScalePanel.java;h=7ed0146de4bb7babefd36e2c400d21fe5f5763d8;hb=0b23947e2cdcd704d3f313b23ba271e43d097344;hp=87e72dc4d34d97e0cc2225cd03bb95a7d20e27a2;hpb=31aef90c8108c0c781d77c7c32402a940b122aa2;p=jalview.git diff --git a/src/jalview/gui/ScalePanel.java b/src/jalview/gui/ScalePanel.java index 87e72dc..7ed0146 100755 --- a/src/jalview/gui/ScalePanel.java +++ b/src/jalview/gui/ScalePanel.java @@ -1,6 +1,6 @@ /* * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * Copyright (C) 2006 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 @@ -43,6 +43,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, MouseList boolean stretchingGroup = false; int min; //used by mouseDragged to see if user int max; //used by mouseDragged to see if user + boolean mouseDragging = false; // wants to delete columns public ScalePanel(AlignViewport av, AlignmentPanel ap) @@ -72,76 +73,95 @@ public class ScalePanel extends JPanel implements MouseMotionListener, MouseList min = res; max = res; - if(reveal != null && SwingUtilities.isRightMouseButton(evt)) + if (SwingUtilities.isRightMouseButton(evt)) + { + JPopupMenu pop = new JPopupMenu(); + if (reveal != null) { - JPopupMenu pop = new JPopupMenu(); JMenuItem item = new JMenuItem("Reveal"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - av.getColumnSelection().revealHiddenColumns(reveal[0], av); + av.showColumn(reveal[0]); reveal = null; ap.repaint(); + if (ap.overviewPanel != null) + ap.overviewPanel.updateOverviewImage(); } }); pop.add(item); - if(av.getColumnSelection().hiddenColumns.size()>1) + if (av.getColumnSelection().getHiddenColumns().size() > 1) { item = new JMenuItem("Reveal All"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - av.getColumnSelection().revealAllHiddenColumns(av); + av.showAllHiddenColumns(); reveal = null; ap.repaint(); + if (ap.overviewPanel != null) + ap.overviewPanel.updateOverviewImage(); } }); pop.add(item); } - pop.show(this, evt.getX(), evt.getY()); - } - else if (av.getColumnSelection().contains(res)) - { - if( SwingUtilities.isRightMouseButton(evt)) + else if (av.getColumnSelection().contains(res)) { - JPopupMenu pop = new JPopupMenu(); JMenuItem item = new JMenuItem("Hide Columns"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - av.getColumnSelection().hideColumns(res, av); + av.hideColumns(res, res); + if(av.getSelectionGroup()!=null + && av.getSelectionGroup().getSize(false)==av.alignment.getHeight()) + av.setSelectionGroup(null); + ap.repaint(); + if (ap.overviewPanel != null) + ap.overviewPanel.updateOverviewImage(); } }); pop.add(item); pop.show(this, evt.getX(), evt.getY()); - - } - else - { - av.getColumnSelection().removeElement(res); - av.setSelectionGroup(null); } } - else + else // LEFT MOUSE TO SELECT { - av.getColumnSelection().addElement(res); - SequenceGroup sg = new SequenceGroup(); + if (!evt.isControlDown() && !evt.isShiftDown()) + { + av.getColumnSelection().clear(); + } + + av.getColumnSelection().addElement(res); + SequenceGroup 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); - for (int i = 0; i < av.alignment.getSequences().size(); i++) + if(evt.isShiftDown()) + { + int min = Math.min(av.getColumnSelection().getMin(), res); + int max = Math.max(av.getColumnSelection().getMax(), res); + for (int i = min; i av.alignment.getWidth()) + { + res = av.alignment.getWidth()-1; + } + if(av.hasHiddenColumns) res = av.getColumnSelection().adjustForHiddenColumns(res); @@ -189,11 +216,21 @@ public class ScalePanel extends JPanel implements MouseMotionListener, MouseList */ public void mouseDragged(MouseEvent evt) { + mouseDragging = true; + int res = (evt.getX() / av.getCharWidth()) + av.getStartRes(); + if(res<0) + res = 0; if(av.hasHiddenColumns) res = av.getColumnSelection().adjustForHiddenColumns(res); + + if(res> av.alignment.getWidth()) + { + res = av.alignment.getWidth()-1; + } + if (res < min) { min = res; @@ -204,6 +241,8 @@ public class ScalePanel extends JPanel implements MouseMotionListener, MouseList max = res; } + + SequenceGroup sg = av.getSelectionGroup(); if (sg != null) @@ -219,7 +258,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, MouseList { sg.setEndRes(res); } - else if (res < sg.getStartRes()) + if (res < sg.getStartRes()) { sg.setStartRes(res); } @@ -240,8 +279,18 @@ public class ScalePanel extends JPanel implements MouseMotionListener, MouseList } } - public void mouseEntered(MouseEvent evt){} - public void mouseExited(MouseEvent evt){} + public void mouseEntered(MouseEvent evt) + { + if(mouseDragging) + ap.seqPanel.scrollCanvas(null); + } + + public void mouseExited(MouseEvent evt) + { + if(mouseDragging) + ap.seqPanel.scrollCanvas(evt); + } + public void mouseClicked(MouseEvent evt){} public void mouseMoved(MouseEvent evt) @@ -260,8 +309,13 @@ public class ScalePanel extends JPanel implements MouseMotionListener, MouseList if(res+1==region[0] || res-1==region[1]) { reveal = region; + ToolTipManager.sharedInstance().registerComponent(this); + this.setToolTipText("Reveal Hidden Columns with Right Mouse Button"); break; } + else + this.setToolTipText(null); + } repaint(); @@ -325,16 +379,27 @@ public class ScalePanel extends JPanel implements MouseMotionListener, MouseList scalestartx += 5; } + String string; + int maxX=0; + for (int i = scalestartx; i < endx; i += 5) { if ((i % 10) == 0) { - gg.drawString(String.valueOf(av.getColumnSelection().adjustForHiddenColumns(i)), - (i - startx - 1) * av.charWidth, y); - gg.drawLine((int) (((i - startx - 1) * av.charWidth) + - (av.charWidth / 2)), y + 2, - (int) (((i - startx - 1) * av.charWidth) + - (av.charWidth / 2)), y + (fm.getDescent() * 2)); + string = String.valueOf(av.getColumnSelection().adjustForHiddenColumns(i)); + if ( (i - startx - 1) * av.charWidth > maxX) + { + gg.drawString(string, + (i - startx - 1) * av.charWidth, y); + maxX = (i - startx + 1) * av.charWidth + fm.stringWidth(string); + } + + gg.drawLine( (int) ( ( (i - startx - 1) * av.charWidth) + + (av.charWidth / 2)), y + 2, + (int) ( ( (i - startx - 1) * av.charWidth) + + (av.charWidth / 2)), + y + (fm.getDescent() * 2)); + } else { @@ -349,19 +414,29 @@ public class ScalePanel extends JPanel implements MouseMotionListener, MouseList { gg.setColor(Color.blue); int res; - for (int i = 0; i < av.getColumnSelection().getHiddenColumns().size(); i++) + if(av.getShowHiddenMarkers()) { - res = av.getColumnSelection().findHiddenRegionPosition( i )-startx; + for (int i = 0; i < av.getColumnSelection().getHiddenColumns().size(); + i++) + { - gg.fillPolygon(new int[] { res*av.charWidth - 4, - res*av.charWidth + 4, - res*av.charWidth }, - new int[] - { - y-av.charHeight/2 , y-av.charHeight/2 , - y + 8 - }, 3); + res = av.getColumnSelection().findHiddenRegionPosition(i) - + startx; + if(res < 0 || res > endx-scalestartx) + continue; + + gg.fillPolygon(new int[] + {res * av.charWidth - av.charHeight / 4, + res * av.charWidth + av.charHeight / 4, + res * av.charWidth}, + new int[] + { + y - av.charHeight / 2, y - av.charHeight / 2, + y + 8 + }, 3); + + } } if (reveal != null && reveal[0] > startx && reveal[0] < endx)