Merge pull request 'appmod/java-upgrade-20260130124304' (#1) from appmod/java-upgrade-20260130124304 into main

Reviewed-on: #1
This commit is contained in:
kamma 2026-01-30 14:02:17 +01:00
commit 9ebb0c3de4
16 changed files with 225 additions and 237 deletions

View File

@ -15,8 +15,8 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source> <maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target> <maven.compiler.target>21</maven.compiler.target>
</properties> </properties>
<build> <build>
@ -41,10 +41,9 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version> <version>3.14.1</version>
<configuration> <configuration>
<source>11</source> <release>21</release>
<target>11</target>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>

View File

@ -138,8 +138,7 @@ public class MainApp {
private static void setupGlobalKeyNavigation() { private static void setupGlobalKeyNavigation() {
Toolkit.getDefaultToolkit().addAWTEventListener(event -> { Toolkit.getDefaultToolkit().addAWTEventListener(event -> {
if (event instanceof KeyEvent) { if (event instanceof KeyEvent ke) {
KeyEvent ke = (KeyEvent) event;
if (ke.getID() == KeyEvent.KEY_PRESSED) { if (ke.getID() == KeyEvent.KEY_PRESSED) {
int code = ke.getKeyCode(); int code = ke.getKeyCode();
if (code == KeyEvent.VK_LEFT || code == KeyEvent.VK_RIGHT) { if (code == KeyEvent.VK_LEFT || code == KeyEvent.VK_RIGHT) {
@ -166,16 +165,15 @@ public class MainApp {
public static void applyReflectiveCaretColor(Container container) { public static void applyReflectiveCaretColor(Container container) {
if (container == null) return; if (container == null) return;
for (Component c : container.getComponents()) { for (Component c : container.getComponents()) {
if (c instanceof javax.swing.text.JTextComponent) { if (c instanceof javax.swing.text.JTextComponent tc) {
javax.swing.text.JTextComponent tc = (javax.swing.text.JTextComponent) c;
Color bg = tc.getBackground(); Color bg = tc.getBackground();
if (bg != null) { if (bg != null) {
double darkness = 1 - (0.299 * bg.getRed() + 0.587 * bg.getGreen() + 0.114 * bg.getBlue()) / 255; double darkness = 1 - (0.299 * bg.getRed() + 0.587 * bg.getGreen() + 0.114 * bg.getBlue()) / 255;
tc.setCaretColor(darkness >= 0.5 ? Color.WHITE : Color.BLACK); tc.setCaretColor(darkness >= 0.5 ? Color.WHITE : Color.BLACK);
} }
} }
if (c instanceof Container) { if (c instanceof Container container1) {
applyReflectiveCaretColor((Container) c); applyReflectiveCaretColor(container1);
} }
} }
} }

View File

@ -466,7 +466,7 @@ public class AppConfig {
if (c == null) { if (c == null) {
properties.remove("appearance.bg"); properties.remove("appearance.bg");
} else { } else {
properties.setProperty("appearance.bg", String.format("#%02x%02x%02x", c.getRed(), c.getGreen(), c.getBlue())); properties.setProperty("appearance.bg", "#%02x%02x%02x".formatted(c.getRed(), c.getGreen(), c.getBlue()));
} }
} }
@ -480,7 +480,7 @@ public class AppConfig {
if (c == null) { if (c == null) {
properties.remove("appearance.selection"); properties.remove("appearance.selection");
} else { } else {
properties.setProperty("appearance.selection", String.format("#%02x%02x%02x", c.getRed(), c.getGreen(), c.getBlue())); properties.setProperty("appearance.selection", "#%02x%02x%02x".formatted(c.getRed(), c.getGreen(), c.getBlue()));
} }
} }
@ -494,7 +494,7 @@ public class AppConfig {
if (c == null) { if (c == null) {
properties.remove("appearance.marked"); properties.remove("appearance.marked");
} else { } else {
properties.setProperty("appearance.marked", String.format("#%02x%02x%02x", c.getRed(), c.getGreen(), c.getBlue())); properties.setProperty("appearance.marked", "#%02x%02x%02x".formatted(c.getRed(), c.getGreen(), c.getBlue()));
} }
} }
@ -508,7 +508,7 @@ public class AppConfig {
if (c == null) { if (c == null) {
properties.remove("appearance.folder"); properties.remove("appearance.folder");
} else { } else {
properties.setProperty("appearance.folder", String.format("#%02x%02x%02x", c.getRed(), c.getGreen(), c.getBlue())); properties.setProperty("appearance.folder", "#%02x%02x%02x".formatted(c.getRed(), c.getGreen(), c.getBlue()));
} }
} }

View File

@ -118,11 +118,11 @@ public class FileItem {
if (size < 1024) { if (size < 1024) {
return size + " B"; return size + " B";
} else if (size < 1024 * 1024) { } else if (size < 1024 * 1024) {
return String.format("%.1f KB", size / 1024.0); return "%.1f KB".formatted(size / 1024.0);
} else if (size < 1024 * 1024 * 1024) { } else if (size < 1024 * 1024 * 1024) {
return String.format("%.1f MB", size / (1024.0 * 1024.0)); return "%.1f MB".formatted(size / (1024.0 * 1024.0));
} else { } else {
return String.format("%.1f GB", size / (1024.0 * 1024.0 * 1024.0)); return "%.1f GB".formatted(size / (1024.0 * 1024.0 * 1024.0));
} }
} }
} }

View File

@ -44,8 +44,7 @@ public class DriveSelector extends JDialog {
int index, boolean isSelected, boolean cellHasFocus) { int index, boolean isSelected, boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value instanceof DriveInfo) { if (value instanceof DriveInfo info) {
DriveInfo info = (DriveInfo) value;
setText(info.getDisplayText()); setText(info.getDisplayText());
} }
@ -142,10 +141,10 @@ public class DriveSelector extends JDialog {
long usedSpace = totalSpace - freeSpace; long usedSpace = totalSpace - freeSpace;
if (totalSpace > 0) { if (totalSpace > 0) {
return String.format("%s %s / %s free", return "%s %s / %s free".formatted(
path, path,
formatSize(usedSpace), formatSize(usedSpace),
formatSize(freeSpace)); formatSize(freeSpace));
} else { } else {
return path; return path;
} }
@ -155,13 +154,13 @@ public class DriveSelector extends JDialog {
if (size < 1024) { if (size < 1024) {
return size + " B"; return size + " B";
} else if (size < 1024L * 1024) { } else if (size < 1024L * 1024) {
return String.format("%.1f KB", size / 1024.0); return "%.1f KB".formatted(size / 1024.0);
} else if (size < 1024L * 1024 * 1024) { } else if (size < 1024L * 1024 * 1024) {
return String.format("%.1f MB", size / (1024.0 * 1024.0)); return "%.1f MB".formatted(size / (1024.0 * 1024.0));
} else if (size < 1024L * 1024 * 1024 * 1024) { } else if (size < 1024L * 1024 * 1024 * 1024) {
return String.format("%.1f GB", size / (1024.0 * 1024.0 * 1024.0)); return "%.1f GB".formatted(size / (1024.0 * 1024.0 * 1024.0));
} else { } else {
return String.format("%.1f TB", size / (1024.0 * 1024.0 * 1024.0 * 1024.0)); return "%.1f TB".formatted(size / (1024.0 * 1024.0 * 1024.0 * 1024.0));
} }
} }
} }

View File

@ -35,8 +35,8 @@ public class FileChooserUtils {
public void hierarchyChanged(HierarchyEvent e) { public void hierarchyChanged(HierarchyEvent e) {
if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0 && chooser.isShowing()) { if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0 && chooser.isShowing()) {
Window window = SwingUtilities.getWindowAncestor(chooser); Window window = SwingUtilities.getWindowAncestor(chooser);
if (window instanceof JDialog) { if (window instanceof JDialog dialog) {
dialogRef[0] = (JDialog) window; dialogRef[0] = dialog;
// Restore size and position // Restore size and position
int w = config.getFileChooserWidth(); int w = config.getFileChooserWidth();
int h = config.getFileChooserHeight(); int h = config.getFileChooserHeight();

View File

@ -137,7 +137,7 @@ public class FileEditor extends JFrame {
} else if (config != null) { } else if (config != null) {
java.util.List<String> hist = config.getContentSearchHistory(); java.util.List<String> hist = config.getContentSearchHistory();
if (hist != null && !hist.isEmpty()) { if (hist != null && !hist.isEmpty()) {
lastSearchValue = hist.get(0); lastSearchValue = hist.getFirst();
searchField.setText(lastSearchValue); searchField.setText(lastSearchValue);
} }
} }
@ -243,7 +243,7 @@ public class FileEditor extends JFrame {
if (config == null || text == null || text.isEmpty()) return; if (config == null || text == null || text.isEmpty()) return;
java.util.List<String> hist = new java.util.ArrayList<>(config.getContentSearchHistory()); java.util.List<String> hist = new java.util.ArrayList<>(config.getContentSearchHistory());
hist.remove(text); hist.remove(text);
hist.add(0, text); hist.addFirst(text);
if (hist.size() > 20) hist = hist.subList(0, 20); if (hist.size() > 20) hist = hist.subList(0, 20);
config.saveContentSearchHistory(hist); config.saveContentSearchHistory(hist);
config.saveConfig(); config.saveConfig();
@ -405,14 +405,13 @@ public class FileEditor extends JFrame {
if (c instanceof JLabel) { if (c instanceof JLabel) {
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 tc) {
javax.swing.text.JTextComponent tc = (javax.swing.text.JTextComponent) c;
tc.setBackground(bg); tc.setBackground(bg);
tc.setForeground(dark ? Color.WHITE : Color.BLACK); tc.setForeground(dark ? Color.WHITE : Color.BLACK);
tc.setCaretColor(dark ? Color.WHITE : Color.BLACK); tc.setCaretColor(dark ? Color.WHITE : Color.BLACK);
} }
if (c instanceof Container) { if (c instanceof Container container1) {
applyRecursiveColors((Container) c, bg, dark); applyRecursiveColors(container1, bg, dark);
} }
} }
} }
@ -717,7 +716,7 @@ public class FileEditor extends JFrame {
int bytesPerLine = 16; int bytesPerLine = 16;
for (int i = 0; i < fileBytes.length; i += bytesPerLine) { for (int i = 0; i < fileBytes.length; i += bytesPerLine) {
long displayOffset = baseOffset + i; long displayOffset = baseOffset + i;
sb.append(String.format("%08X ", displayOffset)); sb.append("%08X ".formatted(displayOffset));
// hex bytes // hex bytes
for (int j = 0; j < bytesPerLine; j++) { for (int j = 0; j < bytesPerLine; j++) {
int idx = i + j; int idx = i + j;
@ -725,7 +724,7 @@ public class FileEditor extends JFrame {
int b = fileBytes[idx] & 0xFF; int b = fileBytes[idx] & 0xFF;
int pos = sb.length(); int pos = sb.length();
byteTextOffsets.add(pos); byteTextOffsets.add(pos);
sb.append(String.format("%02X", b)); sb.append("%02X".formatted(b));
} else { } else {
// placeholder for missing byte // placeholder for missing byte
sb.append(" "); sb.append(" ");
@ -762,7 +761,7 @@ public class FileEditor extends JFrame {
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
try { try {
if (byteTextOffsets != null && !byteTextOffsets.isEmpty()) { if (byteTextOffsets != null && !byteTextOffsets.isEmpty()) {
int pos = Math.max(0, byteTextOffsets.get(0)); int pos = Math.max(0, byteTextOffsets.getFirst());
textArea.setCaretPosition(pos); textArea.setCaretPosition(pos);
// ensure the caret is visible at top-left // ensure the caret is visible at top-left
Rectangle vis = textArea.getVisibleRect(); Rectangle vis = textArea.getVisibleRect();
@ -789,11 +788,11 @@ public class FileEditor extends JFrame {
if (pageOffsetLabel != null) { if (pageOffsetLabel != null) {
long start = pageOffsetBytes; long start = pageOffsetBytes;
long end = pageOffsetBytes + page.length - 1; long end = pageOffsetBytes + page.length - 1;
pageOffsetLabel.setText(String.format("Offset: 0x%08X - 0x%08X", start, end)); pageOffsetLabel.setText("Offset: 0x%08X - 0x%08X".formatted(start, end));
} }
// Position caret at first byte hex position for consistent mapping // Position caret at first byte hex position for consistent mapping
if (byteTextOffsets != null && !byteTextOffsets.isEmpty()) { if (byteTextOffsets != null && !byteTextOffsets.isEmpty()) {
int pos = byteTextOffsets.get(0); int pos = byteTextOffsets.getFirst();
textArea.setCaretPosition(Math.max(0, pos)); textArea.setCaretPosition(Math.max(0, pos));
} else { } else {
textArea.setCaretPosition(0); textArea.setCaretPosition(0);
@ -987,13 +986,13 @@ public class FileEditor extends JFrame {
label.setHorizontalAlignment(JLabel.CENTER); label.setHorizontalAlignment(JLabel.CENTER);
scrollPane.setViewportView(label); scrollPane.setViewportView(label);
String statusText = String.format("Image: %d x %d px", imgW, imgH); String statusText = "Image: %d x %d px".formatted(imgW, imgH);
if (scaled) statusText += " (scaled)"; if (scaled) statusText += " (scaled)";
statusPosLabel.setText(statusText); statusPosLabel.setText(statusText);
String labelText = String.format("Size: %s", FileItem.formatSize(file.length())); String labelText = "Size: %s".formatted(FileItem.formatSize(file.length()));
if (imageFiles.size() > 1) { if (imageFiles.size() > 1) {
labelText += String.format(" [%d / %d]", currentImageIndex + 1, imageFiles.size()); labelText += " [%d / %d]".formatted(currentImageIndex + 1, imageFiles.size());
} }
statusSelLabel.setText(labelText); statusSelLabel.setText(labelText);
@ -1217,7 +1216,7 @@ public class FileEditor extends JFrame {
root.getActionMap().put("press", new AbstractAction() { root.getActionMap().put("press", new AbstractAction() {
@Override public void actionPerformed(java.awt.event.ActionEvent e) { @Override public void actionPerformed(java.awt.event.ActionEvent e) {
java.awt.Component c = dlg.getFocusOwner(); java.awt.Component c = dlg.getFocusOwner();
if (c instanceof JButton) ((JButton)c).doClick(); if (c instanceof JButton button) button.doClick();
} }
}); });
@ -1260,7 +1259,7 @@ public class FileEditor extends JFrame {
long byteIndex = mapCaretToByteIndex(caret); long byteIndex = mapCaretToByteIndex(caret);
long totalBytes = (raf != null && fileLength > 0) ? fileLength : (fileBytes != null ? fileBytes.length : 0); long totalBytes = (raf != null && fileLength > 0) ? fileLength : (fileBytes != null ? fileBytes.length : 0);
int percent = totalBytes > 0 ? (int)((byteIndex * 100L) / totalBytes) : 0; int percent = totalBytes > 0 ? (int)((byteIndex * 100L) / totalBytes) : 0;
statusPosLabel.setText(String.format("Offset %d/%d (%d%%)", byteIndex, totalBytes, percent)); statusPosLabel.setText("Offset %d/%d (%d%%)".formatted(byteIndex, totalBytes, percent));
int selStart = textArea.getSelectionStart(); int selStart = textArea.getSelectionStart();
int selEnd = textArea.getSelectionEnd(); int selEnd = textArea.getSelectionEnd();
@ -1271,7 +1270,7 @@ public class FileEditor extends JFrame {
selBytes = Math.max(0L, b2 - b1 + 1L); selBytes = Math.max(0L, b2 - b1 + 1L);
} }
if (selBytes > 0) { if (selBytes > 0) {
statusSelLabel.setText(String.format("Selected: %d bytes", selBytes)); statusSelLabel.setText("Selected: %d bytes".formatted(selBytes));
} else { } else {
statusSelLabel.setText(" "); statusSelLabel.setText(" ");
} }
@ -1289,7 +1288,7 @@ public class FileEditor extends JFrame {
col = caret - lineStart + 1; col = caret - lineStart + 1;
} }
int percent = total > 0 ? (int) ((caret * 100L) / total) : 0; int percent = total > 0 ? (int) ((caret * 100L) / total) : 0;
statusPosLabel.setText(String.format("Ln %d, Col %d | Offset %d/%d (%d%%)", line, col, caret, total, percent)); statusPosLabel.setText("Ln %d, Col %d | Offset %d/%d (%d%%)".formatted(line, col, caret, total, percent));
int selStart = textArea.getSelectionStart(); int selStart = textArea.getSelectionStart();
int selEnd = textArea.getSelectionEnd(); int selEnd = textArea.getSelectionEnd();
@ -1304,7 +1303,7 @@ public class FileEditor extends JFrame {
} }
} }
if (selChars > 0) { if (selChars > 0) {
statusSelLabel.setText(String.format("Selected: %d chars / %d bytes", selChars, selBytes)); statusSelLabel.setText("Selected: %d chars / %d bytes".formatted(selChars, selBytes));
} else { } else {
statusSelLabel.setText(" "); statusSelLabel.setText(" ");
} }

View File

@ -96,8 +96,7 @@ public class FilePanel extends JPanel {
@Override @Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value instanceof File) { if (value instanceof File f) {
File f = (File) value;
String name = fsv.getSystemDisplayName(f); String name = fsv.getSystemDisplayName(f);
if (name == null) name = ""; if (name == null) name = "";
name = name.trim(); name = name.trim();
@ -141,16 +140,14 @@ public class FilePanel extends JPanel {
// Determine if we should trigger directory load. // Determine if we should trigger directory load.
// We want to skip arrow keys and only react to Mouse or Enter. // We want to skip arrow keys and only react to Mouse or Enter.
java.awt.AWTEvent currentEvent = java.awt.EventQueue.getCurrentEvent(); java.awt.AWTEvent currentEvent = java.awt.EventQueue.getCurrentEvent();
if (currentEvent instanceof java.awt.event.KeyEvent) { if (currentEvent instanceof java.awt.event.KeyEvent ke) {
java.awt.event.KeyEvent ke = (java.awt.event.KeyEvent) currentEvent;
if (ke.getKeyCode() != java.awt.event.KeyEvent.VK_ENTER) { if (ke.getKeyCode() != java.awt.event.KeyEvent.VK_ENTER) {
return; return;
} }
} }
Object selObj = driveCombo.getSelectedItem(); Object selObj = driveCombo.getSelectedItem();
if (selObj instanceof File) { if (selObj instanceof File sel) {
File sel = (File) selObj;
FilePanelTab currentTab = getCurrentTab(); FilePanelTab currentTab = getCurrentTab();
if (currentTab != null) { if (currentTab != null) {
currentTab.loadDirectory(sel); currentTab.loadDirectory(sel);
@ -237,8 +234,8 @@ public class FilePanel extends JPanel {
}); });
} }
if (comp instanceof Container) { if (comp instanceof Container container) {
for (Component child : ((Container) comp).getComponents()) { for (Component child : container.getComponents()) {
addMouseListenerToComponents(child); addMouseListenerToComponents(child);
} }
} }
@ -362,8 +359,8 @@ public class FilePanel extends JPanel {
// propagate to existing tabs // propagate to existing tabs
for (int i = 0; i < tabbedPane.getTabCount(); i++) { for (int i = 0; i < tabbedPane.getTabCount(); i++) {
Component c = tabbedPane.getComponentAt(i); Component c = tabbedPane.getComponentAt(i);
if (c instanceof FilePanelTab) { if (c instanceof FilePanelTab tab) {
((FilePanelTab) c).setAppConfig(cfg); tab.setAppConfig(cfg);
} }
} }
} }
@ -372,8 +369,7 @@ public class FilePanel extends JPanel {
java.util.List<String> paths = new java.util.ArrayList<>(); java.util.List<String> paths = new java.util.ArrayList<>();
for (int i = 0; i < tabbedPane.getTabCount(); i++) { for (int i = 0; i < tabbedPane.getTabCount(); i++) {
Component c = tabbedPane.getComponentAt(i); Component c = tabbedPane.getComponentAt(i);
if (c instanceof FilePanelTab) { if (c instanceof FilePanelTab t) {
FilePanelTab t = (FilePanelTab) c;
File dir = t.getCurrentDirectory(); File dir = t.getCurrentDirectory();
paths.add(dir != null ? dir.getAbsolutePath() : System.getProperty("user.home")); paths.add(dir != null ? dir.getAbsolutePath() : System.getProperty("user.home"));
} }
@ -385,8 +381,7 @@ public class FilePanel extends JPanel {
java.util.List<String> modes = new java.util.ArrayList<>(); java.util.List<String> modes = new java.util.ArrayList<>();
for (int i = 0; i < tabbedPane.getTabCount(); i++) { for (int i = 0; i < tabbedPane.getTabCount(); i++) {
Component c = tabbedPane.getComponentAt(i); Component c = tabbedPane.getComponentAt(i);
if (c instanceof FilePanelTab) { if (c instanceof FilePanelTab t) {
FilePanelTab t = (FilePanelTab) c;
modes.add(t.getViewMode() != null ? t.getViewMode().name() : ViewMode.FULL.name()); modes.add(t.getViewMode() != null ? t.getViewMode().name() : ViewMode.FULL.name());
} }
} }
@ -397,8 +392,8 @@ public class FilePanel extends JPanel {
java.util.List<String> items = new java.util.ArrayList<>(); java.util.List<String> items = new java.util.ArrayList<>();
for (int i = 0; i < tabbedPane.getTabCount(); i++) { for (int i = 0; i < tabbedPane.getTabCount(); i++) {
Component c = tabbedPane.getComponentAt(i); Component c = tabbedPane.getComponentAt(i);
if (c instanceof FilePanelTab) { if (c instanceof FilePanelTab tab) {
cz.kamma.kfmanager.model.FileItem focused = ((FilePanelTab) c).getFocusedItem(); cz.kamma.kfmanager.model.FileItem focused = tab.getFocusedItem();
items.add(focused != null ? focused.getName() : null); items.add(focused != null ? focused.getName() : null);
} }
} }
@ -559,8 +554,8 @@ public class FilePanel extends JPanel {
// Propagate active state to all tabs // Propagate active state to all tabs
for (int i = 0; i < tabbedPane.getTabCount(); i++) { for (int i = 0; i < tabbedPane.getTabCount(); i++) {
Component c = tabbedPane.getComponentAt(i); Component c = tabbedPane.getComponentAt(i);
if (c instanceof FilePanelTab) { if (c instanceof FilePanelTab tab) {
((FilePanelTab) c).setActive(active); tab.setActive(active);
} }
} }
@ -576,8 +571,7 @@ public class FilePanel extends JPanel {
int selectedIndex = tabbedPane.getSelectedIndex(); int selectedIndex = tabbedPane.getSelectedIndex();
for (int i = 0; i < tabbedPane.getTabCount(); i++) { for (int i = 0; i < tabbedPane.getTabCount(); i++) {
Component c = tabbedPane.getComponentAt(i); Component c = tabbedPane.getComponentAt(i);
if (c instanceof FilePanelTab) { if (c instanceof FilePanelTab tab) {
FilePanelTab tab = (FilePanelTab) c;
File dir = tab.getCurrentDirectory(); File dir = tab.getCurrentDirectory();
String title = getTabTitle(dir != null ? dir.getAbsolutePath() : ""); String title = getTabTitle(dir != null ? dir.getAbsolutePath() : "");
@ -648,8 +642,8 @@ public class FilePanel extends JPanel {
private void updateDriveInfoFromSelection() { private void updateDriveInfoFromSelection() {
Object sel = driveCombo.getSelectedItem(); Object sel = driveCombo.getSelectedItem();
if (sel instanceof File) { if (sel instanceof File file) {
updateDriveInfo((File) sel); updateDriveInfo(file);
} else { } else {
driveInfoLabel.setText(""); driveInfoLabel.setText("");
} }
@ -678,7 +672,7 @@ public class FilePanel extends JPanel {
long free = drive.getUsableSpace(); long free = drive.getUsableSpace();
String freeGb = formatGbShort(free); String freeGb = formatGbShort(free);
String totalGb = formatGbShort(total); String totalGb = formatGbShort(total);
String info = String.format("%s %s GB free of %s GB", name, freeGb, totalGb); String info = "%s %s GB free of %s GB".formatted(name, freeGb, totalGb);
driveInfoLabel.setText(info); driveInfoLabel.setText(info);
} catch (Exception ex) { } catch (Exception ex) {
driveInfoLabel.setText(""); driveInfoLabel.setText("");
@ -688,7 +682,7 @@ public class FilePanel extends JPanel {
private static String formatGbShort(long bytes) { private static String formatGbShort(long bytes) {
if (bytes <= 0) return "0"; // fallback if (bytes <= 0) return "0"; // fallback
double gb = bytes / 1024.0 / 1024.0 / 1024.0; double gb = bytes / 1024.0 / 1024.0 / 1024.0;
return String.format("%.1f", gb); return "%.1f".formatted(gb);
} }
/** /**
@ -821,8 +815,8 @@ public class FilePanel extends JPanel {
// Apply to all existing tabs // Apply to all existing tabs
for (int i = 0; i < tabbedPane.getTabCount(); i++) { for (int i = 0; i < tabbedPane.getTabCount(); i++) {
Component c = tabbedPane.getComponentAt(i); Component c = tabbedPane.getComponentAt(i);
if (c instanceof FilePanelTab) { if (c instanceof FilePanelTab tab) {
((FilePanelTab) c).applyGlobalFont(font); tab.applyGlobalFont(font);
} }
} }
} }
@ -832,8 +826,8 @@ public class FilePanel extends JPanel {
updateComponentBackground(this, bg); updateComponentBackground(this, bg);
for (int i = 0; i < tabbedPane.getTabCount(); i++) { for (int i = 0; i < tabbedPane.getTabCount(); i++) {
Component c = tabbedPane.getComponentAt(i); Component c = tabbedPane.getComponentAt(i);
if (c instanceof FilePanelTab) { if (c instanceof FilePanelTab tab) {
((FilePanelTab) c).applyBackgroundColor(bg); tab.applyBackgroundColor(bg);
} }
} }
} }
@ -849,8 +843,8 @@ public class FilePanel extends JPanel {
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 JButton) {
c.setForeground(dark ? Color.WHITE : Color.BLACK); c.setForeground(dark ? Color.WHITE : Color.BLACK);
} }
if (c instanceof Container) { if (c instanceof Container container1) {
updateComponentBackground((Container) c, bg); updateComponentBackground(container1, bg);
} }
} }
} }
@ -864,8 +858,8 @@ public class FilePanel extends JPanel {
public void applySelectionColor(Color sel) { public void applySelectionColor(Color sel) {
for (int i = 0; i < tabbedPane.getTabCount(); i++) { for (int i = 0; i < tabbedPane.getTabCount(); i++) {
Component c = tabbedPane.getComponentAt(i); Component c = tabbedPane.getComponentAt(i);
if (c instanceof FilePanelTab) { if (c instanceof FilePanelTab tab) {
((FilePanelTab) c).applySelectionColor(sel); tab.applySelectionColor(sel);
} }
} }
} }
@ -873,8 +867,8 @@ public class FilePanel extends JPanel {
public void applyMarkedColor(Color mark) { public void applyMarkedColor(Color mark) {
for (int i = 0; i < tabbedPane.getTabCount(); i++) { for (int i = 0; i < tabbedPane.getTabCount(); i++) {
Component c = tabbedPane.getComponentAt(i); Component c = tabbedPane.getComponentAt(i);
if (c instanceof FilePanelTab) { if (c instanceof FilePanelTab tab) {
((FilePanelTab) c).applyMarkedColor(mark); tab.applyMarkedColor(mark);
} }
} }
} }

View File

@ -85,8 +85,7 @@ public class FilePanelTab extends JPanel {
// If already editing, special logic: select filename without extension // If already editing, special logic: select filename without extension
if (fileTable.isEditing()) { if (fileTable.isEditing()) {
Component ed = fileTable.getEditorComponent(); Component ed = fileTable.getEditorComponent();
if (ed instanceof JTextField) { if (ed instanceof JTextField tf) {
JTextField tf = (JTextField) ed;
// Ensure caret is visible // Ensure caret is visible
Color bg = tf.getBackground(); Color bg = tf.getBackground();
@ -142,8 +141,7 @@ public class FilePanelTab extends JPanel {
boolean started = fileTable.editCellAt(selRow, editCol); boolean started = fileTable.editCellAt(selRow, editCol);
if (started) { if (started) {
Component ed = fileTable.getEditorComponent(); Component ed = fileTable.getEditorComponent();
if (ed instanceof JTextField) { if (ed instanceof JTextField tf) {
JTextField tf = (JTextField) ed;
// Ensure caret is visible // Ensure caret is visible
Color bg = tf.getBackground(); Color bg = tf.getBackground();
@ -226,8 +224,7 @@ public class FilePanelTab extends JPanel {
c instanceof JTabbedPane || c instanceof JSplitPane || c instanceof JList || c instanceof JTabbedPane || c instanceof JSplitPane || c instanceof JList ||
c instanceof JComboBox || c instanceof JTable || c instanceof JButton) { c instanceof JComboBox || c instanceof JTable || c instanceof JButton) {
c.setBackground(bg); c.setBackground(bg);
if (c instanceof JTable) { if (c instanceof JTable t) {
JTable t = (JTable) c;
if (t.getTableHeader() != null) { if (t.getTableHeader() != null) {
t.getTableHeader().setBackground(bg); t.getTableHeader().setBackground(bg);
t.getTableHeader().setForeground(dark ? Color.WHITE : Color.BLACK); t.getTableHeader().setForeground(dark ? Color.WHITE : Color.BLACK);
@ -238,14 +235,13 @@ public class FilePanelTab extends JPanel {
c instanceof JButton || c instanceof JComboBox || c instanceof JList) { c instanceof JButton || c instanceof JComboBox || c instanceof JList) {
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 tc) {
javax.swing.text.JTextComponent tc = (javax.swing.text.JTextComponent) c;
tc.setBackground(bg); tc.setBackground(bg);
tc.setForeground(dark ? Color.WHITE : Color.BLACK); tc.setForeground(dark ? Color.WHITE : Color.BLACK);
tc.setCaretColor(dark ? Color.WHITE : Color.BLACK); tc.setCaretColor(dark ? Color.WHITE : Color.BLACK);
} }
if (c instanceof Container) { if (c instanceof Container container1) {
updateComponentBackground((Container) c, bg); updateComponentBackground(container1, bg);
} }
} }
} }
@ -1648,14 +1644,14 @@ public class FilePanelTab extends JPanel {
dialog.setVisible(true); dialog.setVisible(true);
Object result = pane.getValue(); Object result = pane.getValue();
int res = (result instanceof Integer) ? (Integer) result : JOptionPane.CLOSED_OPTION; int res = (result instanceof Integer i) ? i : JOptionPane.CLOSED_OPTION;
if (res == JOptionPane.YES_OPTION) { if (res == JOptionPane.YES_OPTION) {
java.util.List<FileItem> toDelete = new java.util.ArrayList<>(); java.util.List<FileItem> toDelete = new java.util.ArrayList<>();
toDelete.add(item); toDelete.add(item);
final int rememberedIndex = getFocusedItemIndex(); final int rememberedIndex = getFocusedItemIndex();
Window parentWindow = SwingUtilities.getWindowAncestor(FilePanelTab.this); Window parentWindow = SwingUtilities.getWindowAncestor(FilePanelTab.this);
ProgressDialog progressDialog = new ProgressDialog(parentWindow instanceof Frame ? (Frame)parentWindow : null, "Deleting"); ProgressDialog progressDialog = new ProgressDialog(parentWindow instanceof Frame f ? f : null, "Deleting");
new Thread(() -> { new Thread(() -> {
try { try {
@ -2096,7 +2092,7 @@ public class FilePanelTab extends JPanel {
File targetDir = getCurrentDirectory(); File targetDir = getCurrentDirectory();
Window parentWindow = SwingUtilities.getWindowAncestor(this); Window parentWindow = SwingUtilities.getWindowAncestor(this);
String titleName = action == ClipboardService.ClipboardAction.CUT ? "Moving" : "Copying"; String titleName = action == ClipboardService.ClipboardAction.CUT ? "Moving" : "Copying";
ProgressDialog progressDialog = new ProgressDialog(parentWindow instanceof Frame ? (Frame)parentWindow : null, titleName); ProgressDialog progressDialog = new ProgressDialog(parentWindow instanceof Frame f ? f : null, titleName);
new Thread(() -> { new Thread(() -> {
try { try {
@ -2122,11 +2118,19 @@ public class FilePanelTab extends JPanel {
try { try {
SwingUtilities.invokeAndWait(() -> { SwingUtilities.invokeAndWait(() -> {
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
String message = String.format( String message = (
"File already exists: %s\n\n" + """
"Source file:\n Size: %s\n Modified: %s\n\n" + File already exists: %s
"Existing file:\n Size: %s\n Modified: %s\n\n" +
"Overwrite?", Source file:
Size: %s
Modified: %s
Existing file:
Size: %s
Modified: %s
Overwrite?""").formatted(
destination.getName(), destination.getName(),
FileItem.formatSize(source.length()), FileItem.formatSize(source.length()),
sdf.format(new Date(source.lastModified())), sdf.format(new Date(source.lastModified())),
@ -2201,8 +2205,8 @@ public class FilePanelTab extends JPanel {
progressDialog.dispose(); progressDialog.dispose();
loadDirectory(targetDir, false); loadDirectory(targetDir, false);
if (!itemsToPaste.isEmpty()) { if (!itemsToPaste.isEmpty()) {
String nameToSelect = itemsToPaste.get(0).getName(); String nameToSelect = itemsToPaste.getFirst().getName();
File firstSource = itemsToPaste.get(0).getFile(); File firstSource = itemsToPaste.getFirst().getFile();
// Check if we were copying within the same directory - if so, it was renamed to copy-of-... // Check if we were copying within the same directory - if so, it was renamed to copy-of-...
if (action == ClipboardService.ClipboardAction.COPY && if (action == ClipboardService.ClipboardAction.COPY &&
firstSource.getParentFile() != null && firstSource.getParentFile() != null &&
@ -2291,8 +2295,7 @@ public class FilePanelTab extends JPanel {
Component parent = fileTable.getParent(); Component parent = fileTable.getParent();
if (parent instanceof JViewport) { if (parent instanceof JViewport) {
Component scroll = parent.getParent(); Component scroll = parent.getParent();
if (scroll instanceof JScrollPane) { if (scroll instanceof JScrollPane sp) {
JScrollPane sp = (JScrollPane) scroll;
sp.setColumnHeaderView(mode == ViewMode.BRIEF ? null : fileTable.getTableHeader()); sp.setColumnHeaderView(mode == ViewMode.BRIEF ? null : fileTable.getTableHeader());
} }
} }
@ -2675,8 +2678,8 @@ public class FilePanelTab extends JPanel {
String newStatus; String newStatus;
if (markedCount > 0) { if (markedCount > 0) {
newStatus = String.format(" Selected: %d files, %d directories (%s)", newStatus = " Selected: %d files, %d directories (%s)".formatted(
fileCount, dirCount, FileItem.formatSize(totalSize)); fileCount, dirCount, FileItem.formatSize(totalSize));
} else { } else {
int selectedRow = fileTable.getSelectedRow(); int selectedRow = fileTable.getSelectedRow();
if (selectedRow >= 0) { if (selectedRow >= 0) {
@ -2690,20 +2693,20 @@ public class FilePanelTab extends JPanel {
if (item != null && !item.getName().equals("..")) { if (item != null && !item.getName().equals("..")) {
if (item.isDirectory()) { if (item.isDirectory()) {
// Always display directory names in square brackets // Always display directory names in square brackets
newStatus = String.format(" [%s] | %s", newStatus = " [%s] | %s".formatted(
item.getName(), item.getName(),
item.getFormattedDate()); item.getFormattedDate());
} else { } else {
newStatus = String.format(" %s | %s | %s", newStatus = " %s | %s | %s".formatted(
item.getName(), item.getName(),
FileItem.formatSize(item.getSize()), FileItem.formatSize(item.getSize()),
item.getFormattedDate()); item.getFormattedDate());
} }
} else { } else {
newStatus = String.format(" Items: %d", tableModel.items.size()); newStatus = " Items: %d".formatted(tableModel.items.size());
} }
} else { } else {
newStatus = String.format(" Items: %d", tableModel.items.size()); newStatus = " Items: %d".formatted(tableModel.items.size());
} }
} }
@ -2930,8 +2933,7 @@ public class FilePanelTab extends JPanel {
boolean isSelected, boolean hasFocus, boolean isSelected, boolean hasFocus,
int row, int column) { int row, int column) {
java.awt.Component c = delegate.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); java.awt.Component c = delegate.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (c instanceof javax.swing.JLabel) { if (c instanceof javax.swing.JLabel lbl) {
javax.swing.JLabel lbl = (javax.swing.JLabel) c;
String txt = value != null ? value.toString() : ""; String txt = value != null ? value.toString() : "";
if (sortColumn == column && fileTable.getTableHeader().isVisible()) { if (sortColumn == column && fileTable.getTableHeader().isVisible()) {
String arrow = sortAscending ? "" : ""; String arrow = sortAscending ? "" : "";

View File

@ -312,8 +312,7 @@ public class MainWindow extends JFrame {
// Handle the editor component (usually a JTextField) // Handle the editor component (usually a JTextField)
Component editorComp = commandLine.getEditor().getEditorComponent(); Component editorComp = commandLine.getEditor().getEditorComponent();
if (editorComp instanceof JTextField) { if (editorComp instanceof JTextField tf) {
JTextField tf = (JTextField) editorComp;
tf.setFocusTraversalKeysEnabled(false); tf.setFocusTraversalKeysEnabled(false);
tf.putClientProperty("JTextField.selectAllOnFocus", Boolean.FALSE); tf.putClientProperty("JTextField.selectAllOnFocus", Boolean.FALSE);
tf.addActionListener(e -> executeCommand(tf.getText())); tf.addActionListener(e -> executeCommand(tf.getText()));
@ -432,7 +431,7 @@ public class MainWindow extends JFrame {
try { try {
List<File> files = (List<File>) support.getTransferable().getTransferData(DataFlavor.javaFileListFlavor); List<File> files = (List<File>) support.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
if (files != null && !files.isEmpty()) { if (files != null && !files.isEmpty()) {
showAddToolbarShortcutDialog(files.get(0)); showAddToolbarShortcutDialog(files.getFirst());
} }
return true; return true;
} catch (Exception e) { } catch (Exception e) {
@ -1014,8 +1013,7 @@ public class MainWindow extends JFrame {
// Update command line colors // Update command line colors
if (commandLine != null) { if (commandLine != null) {
Component ed = commandLine.getEditor().getEditorComponent(); Component ed = commandLine.getEditor().getEditorComponent();
if (ed instanceof JTextField) { if (ed instanceof JTextField tf) {
JTextField tf = (JTextField) ed;
tf.setBackground(bg); tf.setBackground(bg);
boolean dark = isDark(bg); boolean dark = isDark(bg);
tf.setForeground(dark ? Color.WHITE : Color.BLACK); tf.setForeground(dark ? Color.WHITE : Color.BLACK);
@ -1037,8 +1035,7 @@ public class MainWindow extends JFrame {
// Apply selection color to command line editor for selection // Apply selection color to command line editor for selection
if (commandLine != null) { if (commandLine != null) {
Component ed = commandLine.getEditor().getEditorComponent(); Component ed = commandLine.getEditor().getEditorComponent();
if (ed instanceof JTextField) { if (ed instanceof JTextField tf) {
JTextField tf = (JTextField) ed;
tf.setSelectionColor(sel); tf.setSelectionColor(sel);
Color fieldBg = tf.getBackground(); Color fieldBg = tf.getBackground();
boolean darkField = isDark(fieldBg); boolean darkField = isDark(fieldBg);
@ -1082,8 +1079,7 @@ public class MainWindow extends JFrame {
c instanceof JTabbedPane || c instanceof JButton || c instanceof JSplitPane || c instanceof JTabbedPane || c instanceof JButton || c instanceof JSplitPane ||
c instanceof JList || c instanceof JComboBox || c instanceof JTable) { c instanceof JList || c instanceof JComboBox || c instanceof JTable) {
c.setBackground(bg); c.setBackground(bg);
if (c instanceof JTable) { if (c instanceof JTable t) {
JTable t = (JTable) c;
if (t.getTableHeader() != null) { if (t.getTableHeader() != null) {
t.getTableHeader().setBackground(bg); t.getTableHeader().setBackground(bg);
t.getTableHeader().setForeground(dark ? Color.WHITE : Color.BLACK); t.getTableHeader().setForeground(dark ? Color.WHITE : Color.BLACK);
@ -1094,8 +1090,7 @@ public class MainWindow extends JFrame {
c instanceof JButton || c instanceof JComboBox || c instanceof JList) { c instanceof JButton || c instanceof JComboBox || c instanceof JList) {
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 tc) {
javax.swing.text.JTextComponent tc = (javax.swing.text.JTextComponent) c;
tc.setBackground(bg); tc.setBackground(bg);
tc.setForeground(dark ? Color.WHITE : Color.BLACK); tc.setForeground(dark ? Color.WHITE : Color.BLACK);
tc.setCaretColor(dark ? Color.WHITE : Color.BLACK); tc.setCaretColor(dark ? Color.WHITE : Color.BLACK);
@ -1103,11 +1098,9 @@ public class MainWindow extends JFrame {
tc.setSelectionColor(selColor); tc.setSelectionColor(selColor);
} }
} }
if (c instanceof JComboBox) { if (c instanceof JComboBox<?> cb) {
JComboBox<?> cb = (JComboBox<?>) c;
Component ed = cb.getEditor().getEditorComponent(); Component ed = cb.getEditor().getEditorComponent();
if (ed instanceof javax.swing.text.JTextComponent) { if (ed instanceof javax.swing.text.JTextComponent tc) {
javax.swing.text.JTextComponent tc = (javax.swing.text.JTextComponent) ed;
tc.setBackground(bg); tc.setBackground(bg);
tc.setForeground(dark ? Color.WHITE : Color.BLACK); tc.setForeground(dark ? Color.WHITE : Color.BLACK);
tc.setCaretColor(dark ? Color.WHITE : Color.BLACK); tc.setCaretColor(dark ? Color.WHITE : Color.BLACK);
@ -1116,8 +1109,8 @@ public class MainWindow extends JFrame {
} }
} }
} }
if (c instanceof Container) { if (c instanceof Container container1) {
updateComponentBackground((Container) c, bg); updateComponentBackground(container1, bg);
} }
} }
} }
@ -1611,13 +1604,13 @@ public class MainWindow extends JFrame {
FilePanel sourcePanel = activePanel; FilePanel sourcePanel = activePanel;
int result = showConfirmWithBackground( int result = showConfirmWithBackground(
String.format("Copy %d items to:\n%s", selectedItems.size(), targetDir.getAbsolutePath()), "Copy %d items to:\n%s".formatted(selectedItems.size(), targetDir.getAbsolutePath()),
"Copy"); "Copy");
if (result == 0 || result == 1) { if (result == 0 || result == 1) {
boolean background = (result == 1); boolean background = (result == 1);
if (background) { if (background) {
addOperationToQueue("Copy", String.format("Copy %d items to %s", selectedItems.size(), targetDir.getName()), addOperationToQueue("Copy", "Copy %d items to %s".formatted(selectedItems.size(), targetDir.getName()),
(cb) -> FileOperations.copy(selectedItems, targetDir, cb), () -> sourcePanel.unselectAll(), targetPanel); (cb) -> FileOperations.copy(selectedItems, targetDir, cb), () -> sourcePanel.unselectAll(), targetPanel);
} else { } else {
performFileOperation((callback) -> { performFileOperation((callback) -> {
@ -1649,13 +1642,13 @@ public class MainWindow extends JFrame {
File targetDir = targetPanel.getCurrentDirectory(); File targetDir = targetPanel.getCurrentDirectory();
int result = showConfirmWithBackground( int result = showConfirmWithBackground(
String.format("Move %d items to:\n%s", selectedItems.size(), targetDir.getAbsolutePath()), "Move %d items to:\n%s".formatted(selectedItems.size(), targetDir.getAbsolutePath()),
"Move"); "Move");
if (result == 0 || result == 1) { if (result == 0 || result == 1) {
boolean background = (result == 1); boolean background = (result == 1);
if (background) { if (background) {
addOperationToQueue("Move", String.format("Move %d items to %s", selectedItems.size(), targetDir.getName()), addOperationToQueue("Move", "Move %d items to %s".formatted(selectedItems.size(), targetDir.getName()),
(cb) -> FileOperations.move(selectedItems, targetDir, cb), activePanel, targetPanel); (cb) -> FileOperations.move(selectedItems, targetDir, cb), activePanel, targetPanel);
} else { } else {
performFileOperation((callback) -> { performFileOperation((callback) -> {
@ -1736,7 +1729,7 @@ public class MainWindow extends JFrame {
if (result == 0 || result == 1) { if (result == 0 || result == 1) {
boolean background = (result == 1); boolean background = (result == 1);
if (background) { if (background) {
addOperationToQueue("Delete", String.format("Delete %d items", selectedItems.size()), addOperationToQueue("Delete", "Delete %d items".formatted(selectedItems.size()),
(cb) -> FileOperations.delete(selectedItems, cb), activePanel); (cb) -> FileOperations.delete(selectedItems, cb), activePanel);
} else { } else {
performFileOperation((callback) -> { performFileOperation((callback) -> {
@ -1776,7 +1769,7 @@ public class MainWindow extends JFrame {
String defaultName; String defaultName;
if (selectedItems.size() == 1) { if (selectedItems.size() == 1) {
defaultName = selectedItems.get(0).getName(); defaultName = selectedItems.getFirst().getName();
} else { } else {
defaultName = activePanel.getCurrentDirectory().getName(); defaultName = activePanel.getCurrentDirectory().getName();
if (defaultName == null || defaultName.isEmpty() || defaultName.equals("/") || defaultName.endsWith(":")) { if (defaultName == null || defaultName.isEmpty() || defaultName.equals("/") || defaultName.endsWith(":")) {
@ -1822,13 +1815,13 @@ public class MainWindow extends JFrame {
final File finalTargetZip = targetZip; final File finalTargetZip = targetZip;
final FilePanel sourcePanel = activePanel; final FilePanel sourcePanel = activePanel;
int result = showConfirmWithBackground( int result = showConfirmWithBackground(
String.format("Zip %d items to:\n%s", selectedItems.size(), targetZip.getAbsolutePath()), "Zip %d items to:\n%s".formatted(selectedItems.size(), targetZip.getAbsolutePath()),
"Zip"); "Zip");
if (result == 0 || result == 1) { if (result == 0 || result == 1) {
boolean background = (result == 1); boolean background = (result == 1);
if (background) { if (background) {
addOperationToQueue("Zip", String.format("Zip %d items to %s", selectedItems.size(), finalTargetZip.getName()), addOperationToQueue("Zip", "Zip %d items to %s".formatted(selectedItems.size(), finalTargetZip.getName()),
(cb) -> FileOperations.zip(selectedItems, finalTargetZip, cb), () -> sourcePanel.unselectAll(), targetPanel); (cb) -> FileOperations.zip(selectedItems, finalTargetZip, cb), () -> sourcePanel.unselectAll(), targetPanel);
} else { } else {
performFileOperation((callback) -> { performFileOperation((callback) -> {
@ -1854,7 +1847,7 @@ public class MainWindow extends JFrame {
return; return;
} }
File archiveFile = selectedItems.get(0).getFile(); File archiveFile = selectedItems.getFirst().getFile();
if (!FileOperations.isArchiveFile(archiveFile)) { if (!FileOperations.isArchiveFile(archiveFile)) {
JOptionPane.showMessageDialog(this, JOptionPane.showMessageDialog(this,
"Selected file is not a supported archive", "Selected file is not a supported archive",
@ -1869,13 +1862,13 @@ public class MainWindow extends JFrame {
final FilePanel sourcePanel = activePanel; final FilePanel sourcePanel = activePanel;
int result = showConfirmWithBackground( int result = showConfirmWithBackground(
String.format("Extract %s to:\n%s", archiveFile.getName(), targetDir.getAbsolutePath()), "Extract %s to:\n%s".formatted(archiveFile.getName(), targetDir.getAbsolutePath()),
"Extract archive"); "Extract archive");
if (result == 0 || result == 1) { if (result == 0 || result == 1) {
boolean background = (result == 1); boolean background = (result == 1);
if (background) { if (background) {
addOperationToQueue("Extract", String.format("Extract %s to %s", archiveFile.getName(), targetDir.getName()), addOperationToQueue("Extract", "Extract %s to %s".formatted(archiveFile.getName(), targetDir.getName()),
(cb) -> FileOperations.extractArchive(archiveFile, targetDir, cb), () -> sourcePanel.unselectAll(), targetPanel); (cb) -> FileOperations.extractArchive(archiveFile, targetDir, cb), () -> sourcePanel.unselectAll(), targetPanel);
} else { } else {
performFileOperation((callback) -> { performFileOperation((callback) -> {
@ -1908,7 +1901,7 @@ public class MainWindow extends JFrame {
requestFocusInActivePanel(); requestFocusInActivePanel();
return; return;
} }
FileItem item = selectedItems.get(0); FileItem item = selectedItems.getFirst();
String newName = JOptionPane.showInputDialog(this, String newName = JOptionPane.showInputDialog(this,
"New name:", "New name:",
item.getName()); item.getName());
@ -2101,7 +2094,7 @@ public class MainWindow extends JFrame {
return; return;
} }
FileItem item = selectedItems.get(0); FileItem item = selectedItems.getFirst();
if (item.isDirectory() || item.getName().equals("..")) { if (item.isDirectory() || item.getName().equals("..")) {
return; return;
} }
@ -2129,7 +2122,7 @@ public class MainWindow extends JFrame {
return; return;
} }
FileItem item = selectedItems.get(0); FileItem item = selectedItems.getFirst();
if (item.isDirectory() || item.getName().equals("..")) { if (item.isDirectory() || item.getName().equals("..")) {
return; return;
} }
@ -2177,14 +2170,14 @@ public class MainWindow extends JFrame {
File rightFile = null; File rightFile = null;
if (leftSelection.size() == 1) { if (leftSelection.size() == 1) {
leftFile = leftSelection.get(0).getFile(); leftFile = leftSelection.getFirst().getFile();
} else if (leftSelection.size() > 1) { } else if (leftSelection.size() > 1) {
JOptionPane.showMessageDialog(this, "Please select only one file in the left panel.", "Compare Files", JOptionPane.WARNING_MESSAGE); JOptionPane.showMessageDialog(this, "Please select only one file in the left panel.", "Compare Files", JOptionPane.WARNING_MESSAGE);
return; return;
} }
if (rightSelection.size() == 1) { if (rightSelection.size() == 1) {
rightFile = rightSelection.get(0).getFile(); rightFile = rightSelection.getFirst().getFile();
} else if (rightSelection.size() > 1) { } else if (rightSelection.size() > 1) {
JOptionPane.showMessageDialog(this, "Please select only one file in the right panel.", "Compare Files", JOptionPane.WARNING_MESSAGE); JOptionPane.showMessageDialog(this, "Please select only one file in the right panel.", "Compare Files", JOptionPane.WARNING_MESSAGE);
return; return;
@ -2424,8 +2417,8 @@ public class MainWindow extends JFrame {
// Clear after execution and return focus // Clear after execution and return focus
Component editorComp = commandLine.getEditor().getEditorComponent(); Component editorComp = commandLine.getEditor().getEditorComponent();
if (editorComp instanceof JTextField) { if (editorComp instanceof JTextField field) {
((JTextField) editorComp).setText(""); field.setText("");
} else { } else {
commandLine.setSelectedItem(""); commandLine.setSelectedItem("");
} }
@ -2540,23 +2533,26 @@ public class MainWindow extends JFrame {
*/ */
private void showAboutDialog() { private void showAboutDialog() {
JOptionPane.showMessageDialog(this, JOptionPane.showMessageDialog(this,
"KF File Manager 1.0\n\n" + """
"Two-panel file manager\n" + KF File Manager 1.0
"Java 11\n\n" +
"Keyboard shortcuts:\n" + Two-panel file manager
"F5 - Copy\n" + Java 11
"Alt+F5 - Zip\n" +
"Alt+F9 - Unzip\n" + Keyboard shortcuts:
"F6 - Move\n" + F5 - Copy
"F7 - New directory\n" + Alt+F5 - Zip
"F8 - Delete\n" + Alt+F9 - Unzip
"F9 - Open terminal\n" + F6 - Move
"Shift+F6 - Rename\n" + F7 - New directory
"TAB - Switch panel\n" + F8 - Delete
"Ctrl+F - Search\n" + F9 - Open terminal
"Alt+O - Settings\n" + Shift+F6 - Rename
"Enter - Open directory\n" + TAB - Switch panel
"Backspace - Parent directory", Ctrl+F - Search
Alt+O - Settings
Enter - Open directory
Backspace - Parent directory""",
"About", "About",
JOptionPane.INFORMATION_MESSAGE); JOptionPane.INFORMATION_MESSAGE);
requestFocusInActivePanel(); requestFocusInActivePanel();
@ -2608,11 +2604,19 @@ public class MainWindow extends JFrame {
try { try {
SwingUtilities.invokeAndWait(() -> { SwingUtilities.invokeAndWait(() -> {
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
String message = String.format( String message = (
"File already exists: %s\n\n" + """
"Source file:\n Size: %s\n Modified: %s\n\n" + File already exists: %s
"Existing file:\n Size: %s\n Modified: %s\n\n" +
"Overwrite?", Source file:
Size: %s
Modified: %s
Existing file:
Size: %s
Modified: %s
Overwrite?""").formatted(
destination.getName(), destination.getName(),
FileItem.formatSize(source.length()), FileItem.formatSize(source.length()),
sdf.format(new Date(source.lastModified())), sdf.format(new Date(source.lastModified())),
@ -2652,9 +2656,11 @@ public class MainWindow extends JFrame {
final FileOperations.SymlinkResponse[] result = new FileOperations.SymlinkResponse[1]; final FileOperations.SymlinkResponse[] result = new FileOperations.SymlinkResponse[1];
try { try {
SwingUtilities.invokeAndWait(() -> { SwingUtilities.invokeAndWait(() -> {
String message = String.format( String message = (
"Symbolic link encountered: %s\n\n" + """
"What do you want to do?", Symbolic link encountered: %s
What do you want to do?""").formatted(
symlink.getAbsolutePath() symlink.getAbsolutePath()
); );

View File

@ -171,8 +171,7 @@ public class OperationQueueDialog extends JDialog {
@Override @Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
if (value instanceof QueuedTask) { if (value instanceof QueuedTask task) {
QueuedTask task = (QueuedTask) value;
if (task.getStatus() == FileOperationQueue.OperationStatus.FAILED) { if (task.getStatus() == FileOperationQueue.OperationStatus.FAILED) {
progressBar.setIndeterminate(false); progressBar.setIndeterminate(false);
progressBar.setValue(0); progressBar.setValue(0);

View File

@ -184,7 +184,7 @@ public class ProgressDialog extends JDialog {
if (bytes < 1024) return bytes + " B"; if (bytes < 1024) return bytes + " B";
int exp = (int) (Math.log(bytes) / Math.log(1024)); int exp = (int) (Math.log(bytes) / Math.log(1024));
char pre = "KMGTPE".charAt(exp - 1); char pre = "KMGTPE".charAt(exp - 1);
return String.format("%.1f %cB", bytes / Math.pow(1024, exp), pre); return "%.1f %cB".formatted(bytes / Math.pow(1024, exp), pre);
} }
private void checkState() { private void checkState() {

View File

@ -264,7 +264,7 @@ public class PropertiesDialog extends JDialog {
if (permChecks[2][1].isSelected()) octal += 0002; if (permChecks[2][1].isSelected()) octal += 0002;
if (permChecks[2][2].isSelected()) octal += 0001; if (permChecks[2][2].isSelected()) octal += 0001;
octalField.setText(String.format("%03o", octal)); octalField.setText("%03o".formatted(octal));
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(file.isDirectory() ? 'd' : '-'); sb.append(file.isDirectory() ? 'd' : '-');

View File

@ -80,8 +80,7 @@ public class SearchDialog extends JDialog {
c instanceof JTabbedPane || c instanceof JButton || c instanceof JSplitPane || c instanceof JTabbedPane || c instanceof JButton || c instanceof JSplitPane ||
c instanceof JList || c instanceof JComboBox || c instanceof JTable) { c instanceof JList || c instanceof JComboBox || c instanceof JTable) {
c.setBackground(bg); c.setBackground(bg);
if (c instanceof JTable) { if (c instanceof JTable t) {
JTable t = (JTable) c;
if (t.getTableHeader() != null) { if (t.getTableHeader() != null) {
t.getTableHeader().setBackground(bg); t.getTableHeader().setBackground(bg);
t.getTableHeader().setForeground(dark ? Color.WHITE : Color.BLACK); t.getTableHeader().setForeground(dark ? Color.WHITE : Color.BLACK);
@ -92,8 +91,7 @@ public class SearchDialog extends JDialog {
c instanceof JButton || c instanceof JComboBox || c instanceof JList) { c instanceof JButton || c instanceof JComboBox || c instanceof JList) {
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 tc) {
javax.swing.text.JTextComponent tc = (javax.swing.text.JTextComponent) c;
tc.setBackground(bg); tc.setBackground(bg);
tc.setForeground(dark ? Color.WHITE : Color.BLACK); tc.setForeground(dark ? Color.WHITE : Color.BLACK);
tc.setCaretColor(dark ? Color.WHITE : Color.BLACK); tc.setCaretColor(dark ? Color.WHITE : Color.BLACK);
@ -101,11 +99,9 @@ public class SearchDialog extends JDialog {
tc.setSelectionColor(selColor); tc.setSelectionColor(selColor);
} }
} }
if (c instanceof JComboBox) { if (c instanceof JComboBox<?> cb) {
JComboBox<?> cb = (JComboBox<?>) c;
Component ed = cb.getEditor().getEditorComponent(); Component ed = cb.getEditor().getEditorComponent();
if (ed instanceof javax.swing.text.JTextComponent) { if (ed instanceof javax.swing.text.JTextComponent tc) {
javax.swing.text.JTextComponent tc = (javax.swing.text.JTextComponent) ed;
tc.setBackground(bg); tc.setBackground(bg);
tc.setForeground(dark ? Color.WHITE : Color.BLACK); tc.setForeground(dark ? Color.WHITE : Color.BLACK);
tc.setCaretColor(dark ? Color.WHITE : Color.BLACK); tc.setCaretColor(dark ? Color.WHITE : Color.BLACK);
@ -114,8 +110,8 @@ public class SearchDialog extends JDialog {
} }
} }
} }
if (c instanceof Container) { if (c instanceof Container container1) {
updateComponentBackground((Container) c, bg); updateComponentBackground(container1, bg);
} }
} }
} }
@ -309,8 +305,7 @@ public class SearchDialog extends JDialog {
// Bind Enter on the combo editor component so selecting an item from the // Bind Enter on the combo editor component so selecting an item from the
// popup does not automatically trigger search until user confirms. // popup does not automatically trigger search until user confirms.
java.awt.Component editorComp = patternCombo.getEditor().getEditorComponent(); java.awt.Component editorComp = patternCombo.getEditor().getEditorComponent();
if (editorComp instanceof javax.swing.text.JTextComponent) { if (editorComp instanceof javax.swing.text.JTextComponent tc) {
javax.swing.text.JTextComponent tc = (javax.swing.text.JTextComponent) editorComp;
tc.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "confirmSearch"); tc.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "confirmSearch");
tc.getActionMap().put("confirmSearch", new AbstractAction() { tc.getActionMap().put("confirmSearch", new AbstractAction() {
@Override @Override
@ -335,8 +330,7 @@ public class SearchDialog extends JDialog {
// Same explicit-Enter behavior for content text pattern combo // Same explicit-Enter behavior for content text pattern combo
try { try {
java.awt.Component contentEditorComp = contentPatternCombo.getEditor().getEditorComponent(); java.awt.Component contentEditorComp = contentPatternCombo.getEditor().getEditorComponent();
if (contentEditorComp instanceof javax.swing.text.JTextComponent) { if (contentEditorComp instanceof javax.swing.text.JTextComponent tc2) {
javax.swing.text.JTextComponent tc2 = (javax.swing.text.JTextComponent) contentEditorComp;
tc2.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "confirmSearchContent"); tc2.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "confirmSearchContent");
tc2.getActionMap().put("confirmSearchContent", new AbstractAction() { tc2.getActionMap().put("confirmSearchContent", new AbstractAction() {
@Override @Override
@ -365,8 +359,8 @@ public class SearchDialog extends JDialog {
java.awt.Component ed = patternCombo.getEditor().getEditorComponent(); java.awt.Component ed = patternCombo.getEditor().getEditorComponent();
if (ed != null) { if (ed != null) {
ed.requestFocusInWindow(); ed.requestFocusInWindow();
if (ed instanceof javax.swing.text.JTextComponent) { if (ed instanceof javax.swing.text.JTextComponent component) {
((javax.swing.text.JTextComponent) ed).selectAll(); component.selectAll();
} }
} }
} catch (Exception ignore) {} } catch (Exception ignore) {}
@ -388,8 +382,8 @@ public class SearchDialog extends JDialog {
java.awt.Component ed = contentPatternCombo.getEditor().getEditorComponent(); java.awt.Component ed = contentPatternCombo.getEditor().getEditorComponent();
if (ed != null) { if (ed != null) {
ed.requestFocusInWindow(); ed.requestFocusInWindow();
if (ed instanceof javax.swing.text.JTextComponent) { if (ed instanceof javax.swing.text.JTextComponent component) {
((javax.swing.text.JTextComponent) ed).selectAll(); component.selectAll();
} }
} }
} catch (Exception ignore) {} } catch (Exception ignore) {}
@ -445,9 +439,9 @@ public class SearchDialog extends JDialog {
if (cur != null && !cur.isEmpty()) { if (cur != null && !cur.isEmpty()) {
java.util.List<String> hist = new java.util.ArrayList<>(config.getSearchHistory()); java.util.List<String> hist = new java.util.ArrayList<>(config.getSearchHistory());
hist.remove(cur); hist.remove(cur);
hist.add(0, cur); hist.addFirst(cur);
int max = 20; int max = 20;
while (hist.size() > max) hist.remove(hist.size() - 1); while (hist.size() > max) hist.removeLast();
config.saveSearchHistory(hist); config.saveSearchHistory(hist);
} }
} catch (Exception ignore) {} } catch (Exception ignore) {}
@ -458,9 +452,9 @@ public class SearchDialog extends JDialog {
if (ccur != null && !ccur.isEmpty()) { if (ccur != null && !ccur.isEmpty()) {
java.util.List<String> chist = new java.util.ArrayList<>(config.getContentSearchHistory()); java.util.List<String> chist = new java.util.ArrayList<>(config.getContentSearchHistory());
chist.remove(ccur); chist.remove(ccur);
chist.add(0, ccur); chist.addFirst(ccur);
int maxc = 20; int maxc = 20;
while (chist.size() > maxc) chist.remove(chist.size() - 1); while (chist.size() > maxc) chist.removeLast();
config.saveContentSearchHistory(chist); config.saveContentSearchHistory(chist);
} }
} catch (Exception ignore) {} } catch (Exception ignore) {}
@ -516,9 +510,9 @@ public class SearchDialog extends JDialog {
if (!namePat.isEmpty()) { if (!namePat.isEmpty()) {
java.util.List<String> hist = new java.util.ArrayList<>(config.getSearchHistory()); java.util.List<String> hist = new java.util.ArrayList<>(config.getSearchHistory());
hist.remove(namePat); hist.remove(namePat);
hist.add(0, namePat); hist.addFirst(namePat);
int max = 20; int max = 20;
while (hist.size() > max) hist.remove(hist.size() - 1); while (hist.size() > max) hist.removeLast();
config.saveSearchHistory(hist); config.saveSearchHistory(hist);
// update combo model // update combo model
@ -531,9 +525,9 @@ public class SearchDialog extends JDialog {
if (isContentSearch && !contentPat.isEmpty()) { if (isContentSearch && !contentPat.isEmpty()) {
java.util.List<String> chist = new java.util.ArrayList<>(config.getContentSearchHistory()); java.util.List<String> chist = new java.util.ArrayList<>(config.getContentSearchHistory());
chist.remove(contentPat); chist.remove(contentPat);
chist.add(0, contentPat); chist.addFirst(contentPat);
int max = 20; int max = 20;
while (chist.size() > max) chist.remove(chist.size() - 1); while (chist.size() > max) chist.removeLast();
config.saveContentSearchHistory(chist); config.saveContentSearchHistory(chist);
// update content combo model // update content combo model
@ -655,8 +649,7 @@ public class SearchDialog extends JDialog {
try { try {
// Open location inside the application: show parent directory in the focused panel and select the file // Open location inside the application: show parent directory in the focused panel and select the file
java.awt.Window w = SwingUtilities.getWindowAncestor(this); java.awt.Window w = SwingUtilities.getWindowAncestor(this);
if (w instanceof MainWindow) { if (w instanceof MainWindow mw) {
MainWindow mw = (MainWindow) w;
String fullPath = item.getPath(); String fullPath = item.getPath();
File file = item.getFile(); File file = item.getFile();

View File

@ -1,6 +1,7 @@
package cz.kamma.kfmanager.ui; package cz.kamma.kfmanager.ui;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.event.KeyEvent;
import java.awt.CardLayout; import java.awt.CardLayout;
import java.awt.Color; import java.awt.Color;
import java.awt.Component; import java.awt.Component;
@ -24,6 +25,7 @@ import javax.swing.Box;
import javax.swing.BoxLayout; import javax.swing.BoxLayout;
import javax.swing.DefaultListModel; import javax.swing.DefaultListModel;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.KeyStroke;
import javax.swing.JCheckBox; import javax.swing.JCheckBox;
import javax.swing.JColorChooser; import javax.swing.JColorChooser;
import javax.swing.JComboBox; import javax.swing.JComboBox;
@ -297,6 +299,11 @@ public class SettingsDialog extends JDialog {
btns.add(cancel); btns.add(cancel);
add(btns, BorderLayout.SOUTH); add(btns, BorderLayout.SOUTH);
// Close on Escape
getRootPane().registerKeyboardAction(e -> cancel.doClick(),
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
JComponent.WHEN_IN_FOCUSED_WINDOW);
// Ensure dialog has focus when opened // Ensure dialog has focus when opened
addWindowListener(new java.awt.event.WindowAdapter() { addWindowListener(new java.awt.event.WindowAdapter() {
@Override @Override
@ -321,7 +328,7 @@ public class SettingsDialog extends JDialog {
for (Component c : container.getComponents()) { for (Component c : container.getComponents()) {
// Skip specialized buttons that manage their own background colors // Skip specialized buttons that manage their own background colors
if (c instanceof JComponent && Boolean.TRUE.equals(((JComponent) c).getClientProperty("isColorButton"))) { if (c instanceof JComponent component && Boolean.TRUE.equals(component.getClientProperty("isColorButton"))) {
continue; continue;
} }
@ -329,8 +336,7 @@ public class SettingsDialog extends JDialog {
c instanceof JTabbedPane || c instanceof JButton || c instanceof JSplitPane || c instanceof JTabbedPane || c instanceof JButton || c instanceof JSplitPane ||
c instanceof JList || c instanceof JComboBox || c instanceof JTable) { c instanceof JList || c instanceof JComboBox || c instanceof JTable) {
c.setBackground(bg); c.setBackground(bg);
if (c instanceof JTable) { if (c instanceof JTable t) {
JTable t = (JTable) c;
if (t.getTableHeader() != null) { if (t.getTableHeader() != null) {
t.getTableHeader().setBackground(bg); t.getTableHeader().setBackground(bg);
t.getTableHeader().setForeground(dark ? Color.WHITE : Color.BLACK); t.getTableHeader().setForeground(dark ? Color.WHITE : Color.BLACK);
@ -341,8 +347,7 @@ public class SettingsDialog extends JDialog {
c instanceof JButton || c instanceof JComboBox || c instanceof JList) { c instanceof JButton || c instanceof JComboBox || c instanceof JList) {
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 tc) {
javax.swing.text.JTextComponent tc = (javax.swing.text.JTextComponent) c;
tc.setBackground(bg); tc.setBackground(bg);
tc.setForeground(dark ? Color.WHITE : Color.BLACK); tc.setForeground(dark ? Color.WHITE : Color.BLACK);
tc.setCaretColor(dark ? Color.WHITE : Color.BLACK); tc.setCaretColor(dark ? Color.WHITE : Color.BLACK);
@ -350,11 +355,9 @@ public class SettingsDialog extends JDialog {
tc.setSelectionColor(selColor); tc.setSelectionColor(selColor);
} }
} }
if (c instanceof JComboBox) { if (c instanceof JComboBox<?> cb) {
JComboBox<?> cb = (JComboBox<?>) c;
Component ed = cb.getEditor().getEditorComponent(); Component ed = cb.getEditor().getEditorComponent();
if (ed instanceof javax.swing.text.JTextComponent) { if (ed instanceof javax.swing.text.JTextComponent tc) {
javax.swing.text.JTextComponent tc = (javax.swing.text.JTextComponent) ed;
tc.setBackground(bg); tc.setBackground(bg);
tc.setForeground(dark ? Color.WHITE : Color.BLACK); tc.setForeground(dark ? Color.WHITE : Color.BLACK);
tc.setCaretColor(dark ? Color.WHITE : Color.BLACK); tc.setCaretColor(dark ? Color.WHITE : Color.BLACK);
@ -363,8 +366,8 @@ public class SettingsDialog extends JDialog {
} }
} }
} }
if (c instanceof Container) { if (c instanceof Container container1) {
updateComponentBackground((Container) c, bg); updateComponentBackground(container1, bg);
} }
} }
} }
@ -692,7 +695,7 @@ public class SettingsDialog extends JDialog {
try { try {
// parse strings like "name:asc" // parse strings like "name:asc"
if (crit.size() > 0) { if (crit.size() > 0) {
String[] parts = crit.get(0).split(":"); String[] parts = crit.getFirst().split(":");
if (parts.length >= 1) primaryField.setSelectedItem(capitalize(parts[0])); if (parts.length >= 1) primaryField.setSelectedItem(capitalize(parts[0]));
if (parts.length == 2 && parts[1].equalsIgnoreCase("desc")) primaryOrder.setSelectedItem("Descending"); if (parts.length == 2 && parts[1].equalsIgnoreCase("desc")) primaryOrder.setSelectedItem("Descending");
} }
@ -953,6 +956,6 @@ public class SettingsDialog extends JDialog {
private String getFontDescription(Font f) { private String getFontDescription(Font f) {
if (f == null) return "(default)"; if (f == null) return "(default)";
return String.format("%s %dpt", f.getName(), f.getSize()); return "%s %dpt".formatted(f.getName(), f.getSize());
} }
} }

View File

@ -285,8 +285,7 @@ public class SyncDirectoriesDialog extends JDialog {
if (!(c instanceof JToggleButton)) { if (!(c instanceof JToggleButton)) {
c.setBackground(bg); c.setBackground(bg);
} }
if (c instanceof JTable) { if (c instanceof JTable t) {
JTable t = (JTable) c;
if (t.getTableHeader() != null) { if (t.getTableHeader() != null) {
t.getTableHeader().setBackground(bg); t.getTableHeader().setBackground(bg);
t.getTableHeader().setForeground(dark ? Color.WHITE : Color.BLACK); t.getTableHeader().setForeground(dark ? Color.WHITE : Color.BLACK);
@ -299,8 +298,7 @@ public class SyncDirectoriesDialog extends JDialog {
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 tc) {
javax.swing.text.JTextComponent tc = (javax.swing.text.JTextComponent) c;
tc.setBackground(bg); tc.setBackground(bg);
tc.setForeground(dark ? Color.WHITE : Color.BLACK); tc.setForeground(dark ? Color.WHITE : Color.BLACK);
tc.setCaretColor(dark ? Color.WHITE : Color.BLACK); tc.setCaretColor(dark ? Color.WHITE : Color.BLACK);
@ -308,11 +306,9 @@ public class SyncDirectoriesDialog extends JDialog {
tc.setSelectionColor(selColor); tc.setSelectionColor(selColor);
} }
} }
if (c instanceof JComboBox) { if (c instanceof JComboBox<?> cb) {
JComboBox<?> cb = (JComboBox<?>) c;
Component ed = cb.getEditor().getEditorComponent(); Component ed = cb.getEditor().getEditorComponent();
if (ed instanceof javax.swing.text.JTextComponent) { if (ed instanceof javax.swing.text.JTextComponent tc) {
javax.swing.text.JTextComponent tc = (javax.swing.text.JTextComponent) ed;
tc.setBackground(bg); tc.setBackground(bg);
tc.setForeground(dark ? Color.WHITE : Color.BLACK); tc.setForeground(dark ? Color.WHITE : Color.BLACK);
tc.setCaretColor(dark ? Color.WHITE : Color.BLACK); tc.setCaretColor(dark ? Color.WHITE : Color.BLACK);
@ -321,8 +317,8 @@ public class SyncDirectoriesDialog extends JDialog {
} }
} }
} }
if (c instanceof Container) { if (c instanceof Container container1) {
updateComponentBackground((Container) c, bg); updateComponentBackground(container1, bg);
} }
} }
} }
@ -440,7 +436,7 @@ public class SyncDirectoriesDialog extends JDialog {
else if ("<-".equals(e.relation) && showRightOnlyBtn.isSelected()) filtered.add(e); else if ("<-".equals(e.relation) && showRightOnlyBtn.isSelected()) filtered.add(e);
} }
tableModel.setResults(filtered); tableModel.setResults(filtered);
statusLabel.setText(String.format("Showing %d of %d items.", filtered.size(), allEntries.size())); statusLabel.setText("Showing %d of %d items.".formatted(filtered.size(), allEntries.size()));
} }
private void updateRelation(SyncEntry entry) { private void updateRelation(SyncEntry entry) {
@ -541,7 +537,7 @@ public class SyncDirectoriesDialog extends JDialog {
private String formatSize(long size) { private String formatSize(long size) {
if (size < 0) return "<DIR>"; if (size < 0) return "<DIR>";
return String.format("%,d", size); return "%,d".formatted(size);
} }
private String formatDate(long time) { private String formatDate(long time) {
@ -586,8 +582,8 @@ public class SyncDirectoriesDialog extends JDialog {
setHorizontalAlignment(LEFT); setHorizontalAlignment(LEFT);
} }
if (c instanceof JComponent) { if (c instanceof JComponent component) {
((JComponent) c).setBorder(BorderFactory.createMatteBorder(0, 0, 1, 1, dark ? new Color(60, 60, 60) : new Color(220, 220, 220))); component.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 1, dark ? new Color(60, 60, 60) : new Color(220, 220, 220)));
} }
return c; return c;