Browse Source

Added property for high contrast.

Added property for cell margins.
Refactored table cell bound calculation.
pull/127/head
weisj 5 years ago
parent
commit
76c0588a05
  1. 81
      core/src/main/java/com/github/weisj/darklaf/ui/cell/CellUtil.java
  2. 3
      core/src/main/java/com/github/weisj/darklaf/ui/cell/DarkCellBorder.java
  3. 13
      core/src/main/java/com/github/weisj/darklaf/ui/combobox/DarkComboBoxBorder.java
  4. 13
      core/src/main/java/com/github/weisj/darklaf/ui/spinner/DarkSpinnerBorder.java
  5. 2
      core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellEditor.java
  6. 18
      core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableUI.java
  7. 65
      core/src/main/java/com/github/weisj/darklaf/ui/table/TextTableCellEditorBorder.java
  8. 6
      core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextUI.java
  9. 3
      core/src/main/resources/com/github/weisj/darklaf/properties/ui/borders.properties
  10. 1
      core/src/main/resources/com/github/weisj/darklaf/theme/darcula/darcula_defaults.properties
  11. 1
      core/src/main/resources/com/github/weisj/darklaf/theme/high_contrast_dark/high_contrast_dark_defaults.properties
  12. 1
      core/src/main/resources/com/github/weisj/darklaf/theme/intellij/intellij_defaults.properties
  13. 1
      core/src/main/resources/com/github/weisj/darklaf/theme/solarized_dark/solarized_dark_defaults.properties
  14. 1
      core/src/main/resources/com/github/weisj/darklaf/theme/solarized_light/solarized_light_defaults.properties
  15. 6
      core/src/test/java/ui/DemoPanel.java
  16. 14
      core/src/test/java/ui/button/ButtonDemo.java
  17. 16
      core/src/test/java/ui/table/TableDemo.java

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

@ -24,6 +24,7 @@
package com.github.weisj.darklaf.ui.cell;
import com.github.weisj.darklaf.ui.list.DarkListUI;
import com.github.weisj.darklaf.ui.table.DarkTableCellEditor;
import com.github.weisj.darklaf.util.DarkUIUtil;
import javax.swing.*;
@ -117,4 +118,84 @@ public class CellUtil {
comp.setBackground(background);
}
}
public static void paintTableEditorBorder(final Graphics g, final Component c, final JTable table,
final int width, final int height) {
int row = table.getEditingRow();
int col = table.getEditingColumn();
if (!table.getShowHorizontalLines()) {
if (row > CellUtil.getMinRowIndex(table)) g.fillRect(0, 0, width, 1);
g.fillRect(0, height - 1, width, 1);
}
if (!table.getShowVerticalLines()) {
if (col > CellUtil.getMinColumnIndex(table)) g.fillRect(0, 0, 1, height);
if (col < CellUtil.getMaxColumnIndex(table)) g.fillRect(width - 1, 0, 1, height);
} else if (isInWrapper(c)) {
if (table.getComponentOrientation().isLeftToRight()) {
g.fillRect(0, 0, 1, height);
} else {
g.fillRect(width - 1, 0, 1, height);
}
}
}
protected static boolean isInWrapper(final Component c) {
return c.getParent() instanceof DarkTableCellEditor.IconWrapper;
}
protected static boolean isListEditor(final Component c) {
return c instanceof JComponent
&& Boolean.TRUE.equals(((JComponent) c).getClientProperty(DarkListUI.KEY_IS_LIST_RENDERER))
&& c.getParent() instanceof JList;
}
public static Insets adjustEditorInsets(final Insets ins, final Component c) {
if (isInWrapper(c)) {
if (parentLTR(c)) {
ins.left -= ((DarkTableCellEditor.IconWrapper) c.getParent()).getIconCompGap();
} else {
ins.right -= ((DarkTableCellEditor.IconWrapper) c.getParent()).getIconCompGap();
}
} else if (isListEditor(c)) {
ListCellRenderer<?> renderer = ((JList<?>) c.getParent()).getCellRenderer();
if (renderer instanceof JLabel) {
if (parentLTR(c)) {
ins.left -= ((JLabel) renderer).getIconTextGap() - 1;
} else {
ins.right -= ((JLabel) renderer).getIconTextGap() - 1;
}
}
}
return adjustTableCellEditorInsets(ins, DarkUIUtil.getParentOfType(JTable.class, c));
}
public static Insets adjustTableCellEditorInsets(final Insets ins, final JTable table) {
if (table != null && !table.getShowVerticalLines()) {
int cMin = getMinColumnIndex(table);
int column = table.getEditingColumn();
if (column > cMin) ins.left++;
}
return ins;
}
protected static boolean parentLTR(final Component c) {
return c.getParent().getComponentOrientation().isLeftToRight();
}
public static int getMinColumnIndex(final JTable table) {
Rectangle rect = table.getVisibleRect();
return table.columnAtPoint(rect.getLocation());
}
public static int getMaxColumnIndex(final JTable table) {
Rectangle rect = table.getVisibleRect();
Point p = rect.getLocation();
p.x += rect.width - 1;
return table.columnAtPoint(p);
}
public static int getMinRowIndex(final JTable table) {
Rectangle rect = table.getVisibleRect();
return table.rowAtPoint(rect.getLocation());
}
}

3
core/src/main/java/com/github/weisj/darklaf/ui/cell/DarkCellBorder.java

@ -23,6 +23,7 @@
*/
package com.github.weisj.darklaf.ui.cell;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.plaf.UIResource;
@ -32,6 +33,6 @@ import javax.swing.plaf.UIResource;
public class DarkCellBorder extends EmptyBorder implements UIResource {
public DarkCellBorder() {
super(2, 5, 2, 5);
super(UIManager.getInsets("Cell.borderInsets"));
}
}

13
core/src/main/java/com/github/weisj/darklaf/ui/combobox/DarkComboBoxBorder.java

@ -23,6 +23,7 @@
*/
package com.github.weisj.darklaf.ui.combobox;
import com.github.weisj.darklaf.ui.cell.CellUtil;
import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.GraphicsContext;
@ -140,14 +141,7 @@ public class DarkComboBoxBorder implements Border, UIResource {
Component parent = c.getParent();
if (isTableCellEditor && parent instanceof JTable) {
JTable table = ((JTable) parent);
if (!table.getShowHorizontalLines()) {
g.fillRect(0, 0, width, 1);
g.fillRect(0, height - 1, width, 1);
}
if (!table.getShowVerticalLines()) {
g.fillRect(0, 0, 1, height);
g.fillRect(width - 1, 0, 1, height);
}
CellUtil.paintTableEditorBorder(g, c, table, width, height);
} else {
DarkUIUtil.drawRect(g, 0, 0, width, height, 1);
}
@ -167,7 +161,8 @@ public class DarkComboBoxBorder implements Border, UIResource {
@Override
public Insets getBorderInsets(final Component c) {
if (ComboBoxConstants.isTreeOrTableCellEditor(c)) {
return new InsetsUIResource(cellPadding.top, cellPadding.left, cellPadding.bottom, cellPadding.right);
return CellUtil.adjustEditorInsets(new InsetsUIResource(cellPadding.top, cellPadding.left,
cellPadding.bottom, cellPadding.right), c);
}
if (c.getComponentOrientation().isLeftToRight()) {
return new InsetsUIResource(boxPadding.top, boxPadding.left, boxPadding.bottom, borderSize);

13
core/src/main/java/com/github/weisj/darklaf/ui/spinner/DarkSpinnerBorder.java

@ -23,6 +23,7 @@
*/
package com.github.weisj.darklaf.ui.spinner;
import com.github.weisj.darklaf.ui.cell.CellUtil;
import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.GraphicsContext;
@ -98,14 +99,7 @@ public class DarkSpinnerBorder implements Border, UIResource {
DarkUIUtil.paintLineBorder(g, size, size, width - 2 * size, height - 2 * size, arc);
} else if (tableCellEditor && (c.getParent() instanceof JTable)) {
JTable table = (JTable) c.getParent();
if (!table.getShowHorizontalLines()) {
g.fillRect(0, 0, width, 1);
g.fillRect(0, height - 1, width, 1);
}
if (!table.getShowVerticalLines()) {
g.fillRect(0, 0, 1, height);
g.fillRect(width - 1, 0, 1, height);
}
CellUtil.paintTableEditorBorder(g, c, table, width, height);
} else {
DarkUIUtil.drawRect(g, 0, 0, width, height, 1);
}
@ -121,7 +115,8 @@ public class DarkSpinnerBorder implements Border, UIResource {
@Override
public Insets getBorderInsets(final Component c) {
if (SpinnerConstants.isTreeOrTableCellEditor(c)) {
return new InsetsUIResource(cellInsets.top, cellInsets.left, cellInsets.bottom, cellInsets.right);
return CellUtil.adjustEditorInsets(new InsetsUIResource(cellInsets.top, cellInsets.left,
cellInsets.bottom, cellInsets.right), c);
}
return new InsetsUIResource(insets.top, insets.left, insets.bottom, insets.right);
}

2
core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellEditor.java

@ -289,7 +289,7 @@ public class DarkTableCellEditor extends DefaultCellEditor {
return checkBoxEditor;
}
protected static class IconWrapper extends JPanel {
public static class IconWrapper extends JPanel {
private final JLabel label;
private JComponent c;

18
core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableUI.java

@ -535,6 +535,7 @@ public class DarkTableUI extends DarkTableUIBridge implements FocusListener {
boolean scrollLtR = !isScrollPaneRtl();
boolean ltr = table.getComponentOrientation().isLeftToRight();
boolean isEditorCell = table.isEditing() && table.getEditingRow() == row && table.getEditingColumn() == column;
JTableHeader header = table.getTableHeader();
int draggedIndex = header != null ? viewIndexForColumn(header.getDraggedColumn())
@ -543,7 +544,13 @@ public class DarkTableUI extends DarkTableUIBridge implements FocusListener {
table.getCellRect(row, draggedIndex, true),
table) : 0;
boolean isDragged = column == draggedIndex && dist != 0;
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;
@ -565,12 +572,13 @@ public class DarkTableUI extends DarkTableUIBridge implements FocusListener {
}
}
}
if (!table.getShowVerticalLines() && column > cMin && isFocusCell(row, column)) {
r.x -= 1;
if (column < cMax) r.width += 1;
if (isEditorCell) {
if (!table.getShowVerticalLines()) {
if (column > cMin) r.x -= 1;
if (column > cMin && column < cMax) r.width += 1;
}
}
if (table.isEditing() && table.getEditingRow() == row && table.getEditingColumn() == column) {
if (isEditorCell) {
Component component = table.getEditorComponent();
component.setBounds(r);
component.validate();

65
core/src/main/java/com/github/weisj/darklaf/ui/table/TextTableCellEditorBorder.java

@ -23,7 +23,7 @@
*/
package com.github.weisj.darklaf.ui.table;
import com.github.weisj.darklaf.ui.text.DarkTextUI;
import com.github.weisj.darklaf.ui.cell.CellUtil;
import com.github.weisj.darklaf.util.DarkUIUtil;
import javax.swing.*;
@ -40,80 +40,21 @@ public class TextTableCellEditorBorder extends DarkTableCellBorder {
borderColor = UIManager.getColor("TextField.border.enabled");
}
protected static boolean parentLTR(final Component c) {
return c.getParent().getComponentOrientation().isLeftToRight();
}
@Override
public void paintBorder(final Component c, final Graphics g, final int x, final int y,
final int width, final int height) {
g.setColor(borderColor);
JTable table = DarkUIUtil.getParentOfType(JTable.class, c);
if (table != null) {
int row = table.getEditingRow();
if (!table.getShowHorizontalLines()) {
if (row > getMinRowIndex(table)) g.fillRect(0, 0, width, 1);
g.fillRect(0, height - 1, width, 1);
}
if (!table.getShowVerticalLines()) {
g.fillRect(0, 0, 1, height);
g.fillRect(width - 1, 0, 1, height);
} else if (isInWrapper(c)) {
if (c.getParent().getComponentOrientation().isLeftToRight()) {
g.fillRect(0, 0, 1, height);
} else {
g.fillRect(width - 1, 0, 1, height);
}
}
CellUtil.paintTableEditorBorder(g, c, table, width, height);
} else {
DarkUIUtil.drawRect(g, x, y, width, height, 1);
}
}
protected int getMinColumnIndex(final JTable table) {
Rectangle rect = table.getVisibleRect();
return table.columnAtPoint(rect.getLocation());
}
protected int getMinRowIndex(final JTable table) {
Rectangle rect = table.getVisibleRect();
return table.rowAtPoint(rect.getLocation());
}
protected static boolean isListEditor(final Component c) {
return c instanceof JComponent
&& Boolean.TRUE.equals(((JComponent) c).getClientProperty(DarkTextUI.KEY_IS_LIST_RENDER))
&& c.getParent() instanceof JList;
}
protected static boolean isInWrapper(final Component c) {
return c.getParent() instanceof DarkTableCellEditor.IconWrapper;
}
@Override
public Insets getBorderInsets(final Component c) {
Insets ins = super.getBorderInsets();
if (isInWrapper(c)) {
if (parentLTR(c)) {
ins.left -= ((DarkTableCellEditor.IconWrapper) c.getParent()).getIconCompGap();
} else {
ins.right -= ((DarkTableCellEditor.IconWrapper) c.getParent()).getIconCompGap();
}
} else if (isListEditor(c)) {
ListCellRenderer<?> renderer = ((JList<?>) c.getParent()).getCellRenderer();
if (renderer instanceof JLabel) {
if (parentLTR(c)) {
ins.left -= ((JLabel) renderer).getIconTextGap() - 1;
} else {
ins.right -= ((JLabel) renderer).getIconTextGap() - 1;
}
}
}
JTable table = DarkUIUtil.getParentOfType(JTable.class, c);
if (table != null && !table.getShowVerticalLines() && table.getEditingColumn() > getMinColumnIndex(table)) {
ins.left++;
}
return ins;
return CellUtil.adjustEditorInsets(super.getBorderInsets(), c);
}
}

6
core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextUI.java

@ -188,6 +188,12 @@ public abstract class DarkTextUI extends BasicTextUI implements PropertyChangeLi
config.restore();
}
@Override
protected Rectangle getVisibleEditorRect() {
Rectangle rect = super.getVisibleEditorRect();
return rect;
}
protected void paintBorderBackground(final Graphics2D g, final JTextComponent c) {
g.setColor(getBackground(c));
Rectangle r = getDrawingRect(c);

3
core/src/main/resources/com/github/weisj/darklaf/properties/ui/borders.properties

@ -24,4 +24,5 @@
#
TitledBorder.titleColor = %textForeground
TitledBorder.border = com.github.weisj.darklaf.ui.titledborder.DarkTitledBorder
TitledBorder.borderColor = %borderSecondary
TitledBorder.borderColor = %borderSecondary
Cell.borderInsets = 2,5,2,5

1
core/src/main/resources/com/github/weisj/darklaf/theme/darcula/darcula_defaults.properties

@ -22,6 +22,7 @@
#
# suppress inspection "UnusedProperty" for whole file
Theme.dark = true
Theme.highContrast = false
####Background####
%background = 3c3f41

1
core/src/main/resources/com/github/weisj/darklaf/theme/high_contrast_dark/high_contrast_dark_defaults.properties

@ -22,6 +22,7 @@
#
# suppress inspection "UnusedProperty" for whole file
Theme.dark = true
Theme.highContrast = true
####Background####
%background = 000000

1
core/src/main/resources/com/github/weisj/darklaf/theme/intellij/intellij_defaults.properties

@ -23,6 +23,7 @@
#
# suppress inspection "UnusedProperty" for whole file
Theme.dark = false
Theme.highContrast = false
####Background####
%background = F2F2F2

1
core/src/main/resources/com/github/weisj/darklaf/theme/solarized_dark/solarized_dark_defaults.properties

@ -22,6 +22,7 @@
#
# suppress inspection "UnusedProperty" for whole file
Theme.dark = true
Theme.highContrast = false
####Background####
%background = 0E3C4A

1
core/src/main/resources/com/github/weisj/darklaf/theme/solarized_light/solarized_light_defaults.properties

@ -23,6 +23,7 @@
#
# suppress inspection "UnusedProperty" for whole file
Theme.dark = false
Theme.highContrast = false
####Background####
%background = EEE8D5

6
core/src/test/java/ui/DemoPanel.java

@ -58,7 +58,11 @@ public class DemoPanel extends JPanel {
public JPanel addControls(final int columns) {
JPanel control = new JPanel();
control.setLayout(new MigLayout("fillx, wrap " + columns, "[][grow]"));
String constraints = "fillx";
if (columns > 0) {
constraints += ", wrap" + columns;
}
control.setLayout(new MigLayout(constraints, "[][grow]"));
control.setBorder(DarkBorders.createLineBorder(1, 0, 0, 0));
controls.add(control);
return control;

14
core/src/test/java/ui/button/ButtonDemo.java

@ -84,6 +84,16 @@ public class ButtonDemo implements ComponentDemo {
addActionListener(e -> UIManager.put("Button.defaultButtonFollowsFocus", isSelected()));
}});
controlPanel = panel.addControls();
controlPanel.add(new JCheckBox("Text enabled") {{
setSelected(true);
addActionListener(e -> button.setText(isSelected() ? "Test Button" : null));
}});
controlPanel.add(new JCheckBox("Icon enabled") {{
setSelected(true);
addActionListener(e -> button.setIcon(isSelected() ? icon : null));
}});
controlPanel = panel.addControls();
controlPanel.add(new QuickColorChooser(DarkButtonUI.KEY_HOVER_COLOR, Color.BLACK,
(b, c) -> button
@ -117,10 +127,6 @@ public class ButtonDemo implements ComponentDemo {
}
});
}});
controlPanel.add(new JCheckBox("Icon Only") {{
setSelected(false);
addActionListener(e -> button.setText(isSelected() ? null : "Test Button"));
}});
return panel;
}

16
core/src/test/java/ui/table/TableDemo.java

@ -46,11 +46,9 @@ public class TableDemo implements ComponentDemo {
"Id", "Name", "Hourly Rate", "Part Time", "Components"
};
Object[][] data = new Object[][]{
{1, "John", 40.0, false, "Item"},
{2, "Rambo", 70.0, false, 10},
{3, "Zorro", 60.0, true, "cell"},
};
Object[][] data = new Object[][]{{1, "John", 40.0, false, "Item"},
{2, "Rambo", 70.0, false, 10},
{3, "Zorro", 60.0, true, "cell"}};
AtomicBoolean editable = new AtomicBoolean(true);
JTable table = new JTable(data, columns) {
final TableCellEditor comboEditor = new DarkTableCellEditor(new JComboBox<>());
@ -76,7 +74,7 @@ public class TableDemo implements ComponentDemo {
JTableHeader header = table.getTableHeader();
DemoPanel panel = new DemoPanel(new JScrollPane(table));
JPanel controlPanel = panel.addControls();
JPanel controlPanel = panel.addControls(3);
controlPanel.add(new JCheckBox("enabled") {{
setSelected(table.isEnabled());
addActionListener(e -> table.setEnabled(isSelected()));
@ -116,6 +114,12 @@ public class TableDemo implements ComponentDemo {
addActionListener(e -> table.setRowSelectionAllowed(isSelected()));
table.addPropertyChangeListener(e -> setSelected(table.getRowSelectionAllowed()));
}});
controlPanel = panel.addControls(3);
controlPanel.add(new JLabel("Row height:"));
controlPanel.add(new JSpinner() {{
setValue(table.getRowHeight());
addChangeListener(e -> table.setRowHeight(Integer.parseInt(getValue().toString())));
}});
return panel;
}

Loading…
Cancel
Save