nicer icons

This commit is contained in:
rdavidek 2026-01-21 19:45:59 +01:00
parent 3471f7ad68
commit bc95ce2e39
2 changed files with 137 additions and 25 deletions

View File

@ -415,8 +415,7 @@ public class MainWindow extends JFrame {
// Refresh button // Refresh button
JButton btnRefresh = new JButton(""); JButton btnRefresh = new JButton("");
btnRefresh.setToolTipText("Refresh active panel"); setupMainToolbarButton(btnRefresh, "Refresh active panel", new Color(140, 190, 140));
btnRefresh.setFocusable(false);
btnRefresh.addActionListener(e -> { btnRefresh.addActionListener(e -> {
if (activePanel != null && activePanel.getCurrentDirectory() != null) { if (activePanel != null && activePanel.getCurrentDirectory() != null) {
activePanel.refresh(true); activePanel.refresh(true);
@ -427,8 +426,7 @@ public class MainWindow extends JFrame {
// Button for BRIEF mode // Button for BRIEF mode
JButton btnBrief = new JButton(""); JButton btnBrief = new JButton("");
btnBrief.setToolTipText("Brief mode - multiple columns (Ctrl+F1)"); setupMainToolbarButton(btnBrief, "Brief mode - multiple columns (Ctrl+F1)", new Color(230, 180, 130));
btnBrief.setFocusable(false);
btnBrief.addActionListener(e -> { btnBrief.addActionListener(e -> {
if (activePanel != null) { if (activePanel != null) {
activePanel.setViewMode(ViewMode.BRIEF); activePanel.setViewMode(ViewMode.BRIEF);
@ -437,8 +435,7 @@ public class MainWindow extends JFrame {
// Button for FULL mode // Button for FULL mode
JButton btnFull = new JButton(""); JButton btnFull = new JButton("");
btnFull.setToolTipText("Full mode - full information (Ctrl+F2)"); setupMainToolbarButton(btnFull, "Full mode - full information (Ctrl+F2)", new Color(140, 170, 220));
btnFull.setFocusable(false);
btnFull.addActionListener(e -> { btnFull.addActionListener(e -> {
if (activePanel != null) { if (activePanel != null) {
activePanel.setViewMode(ViewMode.FULL); activePanel.setViewMode(ViewMode.FULL);
@ -452,15 +449,13 @@ public class MainWindow extends JFrame {
// Search button // Search button
JButton btnSearch = new JButton("🔍"); JButton btnSearch = new JButton("🔍");
btnSearch.setToolTipText("Search files (Alt+F7)"); setupMainToolbarButton(btnSearch, "Search files (Alt+F7)", new Color(200, 160, 200));
btnSearch.setFocusable(false);
btnSearch.addActionListener(e -> showSearchDialog()); btnSearch.addActionListener(e -> showSearchDialog());
toolBar.add(btnSearch); toolBar.add(btnSearch);
// Sync button // Sync button
JButton btnSync = new JButton(""); JButton btnSync = new JButton("");
btnSync.setToolTipText("Compare directories"); setupMainToolbarButton(btnSync, "Compare directories", new Color(150, 200, 200));
btnSync.setFocusable(false);
btnSync.addActionListener(e -> showSyncDialog()); btnSync.addActionListener(e -> showSyncDialog());
toolBar.add(btnSync); toolBar.add(btnSync);
@ -477,9 +472,7 @@ public class MainWindow extends JFrame {
for (AppConfig.ToolbarShortcut s : shortcuts) { for (AppConfig.ToolbarShortcut s : shortcuts) {
JButton btn = new JButton(); JButton btn = new JButton();
btn.setPreferredSize(new Dimension(btnSize, btnSize)); setupShortcutButton(btn, s.label + " (" + s.command + ")");
btn.setMinimumSize(new Dimension(btnSize, btnSize));
btn.setMaximumSize(new Dimension(btnSize, btnSize));
boolean hasIcon = false; boolean hasIcon = false;
boolean isDirectory = false; boolean isDirectory = false;
@ -521,13 +514,12 @@ public class MainWindow extends JFrame {
} catch (Exception ignore) {} } catch (Exception ignore) {}
} }
// If no icon found, use the label text, otherwise use label as tooltip // If no icon found, use the label text
if (!hasIcon) { if (!hasIcon) {
btn.setText(s.label); btn.setText(s.label);
btn.setFont(btn.getFont().deriveFont(Font.BOLD, 12f));
} }
btn.setToolTipText(s.label + " (" + s.command + ")");
btn.setFocusable(false);
btn.addActionListener(e -> { btn.addActionListener(e -> {
// If command is a directory that exists, change active panel directory // If command is a directory that exists, change active panel directory
File dir = new File(s.command); File dir = new File(s.command);
@ -593,6 +585,70 @@ public class MainWindow extends JFrame {
toolBar.repaint(); toolBar.repaint();
} }
private void setupMainToolbarButton(JButton btn, String tooltip, Color color) {
int btnSize = config != null ? config.getToolbarButtonSize() : 35;
if (btnSize < 35) btnSize = 35;
btn.setPreferredSize(new Dimension(btnSize, btnSize));
btn.setMinimumSize(new Dimension(btnSize, btnSize));
btn.setMaximumSize(new Dimension(btnSize, btnSize));
btn.setToolTipText(tooltip);
btn.setFont(btn.getFont().deriveFont(Font.BOLD, 18f));
btn.setFocusPainted(false);
Color bg = config != null ? config.getBackgroundColor() : Color.WHITE;
boolean dark = isDark(bg);
Color foregroundColor = dark ? color.brighter() : color.darker();
btn.setForeground(foregroundColor);
btn.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
btn.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
btn.setBackground(color);
btn.setForeground(isDark(color) ? Color.WHITE : Color.BLACK);
btn.setOpaque(true);
}
@Override
public void mouseExited(MouseEvent e) {
btn.setBackground(null);
btn.setForeground(foregroundColor);
btn.setOpaque(false);
}
});
btn.setContentAreaFilled(false);
}
private void setupShortcutButton(JButton btn, String tooltip) {
int btnSize = config != null ? config.getToolbarButtonSize() : 35;
btn.setPreferredSize(new Dimension(btnSize, btnSize));
btn.setMinimumSize(new Dimension(btnSize, btnSize));
btn.setMaximumSize(new Dimension(btnSize, btnSize));
btn.setToolTipText(tooltip);
btn.setFocusable(false);
btn.setFocusPainted(false);
btn.setContentAreaFilled(false);
Color bg = config != null ? config.getBackgroundColor() : Color.WHITE;
boolean dark = isDark(bg);
btn.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
btn.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
btn.setBackground(dark ? new Color(80, 80, 80) : new Color(230, 230, 230));
btn.setOpaque(true);
}
@Override
public void mouseExited(MouseEvent e) {
btn.setOpaque(false);
}
});
}
private void showAddToolbarShortcutDialog(File file) { private void showAddToolbarShortcutDialog(File file) {
showToolbarShortcutEditor(null, file); showToolbarShortcutEditor(null, file);
} }

View File

@ -102,21 +102,39 @@ public class SyncDirectoriesDialog extends JDialog {
optionsPanel.add(Box.createHorizontalStrut(20)); optionsPanel.add(Box.createHorizontalStrut(20));
optionsPanel.add(new JLabel("Show:")); optionsPanel.add(new JLabel("Show:"));
showLeftOnlyBtn = new JToggleButton(""); showLeftOnlyBtn = new JToggleButton("");
showEqualBtn = new JToggleButton("="); showEqualBtn = new JToggleButton("=");
showDiffBtn = new JToggleButton(""); showDiffBtn = new JToggleButton("");
showRightOnlyBtn = new JToggleButton(""); showRightOnlyBtn = new JToggleButton("");
Dimension btnSize = new Dimension(45, 30);
setupToolbarButton(showLeftOnlyBtn, btnSize, "Show files only on left or newer on left", new Color(0, 130, 0));
setupToolbarButton(showEqualBtn, btnSize, "Show equal files", Color.GRAY);
setupToolbarButton(showDiffBtn, btnSize, "Show different files", Color.RED);
setupToolbarButton(showRightOnlyBtn, btnSize, "Show files only on right or newer on right", Color.BLUE);
showLeftOnlyBtn.setSelected(config.getSyncShowLeftOnly()); showLeftOnlyBtn.setSelected(config.getSyncShowLeftOnly());
showEqualBtn.setSelected(config.getSyncShowEqual()); showEqualBtn.setSelected(config.getSyncShowEqual());
showDiffBtn.setSelected(config.getSyncShowDiff()); showDiffBtn.setSelected(config.getSyncShowDiff());
showRightOnlyBtn.setSelected(config.getSyncShowRightOnly()); showRightOnlyBtn.setSelected(config.getSyncShowRightOnly());
// Update background/foreground for buttons based on initial selection
updateButtonSelection(showLeftOnlyBtn, new Color(0, 130, 0));
updateButtonSelection(showEqualBtn, Color.GRAY);
updateButtonSelection(showDiffBtn, Color.RED);
updateButtonSelection(showRightOnlyBtn, Color.BLUE);
java.awt.event.ActionListener filterAl = e -> { java.awt.event.ActionListener filterAl = e -> {
config.setSyncShowLeftOnly(showLeftOnlyBtn.isSelected()); config.setSyncShowLeftOnly(showLeftOnlyBtn.isSelected());
config.setSyncShowEqual(showEqualBtn.isSelected()); config.setSyncShowEqual(showEqualBtn.isSelected());
config.setSyncShowDiff(showDiffBtn.isSelected()); config.setSyncShowDiff(showDiffBtn.isSelected());
config.setSyncShowRightOnly(showRightOnlyBtn.isSelected()); config.setSyncShowRightOnly(showRightOnlyBtn.isSelected());
updateButtonSelection(showLeftOnlyBtn, new Color(0, 130, 0));
updateButtonSelection(showEqualBtn, Color.GRAY);
updateButtonSelection(showDiffBtn, Color.RED);
updateButtonSelection(showRightOnlyBtn, Color.BLUE);
applyFilters(); applyFilters();
}; };
showLeftOnlyBtn.addActionListener(filterAl); showLeftOnlyBtn.addActionListener(filterAl);
@ -140,6 +158,12 @@ public class SyncDirectoriesDialog extends JDialog {
config.setSyncShowEqual(true); config.setSyncShowEqual(true);
config.setSyncShowDiff(true); config.setSyncShowDiff(true);
config.setSyncShowRightOnly(false); config.setSyncShowRightOnly(false);
updateButtonSelection(showLeftOnlyBtn, new Color(0, 130, 0));
updateButtonSelection(showEqualBtn, Color.GRAY);
updateButtonSelection(showDiffBtn, Color.RED);
updateButtonSelection(showRightOnlyBtn, Color.BLUE);
applyFilters(); applyFilters();
}); });
JButton singlesBtn = new JButton("singles"); JButton singlesBtn = new JButton("singles");
@ -152,6 +176,12 @@ public class SyncDirectoriesDialog extends JDialog {
config.setSyncShowEqual(false); config.setSyncShowEqual(false);
config.setSyncShowDiff(false); config.setSyncShowDiff(false);
config.setSyncShowRightOnly(true); config.setSyncShowRightOnly(true);
updateButtonSelection(showLeftOnlyBtn, new Color(0, 130, 0));
updateButtonSelection(showEqualBtn, Color.GRAY);
updateButtonSelection(showDiffBtn, Color.RED);
updateButtonSelection(showRightOnlyBtn, Color.BLUE);
applyFilters(); applyFilters();
}); });
optionsPanel.add(duplicatesBtn); optionsPanel.add(duplicatesBtn);
@ -195,6 +225,30 @@ public class SyncDirectoriesDialog extends JDialog {
add(bottomPanel, BorderLayout.SOUTH); add(bottomPanel, BorderLayout.SOUTH);
} }
private void setupToolbarButton(JToggleButton btn, Dimension size, String tooltip, Color color) {
btn.setPreferredSize(size);
btn.setMinimumSize(size);
btn.setMaximumSize(size);
btn.setToolTipText(tooltip);
btn.setFont(btn.getFont().deriveFont(Font.BOLD, 16f));
btn.setFocusPainted(false);
btn.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(color.darker(), 1),
BorderFactory.createEmptyBorder(2, 5, 2, 5)
));
btn.setForeground(color);
}
private void updateButtonSelection(JToggleButton btn, Color color) {
if (btn.isSelected()) {
btn.setBackground(color);
btn.setForeground(isDark(color) ? Color.WHITE : Color.BLACK);
} else {
btn.setBackground(null);
btn.setForeground(color);
}
}
private void saveSettings() { private void saveSettings() {
if (config != null) { if (config != null) {
config.saveSyncDialogState(this); config.saveSyncDialogState(this);
@ -219,14 +273,16 @@ public class SyncDirectoriesDialog extends JDialog {
Color selColor = config != null ? config.getSelectionColor() : null; Color selColor = config != null ? config.getSelectionColor() : null;
for (Component c : container.getComponents()) { for (Component c : container.getComponents()) {
if (c instanceof JPanel || c instanceof JScrollPane || c instanceof JViewport || c instanceof JTabbedPane || c instanceof JButton || c instanceof JComboBox || c instanceof JTable) { if (c instanceof JPanel || c instanceof JScrollPane || c instanceof JViewport || c instanceof JTabbedPane || c instanceof AbstractButton || c instanceof JComboBox || c instanceof JTable) {
if (!(c instanceof JToggleButton)) { if (!(c instanceof JToggleButton)) {
c.setBackground(bg); c.setBackground(bg);
} }
} }
if (c instanceof JLabel || c instanceof JCheckBox || c instanceof JRadioButton || c instanceof JButton) { if (c instanceof JLabel || c instanceof JCheckBox || c instanceof JRadioButton || c instanceof AbstractButton) {
if (!(c instanceof JToggleButton)) {
c.setForeground(dark ? Color.WHITE : Color.BLACK); c.setForeground(dark ? Color.WHITE : Color.BLACK);
} }
}
if (c instanceof javax.swing.text.JTextComponent) { if (c instanceof javax.swing.text.JTextComponent) {
javax.swing.text.JTextComponent tc = (javax.swing.text.JTextComponent) c; javax.swing.text.JTextComponent tc = (javax.swing.text.JTextComponent) c;
tc.setBackground(bg); tc.setBackground(bg);