Skip to content

Commit

Permalink
Everywhere: Remove calls to internal API SwingUtilities2::pointOutsid…
Browse files Browse the repository at this point in the history
…ePrefSize.
  • Loading branch information
weisJ committed May 18, 2021
1 parent e5a5bfd commit f8f12a0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
import javax.swing.text.JTextComponent;
import javax.swing.text.Position;

import sun.swing.SwingUtilities2;

import com.github.weisj.darklaf.components.OverlayScrollPane;
import com.github.weisj.darklaf.listener.AncestorAdapter;
import com.github.weisj.darklaf.ui.table.DarkTableUI;
Expand All @@ -50,6 +48,7 @@
import com.github.weisj.darklaf.ui.table.renderer.DarkTableCellEditorDelegate;
import com.github.weisj.darklaf.ui.text.DarkTextUI;
import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.SwingUtil;

public class DarkFilePane extends DarkFilePaneUIBridge {

Expand Down Expand Up @@ -420,8 +419,7 @@ public void mouseClicked(MouseEvent evt) {
Point p = evt.getPoint();
index = table.rowAtPoint(p);

boolean pointOutsidePrefSize =
SwingUtilities2.pointOutsidePrefSize(table, index, table.columnAtPoint(p), p);
boolean pointOutsidePrefSize = SwingUtil.pointOutsidePrefSize(table, index, table.columnAtPoint(p), p);

if (pointOutsidePrefSize && !fullRowSelection) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import javax.swing.table.TableColumn;

import sun.swing.DefaultLookup;
import sun.swing.SwingUtilities2;

import com.github.weisj.darklaf.ui.DragRecognitionSupport;
import com.github.weisj.darklaf.util.DarkUIUtil;
Expand Down Expand Up @@ -116,8 +115,7 @@ protected boolean pointOutsidePrefSize(final int row, final int column, final Po
if (!isFileList) {
return false;
}

return SwingUtilities2.pointOutsidePrefSize(table, row, column, p);
return SwingUtil.pointOutsidePrefSize(table, row, column, p);
}

//
Expand Down
25 changes: 25 additions & 0 deletions core/src/main/java/com/github/weisj/darklaf/util/SwingUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,20 @@

import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FocusTraversalPolicy;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;

import javax.swing.JComponent;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
import javax.swing.table.TableCellRenderer;

import sun.swing.SwingUtilities2;

Expand Down Expand Up @@ -130,4 +135,24 @@ public static void setLeadAnchorWithoutSelection(final ListSelectionModel model,
model.setAnchorSelectionIndex(anchor);
}
}

public static boolean pointOutsidePrefSize(JTable table, int row, int column, Point p) {
if (table.convertColumnIndexToModel(column) != 0 || row == -1) {
return true;
}
TableCellRenderer tcr = table.getCellRenderer(row, column);
Object value = table.getValueAt(row, column);
Component cell = tcr.getTableCellRendererComponent(table, value, false,
false, row, column);
Dimension itemSize = cell.getPreferredSize();
Rectangle cellBounds = table.getCellRect(row, column, false);
cellBounds.width = itemSize.width;
cellBounds.height = itemSize.height;

// See if coordinates are inside
// ASSUME: mouse x,y will never be < cell's x,y
assert (p.x >= cellBounds.x && p.y >= cellBounds.y);
return p.x > cellBounds.x + cellBounds.width ||
p.y > cellBounds.y + cellBounds.height;
}
}

0 comments on commit f8f12a0

Please sign in to comment.