From a79bf740828ea2af998ff7b5ebd9bdaf73d95b5d Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Tue, 11 Apr 2023 19:03:55 +0200 Subject: [PATCH] FlatLaf: use NetBeans folder icons in NB Explorer component instead of FlatLaf outlined folder icons (e.g. Projects or Files views) patch from https://gist.github.com/eirikbakke/5587bd548a668cb0588c3fdc7d9e9f48 --- .../swing/laf/flatlaf/FlatLaf.properties | 6 ++ .../laf/flatlaf/icons/NBFlatAdapterIcon.java | 68 +++++++++++++++++++ .../flatlaf/icons/NBFlatTreeClosedIcon.java | 26 +++++++ .../laf/flatlaf/icons/NBFlatTreeOpenIcon.java | 26 +++++++ 4 files changed, 126 insertions(+) create mode 100644 platform/o.n.swing.laf.flatlaf/src/org/netbeans/swing/laf/flatlaf/icons/NBFlatAdapterIcon.java create mode 100644 platform/o.n.swing.laf.flatlaf/src/org/netbeans/swing/laf/flatlaf/icons/NBFlatTreeClosedIcon.java create mode 100644 platform/o.n.swing.laf.flatlaf/src/org/netbeans/swing/laf/flatlaf/icons/NBFlatTreeOpenIcon.java diff --git a/platform/o.n.swing.laf.flatlaf/src/org/netbeans/swing/laf/flatlaf/FlatLaf.properties b/platform/o.n.swing.laf.flatlaf/src/org/netbeans/swing/laf/flatlaf/FlatLaf.properties index 72b253d074ae..14e9814aa527 100644 --- a/platform/o.n.swing.laf.flatlaf/src/org/netbeans/swing/laf/flatlaf/FlatLaf.properties +++ b/platform/o.n.swing.laf.flatlaf/src/org/netbeans/swing/laf/flatlaf/FlatLaf.properties @@ -36,6 +36,12 @@ TabbedPane.tabHeight=30 TabbedPane.inactiveUnderlineColor = $TabbedContainer.editor.contentBorderColor +#---- Tree ---- + +Tree.closedIcon = org.netbeans.swing.laf.flatlaf.icons.NBFlatTreeClosedIcon +Tree.openIcon = org.netbeans.swing.laf.flatlaf.icons.NBFlatTreeOpenIcon + + #---- TabbedContainer ---- TabbedContainer.editor.contentBorderColor=$Component.borderColor diff --git a/platform/o.n.swing.laf.flatlaf/src/org/netbeans/swing/laf/flatlaf/icons/NBFlatAdapterIcon.java b/platform/o.n.swing.laf.flatlaf/src/org/netbeans/swing/laf/flatlaf/icons/NBFlatAdapterIcon.java new file mode 100644 index 000000000000..6d7b1cea0a5b --- /dev/null +++ b/platform/o.n.swing.laf.flatlaf/src/org/netbeans/swing/laf/flatlaf/icons/NBFlatAdapterIcon.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.netbeans.swing.laf.flatlaf.icons; + +import com.formdev.flatlaf.util.UIScale; +import java.awt.Component; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Image; +import javax.swing.Icon; +import javax.swing.ImageIcon; +import javax.swing.plaf.UIResource; +import org.openide.util.ImageUtilities; + +/** + * Adapter class which allows a NetBeans-loaded PNG or SVG icon to be used as a FlatLAF + * configuration setting. Respects FlatLAF's own scaling properties, as in + * {@code com.formdev.flatlaf.icons.FlatAbstractIcon}. + */ +abstract class NBFlatAdapterIcon implements Icon, UIResource { + private final Icon delegate; + + public NBFlatAdapterIcon(String resourcePath) { + if (resourcePath == null) { + throw new NullPointerException(); + } + Image delegateImg = ImageUtilities.loadImage(resourcePath); + this.delegate = delegateImg == null ? new ImageIcon() : ImageUtilities.image2Icon(delegateImg); + } + + @Override + public void paintIcon(Component c, Graphics g, int x, int y) { + Graphics2D g2 = (Graphics2D) g.create(); + try { + g2.translate(x, y); + UIScale.scaleGraphics(g2); + delegate.paintIcon(c, g2, 0, 0); + } finally { + g2.dispose(); + } + } + + @Override + public int getIconWidth() { + return UIScale.scale(delegate.getIconWidth()); + } + + @Override + public int getIconHeight() { + return UIScale.scale(delegate.getIconHeight()); + } +} diff --git a/platform/o.n.swing.laf.flatlaf/src/org/netbeans/swing/laf/flatlaf/icons/NBFlatTreeClosedIcon.java b/platform/o.n.swing.laf.flatlaf/src/org/netbeans/swing/laf/flatlaf/icons/NBFlatTreeClosedIcon.java new file mode 100644 index 000000000000..4863184bbad9 --- /dev/null +++ b/platform/o.n.swing.laf.flatlaf/src/org/netbeans/swing/laf/flatlaf/icons/NBFlatTreeClosedIcon.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.netbeans.swing.laf.flatlaf.icons; + +public class NBFlatTreeClosedIcon extends NBFlatAdapterIcon { + public NBFlatTreeClosedIcon() { + // Will load the SVG version if available. + super("org/netbeans/swing/plaf/resources/hidpi-folder-closed.png"); + } +} diff --git a/platform/o.n.swing.laf.flatlaf/src/org/netbeans/swing/laf/flatlaf/icons/NBFlatTreeOpenIcon.java b/platform/o.n.swing.laf.flatlaf/src/org/netbeans/swing/laf/flatlaf/icons/NBFlatTreeOpenIcon.java new file mode 100644 index 000000000000..1e75d7452378 --- /dev/null +++ b/platform/o.n.swing.laf.flatlaf/src/org/netbeans/swing/laf/flatlaf/icons/NBFlatTreeOpenIcon.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.netbeans.swing.laf.flatlaf.icons; + +public class NBFlatTreeOpenIcon extends NBFlatAdapterIcon { + public NBFlatTreeOpenIcon() { + // Will load the SVG version if available. + super("org/netbeans/swing/plaf/resources/hidpi-folder-open.png"); + } +}