Skip to content

Commit

Permalink
Streamlined foreground background setup for cells. Enabled status of …
Browse files Browse the repository at this point in the history
…cell and parent is now respected.

Removed more unused properties.
  • Loading branch information
weisJ committed May 3, 2020
1 parent ec12501 commit dcf8646
Show file tree
Hide file tree
Showing 37 changed files with 933 additions and 2,605 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class ThemeDefaultsInitTask implements DefaultsInitTask {

private static final String GLOBAL_PREFIX = "global.";
private static final String MAC_OS_MENU_BAR_KEY = "apple.laf.useScreenMenuBar";
private static final String[] UI_PROPERTIES = new String[]{"borders", "button", "checkBox", "colorChooser",
private static final String[] UI_PROPERTIES = new String[]{"borders", "button", "cell", "checkBox", "colorChooser",
"comboBox", "fileChooser", "tristate",
"internalFrame", "label", "list", "menu", "menuBar",
"menuItem", "numberingPane", "optionPane", "panel",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.github.weisj.darklaf.icons.AwareIconStyle;
import com.github.weisj.darklaf.icons.IconLoader;
import com.github.weisj.darklaf.theme.Theme;
import com.github.weisj.darklaf.ui.cell.CellUtil;

public class UtilityDefaultsInitTask implements DefaultsInitTask {
@Override
Expand All @@ -54,6 +55,8 @@ private void setupUtils(final Theme currentTheme, final UIDefaults defaults) {

IconLoader.updateAwareStyle(Theme.isDark(currentTheme) ? AwareIconStyle.DARK : AwareIconStyle.LIGHT);
IconLoader.updateThemeStatus(currentTheme);

CellUtil.updateColors(defaults);
}

private float getOpacity(final UIDefaults defaults, final String key) {
Expand Down
420 changes: 368 additions & 52 deletions core/src/main/java/com/github/weisj/darklaf/ui/cell/CellUtil.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* MIT License
*
* Copyright (c) 2020 Jannis Weis
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
package com.github.weisj.darklaf.ui.cell;

import java.awt.*;

import javax.swing.*;

public class DarkCellRendererPane extends CellRendererPane {}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

import com.github.weisj.darklaf.components.SelectableTreeNode;
import com.github.weisj.darklaf.ui.table.DarkTableCellFocusBorder;
import com.github.weisj.darklaf.ui.table.DarkTableUI;
import com.github.weisj.darklaf.ui.togglebutton.ToggleButtonConstants;
import com.github.weisj.darklaf.ui.tree.DarkTreeCellRenderer;
import com.github.weisj.darklaf.util.DarkUIUtil;
Expand Down Expand Up @@ -65,11 +64,8 @@ public Component getTableCellRendererComponent(final JTable table, final Object
&& focus && !DarkTableCellFocusBorder.isRowFocusBorder(table);
boolean paintSelected = isSelected && !isLeadSelectionCell && !table.isEditing();

CellUtil.setupForeground(toggleButton, table, paintSelected,
"Table.selectionForeground", "Table.selectionForegroundInactive");
CellUtil.setupBackground(toggleButton, table, paintSelected, row, DarkTableUI.KEY_ALTERNATE_ROW_COLOR,
"Table.background", "Table.alternateRowBackground",
"Table.selectionNoFocusBackground");
CellUtil.setupTableForeground(toggleButton, table, paintSelected);
CellUtil.setupTableBackground(toggleButton, table, paintSelected, row);
return toggleButton;
}

Expand All @@ -89,8 +85,7 @@ public Component getTreeCellRendererComponent(final JTree tree, final Object val
toggleButton.setHorizontalAlignment(tree.getComponentOrientation().isLeftToRight() ? LEFT : RIGHT);
toggleButton.setHasFocus(false);

CellUtil.setupForeground(toggleButton, tree, selected,
"Tree.selectionForeground", "Tree.selectionForegroundInactive");
CellUtil.setupTreeForeground(toggleButton, tree, selected);

return toggleButton;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
import sun.swing.FilePane;

import com.github.weisj.darklaf.ui.list.DarkListCellRenderer;
import com.github.weisj.darklaf.ui.table.DarkTableCellEditor;
import com.github.weisj.darklaf.ui.table.DarkTableCellRenderer;
import com.github.weisj.darklaf.ui.table.TextTableCellEditorBorder;
import com.github.weisj.darklaf.ui.table.renderer.DarkTableCellEditor;
import com.github.weisj.darklaf.ui.table.renderer.DarkTableCellRenderer;
import com.github.weisj.darklaf.util.PropertyKey;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@

import com.github.weisj.darklaf.graphics.GraphicsContext;
import com.github.weisj.darklaf.graphics.PaintUtil;
import com.github.weisj.darklaf.ui.cell.CellUtil;
import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.PropertyKey;
import com.github.weisj.darklaf.util.PropertyUtil;

/**
* @author Jannis Weis
Expand All @@ -49,10 +47,6 @@ public class DarkLabelUI extends BasicLabelUI implements PropertyChangeListener
protected static final DarkLabelUI darkLabelUI = new DarkLabelUI();

private Color inactiveForeground;
private Color cellForegroundNoFocus;
private Color cellInactiveForeground;
private Color cellInactiveForegroundSelectedNoFocus;
private Color cellInactiveForegroundSelected;

protected final Rectangle paintIconR = new Rectangle();
protected final Rectangle paintTextR = new Rectangle();
Expand All @@ -75,10 +69,6 @@ protected void installDefaults(final JLabel c) {
super.installDefaults(c);
LookAndFeel.installProperty(c, PropertyKey.OPAQUE, false);
inactiveForeground = UIManager.getColor("Label.inactiveForeground");
cellForegroundNoFocus = UIManager.getColor("Label.cellForegroundNoFocus");
cellInactiveForeground = UIManager.getColor("Label.cellInactiveForeground");
cellInactiveForegroundSelected = UIManager.getColor("Label.cellInactiveForegroundSelected");
cellInactiveForegroundSelectedNoFocus = UIManager.getColor("Label.cellInactiveForegroundSelectedNoFocus");
}

@Override
Expand Down Expand Up @@ -113,44 +103,17 @@ public void paint(final Graphics g, final JComponent c) {
protected void paintEnabledText(final JLabel l, final Graphics g, final String s,
final int textX, final int textY) {
int mnemIndex = l.getDisplayedMnemonicIndex();
if (DarkUIUtil.isInCell(l) && !hasFocusInCell(l)) {
g.setColor(cellForegroundNoFocus);
} else {
g.setColor(l.getForeground());
}
g.setColor(l.getForeground());
SwingUtilities2.drawStringUnderlineCharAt(l, g, s, mnemIndex,
textX, textY);
}

protected boolean hasFocusInCell(final JLabel l) {
return (DarkUIUtil.hasFocus(l)
|| DarkUIUtil.hasFocus(DarkUIUtil.getParentOfType(JTree.class, l))
|| DarkUIUtil.hasFocus(DarkUIUtil.getParentOfType(JTable.class, l))
|| DarkUIUtil.hasFocus(DarkUIUtil.getParentOfType(JList.class, l))
|| DarkUIUtil.getParentOfType(JPopupMenu.class, l) != null);
}

@Override
protected void paintDisabledText(final JLabel l, final Graphics g, final String s,
final int textX, final int textY) {
int accChar = l.getDisplayedMnemonicIndex();
if (DarkUIUtil.isInCell(l)) {
boolean selected = PropertyUtil.getBooleanProperty(l, CellUtil.KEY_SELECTED_CELL_RENDERER);
boolean focused = hasFocusInCell(l);
if (focused) {
if (selected) {
g.setColor(cellInactiveForegroundSelected);
} else {
g.setColor(cellInactiveForeground);
}
} else {
if (selected) {
g.setColor(cellInactiveForegroundSelectedNoFocus);
} else {
g.setColor(inactiveForeground);
}
}
} else {
g.setColor(l.getForeground());
if (!DarkUIUtil.isInCell(l)) {
g.setColor(inactiveForeground);
}
SwingUtilities2.drawStringUnderlineCharAt(l, g, s, accChar,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import javax.swing.*;

import com.github.weisj.darklaf.ui.cell.CellUtil;
import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.PropertyUtil;

public class DarkListCellRenderer extends DefaultListCellRenderer {
Expand All @@ -55,19 +54,8 @@ public Component getListCellRendererComponent(final JList<?> list, final Object
if (comp == null) {
comp = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
}
CellUtil.setupBackground(comp, list, isSelected, index, DarkListUI.KEY_ALTERNATE_ROW_COLOR,
"List.alternateRowBackground",
"List.selectionNoFocusBackground");
if (!(isSelected)) {
comp.setForeground(list.getForeground());
} else {
if (DarkUIUtil.hasFocus(list) || DarkUIUtil.getParentOfType(JPopupMenu.class, list) != null) {
comp.setForeground(list.getSelectionForeground());
comp.setBackground(list.getSelectionBackground());
} else {
comp.setForeground(UIManager.getColor("List.selectionForegroundInactive"));
}
}
CellUtil.setupListBackground(comp, list, isSelected, index);
CellUtil.setupListForeground(comp, list, isSelected);
if (getText().isEmpty()) {
// Fix cell height for empty string.
setText(" ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import javax.swing.*;
import javax.swing.plaf.ComponentUI;

import com.github.weisj.darklaf.ui.cell.DarkCellRendererPane;
import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.PropertyUtil;

Expand Down Expand Up @@ -61,9 +62,14 @@ public static ComponentUI createUI(final JComponent list) {
@Override
protected void installDefaults() {
super.installDefaults();
rendererPane = createCellRendererPane();
PropertyUtil.installBooleanProperty(list, KEY_ALTERNATE_ROW_COLOR, "List.alternateRowColor");
}

protected CellRendererPane createCellRendererPane() {
return new DarkCellRendererPane();
}

@Override
protected Handler getHandler() {
if (handler == null) {
Expand Down
Loading

0 comments on commit dcf8646

Please sign in to comment.