Browse Source

Everywhere: Remove calls to internal API SwingUtilities2::loc2IndexFileList.

pull/245/head
weisj 4 years ago
parent
commit
164a9f6b13
No known key found for this signature in database
GPG Key ID: 31124CB75461DA2A
  1. 7
      core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUIBridge.java
  2. 29
      core/src/main/java/com/github/weisj/darklaf/util/SwingUtil.java

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

@ -37,7 +37,6 @@ import javax.swing.plaf.basic.BasicListUI;
import javax.swing.text.Position; import javax.swing.text.Position;
import sun.swing.DefaultLookup; import sun.swing.DefaultLookup;
import sun.swing.SwingUtilities2;
import sun.swing.UIAction; import sun.swing.UIAction;
import com.github.weisj.darklaf.ui.BasicTransferable; import com.github.weisj.darklaf.ui.BasicTransferable;
@ -2479,7 +2478,7 @@ public abstract class DarkListUIBridge extends BasicListUI {
// different behavior if drag is enabled // different behavior if drag is enabled
if (dragEnabled) { if (dragEnabled) {
int row = SwingUtilities2.loc2IndexFileList(list, e.getPoint()); int row = SwingUtil.loc2IndexFileList(list, e.getPoint());
// if we have a valid row and this is a drag initiating event // if we have a valid row and this is a drag initiating event
if (row != -1 && DragRecognitionSupport.mousePressed(e)) { if (row != -1 && DragRecognitionSupport.mousePressed(e)) {
dragPressDidSelection = false; dragPressDidSelection = false;
@ -2520,7 +2519,7 @@ public abstract class DarkListUIBridge extends BasicListUI {
* @param e the e * @param e the e
*/ */
protected void adjustSelection(final MouseEvent e) { protected void adjustSelection(final MouseEvent e) {
int row = SwingUtilities2.loc2IndexFileList(list, e.getPoint()); int row = SwingUtil.loc2IndexFileList(list, e.getPoint());
if (row < 0) { if (row < 0) {
// If shift is down in multi-select, we should do nothing. // If shift is down in multi-select, we should do nothing.
// For single select or non-shift-click, clear the selection // For single select or non-shift-click, clear the selection
@ -2586,7 +2585,7 @@ public abstract class DarkListUIBridge extends BasicListUI {
public void dragStarting(final MouseEvent me) { public void dragStarting(final MouseEvent me) {
if (DarkUIUtil.isMenuShortcutKeyDown(me)) { if (DarkUIUtil.isMenuShortcutKeyDown(me)) {
int row = SwingUtilities2.loc2IndexFileList(list, me.getPoint()); int row = SwingUtil.loc2IndexFileList(list, me.getPoint());
list.addSelectionInterval(row, row); list.addSelectionInterval(row, row);
} }
} }

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

@ -33,13 +33,16 @@ import java.awt.Rectangle;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JList;
import javax.swing.JTable; import javax.swing.JTable;
import javax.swing.ListCellRenderer;
import javax.swing.ListSelectionModel; import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.table.TableCellRenderer; import javax.swing.table.TableCellRenderer;
import sun.swing.SwingUtilities2; import sun.swing.SwingUtilities2;
public final class SwingUtil { public final class SwingUtil {
private SwingUtil() {} private SwingUtil() {}
@ -182,4 +185,30 @@ public final class SwingUtil {
return false; return false;
} }
} }
public static int loc2IndexFileList(final JList<?> list, final Point point) {
int index = list.locationToIndex(point);
if (index != -1) {
boolean bySize = PropertyUtil.getBooleanProperty(list, "List.isFileList");
if (bySize && !pointIsInActualBounds(list, index, point)) {
index = -1;
}
}
return index;
}
private static <T> boolean pointIsInActualBounds(final JList<T> list, int index, final Point point) {
ListCellRenderer<? super T> renderer = list.getCellRenderer();
T value = list.getModel().getElementAt(index);
Component item = renderer.getListCellRendererComponent(list,
value, index, false, false);
Dimension itemSize = item.getPreferredSize();
Rectangle cellBounds = list.getCellBounds(index, index);
if (!item.getComponentOrientation().isLeftToRight()) {
cellBounds.x += (cellBounds.width - itemSize.width);
}
cellBounds.width = itemSize.width;
return cellBounds.contains(point);
}
} }

Loading…
Cancel
Save