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 java.awt.Color;
24 import java.awt.Cursor;
25 import java.awt.Graphics;
26 import java.awt.event.MouseEvent;
27 import java.awt.event.MouseListener;
28 import java.awt.event.MouseMotionListener;
30 import javax.swing.JPanel;
32 import jalview.api.AlignViewportI;
40 public class IdwidthAdjuster extends JPanel
41 implements MouseListener, MouseMotionListener
43 public static final int MIN_ID_WIDTH = 20;
49 private boolean manuallyAdjusted = false;
52 * Creates a new IdwidthAdjuster object.
57 public IdwidthAdjuster(AlignmentPanel ap)
60 setBackground(Color.white);
61 addMouseListener(this);
62 addMouseMotionListener(this);
66 * Action on mouse pressed is to save the start position for any drag
71 public void mousePressed(MouseEvent evt)
77 * On release of mouse drag to resize the width, if there is a complementary
78 * alignment in a split frame, sets the complement to the same id width and
79 * repaints the split frame. Note this is done whether or not the protein
80 * characters are scaled to codon width.
85 public void mouseReleased(MouseEvent evt)
90 * If in a SplitFrame, set the other's id width to match
92 final AlignViewportI viewport = ap.getAlignViewport();
93 if (viewport.getCodingComplement() != null)
95 viewport.getCodingComplement().setIdWidth(viewport.getIdWidth());
96 SplitFrame sf = (SplitFrame) ap.alignFrame.getSplitViewContainer();
102 * When this region is entered, repaints to show a left-right move cursor
107 public void mouseEntered(MouseEvent evt)
113 public void mouseExited(MouseEvent evt)
118 * Adjusts the id panel width for a mouse drag left or right (subject to a
119 * minimum of 20 pixels) and repaints the alignment
124 public void mouseDragged(MouseEvent evt)
126 int mouseX = evt.getX();
127 final AlignViewportI viewport = ap.getAlignViewport();
128 int curwidth = viewport.getIdWidth();
129 int dif = mouseX - oldX;
131 final int newWidth = curwidth + dif;
134 * don't drag below minimum width
136 if (newWidth < MIN_ID_WIDTH)
144 * don't drag right if mouse is to the left of the region
146 if (dif > 0 && mouseX < 0)
150 viewport.setIdWidth(newWidth);
151 ap.validateAnnotationDimensions(false);
152 ap.paintAlignment(true, false);
154 manuallyAdjusted = true;
157 public void setWidth(int newWidth)
159 if (newWidth < MIN_ID_WIDTH)
163 final AlignViewportI viewport = ap.getAlignViewport();
164 viewport.setIdWidth(newWidth);
165 ap.paintAlignment(true, false);
168 public boolean manuallyAdjusted()
170 return manuallyAdjusted;
174 public void mouseMoved(MouseEvent evt)
179 public void mouseClicked(MouseEvent evt)
184 * Paints this region, showing a left-right move cursor if currently 'active'
189 public void paintComponent(Graphics g)
191 g.setColor(Color.white);
192 g.fillRect(0, 0, getWidth(), getHeight());
193 setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR));