From: kiramt Date: Wed, 10 Jan 2018 16:42:03 +0000 (+0000) Subject: JAL-2621 Added custom drag cursor to overview panel X-Git-Tag: Release_2_11_0~17^2~65^2~2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=75aceeffea6e41f77a85ce6732780e760db739e5;p=jalview.git JAL-2621 Added custom drag cursor to overview panel --- diff --git a/resources/images/dragcursor.png b/resources/images/dragcursor.png new file mode 100644 index 0000000..914bb15 Binary files /dev/null and b/resources/images/dragcursor.png differ diff --git a/src/jalview/appletgui/OverviewPanel.java b/src/jalview/appletgui/OverviewPanel.java index 8ce597d..7431f6a 100755 --- a/src/jalview/appletgui/OverviewPanel.java +++ b/src/jalview/appletgui/OverviewPanel.java @@ -32,7 +32,9 @@ import java.awt.CheckboxMenuItem; import java.awt.Cursor; import java.awt.Dimension; import java.awt.Frame; +import java.awt.Image; import java.awt.Panel; +import java.awt.Point; import java.awt.PopupMenu; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; @@ -44,9 +46,14 @@ import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.beans.PropertyChangeEvent; +import javax.swing.ImageIcon; + public class OverviewPanel extends Panel implements Runnable, MouseMotionListener, MouseListener, ViewportListenerI { + protected Image dragImage = new ImageIcon( + getClass().getResource("/images/dragcursor.png")).getImage(); + private OverviewDimensions od; private OverviewCanvas oviewCanvas; @@ -61,6 +68,8 @@ public class OverviewPanel extends Panel implements Runnable, private boolean draggingBox = false; + private Cursor dragCursor; + public OverviewPanel(AlignmentPanel alPanel) { this.av = alPanel.av; @@ -79,6 +88,20 @@ public class OverviewPanel extends Panel implements Runnable, av.getRanges().addPropertyChangeListener(this); + // set up custom cursor for use on Mac... + Point hotSpot = new Point(16, 16); + String cursorName = "Custom drag cursor"; + + if (Platform.isAMac()) + { + dragCursor = getToolkit().createCustomCursor(dragImage, hotSpot, + cursorName); + } + else + { + dragCursor = Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR); + } + addComponentListener(new ComponentAdapter() { @@ -119,20 +142,33 @@ public class OverviewPanel extends Panel implements Runnable, { showPopupMenu(evt); } + else if (od.isPositionInBox(evt.getX(), evt.getY())) + { + // display drag cursor at mouse position + this.getParent().setCursor(dragCursor); + } + else + { + // reset cursor + this.getParent() + .setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + } } @Override public void mouseMoved(MouseEvent evt) { + System.out.println(evt.getY()); if (od.isPositionInBox(evt.getX(), evt.getY())) { // display drag cursor at mouse position - setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); + this.getParent().setCursor(dragCursor); } else { // reset cursor - setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + this.getParent() + .setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } } diff --git a/src/jalview/gui/OverviewPanel.java b/src/jalview/gui/OverviewPanel.java index 43b4310..567a121 100755 --- a/src/jalview/gui/OverviewPanel.java +++ b/src/jalview/gui/OverviewPanel.java @@ -32,6 +32,8 @@ import jalview.viewmodel.ViewportListenerI; import java.awt.BorderLayout; import java.awt.Cursor; import java.awt.Dimension; +import java.awt.Image; +import java.awt.Point; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ComponentAdapter; @@ -42,6 +44,7 @@ import java.awt.event.MouseMotionAdapter; import java.beans.PropertyChangeEvent; import java.beans.PropertyVetoException; +import javax.swing.ImageIcon; import javax.swing.JCheckBoxMenuItem; import javax.swing.JInternalFrame; import javax.swing.JPanel; @@ -58,6 +61,10 @@ import javax.swing.SwingUtilities; public class OverviewPanel extends JPanel implements Runnable, ViewportListenerI { + protected Image dragImage = new ImageIcon( + getClass().getResource("/images/dragcursor.png")) + .getImage(); + private OverviewDimensions od; private OverviewCanvas oviewCanvas; @@ -113,6 +120,22 @@ public class OverviewPanel extends JPanel // without this the overview window does not size to fit the overview canvas setPreferredSize(new Dimension(od.getWidth(), od.getHeight())); + // set up custom cursor for use on Mac... + Point hotSpot = new Point(16, 16); + String cursorName = "Custom drag cursor"; + + Cursor tempCursor; + if (Platform.isAMac()) + { + tempCursor = getToolkit().createCustomCursor(dragImage, hotSpot, + cursorName); + } + else + { + tempCursor = Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR); + } + final Cursor dragCursor = tempCursor; + addComponentListener(new ComponentAdapter() { @Override @@ -173,14 +196,16 @@ public class OverviewPanel extends JPanel if (od.isPositionInBox(evt.getX(), evt.getY())) { // display drag cursor at mouse position - setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); + getParent().setCursor(dragCursor); } else { // reset cursor - setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + getParent().setCursor( + Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } } + }); addMouseListener(new MouseAdapter() @@ -224,6 +249,18 @@ public class OverviewPanel extends JPanel { showPopupMenu(evt); } + // click in box should also reset the cursor + else if (od.isPositionInBox(evt.getX(), evt.getY())) + { + // display drag cursor at mouse position + getParent().setCursor(dragCursor); + } + else + { + // reset cursor + getParent().setCursor( + Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + } } }); }