folder shortcuts
This commit is contained in:
parent
21d8454c61
commit
0cfea69a50
@ -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();
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -447,12 +447,16 @@ public class MainWindow extends JFrame {
|
||||
toolBar.add(btnFull);
|
||||
|
||||
toolBar.addSeparator();
|
||||
|
||||
|
||||
// Load custom shortcuts from config
|
||||
List<AppConfig.ToolbarShortcut> 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<JButton> leftShortcuts = new ArrayList<>();
|
||||
List<JButton> 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();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user