Browse Source

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.
pull/188/head
weisj 4 years ago
parent
commit
e539f28636
  1. 2
      core/src/main/java/com/github/weisj/darklaf/components/tooltip/ToolTipContext.java
  2. 4
      core/src/main/java/com/github/weisj/darklaf/graphics/StringPainter.java
  3. 30
      core/src/main/java/com/github/weisj/darklaf/ui/cell/CellConstants.java
  4. 5
      core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUI.java
  5. 5
      core/src/main/java/com/github/weisj/darklaf/ui/table/TableConstants.java
  6. 39
      core/src/main/java/com/github/weisj/darklaf/ui/text/DarkCaret.java
  7. 3
      core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextFieldUI.java
  8. 1
      core/src/main/java/com/github/weisj/darklaf/ui/tooltip/ToolTipConstants.java
  9. 5
      core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeUI.java
  10. 1
      core/src/test/java/ui/text/TextFieldDemo.java

2
core/src/main/java/com/github/weisj/darklaf/components/tooltip/ToolTipContext.java

@ -49,7 +49,7 @@ public class ToolTipContext {
return defaultContext; return defaultContext;
} }
private static ToolTipContext createDefaultContext() { public static ToolTipContext createDefaultContext() {
return new ToolTipContext().setAlignment(Alignment.SOUTH) return new ToolTipContext().setAlignment(Alignment.SOUTH)
.setCenterAlignment(Alignment.SOUTH) .setCenterAlignment(Alignment.SOUTH)
.setAlignInside(false) .setAlignInside(false)

4
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; boolean imgGraphics = false;
Component window = c; Component window = c;
if (translucentAAPaintingEnabled && SystemInfo.isWindows) { if (translucentAAPaintingEnabled && SystemInfo.isWindows && !GraphicsUtil.isOpaqueBuffered(c)) {
Component comp = c; Component comp = c;
while (comp != null) { while (comp != null) {
Color bg = comp.getBackground(); Color bg = comp.getBackground();

30
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";
}

5
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.*;
import javax.swing.plaf.ComponentUI; 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.CellUtil;
import com.github.weisj.darklaf.ui.cell.DarkCellRendererPane; import com.github.weisj.darklaf.ui.cell.DarkCellRendererPane;
import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.DarkUIUtil;
@ -39,7 +40,7 @@ import com.github.weisj.darklaf.util.PropertyUtil;
/** /**
* @author Jannis Weis * @author Jannis Weis
*/ */
public class DarkListUI extends DarkListUIBridge { public class DarkListUI extends DarkListUIBridge implements CellConstants {
protected static final String KEY_PREFIX = "JList."; protected static final String KEY_PREFIX = "JList.";
public static final String KEY_IS_COMBO_LIST = KEY_PREFIX + ".isComboList"; 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_SHRINK_WRAP = KEY_PREFIX + "shrinkWrap";
public static final String KEY_FULL_ROW_SELECTION = KEY_PREFIX + "fullRowSelection"; 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 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"; public static final String KEY_IS_LIST_EDITOR = "JComponent.listCellEditor";
protected DarkListCellRendererDelegate rendererDelegate; protected DarkListCellRendererDelegate rendererDelegate;

5
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 javax.swing.*;
import com.github.weisj.darklaf.ui.cell.CellConstants;
import com.github.weisj.darklaf.util.PropertyUtil; 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_EDITOR = "JComponent.isTableEditor";
String KEY_IS_TABLE_RENDERER = "JComponent.isTableRenderer"; String KEY_IS_TABLE_RENDERER = "JComponent.isTableRenderer";
@ -44,8 +45,6 @@ public interface TableConstants {
String KEY_VERTICAL_LINES = "showVerticalLines"; String KEY_VERTICAL_LINES = "showVerticalLines";
String KEY_IS_FILE_LIST = "Table.isFileList"; String KEY_IS_FILE_LIST = "Table.isFileList";
String KEY_IS_PRINT_MODE = "Table.printMode"; String KEY_IS_PRINT_MODE = "Table.printMode";
String RENDER_TYPE_CHECKBOX = "checkBox";
String RENDER_TYPE_RADIOBUTTON = "radioButton";
static boolean isBooleanRenderingEnabled(final JTable table) { static boolean isBooleanRenderingEnabled(final JTable table) {
return PropertyUtil.getBooleanProperty(table, DarkTableUI.KEY_RENDER_BOOLEAN_AS_CHECKBOX); return PropertyUtil.getBooleanProperty(table, DarkTableUI.KEY_RENDER_BOOLEAN_AS_CHECKBOX);

39
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); getDarkSelectionPainter().setLineExtendingEnabled(enabled);
} }
public CaretStyle getStyle() { public CaretStyle getEffectiveStyle() {
return isInsertMode() ? insertStyle : style; 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 s = style;
CaretStyle is = insertStyle;
if (s == null) { if (s == null) {
s = CaretStyle.THICK_VERTICAL_LINE_STYLE; 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) { if (is == null) {
is = CaretStyle.BLOCK_BORDER_STYLE; is = CaretStyle.BLOCK_BORDER_STYLE;
} }
if (s != this.style || is != this.insertStyle) { if (is != this.insertStyle) {
this.style = s;
this.insertStyle = is; this.insertStyle = is;
repaint(); repaint();
} }
} }
public void setStyles(final CaretStyle style, final CaretStyle insertStyle) {
setInsertStyle(insertStyle);
setStyle(style);
}
public boolean isAlwaysVisible() { public boolean isAlwaysVisible() {
return alwaysVisible; return alwaysVisible;
} }
@ -201,7 +220,7 @@ public class DarkCaret extends DefaultCaret implements UIResource {
@Override @Override
public double getWidth() { public double getWidth() {
return getStyle().getSize(); return getEffectiveStyle().getSize();
} }
/** /**
@ -377,18 +396,18 @@ public class DarkCaret extends DefaultCaret implements UIResource {
if (textAreaBg == null) { if (textAreaBg == null) {
textAreaBg = Color.white; textAreaBg = Color.white;
} }
switch (getStyle()) { switch (getEffectiveStyle()) {
case BLOCK_STYLE : case BLOCK_STYLE :
g.setXORMode(textAreaBg); g.setXORMode(textAreaBg);
g.fillRect(r.x, r.y, r.width, r.height); g.fillRect(r.x, r.y, r.width, r.height);
break; break;
case BLOCK_BORDER_STYLE : 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; break;
case UNDERLINE_STYLE : case UNDERLINE_STYLE :
g.setXORMode(textAreaBg); g.setXORMode(textAreaBg);
int y = r.y + r.height; 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; break;
case THICK_VERTICAL_LINE_STYLE : case THICK_VERTICAL_LINE_STYLE :
case VERTICAL_LINE_STYLE : case VERTICAL_LINE_STYLE :
@ -464,7 +483,7 @@ public class DarkCaret extends DefaultCaret implements UIResource {
} }
private void validateWidth(final Rectangle rect) { 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(); JTextComponent textArea = getComponent();
try { try {
textArea.getDocument().getText(getDot(), 1, seg); textArea.getDocument().getText(getDot(), 1, seg);

3
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.plaf.ComponentUI;
import javax.swing.text.JTextComponent; import javax.swing.text.JTextComponent;
import sun.swing.SwingUtilities2;
import com.github.weisj.darklaf.graphics.GraphicsContext; import com.github.weisj.darklaf.graphics.GraphicsContext;
import com.github.weisj.darklaf.listener.MouseClickListener; import com.github.weisj.darklaf.listener.MouseClickListener;
import com.github.weisj.darklaf.listener.MouseMovementListener; 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.ui.text.bridge.DarkTextFieldUIBridge;
import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.PropertyUtil; import com.github.weisj.darklaf.util.PropertyUtil;
import sun.swing.SwingUtilities2;
/** /**
* @author Jannis Weis * @author Jannis Weis

1
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_LOCATION = "JToolTip.pointerLocation";
String KEY_POINTER_WIDTH = "JToolTip.pointerWidth"; String KEY_POINTER_WIDTH = "JToolTip.pointerWidth";
String KEY_POINTER_HEIGHT = "JToolTip.pointerHeight"; String KEY_POINTER_HEIGHT = "JToolTip.pointerHeight";
String KEY_PLAIN_TOOLTIP = "JComponent.plainTooltip";
String VARIANT_PLAIN = "plain"; String VARIANT_PLAIN = "plain";
String VARIANT_BALLOON = "balloon"; String VARIANT_BALLOON = "balloon";
String VARIANT_PLAIN_BALLOON = "plainBalloon"; String VARIANT_PLAIN_BALLOON = "plainBalloon";

5
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.plaf.basic.BasicTreeUI;
import javax.swing.tree.*; 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.CellUtil;
import com.github.weisj.darklaf.ui.cell.DarkCellRendererPane; import com.github.weisj.darklaf.ui.cell.DarkCellRendererPane;
import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.DarkUIUtil;
@ -46,7 +47,7 @@ import com.github.weisj.darklaf.util.SystemInfo;
* @author Konstantin Bulenkov * @author Konstantin Bulenkov
* @author Jannis Weis * @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."; protected static final String KEY_PREFIX = "JTree.";
public static final String KEY_ALTERNATE_ROW_COLOR = KEY_PREFIX + "alternateRowColor"; 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_BOOLEAN_RENDER_TYPE = KEY_PREFIX + "booleanRenderType";
public static final String KEY_LINE_STYLE = KEY_PREFIX + "lineStyle"; public static final String KEY_LINE_STYLE = KEY_PREFIX + "lineStyle";
public static final String KEY_MAC_ACTIONS_INSTALLED = "MacTreeUi.actionsInstalled"; 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_LINE = "line";
public static final String STYLE_DASHED = "dashed"; public static final String STYLE_DASHED = "dashed";
public static final String STYLE_NONE = "none"; public static final String STYLE_NONE = "none";

1
core/src/test/java/ui/text/TextFieldDemo.java

@ -46,6 +46,7 @@ public class TextFieldDemo implements ComponentDemo {
public JComponent createComponent() { public JComponent createComponent() {
JTextField textField = createTextField(); JTextField textField = createTextField();
textField.putClientProperty(DarkTextUI.KEY_DEFAULT_TEXT, "Default Text"); textField.putClientProperty(DarkTextUI.KEY_DEFAULT_TEXT, "Default Text");
textField.setFont(new Font("Roboto", Font.PLAIN, 13));
DemoPanel panel = new DemoPanel(textField); DemoPanel panel = new DemoPanel(textField);
JPanel controlPanel = panel.addControls(); JPanel controlPanel = panel.addControls();

Loading…
Cancel
Save