@ -38,9 +38,13 @@ import javax.swing.table.*;
import sun.swing.SwingUtilities2 ;
import sun.swing.SwingUtilities2 ;
import com.github.weisj.darklaf.components.OverlayScrollPane ;
import com.github.weisj.darklaf.components.OverlayScrollPane ;
import com.github.weisj.darklaf.graphics.PaintUtil ;
import com.github.weisj.darklaf.ui.cell.CellUtil ;
import com.github.weisj.darklaf.ui.cell.CellUtil ;
import com.github.weisj.darklaf.ui.cell.DarkCellRendererPane ;
import com.github.weisj.darklaf.ui.cell.DarkCellRendererPane ;
import com.github.weisj.darklaf.ui.table.renderer.* ;
import com.github.weisj.darklaf.ui.table.renderer.DarkColorTableCellRendererEditor ;
import com.github.weisj.darklaf.ui.table.renderer.DarkTableCellEditorDelegate ;
import com.github.weisj.darklaf.ui.table.renderer.DarkTableCellRenderer ;
import com.github.weisj.darklaf.ui.table.renderer.DarkTableCellRendererDelegate ;
import com.github.weisj.darklaf.util.DarkUIUtil ;
import com.github.weisj.darklaf.util.DarkUIUtil ;
import com.github.weisj.darklaf.util.PropertyKey ;
import com.github.weisj.darklaf.util.PropertyKey ;
import com.github.weisj.darklaf.util.PropertyUtil ;
import com.github.weisj.darklaf.util.PropertyUtil ;
@ -205,8 +209,9 @@ public class DarkTableUI extends DarkTableUIBridge implements TableConstants {
protected boolean scrollBarVisible ( ) {
protected boolean scrollBarVisible ( ) {
JScrollPane comp = DarkUIUtil . getParentOfType ( JScrollPane . class , table , 2 ) ;
JScrollPane comp = DarkUIUtil . getParentOfType ( JScrollPane . class , table , 2 ) ;
if ( comp = = null ) return false ;
OverlayScrollPane overlayScrollPane = DarkUIUtil . getParentOfType ( OverlayScrollPane . class , table , 3 ) ;
OverlayScrollPane overlayScrollPane = DarkUIUtil . getParentOfType ( OverlayScrollPane . class , table , 3 ) ;
return comp ! = null & & overlayScrollPane = = null & & comp . getVerticalScrollBar ( ) . isVisible ( ) ;
return overlayScrollPane = = null & & comp . getVerticalScrollBar ( ) . isVisible ( ) ;
}
}
protected boolean showVerticalLine ( final boolean ltr , final boolean scrollVisible ,
protected boolean showVerticalLine ( final boolean ltr , final boolean scrollVisible ,
@ -272,11 +277,17 @@ public class DarkTableUI extends DarkTableUIBridge implements TableConstants {
}
}
int tableHeight = getPreferredSize ( table ) . height ;
int tableHeight = getPreferredSize ( table ) . height ;
g . setColor ( parent . getBackground ( ) ) ;
g . setColor ( parent . getBackground ( ) ) ;
g . fillRect ( vacatedColumnRect . x , 0 , vacatedColumnRect . width - 1 , tableHeight ) ;
int width = vacatedColumnRect . width ;
if ( draggedColumnIndex < cMax ) width - - ;
g . fillRect ( vacatedColumnRect . x , 0 , width , tableHeight ) ;
// Move to the where the cell has been dragged.
// Move to the where the cell has been dragged.
vacatedColumnRect . x + = dist ;
vacatedColumnRect . x + = dist ;
g . setColor ( Color . RED ) ;
PaintUtil . drawRect ( g , vacatedColumnRect ) ;
boolean ltr = table . getComponentOrientation ( ) . isLeftToRight ( ) ;
boolean ltr = table . getComponentOrientation ( ) . isLeftToRight ( ) ;
// Fill the background.
// Fill the background.
@ -315,9 +326,8 @@ public class DarkTableUI extends DarkTableUIBridge implements TableConstants {
// Render the cell value
// Render the cell value
Rectangle r = table . getCellRect ( row , draggedColumnIndex , false ) ;
Rectangle r = table . getCellRect ( row , draggedColumnIndex , false ) ;
r . x + = dist ;
r . x + = dist ;
paintCell ( g , r , row , draggedColumnIndex ) ;
paintCell ( g , r , row , draggedColumnIndex , cMin , cMax ) ;
// Paint the (lower) horizontal grid line if necessary.
if ( table . getShowHorizontalLines ( ) ) {
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 ) ;
@ -331,6 +341,24 @@ public class DarkTableUI extends DarkTableUIBridge implements TableConstants {
}
}
}
}
@Override
public void paint ( final Graphics g , final JComponent c ) {
/ *
* JTable always subtracts the cell margins even if for the last column . This results in
* part of the cell not being repainted . Dispatch repaint here manually .
* /
if ( table . getShowVerticalLines ( ) ) {
Rectangle r = g . getClipBounds ( ) ;
int spacing = table . getColumnModel ( ) . getColumnMargin ( ) ;
if ( r . x + r . width = = c . getWidth ( ) - spacing ) {
r . x = r . x + r . width ;
r . width = spacing ;
c . repaint ( r ) ;
}
}
super . paint ( g , c ) ;
}
public static boolean ignoreKeyCodeOnEdit ( final KeyEvent event , final JTable table ) {
public static boolean ignoreKeyCodeOnEdit ( final KeyEvent event , final JTable table ) {
if ( event ! = null ) {
if ( event ! = null ) {
int keyCode = event . getKeyCode ( ) ;
int keyCode = event . getKeyCode ( ) ;
@ -364,74 +392,43 @@ public class DarkTableUI extends DarkTableUIBridge implements TableConstants {
return false ;
return false ;
}
}
@Override
protected void paintCell ( final Graphics g , final Rectangle r , final int row , final int column ,
protected void paintCell ( final Graphics g , final Rectangle cellRect , final int row , final int column ) {
final int cMin , final int cMax ) {
Rectangle bounds = table . getVisibleRect ( ) ;
// if (true) return;
Point upperLeft = bounds . getLocation ( ) ;
Point lowerRight = new Point ( upperLeft . x + bounds . width - 1 , upperLeft . y + bounds . height - 1 ) ;
int cMin = table . columnAtPoint ( upperLeft ) ;
int cMax = table . columnAtPoint ( lowerRight ) ;
boolean scrollLtR = ! isScrollPaneRtl ( ) ;
boolean ltr = table . getComponentOrientation ( ) . isLeftToRight ( ) ;
boolean isEditorCell = table . isEditing ( ) & & table . getEditingRow ( ) = = row & & table . getEditingColumn ( ) = = column ;
boolean isEditorCell = table . isEditing ( ) & & table . getEditingRow ( ) = = row & & table . getEditingColumn ( ) = = column ;
JTableHeader header = table . getTableHeader ( ) ;
int x = r . x ;
int draggedIndex = header ! = null ? viewIndexForColumn ( header . getDraggedColumn ( ) )
int y = r . y ;
: - 1 ;
int w = r . width ;
int dist = header ! = null ? adjustDistance ( header . getDraggedDistance ( ) ,
int h = r . height ;
table . getCellRect ( row , draggedIndex , true ) ,
table )
if ( table . getShowVerticalLines ( ) & & ! scrollBarVisible ( ) ) {
: 0 ;
if ( column = = table . getColumnCount ( ) - 1 ) {
boolean isDragged = column = = draggedIndex & & dist ! = 0 ;
w + + ;
Rectangle rectWithSpacing = table . getCellRect ( row , cMin , true ) ;
Rectangle r = new Rectangle ( cellRect ) ;
r . y = rectWithSpacing . y ;
r . height = rectWithSpacing . height ;
if ( table . getShowHorizontalLines ( ) ) {
r . height - - ;
}
if ( ! scrollBarVisible ( ) ) {
if ( ltr ) {
if ( column = = cMax & & ! isDragged ) r . width + = 1 ;
} else {
if ( column = = cMin & & ! isDragged ) r . width + = 1 ;
}
} else if ( ! scrollLtR ) {
if ( ltr ) {
if ( column = = cMax & & ! isDragged ) r . width + = 1 ;
if ( column = = cMin & & ! isDragged ) {
r . width - = 1 ;
r . x + = 1 ;
}
} else {
if ( column = = cMin & & ! isDragged ) r . width + = 1 ;
if ( column = = cMax & & ! isDragged ) {
r . width - = 1 ;
r . x + = 1 ;
}
}
}
}
}
if ( isEditorCell ) {
if ( isEditorCell ) {
if ( ! table . getShowVerticalLines ( ) ) {
if ( ! table . getShowVerticalLines ( ) ) {
if ( column > cMin ) r . x - = 1 ;
if ( column > cMin ) x - - ;
if ( column > cMin & & column < cMax ) r . width + = 1 ;
if ( column > cMin & & column < cMax ) w + + ;
}
}
}
}
if ( isEditorCell ) {
if ( isEditorCell ) {
Component component = getCellEditorComponent ( ) ;
Component component = getCellEditorComponent ( ) ;
component . setBounds ( r ) ;
component . setBounds ( x , y , w , h ) ;
component . validate ( ) ;
component . validate ( ) ;
} else {
} else {
TableCellRenderer renderer = getCellRenderer ( row , column ) ;
TableCellRenderer renderer = getCellRenderer ( row , column ) ;
Component component = table . prepareRenderer ( renderer , row , column ) ;
Component component = table . prepareRenderer ( renderer , row , column ) ;
CellUtil . setSelectedFlag ( component , table . isCellSelected ( row , column ) ) ;
CellUtil . setSelectedFlag ( component , table . isCellSelected ( row , column ) ) ;
rendererPane . paintComponent ( g , component , table , r . x , r . y , r . width , r . height , true ) ;
rendererPane . paintComponent ( g , component , table , x , y , w , h , true ) ;
}
}
}
}
protected TableCellRenderer getCellRenderer ( final int row , final int column ) {
protected TableCellRenderer getCellRenderer ( final int row , final int column ) {
TableCellRenderer renderer = table . getCellRenderer ( row , column ) ;
TableCellRenderer renderer = table . getCellRenderer ( row , column ) ;
if ( renderer instanceof DarkTableCellRendererDelegate ) return renderer ;
if ( rendererDelegate = = null ) {
if ( rendererDelegate = = null ) {
rendererDelegate = new DarkTableCellRendererDelegate ( renderer ) ;
rendererDelegate = new DarkTableCellRendererDelegate ( renderer ) ;
}
}
@ -455,7 +452,7 @@ public class DarkTableUI extends DarkTableUIBridge implements TableConstants {
final JTable comp ) {
final JTable comp ) {
int dist = distance ;
int dist = distance ;
int min = 0 ;
int min = 0 ;
int max = comp . getX ( ) + comp . get Width ( ) ;
int max = comp . getWidth ( ) ;
if ( rect . x + dist < = min ) {
if ( rect . x + dist < = min ) {
dist = min - rect . x ;
dist = min - rect . x ;
}
}
@ -493,14 +490,6 @@ public class DarkTableUI extends DarkTableUIBridge implements TableConstants {
}
}
}
}
@Override
public void mousePressed ( final MouseEvent e ) {
super . mousePressed ( e ) ;
if ( SwingUtilities . isLeftMouseButton ( e ) ) {
table . repaint ( ) ;
}
}
protected JFileChooser getFileChooser ( ) {
protected JFileChooser getFileChooser ( ) {
Object obj = PropertyUtil . getObject ( table , DarkTableUI . KEY_FILE_CHOOSER_PARENT , Supplier . class , Object : : new )
Object obj = PropertyUtil . getObject ( table , DarkTableUI . KEY_FILE_CHOOSER_PARENT , Supplier . class , Object : : new )
. get ( ) ;
. get ( ) ;
@ -540,7 +529,8 @@ public class DarkTableUI extends DarkTableUIBridge implements TableConstants {
table . setRowMargin ( b ? 1 : 0 ) ;
table . setRowMargin ( b ? 1 : 0 ) ;
} else if ( KEY_VERTICAL_LINES . equals ( key ) ) {
} else if ( KEY_VERTICAL_LINES . equals ( key ) ) {
boolean b = Boolean . TRUE . equals ( e . getNewValue ( ) ) ;
boolean b = Boolean . TRUE . equals ( e . getNewValue ( ) ) ;
table . getColumnModel ( ) . setColumnMargin ( b ? 1 : 0 ) ;
TableColumnModel cm = table . getColumnModel ( ) ;
cm . setColumnMargin ( b ? 1 : 0 ) ;
} else if ( PropertyKey . ANCESTOR . equals ( key ) ) {
} else if ( PropertyKey . ANCESTOR . equals ( key ) ) {
Object oldVal = e . getOldValue ( ) ;
Object oldVal = e . getOldValue ( ) ;
Object newVal = e . getNewValue ( ) ;
Object newVal = e . getNewValue ( ) ;