Browse Source

Provide more descriptive error messages when the window isn't displayable

pull/323/head v3.0.0-rc1
Jannis Weis 3 years ago
parent
commit
880ad6d681
No known key found for this signature in database
GPG Key ID: 7C9D8D4B558049AB
  1. 6
      macos/src/main/java/com/github/weisj/darklaf/platform/macos/MacOSDecorationsProvider.java
  2. 2
      macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/MacOSTitlePane.java
  3. 3
      platform-decorations/src/main/java/com/github/weisj/darklaf/platform/decorations/NativeDecorationsManager.java

6
macos/src/main/java/com/github/weisj/darklaf/platform/macos/MacOSDecorationsProvider.java

@ -67,7 +67,11 @@ public class MacOSDecorationsProvider implements DecorationsProvider {
public TitlePaneLayoutInfo titlePaneLayoutInfo(final CustomTitlePane customTitlePane) {
if (!(customTitlePane instanceof MacOSTitlePane)) throw new IllegalStateException();
long hwnd = ((MacOSTitlePane) customTitlePane).windowHandle();
if (hwnd == 0) return new TitlePaneLayoutInfo(new Rectangle(0, 0, -1, -1));
if (hwnd == 0) {
throw new IllegalStateException(
"Window isn't displayable (but has to in order to compute the title pane layout."
+ " If you need this information before the window is displayed call `frame.addNotify()` to make it displayable.");
}
float[] b = JNIDecorationsMacOS.windowButtonRect(((MacOSTitlePane) customTitlePane).windowHandle());
return new TitlePaneLayoutInfo(new Rectangle((int) b[0], (int) b[1], (int) b[2], (int) b[3]));
}

2
macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/MacOSTitlePane.java

@ -200,7 +200,7 @@ public class MacOSTitlePane extends CustomTitlePane {
}
public long windowHandle() {
return decorationInformation.windowHandle;
return decorationInformation != null ? decorationInformation.windowHandle : 0;
}
protected class RootPanePropertyChangeListener implements PropertyChangeListener {

3
platform-decorations/src/main/java/com/github/weisj/darklaf/platform/decorations/NativeDecorationsManager.java

@ -119,7 +119,8 @@ public class NativeDecorationsManager {
public TitlePaneLayoutInfo titlePaneLayoutInfo(final JRootPane rootPane) {
RootPaneUI ui = rootPane.getUI();
if (!(ui instanceof AbstractNativeDecorationsRootPaneUI)) throw new IllegalStateException();
if (!(ui instanceof AbstractNativeDecorationsRootPaneUI))
throw new IllegalStateException("UI is not of type " + AbstractNativeDecorationsRootPaneUI.class);
return decorationsProvider.titlePaneLayoutInfo(((AbstractNativeDecorationsRootPaneUI) ui).titlePane());
}

Loading…
Cancel
Save