Compare commits

..

No commits in common. "9f6923d7d0c172b1e089b2ec157648857ffe9011" and "4756d4f486c0af93a6196b1dd8ff30cd0cbdf363" have entirely different histories.

16 changed files with 237 additions and 225 deletions

View File

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

View File

@ -138,7 +138,8 @@ public class MainApp {
private static void setupGlobalKeyNavigation() {
Toolkit.getDefaultToolkit().addAWTEventListener(event -> {
if (event instanceof KeyEvent ke) {
if (event instanceof KeyEvent) {
KeyEvent ke = (KeyEvent) event;
if (ke.getID() == KeyEvent.KEY_PRESSED) {
int code = ke.getKeyCode();
if (code == KeyEvent.VK_LEFT || code == KeyEvent.VK_RIGHT) {
@ -165,15 +166,16 @@ public class MainApp {
public static void applyReflectiveCaretColor(Container container) {
if (container == null) return;
for (Component c : container.getComponents()) {
if (c instanceof javax.swing.text.JTextComponent tc) {
if (c instanceof javax.swing.text.JTextComponent) {
javax.swing.text.JTextComponent tc = (javax.swing.text.JTextComponent) c;
Color bg = tc.getBackground();
if (bg != null) {
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);
}
}
if (c instanceof Container container1) {
applyReflectiveCaretColor(container1);
if (c instanceof Container) {
applyReflectiveCaretColor((Container) c);
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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