2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.api.AlignViewportI;
25 import java.awt.Color;
26 import java.awt.Cursor;
27 import java.awt.Graphics;
28 import java.awt.event.MouseEvent;
29 import java.awt.event.MouseListener;
30 import java.awt.event.MouseMotionListener;
32 import javax.swing.JPanel;
40 public class IdwidthAdjuster extends JPanel
41 implements MouseListener, MouseMotionListener
43 public static final int MIN_ID_WIDTH = 20;
50 * Creates a new IdwidthAdjuster object.
55 public IdwidthAdjuster(AlignmentPanel ap)
58 setBackground(Color.white);
59 addMouseListener(this);
60 addMouseMotionListener(this);
64 * Action on mouse pressed is to save the start position for any drag
69 public void mousePressed(MouseEvent evt)
75 * On release of mouse drag to resize the width, if there is a complementary
76 * alignment in a split frame, sets the complement to the same id width and
77 * repaints the split frame. Note this is done whether or not the protein
78 * characters are scaled to codon width.
83 public void mouseReleased(MouseEvent evt)
88 * If in a SplitFrame, set the other's id width to match
90 final AlignViewportI viewport = ap.getAlignViewport();
91 if (viewport.getCodingComplement() != null)
93 viewport.getCodingComplement().setIdWidth(viewport.getIdWidth());
94 SplitFrame sf = (SplitFrame) ap.alignFrame.getSplitViewContainer();
100 * When this region is entered, repaints to show a left-right move cursor
105 public void mouseEntered(MouseEvent evt)
111 public void mouseExited(MouseEvent evt)
116 * Adjusts the id panel width for a mouse drag left or right (subject to a
117 * minimum of 20 pixels) and repaints the alignment
122 public void mouseDragged(MouseEvent evt)
124 int mouseX = evt.getX();
125 final AlignViewportI viewport = ap.getAlignViewport();
126 int curwidth = viewport.getIdWidth();
127 int dif = mouseX - oldX;
129 final int newWidth = curwidth + dif;
132 * don't drag below minimum width
134 if (newWidth < MIN_ID_WIDTH)
142 * don't drag right if mouse is to the left of the region
144 if (dif > 0 && mouseX < 0)
148 viewport.setIdWidth(newWidth);
149 ap.paintAlignment(true, false);
153 public void mouseMoved(MouseEvent evt)
158 public void mouseClicked(MouseEvent evt)
163 * Paints this region, showing a left-right move cursor if currently 'active'
168 public void paintComponent(Graphics g)
170 g.setColor(Color.white);
171 g.fillRect(0, 0, getWidth(), getHeight());
172 setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR));