Browse Source

Improved TitlePane border painting.

Improved TableHeader border painting.
Fixed incorrect preferred size of table when in scroll pane.
pull/105/head
weisj 5 years ago
parent
commit
c091b4af18
  1. 30
      core/src/main/java/com/github/weisj/darklaf/components/border/MutableLineBorder.java
  2. 4
      core/src/main/java/com/github/weisj/darklaf/decorators/LayoutManagerDelegate.java
  3. 2
      core/src/main/java/com/github/weisj/darklaf/ui/scrollpane/DarkScrollPaneUI.java
  4. 36
      core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneBorder.java
  5. 1
      core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneUI.java
  6. 49
      core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableHeaderBorder.java
  7. 27
      core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableUI.java
  8. 35
      core/src/main/java/com/github/weisj/darklaf/ui/titledborder/DarkTitledBorder.java
  9. 2
      core/src/main/resources/com/github/weisj/darklaf/properties/ui/tabbedPane.properties

30
core/src/main/java/com/github/weisj/darklaf/components/border/MutableLineBorder.java

@ -23,19 +23,27 @@
*/
package com.github.weisj.darklaf.components.border;
import javax.swing.border.EmptyBorder;
import javax.swing.border.AbstractBorder;
import java.awt.*;
/**
* @author Jannis Weis
*/
public class MutableLineBorder extends EmptyBorder {
public class MutableLineBorder extends AbstractBorder {
private Color color;
protected int top;
protected int left;
protected int right;
protected int bottom;
public MutableLineBorder(
final int top, final int left, final int bottom, final int right, final Color color) {
super(top, left, bottom, right);
final int top, final int left, final int bottom, final int right, final Color color) {
this.top = top;
this.left = left;
this.bottom = bottom;
this.right = right;
this.color = color;
}
@ -69,6 +77,20 @@ public class MutableLineBorder extends EmptyBorder {
setRight(right);
}
@Override
public Insets getBorderInsets(final Component c, final Insets insets) {
insets.left = left;
insets.top = top;
insets.right = right;
insets.bottom = bottom;
return insets;
}
public Insets getBorderInsets() {
return new Insets(top, left, bottom, right);
}
public void setTop(final int top) {
this.top = top;
}

4
core/src/main/java/com/github/weisj/darklaf/decorators/LayoutManagerDelegate.java

@ -36,6 +36,10 @@ public class LayoutManagerDelegate implements LayoutManager {
this.delegate = delegate;
}
public LayoutManager getDelegate() {
return delegate;
}
@Override
public void addLayoutComponent(final String name, final Component comp) {
delegate.addLayoutComponent(name, comp);

2
core/src/main/java/com/github/weisj/darklaf/ui/scrollpane/DarkScrollPaneUI.java

@ -128,7 +128,7 @@ public class DarkScrollPaneUI extends BasicScrollPaneUI {
public void installUI(final JComponent x) {
super.installUI(x);
oldLayout = (ScrollPaneLayout) x.getLayout();
if (oldLayout instanceof ScrollLayoutManagerDelegate) {
while (oldLayout instanceof ScrollLayoutManagerDelegate) {
oldLayout = ((ScrollLayoutManagerDelegate) oldLayout).getDelegate();
}
if (oldLayout != null) {

36
core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneBorder.java

@ -0,0 +1,36 @@
/*
* 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.tabbedpane;
import com.github.weisj.darklaf.components.border.MutableLineBorder;
import javax.swing.*;
import javax.swing.plaf.UIResource;
public class DarkTabbedPaneBorder extends MutableLineBorder implements UIResource {
public DarkTabbedPaneBorder() {
super(1, 1, 1, 1, UIManager.getColor("TabbedPane.borderColor"));
}
}

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

@ -800,5 +800,4 @@ public class DarkTabbedPaneUI extends DarkTabbedPaneUIBridge {
public JButton createMoreTabsButton() {
return new MoreTabsButton(this);
}
}

49
core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableHeaderBorder.java

@ -26,7 +26,10 @@ package com.github.weisj.darklaf.ui.table;
import com.github.weisj.darklaf.components.border.MutableLineBorder;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.plaf.UIResource;
import java.awt.*;
/**
* @author Jannis Weis
@ -37,4 +40,50 @@ public class DarkTableHeaderBorder extends MutableLineBorder implements UIResour
super(0, 0, 1, 0, null);
setColor(UIManager.getColor("TableHeader.borderColor"));
}
@Override
public void paintBorder(final Component c, final Graphics g, final int x, final int y,
final int width, final int height) {
adjustTop(c);
super.paintBorder(c, g, x, y, width, height);
}
@Override
public Insets getBorderInsets(final Component c, final Insets insets) {
adjustTop(c);
return super.getBorderInsets(c, insets);
}
@Override
public Insets getBorderInsets(final Component c) {
adjustTop(c);
return super.getBorderInsets(c);
}
protected void adjustTop(final Component c) {
Component parent = SwingUtilities.getUnwrappedParent(c.getParent());
top = 0;
if (parent instanceof JComponent) {
if (hasBorderAbove((JComponent) parent, c)) return;
Border border = ((JComponent) parent).getBorder();
if (border instanceof EmptyBorder || border == null) {
top = 1;
}
}
}
protected boolean hasBorderAbove(final JComponent c, final Component child) {
JComponent comp = c;
Component prev = child;
while (comp instanceof JScrollPane
|| (comp != null
&& comp.getLayout() instanceof BorderLayout
&& ((BorderLayout) comp.getLayout()).getConstraints(prev) == BorderLayout.CENTER)
&& ((BorderLayout) comp.getLayout()).getLayoutComponent(BorderLayout.NORTH) == null) {
if (comp instanceof JTabbedPane) return true;
prev = comp;
comp = (JComponent) comp.getParent();
}
return comp instanceof JTabbedPane;
}
}

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

@ -75,10 +75,7 @@ public class DarkTableUI extends DarkTableUIBridge implements FocusListener {
Object newVal = e.getNewValue();
if (oldVal instanceof Component) {
Container oldUnwrapped = SwingUtilities.getUnwrappedParent((Component) oldVal);
if ((oldUnwrapped instanceof JScrollPane)
&& ((JComponent) oldUnwrapped).getBorder() instanceof UIResource) {
LookAndFeel.uninstallBorder((JComponent) oldUnwrapped);
}
LookAndFeel.uninstallBorder((JComponent) oldUnwrapped);
}
if (newVal instanceof Component) {
Container newUnwrapped = SwingUtilities.getUnwrappedParent((Component) newVal);
@ -154,6 +151,13 @@ public class DarkTableUI extends DarkTableUIBridge implements FocusListener {
table.removePropertyChangeListener(propertyChangeListener);
}
@Override
protected void uninstallDefaults() {
super.uninstallDefaults();
Container oldUnwrapped = SwingUtilities.getUnwrappedParent(table.getParent());
LookAndFeel.uninstallBorder((JComponent) oldUnwrapped);
}
protected static void setupRendererComponents(final JTable table) {
DarkTableCellRenderer cellRenderer = new DarkTableCellRenderer();
DarkTableCellEditor cellEditor = new DarkTableCellEditor();
@ -176,21 +180,6 @@ public class DarkTableUI extends DarkTableUIBridge implements FocusListener {
table.setDefaultEditor(Color.class, colorRendererEditor);
}
@Override
public Dimension getPreferredSize(final JComponent c) {
Dimension prefSize = super.getPreferredSize(c);
if (!isInScrollPane()) {
return prefSize;
} else {
Dimension dim = SwingUtilities.getUnwrappedParent(table).getSize();
if (dim.width < prefSize.width || dim.height < prefSize.height) {
return prefSize;
} else {
return dim;
}
}
}
protected Color getBorderColor() {
return borderColor;
}

35
core/src/main/java/com/github/weisj/darklaf/ui/titledborder/DarkTitledBorder.java

@ -26,7 +26,10 @@ package com.github.weisj.darklaf.ui.titledborder;
import com.github.weisj.darklaf.components.border.MutableLineBorder;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import javax.swing.plaf.UIResource;
import java.awt.*;
public class DarkTitledBorder extends MutableLineBorder implements UIResource {
@ -34,4 +37,36 @@ public class DarkTitledBorder extends MutableLineBorder implements UIResource {
super(1, 0, 0, 0, null);
setColor(UIManager.getColor("TitledBorder.borderColor"));
}
@Override
public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int width, final int height) {
checkInsets(c);
super.paintBorder(c, g, x, y, width, height);
}
@Override
public Insets getBorderInsets(final Component c, final Insets insets) {
checkInsets(c);
return super.getBorderInsets(c, insets);
}
protected void checkInsets(final Component c) {
setInsets(1, 0, 0, 0);
if (c instanceof JComponent) {
JComponent component = (JComponent) c;
Border border = component.getBorder();
if (border instanceof TitledBorder) {
String text = ((TitledBorder) border).getTitle();
int pos = ((TitledBorder) border).getTitlePosition();
boolean onTop = pos == TitledBorder.ABOVE_TOP
|| pos == TitledBorder.BELOW_TOP
|| pos == TitledBorder.TOP
|| pos == TitledBorder.DEFAULT_POSITION;
if (text == null || text.isEmpty() || !onTop) {
setInsets(1, 1, 1, 1);
}
}
}
}
}

2
core/src/main/resources/com/github/weisj/darklaf/properties/ui/tabbedPane.properties

@ -25,7 +25,9 @@
TabbedPaneUI = com.github.weisj.darklaf.ui.tabbedpane.DarkTabbedPaneUI
TabbedPane.tabInsets = 5,7,5,7
TabbedPane.tabRunOverlay = 0
TabbedPane.border = com.github.weisj.darklaf.ui.tabbedpane.DarkTabbedPaneBorder
TabbedPane.borderColor = %border
TabbedPane.tabBorderColor = %border
TabbedPane.accent = %highlightFillMono
TabbedPane.accentFocus = %highlightFillFocusSecondary

Loading…
Cancel
Save