Browse Source

Fixed NPE when trying to access drop target in headless mode.

Fixes #119
pull/127/head
weisj 5 years ago
parent
commit
e54846d27c
  1. 4
      core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkHandler.java
  2. 8
      core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneUI.java
  3. 8
      core/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabFrameUI.java

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

@ -29,6 +29,7 @@ import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.plaf.UIResource;
import java.awt.*;
import java.awt.dnd.DropTarget;
import java.awt.event.ContainerEvent;
import java.awt.event.MouseEvent;
import java.beans.PropertyChangeEvent;
@ -108,7 +109,8 @@ public class DarkHandler extends TabbedPaneHandler {
ui.tabPane.doLayout();
} else if (DarkTabbedPaneUI.KEY_DND.equals(key)) {
ui.dndEnabled = Boolean.TRUE.equals(ui.tabPane.getClientProperty(DarkTabbedPaneUI.KEY_DND));
ui.tabPane.getDropTarget().setActive(ui.dndEnabled);
DropTarget dropTarget = ui.tabPane.getDropTarget();
if (dropTarget != null) dropTarget.setActive(ui.dndEnabled);
} else if (PropertyKey.COMPONENT_ORIENTATION.equals(key)) {
ui.tabPane.doLayout();
ui.tabPane.repaint();

8
core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneUI.java

@ -32,6 +32,7 @@ import javax.swing.*;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.UIResource;
import java.awt.*;
import java.awt.dnd.DropTarget;
import java.awt.event.AWTEventListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
@ -147,8 +148,11 @@ public class DarkTabbedPaneUI extends DarkTabbedPaneUIBridge {
protected void installDragSupport() {
tabPane.setTransferHandler(TRANSFER_HANDLER);
try {
tabPane.getDropTarget().addDropTargetListener(TRANSFER_HANDLER);
tabPane.getDropTarget().setActive(dndEnabled);
DropTarget target = tabPane.getDropTarget();
if (target != null) {
target.addDropTargetListener(TRANSFER_HANDLER);
target.setActive(dndEnabled);
}
} catch (TooManyListenersException e) {
e.printStackTrace();
}

8
core/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabFrameUI.java

@ -35,6 +35,7 @@ import org.pbjar.jxlayer.plaf.ext.transform.TransformUtils;
import javax.swing.*;
import javax.swing.plaf.ComponentUI;
import java.awt.*;
import java.awt.dnd.DropTarget;
import java.awt.event.AWTEventListener;
import java.awt.event.MouseEvent;
import java.util.List;
@ -144,8 +145,11 @@ public class DarkTabFrameUI extends TabFrameUI implements AWTEventListener {
protected void installDnD() {
tabFrame.setTransferHandler(TRANSFER_HANDLER);
try {
tabFrame.getDropTarget().addDropTargetListener(TRANSFER_HANDLER);
tabFrame.getDropTarget().setActive(tabFrame.isDndEnabled());
DropTarget dropTarget = tabFrame.getDropTarget();
if (dropTarget != null) {
dropTarget.addDropTargetListener(TRANSFER_HANDLER);
dropTarget.setActive(tabFrame.isDndEnabled());
}
} catch (TooManyListenersException e) {
e.printStackTrace();
}

Loading…
Cancel
Save