From 6cf75256249b234bea97677cfa244811af1688a3 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Sun, 1 Sep 2019 14:32:31 +0200 Subject: [PATCH] PopupMenuBorder implementation --- .../formdev/flatlaf/ui/FlatComboBoxUI.java | 29 +++++++++++++++ .../flatlaf/ui/FlatPopupMenuBorder.java | 36 +++++++++++++++++++ .../formdev/flatlaf/FlatDarkLaf.properties | 5 +++ .../com/formdev/flatlaf/FlatLaf.properties | 6 ++++ .../formdev/flatlaf/FlatLightLaf.properties | 5 +++ .../formdev/flatlaf/FlatTestLaf.properties | 5 +++ 6 files changed, 86 insertions(+) create mode 100644 flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatPopupMenuBorder.java diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java index cc60a5e9..109e1f51 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java @@ -32,14 +32,18 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import javax.swing.BorderFactory; import javax.swing.JButton; +import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JPanel; import javax.swing.ListCellRenderer; import javax.swing.SwingConstants; import javax.swing.UIManager; +import javax.swing.border.Border; import javax.swing.plaf.ColorUIResource; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicComboBoxUI; +import javax.swing.plaf.basic.BasicComboPopup; +import javax.swing.plaf.basic.ComboPopup; import javax.swing.text.JTextComponent; import com.formdev.flatlaf.util.UIScale; @@ -174,6 +178,11 @@ public class FlatComboBoxUI }; } + @Override + protected ComboPopup createPopup() { + return new FlatComboPopup( comboBox ); + } + @Override protected void configureEditor() { super.configureEditor(); @@ -279,4 +288,24 @@ public class FlatComboBoxUI g.setColor( comboBox.isEnabled() ? comboBox.getBackground() : disabledBackground ); g.fillRect( bounds.x, bounds.y, bounds.width, bounds.height ); } + + //---- class FlatComboPopup ----------------------------------------------- + + private class FlatComboPopup + extends BasicComboPopup + { + @SuppressWarnings( "rawtypes" ) + FlatComboPopup( JComboBox combo ) { + super( combo ); + } + + @Override + protected void configurePopup() { + super.configurePopup(); + + Border border = UIManager.getBorder( "PopupMenu.border" ); + if( border != null ) + setBorder( border ); + } + } } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatPopupMenuBorder.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatPopupMenuBorder.java new file mode 100644 index 00000000..29337781 --- /dev/null +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatPopupMenuBorder.java @@ -0,0 +1,36 @@ +/* + * Copyright 2019 FormDev Software GmbH + * + * 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.formdev.flatlaf.ui; + +import javax.swing.UIManager; + +/** + * Border for {@link javax.swing.JPopupMenu}. + * + * @uiDefault PopupMenu.borderInsets Insets + * @uiDefault PopupMenu.borderColor Color + * + * @author Karl Tauber + */ +public class FlatPopupMenuBorder + extends FlatLineBorder +{ + public FlatPopupMenuBorder() { + super( UIManager.getInsets( "PopupMenu.borderInsets" ), + UIManager.getColor( "PopupMenu.borderColor" ) ); + } +} diff --git a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarkLaf.properties b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarkLaf.properties index a477120b..86d09cd9 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarkLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarkLaf.properties @@ -122,6 +122,11 @@ MenuItemCheckBox.icon.checkmarkColor=A7A7A7 MenuItemCheckBox.icon.disabledCheckmarkColor=606060 +#---- PopupMenu ---- + +PopupMenu.borderColor=515151 + + #---- ProgressBar ---- ProgressBar.background=555555 diff --git a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties index 94912de6..bc68ee85 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties @@ -124,6 +124,12 @@ PasswordField.background=@textComponentBackground PasswordField.margin=@textComponentMargin +#---- PopupMenu ---- + +PopupMenu.border=com.formdev.flatlaf.ui.FlatPopupMenuBorder +PopupMenu.borderInsets=1,1,1,1 + + #---- PopupMenuSeparator ---- PopupMenuSeparator.height=9 diff --git a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties index 62e897de..e67e8c2b 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties @@ -122,6 +122,11 @@ MenuItemCheckBox.icon.checkmarkColor=4D89C9 MenuItemCheckBox.icon.disabledCheckmarkColor=ABABAB +#---- PopupMenu ---- + +PopupMenu.borderColor=cdcdcd + + #---- ProgressBar ---- ProgressBar.background=c4c4c4 diff --git a/flatlaf-core/src/test/resources/com/formdev/flatlaf/FlatTestLaf.properties b/flatlaf-core/src/test/resources/com/formdev/flatlaf/FlatTestLaf.properties index 710389f2..4a9150cf 100644 --- a/flatlaf-core/src/test/resources/com/formdev/flatlaf/FlatTestLaf.properties +++ b/flatlaf-core/src/test/resources/com/formdev/flatlaf/FlatTestLaf.properties @@ -121,6 +121,11 @@ MenuItemCheckBox.icon.checkmarkColor=4D89C9 MenuItemCheckBox.icon.disabledCheckmarkColor=ABABAB +#---- PopupMenu ---- + +PopupMenu.borderColor=0000ff + + #---- PopupMenuSeparator ---- PopupMenuSeparator.height=30