From 95dbd25edb3ed70ed2e14b213cc4deb1e564bcb0 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Sat, 4 Jun 2016 14:48:23 +0200 Subject: [PATCH] win10: text fields --- .../laf/intellij/WinIntelliJTextBorder.java | 90 +++++++++++++++++++ .../laf/intellij/WinIntelliJTextFieldUI.java | 53 +++++++++++ .../ide/ui/laf/intellijlaf_native.properties | 7 +- 3 files changed, 148 insertions(+), 2 deletions(-) create mode 100644 platform/platform-impl/src/com/intellij/ide/ui/laf/intellij/WinIntelliJTextBorder.java create mode 100644 platform/platform-impl/src/com/intellij/ide/ui/laf/intellij/WinIntelliJTextFieldUI.java diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/intellij/WinIntelliJTextBorder.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/intellij/WinIntelliJTextBorder.java new file mode 100644 index 000000000000..7b59c7991446 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/intellij/WinIntelliJTextBorder.java @@ -0,0 +1,90 @@ +/* + * Copyright 2000-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.ide.ui.laf.intellij; + +import com.intellij.ide.ui.laf.darcula.ui.DarculaTextFieldUI; +import com.intellij.ide.ui.laf.darcula.ui.TextFieldWithPopupHandlerUI; +import com.intellij.openapi.ui.GraphicsConfig; +import com.intellij.ui.ColorPanel; +import com.intellij.util.ui.JBUI; + +import javax.swing.*; +import javax.swing.border.Border; +import javax.swing.plaf.UIResource; +import javax.swing.text.JTextComponent; +import java.awt.*; +import java.awt.geom.Area; +import java.awt.geom.Rectangle2D; + +/** + * @author Konstantin Bulenkov + */ +public class WinIntelliJTextBorder implements Border, UIResource { + @Override + public Insets getBorderInsets(Component c) { + int vOffset = TextFieldWithPopupHandlerUI.isSearchField(c) ? 6 : 4; + if (TextFieldWithPopupHandlerUI.isSearchFieldWithHistoryPopup(c)) { + return JBUI.insets(vOffset, 7 + 16 + 3, vOffset, 7 + 16).asUIResource(); + } + else if (TextFieldWithPopupHandlerUI.isSearchField(c)) { + return JBUI.insets(vOffset, 4 + 16 + 3, vOffset, 7 + 16).asUIResource(); + } + else if (c instanceof JTextField && c.getParent() instanceof ColorPanel) { + return JBUI.insets(3, 3, 2, 2).asUIResource(); + } + else { + return JBUI.insets(vOffset, 7, vOffset, 7).asUIResource(); + } + } + + @Override + public boolean isBorderOpaque() { + return false; + } + + @Override + public void paintBorder(Component c, Graphics g2, int x, int y, int width, int height) { + if (DarculaTextFieldUI.isSearchField(c)) return; + Graphics2D g = (Graphics2D)g2; + final GraphicsConfig config = new GraphicsConfig(g); + g.translate(x, y); + boolean editable = !(c instanceof JTextComponent) || ((JTextComponent)c).isEditable(); + + final int d = JBUI.scale(1); + final int dd = JBUI.scale(2); + if (c.hasFocus()) { + g.setColor(getBorderColor(c.isEnabled() && editable, true)); + final Area s1 = new Area(new Rectangle2D.Float(d, d, width - 2 * d, height - 2 * d)); + final Area s2 = new Area(new Rectangle2D.Float(d + dd, d + dd, width - 2*d - 2*dd, height - 2*d - 2*dd)); + s1.subtract(s2); + g.fill(s1); + } + else { + g.setColor(getBorderColor(c.isEnabled() && editable, false)); + g.drawRect(d, d, width - 2 * d, height - 2 * d); + } + g.translate(-x, -y); + config.restore(); + } + + private static Color getBorderColor(boolean enabled, boolean focus) { + if (focus) { + return UIManager.getColor("TextField.activeBorderColor"); + } + return UIManager.getColor(enabled ? "TextField.borderColor" : "disabledBorderColor"); + } +} + diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/intellij/WinIntelliJTextFieldUI.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/intellij/WinIntelliJTextFieldUI.java new file mode 100644 index 000000000000..772a86bfeb91 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/intellij/WinIntelliJTextFieldUI.java @@ -0,0 +1,53 @@ +/* + * Copyright 2000-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.ide.ui.laf.intellij; + +import com.intellij.ide.ui.laf.darcula.ui.DarculaTextFieldUI; + +import javax.swing.*; +import javax.swing.border.Border; +import javax.swing.plaf.ComponentUI; +import javax.swing.text.JTextComponent; +import java.awt.*; + +/** + * @author Konstantin Bulenkov + */ +public class WinIntelliJTextFieldUI extends DarculaTextFieldUI { + public WinIntelliJTextFieldUI(JTextField textField) { + super(textField); + } + + @SuppressWarnings({"MethodOverridesStaticMethodOfSuperclass", "UnusedDeclaration"}) + public static ComponentUI createUI(JComponent c) { + return new WinIntelliJTextFieldUI((JTextField)c); + } + + @Override + protected void paintBackground(Graphics graphics) { + super.paintBackground(graphics); + } + + @Override + protected void paintDarculaBackground(Graphics2D g, JTextComponent c, Border border) { + super.paintDarculaBackground(g, c, border); + } + + @Override + protected void paintSearchField(Graphics2D g, JTextComponent c, Rectangle r) { + super.paintSearchField(g, c, r); + } +} diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/intellijlaf_native.properties b/platform/platform-impl/src/com/intellij/ide/ui/laf/intellijlaf_native.properties index 788a7340587a..119e862b5ec9 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/laf/intellijlaf_native.properties +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/intellijlaf_native.properties @@ -59,8 +59,11 @@ Separator.foreground=cdcdcd Focus.color=ff0000 TextField.background=ffffff -TextFieldUI=com.intellij.ide.ui.laf.darcula.ui.DarculaTextFieldUI -TextField.border=com.intellij.ide.ui.laf.darcula.ui.DarculaTextBorder +TextFieldUI=com.intellij.ide.ui.laf.intellij.WinIntelliJTextFieldUI +TextField.border=com.intellij.ide.ui.laf.intellij.WinIntelliJTextBorder +TextField.activeBorderColor=0078d7 +TextField.borderColor=e8e8e8 +TextField.disabledBorderColor=e8e8e8 TextField.darcula.search.icon=/com/intellij/ide/ui/laf/icons/search.png TextField.darcula.searchWithHistory.icon=/com/intellij/ide/ui/laf/icons/searchWithHistory.png TextField.darcula.clear.icon=/com/intellij/ide/ui/laf/icons/clear.png