import java.awt.Color;
import java.awt.Cursor;
-import java.awt.Graphics;
+import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
-import java.awt.event.MouseListener;
-import java.awt.event.MouseMotionListener;
import javax.swing.JPanel;
* @author $author$
* @version $Revision$
*/
+@SuppressWarnings("serial")
public class IdwidthAdjuster extends JPanel
- implements MouseListener, MouseMotionListener
{
- boolean active = false;
int oldX = 0;
- AlignmentPanel ap;
-
/**
- * Creates a new IdwidthAdjuster object.
+ * Creates a new IdwidthAdjuster object above the id panel that can be dragged
+ * to change the panel's width
*
* @param ap
- * DOCUMENT ME!
- */
- public IdwidthAdjuster(AlignmentPanel ap)
- {
- this.ap = ap;
- setBackground(Color.white);
- addMouseListener(this);
- addMouseMotionListener(this);
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param evt
- * DOCUMENT ME!
- */
- @Override
- public void mousePressed(MouseEvent evt)
- {
- oldX = evt.getX();
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param evt
- * DOCUMENT ME!
- */
- @Override
- public void mouseReleased(MouseEvent evt)
- {
- active = false;
- repaint();
-
- /*
- * If in a SplitFrame with co-scaled alignments, set the other's id width to
- * match
- */
- final AlignViewportI viewport = ap.getAlignViewport();
- if (viewport.getCodingComplement() != null
- && viewport.isScaleProteinAsCdna())
- {
- viewport.getCodingComplement().setIdWidth(viewport.getIdWidth());
- SplitFrame sf = (SplitFrame) ap.alignFrame.getSplitViewContainer();
- sf.repaint();
- }
-
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param evt
- * DOCUMENT ME!
- */
- @Override
- public void mouseEntered(MouseEvent evt)
- {
- active = true;
- repaint();
- }
-
- /**
- * DOCUMENT ME!
+ * The associated AlignmentPanel
*
- * @param evt
- * DOCUMENT ME!
*/
- @Override
- public void mouseExited(MouseEvent evt)
- {
- active = false;
- repaint();
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param evt
- * DOCUMENT ME!
- */
- @Override
- public void mouseDragged(MouseEvent evt)
+ public IdwidthAdjuster(AlignmentPanel ap)
{
- active = true;
+ // BH 2019.07.01 no need for overridden paintComponent, especially as it was
+ // overriding paint(g) so
+ // allowing strange component painting in its place.
- final AlignViewportI viewport = ap.getAlignViewport();
- int curwidth = viewport.getIdWidth();
- int dif = evt.getX() - oldX;
-
- final int newWidth = curwidth + dif;
- if ((newWidth > 20) || (dif > 0))
- {
- viewport.setIdWidth(newWidth);
-
- ap.paintAlignment(true, false);
- }
-
- oldX = evt.getX();
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param evt
- * DOCUMENT ME!
- */
- @Override
- public void mouseMoved(MouseEvent evt)
- {
- }
+ setBackground(Color.white);
+ setOpaque(true);
- /**
- * DOCUMENT ME!
- *
- * @param evt
- * DOCUMENT ME!
- */
- @Override
- public void mouseClicked(MouseEvent evt)
- {
- }
+ setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR));
- /**
- * DOCUMENT ME!
- *
- * @param g
- * DOCUMENT ME!
- */
- @Override
- public void paintComponent(Graphics g)
- {
- g.setColor(Color.white);
- g.fillRect(0, 0, getWidth(), getHeight());
+ // BH 2019.07.01 MouseAdapter is cleaner - no need for fields active or ap
- if (active)
+ MouseAdapter ma = (new MouseAdapter()
{
- setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR));
- }
+ @Override
+ public void mousePressed(MouseEvent evt)
+ {
+ oldX = evt.getX();
+ }
+
+ @Override
+ public void mouseDragged(MouseEvent evt)
+ {
+ AlignViewportI viewport = ap.getAlignViewport();
+ int curwidth = viewport.getIdWidth();
+ int dif = evt.getX() - oldX;
+ int newWidth = curwidth + dif;
+ if ((newWidth > 20) || (dif > 0))
+ {
+ viewport.setIdWidth(newWidth);
+ ap.paintAlignment(true, false);
+ }
+ oldX = evt.getX();
+ }
+
+ @Override
+ public void mouseReleased(MouseEvent evt)
+ {
+
+ // If in a SplitFrame with co-scaled alignments, set the other's id
+ // width to match
+
+ AlignViewportI viewport = ap.getAlignViewport();
+ if (viewport.getCodingComplement() != null
+ && viewport.isScaleProteinAsCdna())
+ {
+ viewport.getCodingComplement().setIdWidth(viewport.getIdWidth());
+ SplitFrame sf = (SplitFrame) ap.alignFrame
+ .getSplitViewContainer();
+ sf.repaint();
+ }
+
+ }
+
+ });
+ addMouseListener(ma);
+ addMouseMotionListener(ma);
}
}