From e539f2863678a7b6f9da4e24f42a8b0be02b0a16 Mon Sep 17 00:00:00 2001 From: weisj Date: Tue, 23 Jun 2020 14:32:10 +0200 Subject: [PATCH] Skip opaque aa for components that are already opaque buffered. Add api for getting individual care styles. Make ToolTipContext#createDefaultContext public. Move boolean renderer type constant to common interface. Removed unused ToolTipConstants.KEY_PLAIN_TOOLTIP value. --- .../components/tooltip/ToolTipContext.java | 2 +- .../weisj/darklaf/graphics/StringPainter.java | 4 +- .../weisj/darklaf/ui/cell/CellConstants.java | 30 ++++++++++++++ .../weisj/darklaf/ui/list/DarkListUI.java | 5 +-- .../darklaf/ui/table/TableConstants.java | 5 +-- .../weisj/darklaf/ui/text/DarkCaret.java | 39 ++++++++++++++----- .../darklaf/ui/text/DarkTextFieldUI.java | 3 +- .../darklaf/ui/tooltip/ToolTipConstants.java | 1 - .../weisj/darklaf/ui/tree/DarkTreeUI.java | 5 +-- core/src/test/java/ui/text/TextFieldDemo.java | 1 + 10 files changed, 71 insertions(+), 24 deletions(-) create mode 100644 core/src/main/java/com/github/weisj/darklaf/ui/cell/CellConstants.java diff --git a/core/src/main/java/com/github/weisj/darklaf/components/tooltip/ToolTipContext.java b/core/src/main/java/com/github/weisj/darklaf/components/tooltip/ToolTipContext.java index ce3e61ff..1d5f4eae 100644 --- a/core/src/main/java/com/github/weisj/darklaf/components/tooltip/ToolTipContext.java +++ b/core/src/main/java/com/github/weisj/darklaf/components/tooltip/ToolTipContext.java @@ -49,7 +49,7 @@ public class ToolTipContext { return defaultContext; } - private static ToolTipContext createDefaultContext() { + public static ToolTipContext createDefaultContext() { return new ToolTipContext().setAlignment(Alignment.SOUTH) .setCenterAlignment(Alignment.SOUTH) .setAlignInside(false) diff --git a/core/src/main/java/com/github/weisj/darklaf/graphics/StringPainter.java b/core/src/main/java/com/github/weisj/darklaf/graphics/StringPainter.java index 65780b11..ac8738d2 100644 --- a/core/src/main/java/com/github/weisj/darklaf/graphics/StringPainter.java +++ b/core/src/main/java/com/github/weisj/darklaf/graphics/StringPainter.java @@ -208,10 +208,10 @@ public class StringPainter { } } - private static Component getNonOpaqueWindow(final Component c) { + private static Component getNonOpaqueWindow(final JComponent c) { boolean imgGraphics = false; Component window = c; - if (translucentAAPaintingEnabled && SystemInfo.isWindows) { + if (translucentAAPaintingEnabled && SystemInfo.isWindows && !GraphicsUtil.isOpaqueBuffered(c)) { Component comp = c; while (comp != null) { Color bg = comp.getBackground(); diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/cell/CellConstants.java b/core/src/main/java/com/github/weisj/darklaf/ui/cell/CellConstants.java new file mode 100644 index 00000000..e56a2ffe --- /dev/null +++ b/core/src/main/java/com/github/weisj/darklaf/ui/cell/CellConstants.java @@ -0,0 +1,30 @@ +/* + * 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; + +public interface CellConstants { + String RENDER_TYPE_CHECKBOX = "checkBox"; + String RENDER_TYPE_RADIOBUTTON = "radioButton"; +} diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUI.java index 4bded42a..e058eb88 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUI.java @@ -31,6 +31,7 @@ import java.beans.PropertyChangeEvent; import javax.swing.*; import javax.swing.plaf.ComponentUI; +import com.github.weisj.darklaf.ui.cell.CellConstants; import com.github.weisj.darklaf.ui.cell.CellUtil; import com.github.weisj.darklaf.ui.cell.DarkCellRendererPane; import com.github.weisj.darklaf.util.DarkUIUtil; @@ -39,7 +40,7 @@ import com.github.weisj.darklaf.util.PropertyUtil; /** * @author Jannis Weis */ -public class DarkListUI extends DarkListUIBridge { +public class DarkListUI extends DarkListUIBridge implements CellConstants { protected static final String KEY_PREFIX = "JList."; public static final String KEY_IS_COMBO_LIST = KEY_PREFIX + ".isComboList"; @@ -49,8 +50,6 @@ public class DarkListUI extends DarkListUIBridge { public static final String KEY_SHRINK_WRAP = KEY_PREFIX + "shrinkWrap"; public static final String KEY_FULL_ROW_SELECTION = KEY_PREFIX + "fullRowSelection"; public static final String KEY_IS_EDITING = KEY_PREFIX + "isEditing"; - public static final String RENDER_TYPE_CHECKBOX = "checkBox"; - public static final String RENDER_TYPE_RADIOBUTTON = "radioButton"; public static final String KEY_IS_LIST_EDITOR = "JComponent.listCellEditor"; protected DarkListCellRendererDelegate rendererDelegate; diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/table/TableConstants.java b/core/src/main/java/com/github/weisj/darklaf/ui/table/TableConstants.java index a50776c4..d70e3b24 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/table/TableConstants.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/table/TableConstants.java @@ -26,9 +26,10 @@ package com.github.weisj.darklaf.ui.table; import javax.swing.*; +import com.github.weisj.darklaf.ui.cell.CellConstants; import com.github.weisj.darklaf.util.PropertyUtil; -public interface TableConstants { +public interface TableConstants extends CellConstants { String KEY_IS_TABLE_EDITOR = "JComponent.isTableEditor"; String KEY_IS_TABLE_RENDERER = "JComponent.isTableRenderer"; @@ -44,8 +45,6 @@ public interface TableConstants { String KEY_VERTICAL_LINES = "showVerticalLines"; String KEY_IS_FILE_LIST = "Table.isFileList"; String KEY_IS_PRINT_MODE = "Table.printMode"; - String RENDER_TYPE_CHECKBOX = "checkBox"; - String RENDER_TYPE_RADIOBUTTON = "radioButton"; static boolean isBooleanRenderingEnabled(final JTable table) { return PropertyUtil.getBooleanProperty(table, DarkTableUI.KEY_RENDER_BOOLEAN_AS_CHECKBOX); diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkCaret.java b/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkCaret.java index 1fd77547..9f1357ef 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkCaret.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkCaret.java @@ -132,26 +132,45 @@ public class DarkCaret extends DefaultCaret implements UIResource { getDarkSelectionPainter().setLineExtendingEnabled(enabled); } - public CaretStyle getStyle() { + public CaretStyle getEffectiveStyle() { return isInsertMode() ? insertStyle : style; } - public void setStyles(final CaretStyle style, final CaretStyle insertStyle) { + public CaretStyle getStyle() { + return style; + } + + public CaretStyle getInsertStyle() { + return insertStyle; + } + + public void setStyle(final CaretStyle style) { CaretStyle s = style; - CaretStyle is = insertStyle; if (s == null) { s = CaretStyle.THICK_VERTICAL_LINE_STYLE; } + if (s != this.style) { + this.style = s; + repaint(); + } + } + + public void setInsertStyle(final CaretStyle insertStyle) { + CaretStyle is = insertStyle; if (is == null) { is = CaretStyle.BLOCK_BORDER_STYLE; } - if (s != this.style || is != this.insertStyle) { - this.style = s; + if (is != this.insertStyle) { this.insertStyle = is; repaint(); } } + public void setStyles(final CaretStyle style, final CaretStyle insertStyle) { + setInsertStyle(insertStyle); + setStyle(style); + } + public boolean isAlwaysVisible() { return alwaysVisible; } @@ -201,7 +220,7 @@ public class DarkCaret extends DefaultCaret implements UIResource { @Override public double getWidth() { - return getStyle().getSize(); + return getEffectiveStyle().getSize(); } /** @@ -377,18 +396,18 @@ public class DarkCaret extends DefaultCaret implements UIResource { if (textAreaBg == null) { textAreaBg = Color.white; } - switch (getStyle()) { + switch (getEffectiveStyle()) { case BLOCK_STYLE : g.setXORMode(textAreaBg); g.fillRect(r.x, r.y, r.width, r.height); break; case BLOCK_BORDER_STYLE : - PaintUtil.drawRect(g, r.x, r.y, r.width, r.height, getStyle().getSize()); + PaintUtil.drawRect(g, r.x, r.y, r.width, r.height, getEffectiveStyle().getSize()); break; case UNDERLINE_STYLE : g.setXORMode(textAreaBg); int y = r.y + r.height; - g.fillRect(r.x, y - getStyle().getSize(), r.width, getStyle().getSize()); + g.fillRect(r.x, y - getEffectiveStyle().getSize(), r.width, getEffectiveStyle().getSize()); break; case THICK_VERTICAL_LINE_STYLE : case VERTICAL_LINE_STYLE : @@ -464,7 +483,7 @@ public class DarkCaret extends DefaultCaret implements UIResource { } private void validateWidth(final Rectangle rect) { - if (rect != null && (rect.width <= 1 || getStyle().isCharacterWidth())) { + if (rect != null && (rect.width <= 1 || getEffectiveStyle().isCharacterWidth())) { JTextComponent textArea = getComponent(); try { textArea.getDocument().getText(getDot(), 1, seg); diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextFieldUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextFieldUI.java index b57d3485..0e4a64f3 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextFieldUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextFieldUI.java @@ -35,6 +35,8 @@ import javax.swing.event.PopupMenuListener; import javax.swing.plaf.ComponentUI; import javax.swing.text.JTextComponent; +import sun.swing.SwingUtilities2; + import com.github.weisj.darklaf.graphics.GraphicsContext; import com.github.weisj.darklaf.listener.MouseClickListener; import com.github.weisj.darklaf.listener.MouseMovementListener; @@ -42,7 +44,6 @@ import com.github.weisj.darklaf.listener.PopupMenuAdapter; import com.github.weisj.darklaf.ui.text.bridge.DarkTextFieldUIBridge; import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.PropertyUtil; -import sun.swing.SwingUtilities2; /** * @author Jannis Weis diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/tooltip/ToolTipConstants.java b/core/src/main/java/com/github/weisj/darklaf/ui/tooltip/ToolTipConstants.java index 1ea894f8..42f7e929 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/tooltip/ToolTipConstants.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/tooltip/ToolTipConstants.java @@ -30,7 +30,6 @@ public interface ToolTipConstants { String KEY_POINTER_LOCATION = "JToolTip.pointerLocation"; String KEY_POINTER_WIDTH = "JToolTip.pointerWidth"; String KEY_POINTER_HEIGHT = "JToolTip.pointerHeight"; - String KEY_PLAIN_TOOLTIP = "JComponent.plainTooltip"; String VARIANT_PLAIN = "plain"; String VARIANT_BALLOON = "balloon"; String VARIANT_PLAIN_BALLOON = "plainBalloon"; diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeUI.java index 7c731461..f607ec10 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeUI.java @@ -36,6 +36,7 @@ import javax.swing.plaf.UIResource; import javax.swing.plaf.basic.BasicTreeUI; import javax.swing.tree.*; +import com.github.weisj.darklaf.ui.cell.CellConstants; import com.github.weisj.darklaf.ui.cell.CellUtil; import com.github.weisj.darklaf.ui.cell.DarkCellRendererPane; import com.github.weisj.darklaf.util.DarkUIUtil; @@ -46,7 +47,7 @@ import com.github.weisj.darklaf.util.SystemInfo; * @author Konstantin Bulenkov * @author Jannis Weis */ -public class DarkTreeUI extends BasicTreeUI implements PropertyChangeListener { +public class DarkTreeUI extends BasicTreeUI implements PropertyChangeListener, CellConstants { protected static final String KEY_PREFIX = "JTree."; public static final String KEY_ALTERNATE_ROW_COLOR = KEY_PREFIX + "alternateRowColor"; @@ -54,8 +55,6 @@ public class DarkTreeUI extends BasicTreeUI implements PropertyChangeListener { public static final String KEY_BOOLEAN_RENDER_TYPE = KEY_PREFIX + "booleanRenderType"; public static final String KEY_LINE_STYLE = KEY_PREFIX + "lineStyle"; public static final String KEY_MAC_ACTIONS_INSTALLED = "MacTreeUi.actionsInstalled"; - public static final String RENDER_TYPE_CHECKBOX = "checkBox"; - public static final String RENDER_TYPE_RADIOBUTTON = "radioButton"; public static final String STYLE_LINE = "line"; public static final String STYLE_DASHED = "dashed"; public static final String STYLE_NONE = "none"; diff --git a/core/src/test/java/ui/text/TextFieldDemo.java b/core/src/test/java/ui/text/TextFieldDemo.java index 0d796116..1cfd9e35 100644 --- a/core/src/test/java/ui/text/TextFieldDemo.java +++ b/core/src/test/java/ui/text/TextFieldDemo.java @@ -46,6 +46,7 @@ public class TextFieldDemo implements ComponentDemo { public JComponent createComponent() { JTextField textField = createTextField(); textField.putClientProperty(DarkTextUI.KEY_DEFAULT_TEXT, "Default Text"); + textField.setFont(new Font("Roboto", Font.PLAIN, 13)); DemoPanel panel = new DemoPanel(textField); JPanel controlPanel = panel.addControls();