Browse Source

Fixed foreground for labels used as cell editors.

pull/75/head
weisj 5 years ago
parent
commit
30605d0d91
  1. 2
      core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java
  2. 20
      core/src/main/java/com/github/weisj/darklaf/ui/label/DarkLabelUI.java
  3. 37
      core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeCellEditor.java
  4. 1
      core/src/main/java/com/github/weisj/darklaf/util/DarkUIUtil.java
  5. 5
      core/src/main/resources/com/github/weisj/darklaf/properties/ui/label.properties

2
core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java

@ -144,7 +144,7 @@ public class DarkButtonUI extends BasicButtonUI implements PropertyChangeListene
b.setFont(b.getFont().deriveFont(Font.BOLD));
Dimension size = BasicGraphicsUtils.getPreferredButtonSize(b, b.getIconTextGap());
b.setFont(oldFont);
size.width += 2 * borderSize;
// size.width += 2 * borderSize;
return size;
}

20
core/src/main/java/com/github/weisj/darklaf/ui/label/DarkLabelUI.java

@ -23,6 +23,7 @@
*/
package com.github.weisj.darklaf.ui.label;
import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.GraphicsContext;
import com.github.weisj.darklaf.util.GraphicsUtil;
import sun.swing.SwingUtilities2;
@ -44,11 +45,13 @@ public class DarkLabelUI extends BasicLabelUI implements PropertyChangeListener
protected static final DarkLabelUI darkLabelUI = new DarkLabelUI();
private final Color inactiveForeground;
private final Color cellForegroundNoFocus;
protected Rectangle paintIconR = new Rectangle();
protected Rectangle paintTextR = new Rectangle();
public DarkLabelUI() {
inactiveForeground = UIManager.getColor("Label.inactiveForeground");
cellForegroundNoFocus = UIManager.getColor("Label.cellForegroundNoFocus");
}
public static ComponentUI createUI(final JComponent c) {
@ -92,6 +95,23 @@ public class DarkLabelUI extends BasicLabelUI implements PropertyChangeListener
config.restore();
}
@Override
protected void paintEnabledText(final JLabel l, final Graphics g, final String s,
final int textX, final int textY) {
int mnemIndex = l.getDisplayedMnemonicIndex();
boolean focus = DarkUIUtil.hasFocus(l)
|| DarkUIUtil.hasFocus(DarkUIUtil.getParentOfType(JTree.class, l))
|| DarkUIUtil.hasFocus(DarkUIUtil.getParentOfType(JTable.class, l))
|| DarkUIUtil.hasFocus(DarkUIUtil.getParentOfType(JList.class, l));
if (DarkUIUtil.isInCell(l) && !focus) {
g.setColor(cellForegroundNoFocus);
} else {
g.setColor(l.getForeground());
}
SwingUtilities2.drawStringUnderlineCharAt(l, g, s, mnemIndex,
textX, textY);
}
@Override
protected void paintDisabledText(final JLabel l, final Graphics g, final String s,
final int textX, final int textY) {

37
core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeCellEditor.java

@ -31,6 +31,8 @@ import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
import javax.swing.tree.TreeCellEditor;
import java.awt.*;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.MouseEvent;
import java.text.DateFormat;
import java.text.NumberFormat;
@ -40,7 +42,7 @@ import java.util.EventObject;
/**
* @author Jannis Weis
*/
public class DarkTreeCellEditor extends DefaultCellEditor implements TreeCellEditor {
public class DarkTreeCellEditor extends DefaultCellEditor implements TreeCellEditor, FocusListener {
private static final JCheckBox dummyCheckBox = new JCheckBox();
private JTree tree;
@ -50,6 +52,7 @@ public class DarkTreeCellEditor extends DefaultCellEditor implements TreeCellEdi
public DarkTreeCellEditor(final JTextField textField) {
super(textField);
textField.setBorder(UIManager.getBorder("Tree.editorBorder"));
textField.addFocusListener(this);
}
public DarkTreeCellEditor(final JCheckBox checkBox) {
@ -76,6 +79,7 @@ public class DarkTreeCellEditor extends DefaultCellEditor implements TreeCellEdi
toggleButton.putClientProperty("JToggleButton.isTreeCellEditor", Boolean.TRUE);
toggleButton.addActionListener(delegate);
toggleButton.setRequestFocusEnabled(false);
toggleButton.addFocusListener(this);
setClickCountToStart(1);
}
@ -97,12 +101,14 @@ public class DarkTreeCellEditor extends DefaultCellEditor implements TreeCellEdi
}
});
comboBox.addFocusListener(this);
setClickCountToStart(2);
}
public DarkTreeCellEditor(final JSpinner spinner) {
super(dummyCheckBox);
editorComponent = spinner;
editorComponent.addFocusListener(this);
spinner.putClientProperty("JSpinner.isTreeCellEditor", Boolean.TRUE);
setClickCountToStart(2);
delegate = new EditorDelegate() {
@ -162,13 +168,30 @@ public class DarkTreeCellEditor extends DefaultCellEditor implements TreeCellEdi
}
editorComponent.setOpaque(false);
editorComponent.setComponentOrientation(tree.getComponentOrientation());
if (editorComponent instanceof JToggleButton) {
if (DarkUIUtil.hasFocus(tree) || DarkUIUtil.hasFocus(editorComponent)) {
editorComponent.setForeground(UIManager.getColor("Tree.selectionForeground"));
} else {
editorComponent.setForeground(UIManager.getColor("Tree.selectionForegroundInactive"));
}
if (DarkUIUtil.hasFocus(tree) || DarkUIUtil.hasFocus(editorComponent)) {
editorComponent.setForeground(UIManager.getColor("Tree.selectionForeground"));
} else {
editorComponent.setForeground(UIManager.getColor("Tree.selectionForegroundInactive"));
}
return editorComponent;
}
protected void updateFocus() {
if (DarkUIUtil.hasFocus(editorComponent)) {
editorComponent.setForeground(UIManager.getColor("Tree.selectionForeground"));
} else {
editorComponent.setForeground(UIManager.getColor("Tree.selectionForegroundInactive"));
}
}
@Override
public void focusGained(final FocusEvent e) {
updateFocus();
}
@Override
public void focusLost(final FocusEvent e) {
updateFocus();
}
}

1
core/src/main/java/com/github/weisj/darklaf/util/DarkUIUtil.java

@ -164,6 +164,7 @@ public final class DarkUIUtil {
}
public static boolean hasFocus(final Component c) {
if (c == null) return false;
if (c.hasFocus()) return true;
if (c instanceof Window) {
return hasFocus(c);

5
core/src/main/resources/com/github/weisj/darklaf/properties/ui/label.properties

@ -22,5 +22,6 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
LabelUI = com.github.weisj.darklaf.ui.label.DarkLabelUI
Label.inactiveForeground = %textForegroundInactive
LabelUI = com.github.weisj.darklaf.ui.label.DarkLabelUI
Label.inactiveForeground = %textForegroundInactive
Label.cellForegroundNoFocus = %textSelectionForegroundInactive

Loading…
Cancel
Save