Browse Source

Fixed type in native method.

Fixed table cell width adjustment.
Fixed table dragged background painting.

Signed-off-by: weisj <weisj@arcor.de>
pull/15/head
weisj 5 years ago
parent
commit
e6f9cf86b1
  1. 2
      src/jniplatform/cpp/JNIDecorations.cpp
  2. 47
      src/main/java/com/github/weisj/darklaf/ui/table/DarkTableUI.java
  3. 27
      src/main/java/com/github/weisj/darklaf/ui/table/TableUIBridge.java
  4. 2
      src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkTooltipUI.java
  5. BIN
      src/main/resources/com/github/weisj/darklaf/platform/windows/x64/jniplatform.dll
  6. BIN
      src/main/resources/com/github/weisj/darklaf/platform/windows/x86/jniplatform.dll
  7. 5
      src/test/java/UIManagerDefaults.java

2
src/jniplatform/cpp/JNIDecorations.cpp

@ -120,7 +120,7 @@ LRESULT CALLBACK WindowWrapper::WindowProc(_In_ HWND hwnd, _In_ UINT uMsg, _In_
} }
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
JJava_com_github_weisj_darklaf_platform_windows_JNIDecorations_setResizable(JNIEnv *env, jclass obj, jlong hwnd, jboolean res) Java_com_github_weisj_darklaf_platform_windows_JNIDecorations_setResizable(JNIEnv *env, jclass obj, jlong hwnd, jboolean res)
{ {
HWND handle = reinterpret_cast<HWND>(hwnd); HWND handle = reinterpret_cast<HWND>(hwnd);
auto wrap = wrapper_map[handle]; auto wrap = wrapper_map[handle];

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

@ -23,6 +23,7 @@
*/ */
package com.github.weisj.darklaf.ui.table; package com.github.weisj.darklaf.ui.table;
import com.github.weisj.darklaf.components.OverlayScrollPane;
import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.DarkUIUtil;
import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -170,6 +171,7 @@ public class DarkTableUI extends DarkTableUIBridge {
selectionBackground = UIManager.getColor("Table.selectionNoFocusBackground"); selectionBackground = UIManager.getColor("Table.selectionNoFocusBackground");
} }
@Override @Override
protected void paintGrid(@NotNull final Graphics g, protected void paintGrid(@NotNull final Graphics g,
final int rMin, final int rMax, final int cMin, final int cMax) { final int rMin, final int rMax, final int cMin, final int cMax) {
@ -240,11 +242,9 @@ public class DarkTableUI extends DarkTableUIBridge {
} }
protected boolean scrollBarVisible() { protected boolean scrollBarVisible() {
Container comp = SwingUtilities.getUnwrappedParent(table); JScrollPane comp = DarkUIUtil.getParentOfType(JScrollPane.class, table);
if (comp != null) { return comp != null && comp.getVerticalScrollBar().isVisible()
comp = comp.getParent(); && DarkUIUtil.getParentOfType(OverlayScrollPane.class, table) == null;
}
return comp instanceof JScrollPane && ((JScrollPane) comp).getVerticalScrollBar().isVisible();
} }
protected boolean showVerticalLine(final boolean ltr, final boolean scrollVisible, protected boolean showVerticalLine(final boolean ltr, final boolean scrollVisible,
@ -336,16 +336,14 @@ public class DarkTableUI extends DarkTableUIBridge {
} }
} }
} }
if (table.isEditing() && table.getEditingRow() == row && if (table.isEditing() && table.getEditingRow() == row && table.getEditingColumn() == column) {
table.getEditingColumn() == column) {
Component component = table.getEditorComponent(); Component component = table.getEditorComponent();
component.setBounds(cellRect); component.setBounds(r);
component.validate(); component.validate();
} else { } else {
TableCellRenderer renderer = table.getCellRenderer(row, column); TableCellRenderer renderer = table.getCellRenderer(row, column);
Component component = table.prepareRenderer(renderer, row, column); Component component = table.prepareRenderer(renderer, row, column);
rendererPane.paintComponent(g, component, table, cellRect.x, cellRect.y, rendererPane.paintComponent(g, component, table, r.x, r.y, r.width, r.height, true);
cellRect.width, cellRect.height, true);
} }
} }
@ -370,31 +368,28 @@ public class DarkTableUI extends DarkTableUIBridge {
parent = par.getParent(); parent = par.getParent();
} }
} }
int tableHeight = getPreferredSize(table).height;
g.setColor(parent.getBackground()); g.setColor(parent.getBackground());
g.fillRect(vacatedColumnRect.x, vacatedColumnRect.y, g.fillRect(vacatedColumnRect.x, 0, vacatedColumnRect.width - 1, tableHeight);
vacatedColumnRect.width - 1, vacatedColumnRect.height);
// Move to the where the cell has been dragged. // Move to the where the cell has been dragged.
vacatedColumnRect.x += dist; vacatedColumnRect.x += dist;
boolean scrollVisible = scrollBarVisible();
boolean drawBottomBorder = !table.getShowHorizontalLines() && !scrollVisible && table.getShowVerticalLines();
boolean ltr = table.getComponentOrientation().isLeftToRight(); boolean ltr = table.getComponentOrientation().isLeftToRight();
// Fill the background. // Fill the background.
g.setColor(table.getBackground()); g.setColor(table.getBackground());
g.fillRect(vacatedColumnRect.x, vacatedColumnRect.y, g.fillRect(vacatedColumnRect.x, 0, vacatedColumnRect.width, tableHeight);
vacatedColumnRect.width, vacatedColumnRect.height);
// Paint the vertical grid lines if necessary. // Paint the vertical grid lines if necessary.
if (table.getShowVerticalLines()) { if (table.getShowVerticalLines()) {
g.setColor(table.getGridColor()); g.setColor(table.getGridColor());
int x1 = vacatedColumnRect.x; int x1 = vacatedColumnRect.x;
int y1 = vacatedColumnRect.y; int y1 = 0;
int x2 = x1 + vacatedColumnRect.width - 1; int x2 = x1 + vacatedColumnRect.width - 1;
int y2 = y1 + vacatedColumnRect.height - 1; int y2 = y1 + tableHeight;
boolean onLeftEdge = ltr ? draggedColumnIndex == cMin : draggedColumnIndex == cMax; boolean onLeftEdge = ltr ? draggedColumnIndex == cMin : draggedColumnIndex == cMax;
boolean onRightEdge = ltr ? draggedColumnIndex == cMax : draggedColumnIndex == cMin; boolean onRightEdge = ltr ? draggedColumnIndex == cMax : draggedColumnIndex == cMin;
@ -423,13 +418,13 @@ public class DarkTableUI extends DarkTableUIBridge {
paintCell(g, r, row, draggedColumnIndex); paintCell(g, r, row, draggedColumnIndex);
// Paint the (lower) horizontal grid line if necessary. // Paint the (lower) horizontal grid line if necessary.
if (table.getShowHorizontalLines() || (!scrollVisible && row == rMax)) { if (table.getShowHorizontalLines()) {
g.setColor(table.getGridColor()); g.setColor(table.getGridColor());
Rectangle rcr = table.getCellRect(row, draggedColumnIndex, true); Rectangle rcr = table.getCellRect(row, draggedColumnIndex, true);
rcr.x += dist; rcr.x += distance;
int x1 = rcr.x - 1; int x1 = rcr.x;
int y1 = rcr.y; int y1 = rcr.y;
int x2 = x1 + rcr.width + 1; int x2 = x1 + rcr.width;
int y2 = y1 + rcr.height - 1; int y2 = y1 + rcr.height - 1;
g.fillRect(x1, y2, x2 - x1, 1); g.fillRect(x1, y2, x2 - x1, 1);
} }
@ -482,6 +477,14 @@ public class DarkTableUI extends DarkTableUIBridge {
} }
} }
@Override
public void mousePressed(final MouseEvent e) {
super.mousePressed(e);
if (SwingUtilities.isLeftMouseButton(e)) {
table.repaint();
}
}
protected JFileChooser getFileChooser() { protected JFileChooser getFileChooser() {
var obj = table.getClientProperty("JTable.fileChooserParent"); var obj = table.getClientProperty("JTable.fileChooserParent");
if (obj instanceof Supplier) { if (obj instanceof Supplier) {

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

@ -1879,9 +1879,8 @@ public abstract class TableUIBridge extends TableUI {
if (binding != null) { if (binding != null) {
ActionMap am = component.getActionMap(); ActionMap am = component.getActionMap();
Action action = (am != null) ? am.get(binding) : null; Action action = (am != null) ? am.get(binding) : null;
if (action != null && SwingUtilities. if (action != null && SwingUtilities.notifyAction(action, keyStroke, e, component,
notifyAction(action, keyStroke, e, component, e.getModifiers())) {
e.getModifiers())) {
e.consume(); e.consume();
} }
} }
@ -2057,11 +2056,8 @@ public abstract class TableUIBridge extends TableUI {
Component editorComponent = table.getEditorComponent(); Component editorComponent = table.getEditorComponent();
Point p = e.getPoint(); Point p = e.getPoint();
Point p2 = SwingUtilities.convertPoint(table, p, editorComponent); Point p2 = SwingUtilities.convertPoint(table, p, editorComponent);
dispatchComponent = dispatchComponent = SwingUtilities.getDeepestComponentAt(editorComponent, p2.x, p2.y);
SwingUtilities.getDeepestComponentAt(editorComponent, SwingUtilities2.setSkipClickCount(dispatchComponent, e.getClickCount() - 1);
p2.x, p2.y);
SwingUtilities2.setSkipClickCount(dispatchComponent,
e.getClickCount() - 1);
} }
public void mouseEntered(final MouseEvent e) { public void mouseEntered(final MouseEvent e) {
@ -2107,11 +2103,8 @@ public abstract class TableUIBridge extends TableUI {
} else if (!e.isShiftDown() && table.isCellSelected(pressedRow, pressedCol)) { } else if (!e.isShiftDown() && table.isCellSelected(pressedRow, pressedCol)) {
// clicking on something that's already selected // clicking on something that's already selected
// and need to make it the lead now // and need to make it the lead now
table.getSelectionModel().addSelectionInterval(pressedRow, table.getSelectionModel().addSelectionInterval(pressedRow, pressedRow);
pressedRow); table.getColumnModel().getSelectionModel().addSelectionInterval(pressedCol, pressedCol);
table.getColumnModel().getSelectionModel().
addSelectionInterval(pressedCol, pressedCol);
return; return;
} }
@ -2145,7 +2138,6 @@ public abstract class TableUIBridge extends TableUI {
if (editorComponent != null && !editorComponent.hasFocus()) { if (editorComponent != null && !editorComponent.hasFocus()) {
SwingUtilities2.compositeRequestFocus(editorComponent); SwingUtilities2.compositeRequestFocus(editorComponent);
} }
return;
} }
public void dragStarting(final MouseEvent me) { public void dragStarting(final MouseEvent me) {
@ -2166,9 +2158,7 @@ public abstract class TableUIBridge extends TableUI {
return; return;
} }
if (table.getDragEnabled() && if (table.getDragEnabled() && (DragRecognitionSupport.mouseDragged(e, this) || dragStarted)) {
(DragRecognitionSupport.mouseDragged(e, this) || dragStarted)) {
return; return;
} }
@ -2190,8 +2180,7 @@ public abstract class TableUIBridge extends TableUI {
return; return;
} }
table.changeSelection(row, column, table.changeSelection(row, column, DarkUIUtil.isMenuShortcutKeyDown(e), true);
DarkUIUtil.isMenuShortcutKeyDown(e), true);
} }
public void mouseMoved(final MouseEvent e) { public void mouseMoved(final MouseEvent e) {

2
src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkTooltipUI.java

@ -132,7 +132,7 @@ public class DarkTooltipUI extends BasicToolTipUI implements PropertyChangeListe
@Override @Override
protected void installDefaults(final JComponent c) { protected void installDefaults(final JComponent c) {
super.installDefaults(c); super.installDefaults(c);
LookAndFeel.installProperty(c, "opaque", false); c.setOpaque(false);
if (c.getBorder() instanceof DarkTooltipBorder) { if (c.getBorder() instanceof DarkTooltipBorder) {
Alignment align = (Alignment) c.getClientProperty("JToolTip.pointerLocation"); Alignment align = (Alignment) c.getClientProperty("JToolTip.pointerLocation");
((DarkTooltipBorder) c.getBorder()).setPointerLocation(align == null ? Alignment.CENTER : align); ((DarkTooltipBorder) c.getBorder()).setPointerLocation(align == null ? Alignment.CENTER : align);

BIN
src/main/resources/com/github/weisj/darklaf/platform/windows/x64/jniplatform.dll

Binary file not shown.

BIN
src/main/resources/com/github/weisj/darklaf/platform/windows/x86/jniplatform.dll

Binary file not shown.

5
src/test/java/UIManagerDefaults.java

@ -5,6 +5,7 @@
import com.github.weisj.darklaf.DarkLafInfo; import com.github.weisj.darklaf.DarkLafInfo;
import com.github.weisj.darklaf.LafManager; import com.github.weisj.darklaf.LafManager;
import com.github.weisj.darklaf.components.OverlayScrollPane;
import com.github.weisj.darklaf.ui.cell.DarkCellRendererToggleButton; import com.github.weisj.darklaf.ui.cell.DarkCellRendererToggleButton;
import com.github.weisj.darklaf.ui.table.DarkColorTableCellRendererEditor; import com.github.weisj.darklaf.ui.table.DarkColorTableCellRendererEditor;
import org.jdesktop.swingx.JXTaskPane; import org.jdesktop.swingx.JXTaskPane;
@ -203,7 +204,7 @@ public class UIManagerDefaults implements ItemListener {
final DefaultTableModel model = new DefaultTableModel(COLUMN_NAMES, 0); final DefaultTableModel model = new DefaultTableModel(COLUMN_NAMES, 0);
table = new JTable(model); table = new JTable(model);
table.setAutoCreateColumnsFromModel(false); table.setAutoCreateColumnsFromModel(false);
table.setShowHorizontalLines(false); // table.setShowHorizontalLines(false);
table.getColumnModel().getColumn(0).setPreferredWidth(250); table.getColumnModel().getColumn(0).setPreferredWidth(250);
table.getColumnModel().getColumn(1).setPreferredWidth(500); table.getColumnModel().getColumn(1).setPreferredWidth(500);
@ -215,7 +216,7 @@ public class UIManagerDefaults implements ItemListener {
d.height = 350; d.height = 350;
table.setPreferredScrollableViewportSize(d); table.setPreferredScrollableViewportSize(d);
return new JScrollPane(table); return new OverlayScrollPane(table);
} }
/* /*

Loading…
Cancel
Save