1
0
mirror of https://gitlab.com/annimon/imagetagger.git synced 2024-09-19 14:34:21 +03:00

Ability to switch profiles with Page Up / Page Down

This commit is contained in:
aNNiMON 2023-02-02 19:16:29 +02:00
parent 42703a20ed
commit 4e20082b91
5 changed files with 60 additions and 10 deletions

View File

@ -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

View File

@ -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` для смены яркости фона.

View File

@ -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);

View File

@ -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<String, List<TagButton>> tags;
private final Set<String> keys;
private final List<String> profiles;
private int profileIndex;
private TagPanel tagPanel;
private ImagePanel imagePanel;
private ImageProcessor imageProcessor;
public KeyProcessor(List<TagButton> buttons) {
keys = buttons.stream()
.map(TagButton::getKey)
.collect(Collectors.toSet());
public KeyProcessor(Map<String, List<TagButton>> 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<TagButton> 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) {

View File

@ -17,8 +17,18 @@ public class TagPanel extends JPanel {
public TagPanel(List<TagButton> buttons) {
tagButtons = new LinkedHashMap<>();
setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
addTags(buttons);
}
public void rebuildTags(List<TagButton> buttons) {
removeAll();
tagButtons.clear();
addTags(buttons);
validate();
}
private void addTags(List<TagButton> buttons) {
for (TagButton button : buttons) {
final var key = button.getKey();
final var label = new ColoredLabel(key, button.getTag());