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); Decorations.uninstallPopupWindow(window);
} }
} }
System.out.println(popup + " " + contents);
return popup; 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; package com.github.weisj.darklaf.ui.filechooser;
import com.github.weisj.darklaf.components.OverlayScrollPane; 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.DarkTableUI;
import com.github.weisj.darklaf.ui.table.TextTableCellEditorBorder; import com.github.weisj.darklaf.ui.table.TextTableCellEditorBorder;
import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.DarkUIUtil;
@ -86,7 +87,7 @@ public class DarkFilePane extends DarkFilePaneUIBridge {
return -1; return -1;
} }
}; };
list.setCellRenderer(new FileRenderer()); list.setCellRenderer(new DarkFileRenderer());
list.setLayoutOrientation(JList.VERTICAL_WRAP); list.setLayoutOrientation(JList.VERTICAL_WRAP);
LookAndFeel.installColors(list, "FileView.background", "FileView.foreground"); 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") @SuppressWarnings("serial")
// JDK-implementation class // JDK-implementation class
class DetailsTableCellRenderer extends DarkTableCellRenderer { public class DetailsTableCellRenderer extends DarkTableCellRenderer {
JFileChooser chooser; JFileChooser chooser;
DateFormat df; DateFormat df;
DetailsTableCellRenderer(final JFileChooser chooser) { public DetailsTableCellRenderer(final JFileChooser chooser) {
this.chooser = chooser; this.chooser = chooser;
df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT,
chooser.getLocale()); 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; int startColumn, endColumn;
if (c.getComponentOrientation().isLeftToRight()) { if (c.getComponentOrientation().isLeftToRight()) {
startColumn = convertLocationToColumn(paintBounds.x, startColumn = convertLocationToColumn(paintBounds.x, paintBounds.y);
paintBounds.y); endColumn = convertLocationToColumn(paintBounds.x + paintBounds.width, paintBounds.y);
endColumn = convertLocationToColumn(paintBounds.x +
paintBounds.width,
paintBounds.y);
} else { } else {
startColumn = convertLocationToColumn(paintBounds.x + startColumn = convertLocationToColumn(paintBounds.x + paintBounds.width, paintBounds.y);
paintBounds.width, endColumn = convertLocationToColumn(paintBounds.x, paintBounds.y);
paintBounds.y);
endColumn = convertLocationToColumn(paintBounds.x,
paintBounds.y);
} }
int maxY = paintBounds.y + paintBounds.height; int maxY = paintBounds.y + paintBounds.height;
int maxX = paintBounds.x + paintBounds.width;
int leadIndex = adjustIndex(list.getLeadSelectionIndex(), list); int leadIndex = adjustIndex(list.getLeadSelectionIndex(), list);
int rowIncrement = (layoutOrientation == JList.HORIZONTAL_WRAP) ? int rowIncrement = (layoutOrientation == JList.HORIZONTAL_WRAP) ? columnCount : 1;
columnCount : 1;
for (int colCounter = startColumn; colCounter <= endColumn; Rectangle rowBounds;
colCounter++) { for (int colCounter = startColumn; colCounter <= endColumn; colCounter++) {
// And then how many rows in this columnn
int row = convertLocationToRowInColumn(paintBounds.y, colCounter); int row = convertLocationToRowInColumn(paintBounds.y, colCounter);
int rowCount = Math.max(rowsPerColumn, getRowCount(colCounter)); int rowCount = Math.max(rowsPerColumn, getRowCount(colCounter));
int index = getModelIndex(colCounter, row); int index = getModelIndex(colCounter, row);
Rectangle rowBounds = getCellBounds(list, index, index); rowBounds = getCellBounds(list, index);
if (rowBounds == null) { if (rowBounds == null) {
// Not valid, bail! // Not valid, bail!
return; return;
} }
int bgWidth = colCounter == endColumn ? maxX - rowBounds.x : 0;
while (row < rowCount && rowBounds.y < maxY) { while (row < rowCount && rowBounds.y < maxY) {
rowBounds.height = getHeight(colCounter, row); rowBounds.height = getHeight(colCounter, row);
g.setClip(rowBounds.x, rowBounds.y, rowBounds.width, g.setClip(rowBounds.x, rowBounds.y, bgWidth > 0 ? bgWidth : rowBounds.width, rowBounds.height);
rowBounds.height); g.clipRect(paintBounds.x, paintBounds.y, paintBounds.width, paintBounds.height);
g.clipRect(paintBounds.x, paintBounds.y, paintBounds.width, paintCell(g, index, rowBounds, renderer, dataModel, selModel, leadIndex, row, bgWidth);
paintBounds.height);
paintCell(g, index, rowBounds, renderer, dataModel, selModel,
leadIndex, row);
rowBounds.y += rowBounds.height; rowBounds.y += rowBounds.height;
index += rowIncrement; index += rowIncrement;
row++; row++;
@ -151,7 +142,8 @@ public class DarkListUI extends DarkListUIBridge {
protected void paintCell(final Graphics g, final int index, final Rectangle rowBounds, protected void paintCell(final Graphics g, final int index, final Rectangle rowBounds,
final ListCellRenderer<Object> cellRenderer, final ListCellRenderer<Object> cellRenderer,
final ListModel<Object> dataModel, 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(); boolean empty = index >= list.getModel().getSize();
Object value = empty ? null : dataModel.getElementAt(index); Object value = empty ? null : dataModel.getElementAt(index);
boolean cellHasFocus = list.hasFocus() && (index == leadIndex); boolean cellHasFocus = list.hasFocus() && (index == leadIndex);
@ -162,19 +154,19 @@ public class DarkListUI extends DarkListUIBridge {
int cw = rowBounds.width; int cw = rowBounds.width;
int ch = rowBounds.height; int ch = rowBounds.height;
if (empty) { if (empty || bgWidth > 0) {
boolean alternativeRow = Boolean.TRUE.equals(list.getClientProperty(KEY_ALTERNATE_ROW_COLOR)); boolean alternativeRow = Boolean.TRUE.equals(list.getClientProperty(KEY_ALTERNATE_ROW_COLOR));
Color alternativeRowColor = UIManager.getColor("List.alternateRowBackground"); Color alternativeRowColor = UIManager.getColor("List.alternateRowBackground");
Color normalColor = list.getBackground(); Color normalColor = list.getBackground();
Color background = alternativeRow && row % 2 == 1 ? alternativeRowColor : normalColor; Color background = alternativeRow && row % 2 == 1 ? alternativeRowColor : normalColor;
Color c = g.getColor(); Color c = g.getColor();
g.setColor(background); g.setColor(background);
g.fillRect(cx, cy, cw, ch); g.fillRect(cx, cy, bgWidth > 0 ? bgWidth : cw, ch);
g.setColor(c); g.setColor(c);
} else { }
if (!empty) {
Component rendererComponent = Component rendererComponent =
cellRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); cellRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (Boolean.TRUE.equals(list.getClientProperty(KEY_SHRINK_WRAP))) { if (Boolean.TRUE.equals(list.getClientProperty(KEY_SHRINK_WRAP))) {
// Shrink renderer to preferred size. This is mostly used on Windows // Shrink renderer to preferred size. This is mostly used on Windows
// where selection is only shown around the file name, instead of // where selection is only shown around the file name, instead of
@ -185,7 +177,6 @@ public class DarkListUI extends DarkListUIBridge {
} }
cw = w; cw = w;
} }
rendererPane.paintComponent(g, rendererComponent, list, cx, cy, cw, ch, true); rendererPane.paintComponent(g, rendererComponent, list, cx, cy, cw, ch, true);
} }
} }

Loading…
Cancel
Save