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;
33 import jalview.bin.Cache;
41 public class IdwidthAdjuster extends JPanel
42 implements MouseListener, MouseMotionListener
44 public static final int MIN_ID_WIDTH = 20;
51 * Creates a new IdwidthAdjuster object.
56 public IdwidthAdjuster(AlignmentPanel ap)
59 setBackground(Color.white);
60 addMouseListener(this);
61 addMouseMotionListener(this);
65 * Action on mouse pressed is to save the start position for any drag
70 public void mousePressed(MouseEvent evt)
76 * On release of mouse drag to resize the width, if there is a complementary
77 * alignment in a split frame, sets the complement to the same id width and
78 * repaints the split frame. Note this is done whether or not the protein
79 * characters are scaled to codon width.
84 public void mouseReleased(MouseEvent evt)
89 * If in a SplitFrame, set the other's id width to match
91 final AlignViewportI viewport = ap.getAlignViewport();
92 if (viewport.getCodingComplement() != null)
94 viewport.getCodingComplement().setIdWidth(viewport.getIdWidth());
95 SplitFrame sf = (SplitFrame) ap.alignFrame.getSplitViewContainer();
101 * When this region is entered, repaints to show a left-right move cursor
106 public void mouseEntered(MouseEvent evt)
112 public void mouseExited(MouseEvent evt)
117 * Adjusts the id panel width for a mouse drag left or right (subject to a
118 * minimum of 20 pixels) and repaints the alignment
123 public void mouseDragged(MouseEvent evt)
125 int mouseX = evt.getX();
126 final AlignViewportI viewport = ap.getAlignViewport();
127 int curwidth = viewport.getIdWidth();
128 int dif = mouseX - oldX;
130 final int newWidth = curwidth + dif;
133 * don't drag below minimum width
135 if (newWidth < MIN_ID_WIDTH)
141 * don't allow residue width to be < 1 in wrapped format
143 if (viewport.getWrapAlignment())
145 SeqCanvas sc = ap.getSeqPanel().seqCanvas;
146 if (sc != null && sc.getWrappedCanvasWidth(sc.getWidth() - dif) < 1)
155 * don't drag right if mouse is to the left of the region
157 if (dif > 0 && mouseX < 0)
162 // TODO JAL-4260 - work out how to trigger recomputation of wrapped pages !
163 int curCol = viewport.getRanges().getStartRes()
164 + viewport.getRanges().getViewportWidth();
166 viewport.setIdWidth(newWidth);
168 ap.validateAnnotationDimensions(false);
169 if (viewport.getWrapAlignment())
171 viewport.getRanges().scrollToWrappedVisible(
172 curCol - viewport.getRanges().getViewportWidth());
174 ap.paintAlignment(true, false);
176 ap.getIdPanel().getIdCanvas().setManuallyAdjusted(true);
179 public void setWidth(int newWidth)
181 if (newWidth < MIN_ID_WIDTH
182 || ap.getIdPanel().getIdCanvas().isManuallyAdjusted())
186 final AlignViewportI viewport = ap.getAlignViewport();
187 viewport.setIdWidth(newWidth);
188 ap.paintAlignment(true, false);
191 public boolean manuallyAdjusted()
193 return ap.getIdPanel().getIdCanvas().isManuallyAdjusted();
197 public void mouseMoved(MouseEvent evt)
202 public void mouseClicked(MouseEvent evt)
207 * Paints this region, showing a left-right move cursor if currently 'active'
212 public void paintComponent(Graphics g)
214 int width = getWidth();
215 int height = getHeight();
216 g.setColor(Color.white);
217 g.fillRect(0, 0, width, height);
219 if (!Cache.getDefault(AnnotationLabels.RESIZE_MARGINS_MARK_PREF, false))
220 // && !ap.getAlignViewport().getWrapAlignment()) // now allowing adjustment
223 int spacer = Math.max(2, AnnotationLabels.HEIGHT_ADJUSTER_HEIGHT / 4);
224 g.setColor(Color.LIGHT_GRAY);
225 g.drawLine(width - 3 * spacer, 0, width - 3 * spacer, height / 2);
226 g.drawLine(width - spacer, 0, width - spacer, height / 2);
229 setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR));