Browse Source

Ensure decorations are uninstalled if previously displayed heavy weight popup is reused and decorations have been disabled meanwhile.

Ensure cell popup location is calculated correctly if decorations are disabled and the popup is mediumweight or lightweight.
pull/214/head
weisj 4 years ago
parent
commit
12271e32ff
  1. 4
      core/src/main/java/com/github/weisj/darklaf/ui/DarkPopupFactory.java
  2. 29
      core/src/main/java/com/github/weisj/darklaf/ui/cell/hint/CellHintPopupListener.java
  3. 12
      core/src/main/java/com/github/weisj/darklaf/ui/tooltip/ToolTipUtil.java
  4. 14
      core/src/main/java/com/github/weisj/darklaf/ui/tree/TreeRendererComponent.java
  5. 48
      core/src/main/java/com/github/weisj/darklaf/util/WindowUtil.java

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

@ -163,14 +163,12 @@ public class DarkPopupFactory extends PopupFactory {
*/ */
rootPane.putClientProperty("Window.shadow", !noDecorations); rootPane.putClientProperty("Window.shadow", !noDecorations);
} }
if (DecorationsHandler.getSharedInstance().isCustomDecorationSupported()) {
if (noDecorations) { if (noDecorations) {
DecorationsHandler.getSharedInstance().uninstallPopupWindow(window); DecorationsHandler.getSharedInstance().uninstallPopupWindow(window);
} else { } else if (DecorationsHandler.getSharedInstance().isCustomDecorationSupported()) {
DecorationsHandler.getSharedInstance().installPopupWindow(window); DecorationsHandler.getSharedInstance().installPopupWindow(window);
} }
} }
}
protected void setupWindowOpacity(final boolean startHidden, final Window window) { protected void setupWindowOpacity(final boolean startHidden, final Window window) {
boolean translucencySupported = DarkUIUtil.supportsTransparency(window); boolean translucencySupported = DarkUIUtil.supportsTransparency(window);

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

@ -35,6 +35,7 @@ import javax.swing.event.MouseInputAdapter;
import com.github.weisj.darklaf.graphics.PaintUtil; import com.github.weisj.darklaf.graphics.PaintUtil;
import com.github.weisj.darklaf.ui.DarkPopupFactory; import com.github.weisj.darklaf.ui.DarkPopupFactory;
import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.WindowUtil;
public class CellHintPopupListener<T extends JComponent, I> extends MouseInputAdapter { public class CellHintPopupListener<T extends JComponent, I> extends MouseInputAdapter {
@ -109,18 +110,19 @@ public class CellHintPopupListener<T extends JComponent, I> extends MouseInputAd
} }
if (!(visibleBounds.width >= prefSize.width && visibleBounds.height >= prefSize.height)) { if (!(visibleBounds.width >= prefSize.width && visibleBounds.height >= prefSize.height)) {
Point popupLocation = cellContainer.getComponent().getLocationOnScreen(); Point popupLocation = cellContainer.getComponent().getLocationOnScreen();
Rectangle rect = calculatePopupBounds(cellBounds, visibleBounds, !isEditing); Rectangle popupBounds = calculatePopupBounds(cellBounds, visibleBounds, !isEditing);
if (!visibleBounds.contains(rect)) { if (!visibleBounds.contains(popupBounds)) {
cellBounds.x = rect.x - cellBounds.x; cellBounds.x = popupBounds.x - cellBounds.x;
cellBounds.y = rect.y - cellBounds.y; cellBounds.y = popupBounds.y - cellBounds.y;
rect.x += popupLocation.x; popupBounds.x += popupLocation.x;
rect.y += popupLocation.y; popupBounds.y += popupLocation.y;
enter(index, rect, cellBounds); enter(index, popupBounds, cellBounds);
return; return;
} else { } else {
lastIndex = index; lastIndex = index;
} }
} }
leave();
return; return;
} }
} }
@ -238,7 +240,11 @@ public class CellHintPopupListener<T extends JComponent, I> extends MouseInputAd
popup.show(); popup.show();
if (DarkPopupFactory.getPopupType(popup) == DarkPopupFactory.PopupType.HEAVY_WEIGHT) { if (DarkPopupFactory.getPopupType(popup) == DarkPopupFactory.PopupType.HEAVY_WEIGHT) {
// Ensure heavy weight popup is at desired location. // Ensure heavy weight popup is at desired location.
SwingUtilities.invokeLater(() -> movePopup(bounds)); SwingUtilities.invokeLater(() -> {
Window w = DarkUIUtil.getWindow(popupComponent);
w.setBounds(bounds);
WindowUtil.moveWindow(w, popupComponent, bounds.x, bounds.y);
});
} }
} }
} }
@ -264,17 +270,19 @@ public class CellHintPopupListener<T extends JComponent, I> extends MouseInputAd
popup = null; popup = null;
} else { } else {
popupWindow.setBounds(bounds); popupWindow.setBounds(bounds);
WindowUtil.moveWindow(popupWindow, popupComponent, bounds.x, bounds.y);
} }
} }
private void moveMediumLightWeightPopup(final Rectangle bounds, final Window parentWindow) { private void moveMediumLightWeightPopup(final Rectangle bounds, final Window parentWindow) {
JLayeredPane layeredPane = ((RootPaneContainer) parentWindow).getLayeredPane(); JLayeredPane layeredPane = ((RootPaneContainer) parentWindow).getLayeredPane();
JRootPane rootPane = ((RootPaneContainer) parentWindow).getRootPane();
Component comp = DarkUIUtil.getParentBeforeMatching(popupComponent.getParent(), Component comp = DarkUIUtil.getParentBeforeMatching(popupComponent.getParent(),
c -> c == layeredPane); c -> c == layeredPane);
Rectangle windowBounds = parentWindow.getBounds(); Rectangle windowBounds = parentWindow.getBounds();
if (windowBounds.contains(bounds.x, bounds.y) if (windowBounds.contains(bounds.x, bounds.y)
&& windowBounds.contains(bounds.x + bounds.width, bounds.y + bounds.height)) { && windowBounds.contains(bounds.x + bounds.width, bounds.y + bounds.height)) {
Point windowPos = parentWindow.getLocationOnScreen(); Point windowPos = rootPane.getLocationOnScreen();
bounds.x -= windowPos.x; bounds.x -= windowPos.x;
bounds.y -= windowPos.y; bounds.y -= windowPos.y;
comp.setBounds(bounds); comp.setBounds(bounds);
@ -376,7 +384,8 @@ public class CellHintPopupListener<T extends JComponent, I> extends MouseInputAd
// If the renderer is an editor we need to restore the bounds. // If the renderer is an editor we need to restore the bounds.
Rectangle bounds = renderer.getBounds(); Rectangle bounds = renderer.getBounds();
renderer.setBounds(rendererBounds); renderer.setBounds(0, 0, rendererBounds.width, rendererBounds.height);
renderer.doLayout();
renderer.paint(g); renderer.paint(g);
renderer.setBounds(bounds); renderer.setBounds(bounds);

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

@ -28,13 +28,12 @@ import java.awt.*;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import javax.swing.*; import javax.swing.*;
import javax.swing.event.AncestorEvent;
import com.github.weisj.darklaf.components.tooltip.ToolTipContext; import com.github.weisj.darklaf.components.tooltip.ToolTipContext;
import com.github.weisj.darklaf.components.tooltip.ToolTipStyle; 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.Alignment;
import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.WindowUtil;
public class ToolTipUtil { public class ToolTipUtil {
@ -181,13 +180,6 @@ public class ToolTipUtil {
if (window == null) return; if (window == null) return;
Point p = new Point(x, y); Point p = new Point(x, y);
SwingUtilities.convertPointToScreen(p, target); SwingUtilities.convertPointToScreen(p, target);
window.setLocation(p); WindowUtil.moveWindow(window, toolTip, p.x, p.y);
toolTip.addAncestorListener(new AncestorAdapter() {
@Override
public void ancestorAdded(final AncestorEvent event) {
window.setLocation(p.x, p.y);
toolTip.removeAncestorListener(this);
}
});
} }
} }

14
core/src/main/java/com/github/weisj/darklaf/ui/tree/TreeRendererComponent.java

@ -33,6 +33,7 @@ import javax.swing.*;
*/ */
public class TreeRendererComponent extends Container { public class TreeRendererComponent extends Container {
private static final int PAD = 5;
private TreeRendererSupport defaultRenderer; private TreeRendererSupport defaultRenderer;
private Component renderComponent; private Component renderComponent;
@ -80,7 +81,7 @@ public class TreeRendererComponent extends Container {
public Dimension getPreferredSize() { public Dimension getPreferredSize() {
if (defaultRenderer != null) { if (defaultRenderer != null) {
Dimension pSize = renderComponent.getPreferredSize(); Dimension pSize = renderComponent.getPreferredSize();
pSize.width += getOffset() + 5; pSize.width += getOffset() + PAD;
Dimension rSize = defaultRenderer.getPreferredSize(); Dimension rSize = defaultRenderer.getPreferredSize();
@ -98,6 +99,9 @@ public class TreeRendererComponent extends Container {
@Override @Override
public void paint(final Graphics g) { public void paint(final Graphics g) {
g.setColor(getBackground());
g.fillRect(0, 0, getWidth(), getHeight());
int width = getWidth(); int width = getWidth();
Icon icon = defaultRenderer.getIcon(); Icon icon = defaultRenderer.getIcon();
@ -111,7 +115,7 @@ public class TreeRendererComponent extends Container {
icon.paintIcon(this, g, width - icon.getIconWidth(), yLoc); icon.paintIcon(this, g, width - icon.getIconWidth(), yLoc);
} }
} }
super.paint(g); if (renderComponent != null) renderComponent.paint(g);
} }
/** /**
@ -127,6 +131,12 @@ public class TreeRendererComponent extends Container {
return getHeight() / 2 - (totalY + (totalHeight / 2)); return getHeight() / 2 - (totalY + (totalHeight / 2));
} }
@Override
public void setFont(final Font f) {
super.setFont(f);
if (renderComponent != null) renderComponent.setFont(f);
}
@Override @Override
public void setForeground(final Color c) { public void setForeground(final Color c) {
super.setForeground(c); super.setForeground(c);

48
core/src/main/java/com/github/weisj/darklaf/util/WindowUtil.java

@ -0,0 +1,48 @@
/*
* MIT License
*
* Copyright (c) 2020 Jannis Weis
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
package com.github.weisj.darklaf.util;
import java.awt.*;
import javax.swing.*;
import javax.swing.event.AncestorEvent;
import com.github.weisj.darklaf.listener.AncestorAdapter;
public class WindowUtil {
public static void moveWindow(final Window w, final JComponent content, final int x, final int y) {
w.setLocation(x, y);
if (!w.isVisible()) {
content.addAncestorListener(new AncestorAdapter() {
@Override
public void ancestorAdded(final AncestorEvent event) {
w.setLocation(x, y);
content.removeAncestorListener(this);
}
});
}
}
}
Loading…
Cancel
Save