From 92bcc35354b59a04de8e96d9788a467240245f80 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Tue, 3 Sep 2019 10:02:32 +0200 Subject: [PATCH] Tree implementation --- .../java/com/formdev/flatlaf/FlatLaf.java | 3 +- .../com/formdev/flatlaf/ui/FlatTreeUI.java | 61 +++++++++++++++++++ .../formdev/flatlaf/FlatDarkLaf.properties | 4 +- .../com/formdev/flatlaf/FlatLaf.properties | 16 ++++- .../formdev/flatlaf/FlatLightLaf.properties | 3 + .../formdev/flatlaf/FlatTestLaf.properties | 4 ++ 6 files changed, 86 insertions(+), 5 deletions(-) create mode 100644 flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTreeUI.java diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java index 25e7bb23..0441ced3 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java @@ -246,7 +246,8 @@ public abstract class FlatLaf return parseInstance( value ); // insets - if( key.endsWith( ".margin" ) || key.endsWith( ".padding" ) || key.endsWith( "Insets" ) ) + if( key.endsWith( ".margin" ) || key.endsWith( ".padding" ) || + key.endsWith( "Margins" ) || key.endsWith( "Insets" ) ) return parseInsets( value ); // size diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTreeUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTreeUI.java new file mode 100644 index 00000000..a7faf572 --- /dev/null +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTreeUI.java @@ -0,0 +1,61 @@ +/* + * 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.JComponent; +import javax.swing.LookAndFeel; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.basic.BasicTreeUI; +import com.formdev.flatlaf.util.UIScale; + +/** + * Provides the Flat LaF UI delegate for {@link javax.swing.JTree}. + * + * TODO document used UI defaults of superclass + * + * @uiDefault Tree.border Border + * + * @author Karl Tauber + */ +public class FlatTreeUI + extends BasicTreeUI +{ + public static ComponentUI createUI( JComponent c ) { + return new FlatTreeUI(); + } + + @Override + protected void installDefaults() { + super.installDefaults(); + + LookAndFeel.installBorder( tree, "Tree.border" ); + + // scale + int rowHeight = FlatUIUtils.getUIInt( "Tree.rowHeight", 16 ); + if( rowHeight > 0 ) + LookAndFeel.installProperty( tree, "rowHeight", UIScale.scale( rowHeight ) ); + setLeftChildIndent( UIScale.scale( getLeftChildIndent() ) ); + setRightChildIndent( UIScale.scale( getRightChildIndent() ) ); + } + + @Override + protected void uninstallDefaults() { + super.uninstallDefaults(); + + LookAndFeel.uninstallBorder( tree ); + } +} 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 75311438..1d8912ac 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarkLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarkLaf.properties @@ -26,6 +26,7 @@ @selectionForeground=@foreground @disabledText=777777 @textComponentBackground=45494A +@cellFocusColor=000000 @icon=adadad @@ -173,7 +174,6 @@ TabbedPane.contentAreaColor=323232 Table.background=@textComponentBackground Table.gridColor=4F5152 -Table.focusSelectedCellHighlightBorder=2,3,2,3,78c0ff #---- TableHeader ---- @@ -185,3 +185,5 @@ TableHeader.bottomSeparatorColor=585858 #---- Tree ---- +Tree.background=@textComponentBackground +Tree.hash=505355 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 cfe2d97b..eaf8fe12 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties @@ -44,6 +44,7 @@ TableHeaderUI=com.formdev.flatlaf.ui.FlatTableHeaderUI TextAreaUI=com.formdev.flatlaf.ui.FlatTextAreaUI TextFieldUI=com.formdev.flatlaf.ui.FlatTextFieldUI TextPaneUI=com.formdev.flatlaf.ui.FlatTextPaneUI +TreeUI=com.formdev.flatlaf.ui.FlatTreeUI #---- variables ---- @@ -99,8 +100,8 @@ FormattedTextField.margin=@textComponentMargin #---- List ---- List.cellNoFocusBorder=1,6,1,6 -List.focusCellHighlightBorder=1,6,1,6,@selectionBackground -List.focusSelectedCellHighlightBorder=1,6,1,6,@selectionBackground +List.focusCellHighlightBorder=1,6,1,6,@cellFocusColor +List.focusSelectedCellHighlightBorder=1,6,1,6,@cellFocusColor #---- Menu ---- @@ -225,7 +226,7 @@ Table.ascendingSortIcon=com.formdev.flatlaf.icons.FlatAscendingSortIcon Table.descendingSortIcon=com.formdev.flatlaf.icons.FlatDescendingSortIcon Table.sortIconColor=@icon Table.cellNoFocusBorder=2,3,2,3 -Table.focusSelectedCellHighlightBorder=2,3,2,3,@foreground +Table.focusSelectedCellHighlightBorder=2,3,2,3,@cellFocusColor #---- TableHeader ---- @@ -256,6 +257,15 @@ TextPane.margin=@textComponentMargin #---- Tree ---- +Tree.border=1,1,1,1 +Tree.textBackground=@@Tree.background +Tree.selectionBorderColor=@cellFocusColor +Tree.rendererMargins=1,2,1,2 +Tree.paintLines=false +Tree.leftChildIndent=7 +Tree.rightChildIndent=11 +Tree.rowHeight=0 + Tree.expandedIcon=com.formdev.flatlaf.icons.FlatTreeExpandedIcon Tree.collapsedIcon=com.formdev.flatlaf.icons.FlatTreeCollapsedIcon Tree.leafIcon=com.formdev.flatlaf.icons.FlatTreeLeafIcon 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 d74d0a59..8984d47e 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties @@ -26,6 +26,7 @@ @selectionForeground=ffffff @disabledText=999999 @textComponentBackground=ffffff +@cellFocusColor=000000 @icon=afafaf @@ -184,3 +185,5 @@ TableHeader.bottomSeparatorColor=e5e5e5 #---- Tree ---- +Tree.background=@textComponentBackground +Tree.hash=E6E6E6 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 f3bbda7a..c89d2af8 100644 --- a/flatlaf-core/src/test/resources/com/formdev/flatlaf/FlatTestLaf.properties +++ b/flatlaf-core/src/test/resources/com/formdev/flatlaf/FlatTestLaf.properties @@ -19,6 +19,7 @@ @background=ccffcc @selectionBackground=00aa00 @textComponentBackground=ffffff +@cellFocusColor=ff0000 @icon=afafaf @@ -197,3 +198,6 @@ TableHeader.bottomSeparatorColor=00ff00 #---- Tree ---- +Tree.background=fff0ff +Tree.paintLines=true +Tree.hash=ff0000