X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FScalePanel.java;h=7ed0146de4bb7babefd36e2c400d21fe5f5763d8;hb=0b23947e2cdcd704d3f313b23ba271e43d097344;hp=73a9e6e8b1f5e2bcb862987ee964faca44c025ef;hpb=a377b62f440f6afda24b06e26317677904fa2953;p=jalview.git diff --git a/src/jalview/gui/ScalePanel.java b/src/jalview/gui/ScalePanel.java index 73a9e6e..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 @@ -18,227 +18,433 @@ */ package jalview.gui; +import jalview.datamodel.*; + import java.awt.*; import java.awt.event.*; + import javax.swing.*; -import jalview.datamodel.*; -public class ScalePanel - extends JPanel +/** + * DOCUMENT ME! + * + * @author $author$ + * @version $Revision$ + */ +public class ScalePanel extends JPanel implements MouseMotionListener, MouseListener { - protected int offy = 4; - public int width; - protected AlignViewport av; - AlignmentPanel ap; - boolean stretchingGroup = false; - - int min, max; //used by mouseDragged to see if user - // wants to delete columns + 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 + boolean mouseDragging = false; + + // wants to delete columns + public ScalePanel(AlignViewport av, AlignmentPanel ap) + { + this.av = av; + this.ap = ap; - public ScalePanel(AlignViewport av, AlignmentPanel ap) - { - this.av = av; - this.ap = ap; + addMouseListener(this); + addMouseMotionListener(this); + } - addMouseListener(new MouseAdapter() + /** + * DOCUMENT ME! + * + * @param evt DOCUMENT ME! + */ + public void mousePressed(MouseEvent evt) { - public void mousePressed(MouseEvent evt) - { - doMousePressed(evt); - } + int x = (evt.getX() / av.getCharWidth()) + av.getStartRes(); + final int res; - public void mouseReleased(MouseEvent evt) - { - doMouseReleased(evt); - } - }); - addMouseMotionListener(new MouseMotionAdapter() - { - public void mouseDragged(MouseEvent evt) - { - doMouseDragged(evt); - } - }); - } + if(av.hasHiddenColumns) + res = av.getColumnSelection().adjustForHiddenColumns(x); + else + res = x; + + min = res; + max = res; + + if (SwingUtilities.isRightMouseButton(evt)) + { + JPopupMenu pop = new JPopupMenu(); + if (reveal != null) + { + JMenuItem item = new JMenuItem("Reveal"); + item.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + av.showColumn(reveal[0]); + reveal = null; + ap.repaint(); + if (ap.overviewPanel != null) + ap.overviewPanel.updateOverviewImage(); + } + }); + pop.add(item); + + if (av.getColumnSelection().getHiddenColumns().size() > 1) + { + item = new JMenuItem("Reveal All"); + item.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + 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)) + { + JMenuItem item = new JMenuItem("Hide Columns"); + item.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + 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 // LEFT MOUSE TO SELECT + { + 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); + + 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; + } - for (int i = 0; i < av.alignment.getSequences().size(); i++) - { - sg.addSequence(av.alignment.getSequenceAt(i), false); - } + if(av.hasHiddenColumns) + res = av.getColumnSelection().adjustForHiddenColumns(res); - sg.setStartRes(res); - sg.setEndRes(res); + if (!stretchingGroup) + { + ap.repaint(); - } + return; + } - av.setSelectionGroup(sg); - ap.repaint(); - } + SequenceGroup sg = av.getSelectionGroup(); - public void doMouseReleased(MouseEvent evt) - { - int x = evt.getX(); - int res = (x / av.getCharWidth()) + av.getStartRes(); + if (res > sg.getStartRes()) + { + sg.setEndRes(res); + } + else if (res < sg.getStartRes()) + { + sg.setStartRes(res); + } - if(av.getColumnSelection()!=null) - { - for(int i=0; i av.alignment.getWidth()) + { + res = av.alignment.getWidth()-1; + } + + if (res < min) + { + min = res; + } + + if (res > max) + { + max = res; + } + + + + SequenceGroup sg = av.getSelectionGroup(); + + if (sg != null) + { + stretchingGroup = true; + + if (!av.getColumnSelection().contains(res)) + { + av.getColumnSelection().addElement(res); + } + + if (res > sg.getStartRes()) + { + sg.setEndRes(res); + } + if (res < sg.getStartRes()) + { + sg.setStartRes(res); + } + + for (int i = min; i <= max; i++) + { + if ((i < sg.getStartRes()) || (i > sg.getEndRes())) + { + av.getColumnSelection().removeElement(i); + } + else + { + av.getColumnSelection().addElement(i); + } + } + + ap.repaint(); + } } - SequenceGroup sg = av.getSelectionGroup(); - - if (res > sg.getStartRes()) + public void mouseEntered(MouseEvent evt) { - sg.setEndRes(res); + if(mouseDragging) + ap.seqPanel.scrollCanvas(null); } - else if (res < sg.getStartRes()) + + public void mouseExited(MouseEvent evt) { - sg.setStartRes(res); + if(mouseDragging) + ap.seqPanel.scrollCanvas(evt); } - stretchingGroup = false; - ap.repaint(); - } - - public void doMouseDragged(MouseEvent evt) - { - int x = evt.getX(); - int res = (x / av.getCharWidth()) + av.getStartRes(); + public void mouseClicked(MouseEvent evt){} - if(res < min) - min = res; - if(res>max) - max = res; - - SequenceGroup sg = av.getSelectionGroup(); - - if (sg != null) + public void mouseMoved(MouseEvent evt) { - stretchingGroup = true; - if (!av.getColumnSelection().contains(res)) - { - av.getColumnSelection().addElement(res); - } + if(!av.hasHiddenColumns) + return; + int res = (evt.getX() / av.getCharWidth()) + av.getStartRes(); - if (res > sg.getStartRes()) - { - sg.setEndRes(res); - } - else if (res < sg.getStartRes()) - { - sg.setStartRes(res); - } + res = av.getColumnSelection().adjustForHiddenColumns(res); - for(int i=min; i<=max; i++) + reveal = null; + for(int i=0; i sg.getEndRes()) - { - av.getColumnSelection().removeElement(i); - ap.annotationPanel.removeEditableColumn(res); - } + int [] region = (int[])av.getColumnSelection().getHiddenColumns().elementAt(i); + 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 - av.getColumnSelection().addElement(i); - } - ap.repaint(); - } - } - - public void paintComponent(Graphics g) - { - drawScale(g, av.getStartRes(), av.getEndRes(), getWidth(), getHeight()); - } - - // scalewidth will normally be screenwidth, - public void drawScale(Graphics g, int startx, int endx, int width, - int height) - { - Graphics2D gg = (Graphics2D) g; - gg.setFont(av.getFont()); - gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); - - //Fill in the background - gg.setColor(Color.white); - gg.fillRect(0, 0, width, height); - gg.setColor(Color.black); - - //Fill the selected columns - ColumnSelection cs = av.getColumnSelection(); - gg.setColor(new Color(220, 0, 0)); - - for (int i = 0; i < cs.size(); i++) - { - int sel = cs.columnAt(i); + this.setToolTipText(null); - if ( (sel >= startx) && (sel <= endx)) - { - gg.fillRect( (sel - startx) * av.charWidth, 0, av.charWidth, - getHeight()); } - } - // Draw the scale numbers - gg.setColor(Color.black); - - int scalestartx = (startx / 10) * 10; + repaint(); + } - FontMetrics fm = gg.getFontMetrics(av.getFont()); - int y = av.charHeight - fm.getDescent(); + int [] reveal; - if ( (scalestartx % 10) == 0) + /** + * DOCUMENT ME! + * + * @param g DOCUMENT ME! + */ + public void paintComponent(Graphics g) { - scalestartx += 5; + drawScale(g, av.getStartRes(), av.getEndRes(), getWidth(), getHeight()); } - for (int i = scalestartx; i < endx; i += 5) + // scalewidth will normally be screenwidth, + public void drawScale(Graphics g, int startx, int endx, int width, + int height) { - if ( (i % 10) == 0) - { - gg.drawString(String.valueOf(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)); - } - else - { - gg.drawLine( (int) ( ( (i - startx - 1) * av.charWidth) + - (av.charWidth / 2)), y + fm.getDescent(), - (int) ( ( (i - startx - 1) * av.charWidth) + - (av.charWidth / 2)), y + (fm.getDescent() * 2)); - } + Graphics2D gg = (Graphics2D) g; + gg.setFont(av.getFont()); + + if(av.antiAlias) + gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + + //Fill in the background + gg.setColor(Color.white); + gg.fillRect(0, 0, width, height); + gg.setColor(Color.black); + + //Fill the selected columns + ColumnSelection cs = av.getColumnSelection(); + gg.setColor(new Color(220, 0, 0)); + + for (int i = 0; i < cs.size(); i++) + { + int sel = cs.columnAt(i); + if(av.hasHiddenColumns) + sel = av.getColumnSelection().findColumnPosition(sel); + + if ((sel >= startx) && (sel <= endx)) + { + gg.fillRect((sel - startx) * av.charWidth, 0, av.charWidth, + getHeight()); + } + } + + // Draw the scale numbers + gg.setColor(Color.black); + + int scalestartx = (startx / 10) * 10; + + FontMetrics fm = gg.getFontMetrics(av.getFont()); + int y = av.charHeight - fm.getDescent(); + + if ((scalestartx % 10) == 0) + { + scalestartx += 5; + } + + String string; + int maxX=0; + + for (int i = scalestartx; i < endx; i += 5) + { + if ((i % 10) == 0) + { + 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 + { + gg.drawLine((int) (((i - startx - 1) * av.charWidth) + + (av.charWidth / 2)), y + fm.getDescent(), + (int) (((i - startx - 1) * av.charWidth) + + (av.charWidth / 2)), y + (fm.getDescent() * 2)); + } + } + + if (av.hasHiddenColumns) + { + gg.setColor(Color.blue); + int res; + if(av.getShowHiddenMarkers()) + { + for (int i = 0; i < av.getColumnSelection().getHiddenColumns().size(); + i++) + { + + 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) + { + gg.drawString("Reveal Columns", reveal[0] * av.charWidth, 0); + } + } + + } - } }