Browse Source

Fixed table starts editing when meta key is pressed.

pull/97/head
weisj 5 years ago
parent
commit
769fb555e0
  1. 2
      core/src/main/java/com/github/weisj/darklaf/ui/table/DarkColorTableCellRendererEditor.java
  2. 4
      core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellEditor.java
  3. 28
      core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableUI.java
  4. 3
      core/src/main/java/com/github/weisj/darklaf/ui/table/TableUIBridge.java

2
core/src/main/java/com/github/weisj/darklaf/ui/table/DarkColorTableCellRendererEditor.java

@ -77,7 +77,7 @@ public class DarkColorTableCellRendererEditor extends AbstractCellEditor impleme
if (anEvent instanceof MouseEvent) {
return ((MouseEvent) anEvent).getClickCount() >= 2;
}
return true;
return false;
}
@Override

4
core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellEditor.java

@ -34,6 +34,7 @@ import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
import javax.swing.table.TableCellEditor;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.text.DateFormat;
import java.text.NumberFormat;
@ -177,6 +178,9 @@ public class DarkTableCellEditor extends DefaultCellEditor {
@Override
public boolean isCellEditable(final EventObject anEvent) {
if (anEvent == null) return super.isCellEditable(anEvent);
if (anEvent instanceof KeyEvent) {
if (DarkTableUI.ignoreKeyCodeOnEdit((KeyEvent) anEvent)) return false;
}
JTable table = ((JTable) anEvent.getSource());
if (DarkTableCellRenderer.isBooleanRenderingEnabled(table) && anEvent instanceof MouseEvent) {
Point p = ((MouseEvent) anEvent).getPoint();

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

@ -36,10 +36,7 @@ import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.MouseEvent;
import java.awt.event.*;
import java.beans.PropertyChangeListener;
import java.util.function.Supplier;
@ -420,6 +417,23 @@ public class DarkTableUI extends DarkTableUIBridge {
}
}
public static boolean ignoreKeyCodeOnEdit(final KeyEvent event) {
if (event != null) {
int keyCode = event.getKeyCode();
switch (keyCode) {
case KeyEvent.VK_ALT_GRAPH:
case KeyEvent.VK_META:
case KeyEvent.VK_CAPS_LOCK:
case KeyEvent.VK_HOME:
case KeyEvent.VK_WINDOWS:
return true;
default:
break;
}
}
return false;
}
protected class DarkHandler extends Handler {
protected int lastIndex = -1;
@ -481,6 +495,12 @@ public class DarkTableUI extends DarkTableUIBridge {
@Override
public void actionPerformed(final ActionEvent ae) {
}
@Override
public void keyTyped(final KeyEvent e) {
if (ignoreKeyCodeOnEdit(e)) return;
super.keyTyped(e);
}
}
protected boolean isFocusCell(final int row, final int col) {

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

@ -2217,8 +2217,7 @@ public abstract class TableUIBridge extends TableUI {
if (map != null && map.get(keyStroke) != null) {
return;
}
map = table.getInputMap(JComponent.
WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
map = table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
if (map != null && map.get(keyStroke) != null) {
return;
}

Loading…
Cancel
Save