From 4e20082b91e89701a4c0ceff2a65da394b01bd98 Mon Sep 17 00:00:00 2001 From: aNNiMON Date: Thu, 2 Feb 2023 19:16:29 +0200 Subject: [PATCH] Ability to switch profiles with Page Up / Page Down --- README.md | 9 +++- README_ru.md | 5 +++ .../java/com/annimon/imagetagger/Main.java | 2 +- .../imagetagger/logic/KeyProcessor.java | 42 ++++++++++++++++--- .../annimon/imagetagger/views/TagPanel.java | 12 +++++- 5 files changed, 60 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index ddb6de0..9151da6 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,11 @@ The program requires Java 11 to run. ## Changelog +**1.2** + - Ability to change font size with `Ctrl+Plus` and `Ctrl+Minus` + - Ability to change profiles with `Page Up` and `Page Down` + - Dark background and maximized window by default + **1.1** -- Added an ability to set modifiers Ctrl/Alt: `Ctrl+Alt+s`, `Ctrl+Alt+S`. -- `F3` for changing background color + - Added an ability to set modifiers Ctrl/Alt: `Ctrl+Alt+s`, `Ctrl+Alt+S`. + - `F3` for changing background color diff --git a/README_ru.md b/README_ru.md index 0066df0..d3b33ee 100644 --- a/README_ru.md +++ b/README_ru.md @@ -44,6 +44,11 @@ for /f "delims=" %f in ('dir /b "*.jpg"') do exiftool -q -overwrite_original -@ **История изменений** +**1.2** +- Возможность изменить размер шрифта `Ctrl +` и `Ctrl -` +- Возможность смены профиля клавишами `Page Up` и `Page Down` +- Тёмный фон и развёрнутое на весь экран окно по умолчанию + **1.1** - Добавлена возможность назначать модификаторы Ctrl/Alt: `Ctrl+Alt+s`, `Ctrl+Alt+S`. - `F3` для смены яркости фона. \ No newline at end of file diff --git a/src/main/java/com/annimon/imagetagger/Main.java b/src/main/java/com/annimon/imagetagger/Main.java index a2e789b..b6eb343 100644 --- a/src/main/java/com/annimon/imagetagger/Main.java +++ b/src/main/java/com/annimon/imagetagger/Main.java @@ -39,7 +39,7 @@ public class Main extends JFrame { final var files = new CacheableFilesProvider(config.getDir(), config.getCache()); final var imageProcessor = new ImageProcessor(files, config.getFilter(), config.getSort()); final var imagePanel = new ImagePanel(imageProcessor); - final var keyProcessor = new KeyProcessor(tagButtons); + final var keyProcessor = new KeyProcessor(config.getTags(), config.getProfile()); keyProcessor.setTagPanel(tagPanel); keyProcessor.setImagePanel(imagePanel); keyProcessor.setImageProcessor(imageProcessor); diff --git a/src/main/java/com/annimon/imagetagger/logic/KeyProcessor.java b/src/main/java/com/annimon/imagetagger/logic/KeyProcessor.java index 1f37445..71e0923 100644 --- a/src/main/java/com/annimon/imagetagger/logic/KeyProcessor.java +++ b/src/main/java/com/annimon/imagetagger/logic/KeyProcessor.java @@ -7,24 +7,30 @@ import com.annimon.imagetagger.views.UIUtils; import java.awt.*; import java.awt.event.KeyEvent; +import java.util.*; import java.util.List; -import java.util.Locale; -import java.util.Set; import java.util.stream.Collectors; public class KeyProcessor { private static final boolean PREV = false, NEXT = true; + private final Map> tags; private final Set keys; + + private final List profiles; + private int profileIndex; + private TagPanel tagPanel; private ImagePanel imagePanel; private ImageProcessor imageProcessor; - public KeyProcessor(List buttons) { - keys = buttons.stream() - .map(TagButton::getKey) - .collect(Collectors.toSet()); + public KeyProcessor(Map> tags, String profile) { + this.tags = new LinkedHashMap<>(tags); + this.keys = new HashSet<>(); + this.profiles = new ArrayList<>(tags.keySet()); + this.profileIndex = profiles.indexOf(profile); + rebuildKeys(tags.get(profile)); } public void setTagPanel(TagPanel tagPanel) { @@ -51,6 +57,12 @@ public class KeyProcessor { imageProcessor.mergeTags(tagPanel.getEnabledTags(), tagPanel.getDisabledTags()); imageProcessor.writeTagsToFile(); break; + case KeyEvent.VK_PAGE_UP: + switchProfile(PREV); + break; + case KeyEvent.VK_PAGE_DOWN: + switchProfile(NEXT); + break; case KeyEvent.VK_F1: imageInfo(); break; @@ -86,6 +98,17 @@ public class KeyProcessor { tagPanel.repaint(); } + private void switchProfile(boolean switchTo) { + profileIndex += (switchTo == PREV) ? -1 : 1; + if (profileIndex < 0) profileIndex = profiles.size() - 1; + else if (profileIndex >= profiles.size()) profileIndex = 0; + final String profile = profiles.get(profileIndex); + rebuildKeys(tags.get(profile)); + tagPanel.rebuildTags(tags.get(profile)); + tagPanel.enableSupportedTags(imageProcessor.getTags()); + tagPanel.repaint(); + } + private void imageInfo() { System.out.println(imageProcessor.getFilename()); final var image = imageProcessor.getImage(); @@ -121,6 +144,13 @@ public class KeyProcessor { tagPanel.repaint(); } + private void rebuildKeys(List tags) { + keys.clear(); + keys.addAll(tags.stream() + .map(TagButton::getKey) + .collect(Collectors.toSet())); + } + private String getKeyAsString(KeyEvent e) { String prefix = ""; if ((e.getModifiersEx() & KeyEvent.CTRL_DOWN_MASK) != 0) { diff --git a/src/main/java/com/annimon/imagetagger/views/TagPanel.java b/src/main/java/com/annimon/imagetagger/views/TagPanel.java index 0dfea0d..fd857ab 100644 --- a/src/main/java/com/annimon/imagetagger/views/TagPanel.java +++ b/src/main/java/com/annimon/imagetagger/views/TagPanel.java @@ -17,8 +17,18 @@ public class TagPanel extends JPanel { public TagPanel(List buttons) { tagButtons = new LinkedHashMap<>(); - setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS)); + addTags(buttons); + } + + public void rebuildTags(List buttons) { + removeAll(); + tagButtons.clear(); + addTags(buttons); + validate(); + } + + private void addTags(List buttons) { for (TagButton button : buttons) { final var key = button.getKey(); final var label = new ColoredLabel(key, button.getTag());