From 0cfea69a50b97611b050b6082e65a74a879f59ba Mon Sep 17 00:00:00 2001 From: Radek Davidek Date: Tue, 20 Jan 2026 16:18:02 +0100 Subject: [PATCH] folder shortcuts --- .../kamma/kfmanager/ui/ColoredFolderIcon.java | 22 ++++++++++++ .../cz/kamma/kfmanager/ui/FilePanelTab.java | 2 +- .../cz/kamma/kfmanager/ui/MainWindow.java | 36 ++++++++++++++++--- 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/src/main/java/cz/kamma/kfmanager/ui/ColoredFolderIcon.java b/src/main/java/cz/kamma/kfmanager/ui/ColoredFolderIcon.java index 605ef4a..693923b 100644 --- a/src/main/java/cz/kamma/kfmanager/ui/ColoredFolderIcon.java +++ b/src/main/java/cz/kamma/kfmanager/ui/ColoredFolderIcon.java @@ -8,15 +8,22 @@ import java.awt.*; */ public class ColoredFolderIcon implements Icon { private final Color color; + private final String label; public ColoredFolderIcon(Color color) { + this(color, null); + } + + public ColoredFolderIcon(Color color, String label) { this.color = color; + this.label = label; } @Override public void paintIcon(Component c, Graphics g, int x, int y) { Graphics2D g2 = (Graphics2D) g.create(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2.setColor(color); // Draw a simple folder shape @@ -28,6 +35,21 @@ public class ColoredFolderIcon implements Icon { // Optional: outline for depth g2.setColor(color.darker()); g2.drawRect(x + 2, y + 4, 12, 8); + + // Draw label if provided + if (label != null && !label.isEmpty()) { + // Calculate contrast color based on folder color + double luma = (0.299 * color.getRed() + 0.587 * color.getGreen() + 0.114 * color.getBlue()) / 255.0; + g2.setColor(luma > 0.6 ? Color.BLACK : Color.WHITE); + + // Use a small font that fits inside the folder + g2.setFont(new Font("SansSerif", Font.BOLD, 9)); + FontMetrics fm = g2.getFontMetrics(); + String firstLetter = label.substring(0, 1).toUpperCase(); + int lx = x + 2 + (12 - fm.stringWidth(firstLetter)) / 2; + int ly = y + 4 + (8 + fm.getAscent()) / 2 - 2; + g2.drawString(firstLetter, lx, ly); + } g2.dispose(); } diff --git a/src/main/java/cz/kamma/kfmanager/ui/FilePanelTab.java b/src/main/java/cz/kamma/kfmanager/ui/FilePanelTab.java index 7a3a5ab..4339846 100644 --- a/src/main/java/cz/kamma/kfmanager/ui/FilePanelTab.java +++ b/src/main/java/cz/kamma/kfmanager/ui/FilePanelTab.java @@ -2114,7 +2114,7 @@ public class FilePanelTab extends JPanel { icon = new UpArrowIcon(getForeground()); } else if (item.isDirectory()) { if (persistedConfig != null) { - icon = new ColoredFolderIcon(persistedConfig.getFolderColor()); + icon = new ColoredFolderIcon(persistedConfig.getFolderColor(), item.getName()); } } else { // Use type-specific icon for files diff --git a/src/main/java/cz/kamma/kfmanager/ui/MainWindow.java b/src/main/java/cz/kamma/kfmanager/ui/MainWindow.java index 7923fea..621c65e 100644 --- a/src/main/java/cz/kamma/kfmanager/ui/MainWindow.java +++ b/src/main/java/cz/kamma/kfmanager/ui/MainWindow.java @@ -447,12 +447,16 @@ public class MainWindow extends JFrame { toolBar.add(btnFull); toolBar.addSeparator(); - + // Load custom shortcuts from config List shortcuts = config.getToolbarShortcuts(); int btnSize = config.getToolbarButtonSize(); int iconSize = config.getToolbarIconSize(); + // Group shortcuts: directories will go to the right, others stay on the left + List leftShortcuts = new ArrayList<>(); + List rightShortcuts = new ArrayList<>(); + for (AppConfig.ToolbarShortcut s : shortcuts) { JButton btn = new JButton(); btn.setPreferredSize(new Dimension(btnSize, btnSize)); @@ -460,6 +464,12 @@ public class MainWindow extends JFrame { btn.setMaximumSize(new Dimension(btnSize, btnSize)); boolean hasIcon = false; + boolean isDirectory = false; + File target = new File(s.command); + if (target.exists() && target.isDirectory()) { + isDirectory = true; + } + if (s.iconPath != null && !s.iconPath.isEmpty()) { try { File iconFile = new File(s.iconPath); @@ -473,11 +483,10 @@ public class MainWindow extends JFrame { // If no custom icon, try to use the same icons as in file panels if (!hasIcon) { try { - File target = new File(s.command); if (target.exists()) { Icon customIcon; if (target.isDirectory()) { - customIcon = new ColoredFolderIcon(config.getFolderColor()); + customIcon = new ColoredFolderIcon(config.getFolderColor(), s.label); } else { customIcon = new FileSpecificIcon(FileSpecificIcon.getFileType(target.getName())); } @@ -541,8 +550,25 @@ public class MainWindow extends JFrame { } } }); - - toolBar.add(btn); + + if (isDirectory) { + rightShortcuts.add(btn); + } else { + leftShortcuts.add(btn); + } + } + + // Add non-directory shortcuts to the left + for (JButton b : leftShortcuts) { + toolBar.add(b); + } + + // Push directory shortcuts to the right + toolBar.add(javax.swing.Box.createHorizontalGlue()); + + // Add directory shortcuts to the right + for (JButton b : rightShortcuts) { + toolBar.add(b); } toolBar.revalidate();