Browse Source

Decreased sensitivity for DnD to start in TabFrames.

pull/15/head
weisj 5 years ago
parent
commit
ee7e41b7d6
  1. 9
      src/main/java/com/weis/darklaf/ui/tabframe/DarkTabFrameTabContainerUI.java
  2. 5
      src/main/java/com/weis/darklaf/ui/tabframe/DarkTabFrameTabLabelUI.java
  3. 19
      src/main/java/com/weis/darklaf/ui/tabframe/TabDragListener.java

9
src/main/java/com/weis/darklaf/ui/tabframe/DarkTabFrameTabContainerUI.java

@ -38,7 +38,6 @@ import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
@ -54,7 +53,7 @@ public class DarkTabFrameTabContainerUI extends DarkPanelUI implements PropertyC
}
}
};
private MouseMotionListener dragListener;
private TabDragListener dragListener;
private HoverListener hoverListener;
private Color selectedColor;
private Color hoverColor;
@ -81,11 +80,13 @@ public class DarkTabFrameTabContainerUI extends DarkPanelUI implements PropertyC
tabContainer.addMouseListener(hoverListener);
tabContainer.addPropertyChangeListener(this);
tabContainer.addMouseListener(mouseListener);
tabContainer.addMouseListener(dragListener);
tabContainer.addMouseMotionListener(dragListener);
var cont = tabContainer.getContent();
if (cont != null) {
cont.addMouseListener(hoverListener);
cont.addMouseListener(mouseListener);
cont.addMouseListener(dragListener);
cont.addMouseMotionListener(dragListener);
}
}
@ -131,12 +132,14 @@ public class DarkTabFrameTabContainerUI extends DarkPanelUI implements PropertyC
protected void uninstallListeners() {
tabContainer.removeMouseListener(hoverListener);
tabContainer.removeMouseListener(mouseListener);
tabContainer.removeMouseListener(dragListener);
tabContainer.removePropertyChangeListener(this);
tabContainer.removeMouseMotionListener(dragListener);
var cont = tabContainer.getContent();
if (cont != null) {
cont.removeMouseListener(hoverListener);
cont.removeMouseListener(mouseListener);
cont.removeMouseListener(dragListener);
cont.removeMouseMotionListener(dragListener);
}
dragListener = null;
@ -166,11 +169,13 @@ public class DarkTabFrameTabContainerUI extends DarkPanelUI implements PropertyC
if (oldVal instanceof Component) {
((Component) oldVal).removeMouseListener(mouseListener);
((Component) oldVal).removeMouseListener(hoverListener);
((Component) oldVal).removeMouseListener(dragListener);
((Component) oldVal).removeMouseMotionListener(dragListener);
}
if (newVal instanceof Component) {
((Component) newVal).addMouseListener(mouseListener);
((Component) newVal).addMouseListener(hoverListener);
((Component) newVal).addMouseListener(dragListener);
((Component) newVal).addMouseMotionListener(dragListener);
}
} else if ("selected".equals(key)) {

5
src/main/java/com/weis/darklaf/ui/tabframe/DarkTabFrameTabLabelUI.java

@ -44,7 +44,6 @@ import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
@ -60,7 +59,7 @@ public class DarkTabFrameTabLabelUI extends DarkLabelUI implements PropertyChang
}
}
};
private MouseMotionListener dragListener;
private TabDragListener dragListener;
private HoverListener hoverListener;
private Color defaultFontColor;
private Color selectedFontColor;
@ -153,6 +152,7 @@ public class DarkTabFrameTabLabelUI extends DarkLabelUI implements PropertyChang
tabComponent.addMouseListener(mouseListener);
installAccelerator(tabComponent.getTabFrame());
tabComponent.addMouseMotionListener(dragListener);
tabComponent.addMouseListener(dragListener);
}
@Override
@ -162,6 +162,7 @@ public class DarkTabFrameTabLabelUI extends DarkLabelUI implements PropertyChang
tabComponent.removeMouseListener(mouseListener);
uninstallAccelerator(tabComponent.getTabFrame());
tabComponent.removeMouseMotionListener(dragListener);
tabComponent.removeMouseListener(dragListener);
dragListener = null;
}

19
src/main/java/com/weis/darklaf/ui/tabframe/TabDragListener.java

@ -30,6 +30,7 @@ import org.jdesktop.jxlayer.JXLayer;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
@ -41,8 +42,22 @@ public class TabDragListener extends MouseAdapter {
this.tabComponent = tabComponent;
}
protected Point origin;
@Override
public void mousePressed(@NotNull final MouseEvent e) {
origin = e.getPoint();
}
@Override
public void mouseReleased(final MouseEvent e) {
origin = null;
}
@Override
public void mouseDragged(@NotNull final MouseEvent e) {
if (origin == null) origin = e.getPoint();
if (distance(origin, e.getPoint()) < 100) return;
var th = tabComponent.getTabFrame().getTransferHandler();
if (th != null && tabComponent.getTabFrame().isDndEnabled()) {
var p = e.getPoint();
@ -57,4 +72,8 @@ public class TabDragListener extends MouseAdapter {
TransferHandler.MOVE);
}
}
protected int distance(@NotNull final Point p1, @NotNull final Point p2) {
return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y);
}
}

Loading…
Cancel
Save