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.event.ChangeEvent;
import javax.swing.plaf.UIResource; import javax.swing.plaf.UIResource;
import java.awt.*; import java.awt.*;
import java.awt.dnd.DropTarget;
import java.awt.event.ContainerEvent; import java.awt.event.ContainerEvent;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
@ -108,7 +109,8 @@ public class DarkHandler extends TabbedPaneHandler {
ui.tabPane.doLayout(); ui.tabPane.doLayout();
} else if (DarkTabbedPaneUI.KEY_DND.equals(key)) { } else if (DarkTabbedPaneUI.KEY_DND.equals(key)) {
ui.dndEnabled = Boolean.TRUE.equals(ui.tabPane.getClientProperty(DarkTabbedPaneUI.KEY_DND)); 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)) { } else if (PropertyKey.COMPONENT_ORIENTATION.equals(key)) {
ui.tabPane.doLayout(); ui.tabPane.doLayout();
ui.tabPane.repaint(); 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.ComponentUI;
import javax.swing.plaf.UIResource; import javax.swing.plaf.UIResource;
import java.awt.*; import java.awt.*;
import java.awt.dnd.DropTarget;
import java.awt.event.AWTEventListener; import java.awt.event.AWTEventListener;
import java.awt.event.FocusEvent; import java.awt.event.FocusEvent;
import java.awt.event.FocusListener; import java.awt.event.FocusListener;
@ -147,8 +148,11 @@ public class DarkTabbedPaneUI extends DarkTabbedPaneUIBridge {
protected void installDragSupport() { protected void installDragSupport() {
tabPane.setTransferHandler(TRANSFER_HANDLER); tabPane.setTransferHandler(TRANSFER_HANDLER);
try { try {
tabPane.getDropTarget().addDropTargetListener(TRANSFER_HANDLER); DropTarget target = tabPane.getDropTarget();
tabPane.getDropTarget().setActive(dndEnabled); if (target != null) {
target.addDropTargetListener(TRANSFER_HANDLER);
target.setActive(dndEnabled);
}
} catch (TooManyListenersException e) { } catch (TooManyListenersException e) {
e.printStackTrace(); 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.*;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
import java.awt.*; import java.awt.*;
import java.awt.dnd.DropTarget;
import java.awt.event.AWTEventListener; import java.awt.event.AWTEventListener;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.util.List; import java.util.List;
@ -144,8 +145,11 @@ public class DarkTabFrameUI extends TabFrameUI implements AWTEventListener {
protected void installDnD() { protected void installDnD() {
tabFrame.setTransferHandler(TRANSFER_HANDLER); tabFrame.setTransferHandler(TRANSFER_HANDLER);
try { try {
tabFrame.getDropTarget().addDropTargetListener(TRANSFER_HANDLER); DropTarget dropTarget = tabFrame.getDropTarget();
tabFrame.getDropTarget().setActive(tabFrame.isDndEnabled()); if (dropTarget != null) {
dropTarget.addDropTargetListener(TRANSFER_HANDLER);
dropTarget.setActive(tabFrame.isDndEnabled());
}
} catch (TooManyListenersException e) { } catch (TooManyListenersException e) {
e.printStackTrace(); e.printStackTrace();
} }

Loading…
Cancel
Save