Browse Source

Fixed list background not extending to end of viewport.

Fixed fileChooser list selection disappearing when focus is lost.
pull/97/head
weisj 5 years ago
parent
commit
c9b944e08f
  1. 1
      core/src/main/java/com/github/weisj/darklaf/ui/DarkPopupFactory.java
  2. 26
      core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFilePane.java
  3. 4
      core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFilePaneUIBridge.java
  4. 47
      core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUI.java

1
core/src/main/java/com/github/weisj/darklaf/ui/DarkPopupFactory.java

@ -64,7 +64,6 @@ public class DarkPopupFactory extends PopupFactory {
Decorations.uninstallPopupWindow(window);
}
}
System.out.println(popup + " " + contents);
return popup;
}
}

26
core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFilePane.java

@ -24,6 +24,7 @@
package com.github.weisj.darklaf.ui.filechooser;
import com.github.weisj.darklaf.components.OverlayScrollPane;
import com.github.weisj.darklaf.ui.list.DarkListCellRenderer;
import com.github.weisj.darklaf.ui.table.DarkTableUI;
import com.github.weisj.darklaf.ui.table.TextTableCellEditorBorder;
import com.github.weisj.darklaf.util.DarkUIUtil;
@ -86,7 +87,7 @@ public class DarkFilePane extends DarkFilePaneUIBridge {
return -1;
}
};
list.setCellRenderer(new FileRenderer());
list.setCellRenderer(new DarkFileRenderer());
list.setLayoutOrientation(JList.VERTICAL_WRAP);
LookAndFeel.installColors(list, "FileView.background", "FileView.foreground");
@ -436,4 +437,27 @@ public class DarkFilePane extends DarkFilePaneUIBridge {
}
}
}
public class DarkFileRenderer extends DarkListCellRenderer {
@Override
public Component getListCellRendererComponent(final JList<?> list, final Object value, final int index,
final boolean isSelected, final boolean cellHasFocus) {
Component comp = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (comp instanceof JLabel) {
File file = (File) value;
String fileName = getFileChooser().getName(file);
((JLabel) comp).setText(fileName);
Icon icon = getFileChooser().getIcon(file);
if (icon != null) {
((JLabel) comp).setIcon(icon);
} else {
if (getFileChooser().getFileSystemView().isTraversable(file)) {
((JLabel) comp).setText(fileName + File.separator);
}
}
}
return comp;
}
}
}

4
core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFilePaneUIBridge.java

@ -1732,11 +1732,11 @@ public class DarkFilePaneUIBridge extends JPanel implements PropertyChangeListen
@SuppressWarnings("serial")
// JDK-implementation class
class DetailsTableCellRenderer extends DarkTableCellRenderer {
public class DetailsTableCellRenderer extends DarkTableCellRenderer {
JFileChooser chooser;
DateFormat df;
DetailsTableCellRenderer(final JFileChooser chooser) {
public DetailsTableCellRenderer(final JFileChooser chooser) {
this.chooser = chooser;
df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT,
chooser.getLocale());

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

@ -101,44 +101,35 @@ public class DarkListUI extends DarkListUIBridge {
int startColumn, endColumn;
if (c.getComponentOrientation().isLeftToRight()) {
startColumn = convertLocationToColumn(paintBounds.x,
paintBounds.y);
endColumn = convertLocationToColumn(paintBounds.x +
paintBounds.width,
paintBounds.y);
startColumn = convertLocationToColumn(paintBounds.x, paintBounds.y);
endColumn = convertLocationToColumn(paintBounds.x + paintBounds.width, paintBounds.y);
} else {
startColumn = convertLocationToColumn(paintBounds.x +
paintBounds.width,
paintBounds.y);
endColumn = convertLocationToColumn(paintBounds.x,
paintBounds.y);
startColumn = convertLocationToColumn(paintBounds.x + paintBounds.width, paintBounds.y);
endColumn = convertLocationToColumn(paintBounds.x, paintBounds.y);
}
int maxY = paintBounds.y + paintBounds.height;
int maxX = paintBounds.x + paintBounds.width;
int leadIndex = adjustIndex(list.getLeadSelectionIndex(), list);
int rowIncrement = (layoutOrientation == JList.HORIZONTAL_WRAP) ?
columnCount : 1;
int rowIncrement = (layoutOrientation == JList.HORIZONTAL_WRAP) ? columnCount : 1;
for (int colCounter = startColumn; colCounter <= endColumn;
colCounter++) {
// And then how many rows in this columnn
Rectangle rowBounds;
for (int colCounter = startColumn; colCounter <= endColumn; colCounter++) {
int row = convertLocationToRowInColumn(paintBounds.y, colCounter);
int rowCount = Math.max(rowsPerColumn, getRowCount(colCounter));
int index = getModelIndex(colCounter, row);
Rectangle rowBounds = getCellBounds(list, index, index);
rowBounds = getCellBounds(list, index);
if (rowBounds == null) {
// Not valid, bail!
return;
}
int bgWidth = colCounter == endColumn ? maxX - rowBounds.x : 0;
while (row < rowCount && rowBounds.y < maxY) {
rowBounds.height = getHeight(colCounter, row);
g.setClip(rowBounds.x, rowBounds.y, rowBounds.width,
rowBounds.height);
g.clipRect(paintBounds.x, paintBounds.y, paintBounds.width,
paintBounds.height);
paintCell(g, index, rowBounds, renderer, dataModel, selModel,
leadIndex, 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);
rowBounds.y += rowBounds.height;
index += rowIncrement;
row++;
@ -151,7 +142,8 @@ public class DarkListUI extends DarkListUIBridge {
protected void paintCell(final Graphics g, final int index, final Rectangle rowBounds,
final ListCellRenderer<Object> cellRenderer,
final ListModel<Object> dataModel,
final ListSelectionModel selModel, final int leadIndex, final int row) {
final ListSelectionModel selModel, final int leadIndex, final int row,
final int bgWidth) {
boolean empty = index >= list.getModel().getSize();
Object value = empty ? null : dataModel.getElementAt(index);
boolean cellHasFocus = list.hasFocus() && (index == leadIndex);
@ -162,19 +154,19 @@ public class DarkListUI extends DarkListUIBridge {
int cw = rowBounds.width;
int ch = rowBounds.height;
if (empty) {
if (empty || bgWidth > 0) {
boolean alternativeRow = Boolean.TRUE.equals(list.getClientProperty(KEY_ALTERNATE_ROW_COLOR));
Color alternativeRowColor = UIManager.getColor("List.alternateRowBackground");
Color normalColor = list.getBackground();
Color background = alternativeRow && row % 2 == 1 ? alternativeRowColor : normalColor;
Color c = g.getColor();
g.setColor(background);
g.fillRect(cx, cy, cw, ch);
g.fillRect(cx, cy, bgWidth > 0 ? bgWidth : cw, ch);
g.setColor(c);
} else {
}
if (!empty) {
Component rendererComponent =
cellRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (Boolean.TRUE.equals(list.getClientProperty(KEY_SHRINK_WRAP))) {
// Shrink renderer to preferred size. This is mostly used on Windows
// where selection is only shown around the file name, instead of
@ -185,7 +177,6 @@ public class DarkListUI extends DarkListUIBridge {
}
cw = w;
}
rendererPane.paintComponent(g, rendererComponent, list, cx, cy, cw, ch, true);
}
}

Loading…
Cancel
Save