Browse Source

Everywhere: Move calls to internal API SwingUtilities2::setSkipClickCount to SwingUtil. Remove calls to internal API SwingUtilities2::setLeadAnchorWithoutSelection.

pull/245/head
weisj 4 years ago
parent
commit
4b11cc84b9
No known key found for this signature in database
GPG Key ID: 31124CB75461DA2A
  1. 6
      core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUIBridge.java
  2. 5
      core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableUI.java
  3. 12
      core/src/main/java/com/github/weisj/darklaf/ui/table/TableUIBridge.java
  4. 76
      core/src/main/java/com/github/weisj/darklaf/util/SwingUtil.java
  5. 4
      core/src/main/java/javax/swing/text/DefaultHighlighterDark/DarkHighlightPainter.java

6
core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUIBridge.java

@ -1913,7 +1913,7 @@ public abstract class DarkListUIBridge extends BasicListUI {
list.setSelectionInterval(0, size - 1);
// this is done to restore the anchor and lead
SwingUtilities2.setLeadAnchorWithoutSelection(lsm, anchor, lead);
SwingUtil.setLeadAnchorWithoutSelection(lsm, anchor, lead);
list.setValueIsAdjusting(false);
}
@ -2508,7 +2508,7 @@ public abstract class DarkListUIBridge extends BasicListUI {
}
if (grabFocus) {
SwingUtilities2.adjustFocus(list);
SwingUtil.adjustFocus(list);
}
adjustSelection(e);
@ -2570,7 +2570,7 @@ public abstract class DarkListUIBridge extends BasicListUI {
if (list.getDragEnabled()) {
MouseEvent me = DragRecognitionSupport.mouseReleased(e);
if (me != null) {
SwingUtilities2.adjustFocus(list);
SwingUtil.adjustFocus(list);
if (!dragPressDidSelection) {
adjustSelection(me);
}

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

@ -32,8 +32,6 @@ import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.UIResource;
import javax.swing.table.*;
import sun.swing.SwingUtilities2;
import com.github.weisj.darklaf.components.OverlayScrollPane;
import com.github.weisj.darklaf.graphics.PaintUtil;
import com.github.weisj.darklaf.ui.HasRendererPane;
@ -47,6 +45,7 @@ import com.github.weisj.darklaf.ui.table.renderer.DarkTableCellRendererDelegate;
import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.PropertyKey;
import com.github.weisj.darklaf.util.PropertyUtil;
import com.github.weisj.darklaf.util.SwingUtil;
/** @author Jannis Weis */
public class DarkTableUI extends DarkTableUIBridge implements TableConstants, HasRendererPane {
@ -498,7 +497,7 @@ public class DarkTableUI extends DarkTableUIBridge implements TableConstants, Ha
table.editCellAt(row, column, null);
Component editorComponent = table.getEditorComponent();
if (editorComponent != null && !editorComponent.hasFocus()) {
SwingUtilities2.compositeRequestFocus(editorComponent);
SwingUtil.compositeRequestFocus(editorComponent);
}
}

12
core/src/main/java/com/github/weisj/darklaf/ui/table/TableUIBridge.java

@ -581,7 +581,7 @@ public abstract class TableUIBridge extends BasicTableUI {
if (table.isEditing() && !table.getCellEditor().stopCellEditing()) {
Component editorComponent = table.getEditorComponent();
if (editorComponent != null && !editorComponent.hasFocus()) {
SwingUtilities2.compositeRequestFocus(editorComponent);
SwingUtil.compositeRequestFocus(editorComponent);
}
return;
}
@ -599,7 +599,7 @@ public abstract class TableUIBridge extends BasicTableUI {
if (table.getDragEnabled()) {
mousePressedDND(e);
} else {
SwingUtilities2.adjustFocus(table);
SwingUtil.adjustFocus(table);
if (!isFileList) {
setValueIsAdjusting(true);
}
@ -634,7 +634,7 @@ public abstract class TableUIBridge extends BasicTableUI {
protected void mouseReleasedDND(final MouseEvent e) {
MouseEvent me = DragRecognitionSupport.mouseReleased(e);
if (me != null) {
SwingUtilities2.adjustFocus(table);
SwingUtil.adjustFocus(table);
if (!dragPressDidSelection) {
adjustSelection(me);
}
@ -728,7 +728,7 @@ public abstract class TableUIBridge extends BasicTableUI {
Point p = e.getPoint();
Point p2 = SwingUtilities.convertPoint(table, p, editorComponent);
dispatchComponent = SwingUtilities.getDeepestComponentAt(editorComponent, p2.x, p2.y);
SwingUtilities2.setSkipClickCount(dispatchComponent, e.getClickCount() - 1);
SwingUtil.setSkipClickCount(dispatchComponent, e.getClickCount() - 1);
}
/**
@ -785,7 +785,7 @@ public abstract class TableUIBridge extends BasicTableUI {
}
if (grabFocus) {
SwingUtilities2.adjustFocus(table);
SwingUtil.adjustFocus(table);
}
adjustSelection(e);
@ -840,7 +840,7 @@ public abstract class TableUIBridge extends BasicTableUI {
table.editCellAt(pressedRow, pressedCol, null);
Component editorComponent = table.getEditorComponent();
if (editorComponent != null && !editorComponent.hasFocus()) {
SwingUtilities2.compositeRequestFocus(editorComponent);
SwingUtil.compositeRequestFocus(editorComponent);
}
}

76
core/src/main/java/com/github/weisj/darklaf/util/SwingUtil.java

@ -21,12 +21,16 @@
*/
package com.github.weisj.darklaf.util;
import java.awt.Component;
import java.awt.Container;
import java.awt.FocusTraversalPolicy;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import javax.swing.JComponent;
import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
import sun.swing.SwingUtilities2;
@ -35,6 +39,19 @@ public final class SwingUtil {
private SwingUtil() {}
public static void drawStringUnderlineCharAt(JComponent c, Graphics g,
String text, int underlinedIndex, int x, int y) {
SwingUtilities2.drawStringUnderlineCharAt(c, g, text, underlinedIndex, x, y);
}
public static void drawString(final JComponent c, final Graphics g, final String text, int x, int y) {
SwingUtilities2.drawString(c, g, text, x, y);
}
public static void setSkipClickCount(final Component comp, int count) {
SwingUtilities2.setSkipClickCount(comp, count);
}
public static FontMetrics getFontMetrics(final JComponent c, final Graphics g) {
if (g == null) throw new IllegalArgumentException("Graphics must not be null");
return getFontMetrics(c, g.getFont());
@ -49,15 +66,6 @@ public final class SwingUtil {
return c.getFontMetrics(font);
}
public static void drawStringUnderlineCharAt(JComponent c, Graphics g,
String text, int underlinedIndex, int x, int y) {
SwingUtilities2.drawStringUnderlineCharAt(c, g, text, underlinedIndex, x, y);
}
public static void drawString(final JComponent c, final Graphics g, final String text, int x, int y) {
SwingUtilities2.drawString(c, g, text, x, y);
}
public static int stringWidth(final JComponent c, final FontMetrics fm, final String string) {
return SwingUtilities2.stringWidth(c, fm, string);
}
@ -67,4 +75,54 @@ public final class SwingUtil {
|| !SwingUtilities.isLeftMouseButton(me)
|| me.isConsumed();
}
public static void adjustFocus(JComponent c) {
if (!c.hasFocus() && c.isRequestFocusEnabled()) {
c.requestFocus();
}
}
public static void compositeRequestFocus(final Component component) {
if (component instanceof Container) {
Container container = (Container) component;
if (container.isFocusCycleRoot()) {
FocusTraversalPolicy policy = container.getFocusTraversalPolicy();
Component comp = policy.getDefaultComponent(container);
if (comp != null) {
comp.requestFocus();
return;
}
}
Container rootAncestor = container.getFocusCycleRootAncestor();
if (rootAncestor != null) {
FocusTraversalPolicy policy = rootAncestor.getFocusTraversalPolicy();
Component comp = policy.getComponentAfter(rootAncestor, container);
if (comp != null && SwingUtilities.isDescendingFrom(comp, container)) {
comp.requestFocus();
return;
}
}
}
if (component.isFocusable()) {
component.requestFocus();
}
}
public static void setLeadAnchorWithoutSelection(final ListSelectionModel model, int lead, int anchor) {
if (anchor == -1) {
anchor = lead;
}
if (lead == -1) {
model.setAnchorSelectionIndex(-1);
model.setLeadSelectionIndex(-1);
} else {
if (model.isSelectedIndex(lead)) {
model.addSelectionInterval(lead, lead);
} else {
model.removeSelectionInterval(lead, lead);
}
model.setAnchorSelectionIndex(anchor);
}
}
}

4
core/src/main/java/javax/swing/text/DefaultHighlighterDark/DarkHighlightPainter.java

@ -31,8 +31,6 @@ import java.util.Objects;
import javax.swing.*;
import javax.swing.text.*;
import sun.swing.SwingUtilities2;
import com.github.weisj.darklaf.graphics.PaintUtil;
import com.github.weisj.darklaf.ui.text.StyleConstantsEx;
import com.github.weisj.darklaf.util.Alignment;
@ -42,7 +40,7 @@ import com.github.weisj.darklaf.util.graphics.GraphicsUtil;
/**
* Note this class only sits inside this weird package because of a hack used in
* {@link SwingUtilities2#useSelectedTextColor(Highlighter.Highlight, JTextComponent)} that makes it
* SwingUtilities2#useSelectedTextColor(Highlighter.Highlight, JTextComponent) that makes it
* impossible for custom highlighters to use the correct text foreground specified by
* {@link JTextComponent#getSelectedTextColor()}.
*

Loading…
Cancel
Save