Browse Source

Ensure row height is calculated based on existing cell.

pull/188/head
weisj 5 years ago
parent
commit
e60e8cecf4
  1. 84
      core/src/main/java/com/github/weisj/darklaf/ui/cell/CellUtil.java
  2. 15
      core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUI.java

84
core/src/main/java/com/github/weisj/darklaf/ui/cell/CellUtil.java

@ -294,16 +294,15 @@ public class CellUtil {
final Color fgNoFocus, final Color selFgNoFocus,
final Color inactiveFg, final Color inactiveSelFg,
final Color inactiveFgNoFocus, final Color inactiveSelFgNoFocus) {
Color c = getColor(enabled, selected, focus,
fg, selFg, fgNoFocus, selFgNoFocus, inactiveFg, inactiveSelFg,
Color c = getColor(enabled, focus, selected, fg, selFg, fgNoFocus, selFgNoFocus, inactiveFg, inactiveSelFg,
inactiveFgNoFocus, inactiveSelFgNoFocus);
PropertyUtil.installForeground(comp, c);
}
public static void setupTableBackground(final Component comp, final JTable parent, final boolean selected,
final int row) {
public static Color getTableBackground(final Component comp, final JTable parent, final boolean selected,
final int row) {
boolean alt = row % 2 == 1 && PropertyUtil.getBooleanProperty(parent, DarkTableUI.KEY_ALTERNATE_ROW_COLOR);
setupBackground(comp, hasFocus(parent, comp), selected,
return getColor(comp, hasFocus(parent, comp), selected,
alt ? tableCellBackgroundAlternative : tableCellBackground,
tableCellBackgroundSelected,
alt ? tableCellBackgroundNoFocusAlternative : tableCellBackgroundNoFocus,
@ -314,10 +313,15 @@ public class CellUtil {
tableCellInactiveBackgroundSelectedNoFocus);
}
public static void setupTreeBackground(final Component comp, final JTree parent, final boolean selected,
final int row) {
public static void setupTableBackground(final Component comp, final JTable parent, final boolean selected,
final int row) {
setupBackground(comp, getTableBackground(comp, parent, selected, row));
}
public static Color getTreeBackground(final Component comp, final JTree parent, final boolean selected,
final int row) {
boolean alt = row % 2 == 1 && PropertyUtil.getBooleanProperty(parent, DarkTreeUI.KEY_ALTERNATE_ROW_COLOR);
setupBackground(comp, hasFocus(parent, comp), selected,
return getColor(comp, hasFocus(parent, comp), selected,
alt ? treeCellBackgroundAlternative : treeCellBackground,
treeCellBackgroundSelected,
alt ? treeCellBackgroundNoFocusAlternative : treeCellBackgroundNoFocus,
@ -328,9 +332,14 @@ public class CellUtil {
treeCellInactiveBackgroundSelectedNoFocus);
}
public static void setupTreeBackground(final Component comp, final JTree parent, final boolean selected,
final int row) {
setupBackground(comp, getTreeBackground(comp, parent, selected, row));
}
public static Color getTreeBackground(final JTree tree, final boolean selected, final int row) {
boolean alt = row % 2 == 1 && PropertyUtil.getBooleanProperty(tree, DarkTreeUI.KEY_ALTERNATE_ROW_COLOR);
return getColor(tree.isEnabled(), selected, hasFocus(tree, tree),
return getColor(tree.isEnabled(), hasFocus(tree, tree), selected,
alt ? treeCellBackgroundAlternative : treeCellBackground,
treeCellBackgroundSelected,
alt ? treeCellBackgroundNoFocusAlternative : treeCellBackgroundNoFocus,
@ -341,8 +350,8 @@ public class CellUtil {
treeCellInactiveBackgroundSelectedNoFocus);
}
public static void setupListBackground(final Component comp, final JList<?> parent, final boolean selected,
final int index) {
public static Color getListBackground(final Component comp, final JList<?> parent,
final boolean selected, final int index) {
int layout = parent.getLayoutOrientation();
boolean altRow = false;
if (layout == JList.VERTICAL) {
@ -362,14 +371,14 @@ public class CellUtil {
altRow = false;
}
}
setupListBackground(comp, parent, selected, altRow);
return getListBackground(comp, parent, selected, altRow);
}
public static void setupListBackground(final Component comp, final JList<?> parent, final boolean selected,
final boolean altRow) {
public static Color getListBackground(final Component comp, final JList<?> parent, final boolean selected,
final boolean altRow) {
boolean alt = altRow && PropertyUtil.getBooleanProperty(parent, DarkListUI.KEY_ALTERNATE_ROW_COLOR);
boolean comboList = PropertyUtil.getBooleanProperty(parent, DarkListUI.KEY_IS_COMBO_LIST);
setupBackground(comp, hasFocus(parent, comp), selected,
return getColor(comp, hasFocus(parent, comp), selected,
alt ? listCellBackgroundAlternative : listCellBackground,
comboList ? comboListCellBackgroundSelected : listCellBackgroundSelected,
alt ? listCellBackgroundNoFocusAlternative : listCellBackgroundNoFocus,
@ -380,30 +389,41 @@ public class CellUtil {
listCellInactiveBackgroundSelectedNoFocus);
}
public static void setupListBackground(final Component comp, final JList<?> parent, final boolean selected,
final int index) {
setupBackground(comp, getListBackground(comp, parent, selected, index));
}
public static void setupListBackground(final Component comp, final JList<?> parent, final boolean selected,
final boolean altRow) {
setupBackground(comp, getListBackground(comp, parent, selected, altRow));
}
public static void setupStandardBackground(final Component comp, final JComponent parent, final boolean selected) {
setupBackground(comp, hasFocus(parent, comp), selected,
cellBackground, cellBackgroundSelected,
cellBackgroundNoFocus, cellBackgroundSelectedNoFocus,
cellInactiveBackground, cellInactiveBackgroundSelected,
cellInactiveBackgroundNoFocus, cellInactiveBackgroundSelectedNoFocus);
}
public static void setupBackground(final Component comp, final boolean focus, final boolean selected,
final Color bg, final Color selBg,
final Color bgNoFocus, final Color selBgNoFocus,
final Color inactiveBg, final Color inactiveSelBg,
final Color inactiveBgNoFocus, final Color inactiveSelBgNoFocus) {
boolean enabled = comp.isEnabled();
Color c = getColor(enabled, selected, focus,
bg, selBg, bgNoFocus, selBgNoFocus, inactiveBg, inactiveSelBg,
inactiveBgNoFocus, inactiveSelBgNoFocus);
setupBackground(comp, getColor(comp, hasFocus(parent, comp), selected,
cellBackground, cellBackgroundSelected,
cellBackgroundNoFocus, cellBackgroundSelectedNoFocus,
cellInactiveBackground, cellInactiveBackgroundSelected,
cellInactiveBackgroundNoFocus, cellInactiveBackgroundSelectedNoFocus));
}
public static void setupBackground(final Component comp, final Color c) {
PropertyUtil.installBackground(comp, c);
if (comp instanceof JComponent) {
LookAndFeel.installProperty((JComponent) comp, PropertyKey.OPAQUE, true);
}
}
public static Color getColor(final boolean enabled, final boolean selected, final boolean focus,
public static Color getColor(final Component comp, final boolean focus, final boolean selected,
final Color bg, final Color selBg,
final Color bgNoFocus, final Color selBgNoFocus,
final Color inactiveBg, final Color inactiveSelBg,
final Color inactiveBgNoFocus, final Color inactiveSelBgNoFocus) {
return getColor(comp.isEnabled(), focus, selected, bg, selBg, bgNoFocus, selBgNoFocus, inactiveBg,
inactiveSelBg, inactiveBgNoFocus, inactiveSelBgNoFocus);
}
public static Color getColor(final boolean enabled, final boolean focus, final boolean selected,
final Color color, final Color selColor,
final Color colorNoFocus, final Color selColorNoFocus,
final Color inactiveColor, final Color inactiveSelColor,

15
core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUI.java

@ -54,7 +54,6 @@ public class DarkListUI extends DarkListUIBridge {
public static final String KEY_IS_LIST_EDITOR = "JComponent.listCellEditor";
protected DarkListCellRendererDelegate rendererDelegate;
private final JLabel emptyRenderer = new JLabel();
public static ComponentUI createUI(final JComponent list) {
return new DarkListUI();
@ -142,11 +141,15 @@ public class DarkListUI extends DarkListUIBridge {
return;
}
boolean lastColumn = colCounter == endColumn
&& getColumnCount() > 1
&& colCounter * rowsPerColumn + rowCount >= dataModel.getSize();
int bgWidth = lastColumn ? maxX - rowBounds.x : 0;
int maxRow = lastColumn ? Integer.MAX_VALUE : rowCount;
while (row < maxRow && rowBounds.y < maxY) {
rowBounds.height = getHeight(colCounter, row);
if (rowBounds.height <= 0) {
rowBounds.height = colCounter >= 1 ? getHeight(colCounter - 1, row) : getRowHeight(row);
}
g.setClip(rowBounds.x, rowBounds.y, bgWidth > 0 ? bgWidth : rowBounds.width, rowBounds.height);
g.clipRect(paintBounds.x, paintBounds.y, paintBounds.width, paintBounds.height);
paintCell(g, index, rowBounds, renderer, dataModel, selModel, leadIndex, row, bgWidth);
@ -180,12 +183,10 @@ public class DarkListUI extends DarkListUIBridge {
int cw = rowBounds.width;
int ch = rowBounds.height;
if (empty || bgWidth > 0) {
CellUtil.setupListBackground(emptyRenderer, list, false, row);
rendererPane.paintComponent(g, emptyRenderer, list,
cx, cy, bgWidth > 0 ? bgWidth : cw, ch, false);
}
if (!empty) {
if (empty) {
g.setColor(CellUtil.getListBackground(list, list, false, row));
// g.fillRect(cx, cy, bgWidth > 0 ? bgWidth : cw, ch);
} else {
Component rendererComponent = cellRenderer.getListCellRendererComponent(list, value, index, isSelected,
cellHasFocus);
if (PropertyUtil.getBooleanProperty(list, KEY_SHRINK_WRAP)) {

Loading…
Cancel
Save