Browse Source

Make sure position provided by ToolTipUtil has the highest priority.

Don't show cell hint if only part of the border is obscured.
pull/198/head
weisj 4 years ago
parent
commit
2234c0dd20
  1. 5
      core/src/main/java/com/github/weisj/darklaf/ui/DarkPopupFactory.java
  2. 15
      core/src/main/java/com/github/weisj/darklaf/ui/cell/hint/CellHintPopupListener.java
  3. 1
      core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFilePane.java
  4. 10
      core/src/main/java/com/github/weisj/darklaf/ui/tooltip/ToolTipUtil.java

5
core/src/main/java/com/github/weisj/darklaf/ui/DarkPopupFactory.java

@ -84,8 +84,9 @@ public class DarkPopupFactory extends PopupFactory {
window = DarkUIUtil.getWindow(contents);
}
if (window != null) {
Window finalWindow = window;
SwingUtilities.invokeLater(() -> finalWindow.setLocation(x, y));
Window w = window;
w.setLocation(x, y);
SwingUtilities.invokeLater(() -> w.setLocation(x, y));
}
}
return new Pair<>(popup, type);

15
core/src/main/java/com/github/weisj/darklaf/ui/cell/hint/CellHintPopupListener.java

@ -29,6 +29,7 @@ import java.awt.event.MouseEvent;
import java.util.Objects;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.event.MouseInputAdapter;
import com.github.weisj.darklaf.graphics.PaintUtil;
@ -97,6 +98,15 @@ public class CellHintPopupListener<T extends JComponent, I> extends MouseInputAd
final Dimension prefSize = isEditing
? comp.getBounds().getSize()
: comp.getPreferredSize();
if (comp instanceof JComponent) {
// Avoid showing the popup if only the border is obscured.
Border border = ((JComponent) comp).getBorder();
if (border != null) {
Insets borderInsets = border.getBorderInsets(comp);
prefSize.width -= borderInsets.left + borderInsets.right;
prefSize.height -= borderInsets.top + borderInsets.bottom;
}
}
if (!(visibleBounds.width >= prefSize.width && visibleBounds.height >= prefSize.height)) {
Point popupLocation = cellContainer.getComponent().getLocationOnScreen();
Rectangle rect = calculatePopupBounds(cellBounds, visibleBounds, !isEditing);
@ -105,6 +115,9 @@ public class CellHintPopupListener<T extends JComponent, I> extends MouseInputAd
cellBounds.y = rect.y - cellBounds.y;
rect.x += popupLocation.x;
rect.y += popupLocation.y;
System.out.println("Allocation " + allocation);
System.out.println("CellBounds " + cellBounds);
System.out.println("PreffeSize " + prefSize);
enter(index, rect, cellBounds);
return;
} else {
@ -228,7 +241,7 @@ public class CellHintPopupListener<T extends JComponent, I> extends MouseInputAd
popup.show();
if (DarkPopupFactory.getPopupType(popup) == DarkPopupFactory.PopupType.HEAVY_WEIGHT) {
// Ensure heavy weight popup is at desired location.
movePopup(bounds);
SwingUtilities.invokeLater(() -> movePopup(bounds));
}
}
}

1
core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFilePane.java

@ -43,7 +43,6 @@ import javax.swing.text.Position;
import sun.swing.SwingUtilities2;
import com.github.weisj.darklaf.components.OverlayScrollPane;
import com.github.weisj.darklaf.ui.list.DarkListCellRendererDelegate;
import com.github.weisj.darklaf.ui.table.DarkTableUI;
import com.github.weisj.darklaf.ui.table.TextTableCellEditorBorder;
import com.github.weisj.darklaf.ui.text.DarkTextUI;

10
core/src/main/java/com/github/weisj/darklaf/ui/tooltip/ToolTipUtil.java

@ -28,9 +28,11 @@ import java.awt.*;
import java.util.function.BiConsumer;
import javax.swing.*;
import javax.swing.event.AncestorEvent;
import com.github.weisj.darklaf.components.tooltip.ToolTipContext;
import com.github.weisj.darklaf.components.tooltip.ToolTipStyle;
import com.github.weisj.darklaf.listener.AncestorAdapter;
import com.github.weisj.darklaf.util.Alignment;
import com.github.weisj.darklaf.util.DarkUIUtil;
@ -180,6 +182,12 @@ public class ToolTipUtil {
Point p = new Point(x, y);
SwingUtilities.convertPointToScreen(p, target);
window.setLocation(p);
SwingUtilities.invokeLater(() -> window.setLocation(p));
toolTip.addAncestorListener(new AncestorAdapter() {
@Override
public void ancestorAdded(final AncestorEvent event) {
window.setLocation(p.x, p.y);
toolTip.removeAncestorListener(this);
}
});
}
}

Loading…
Cancel
Save