From 4d7a40b31b7802350d06b5d0dafbb69acdf338aa Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Thu, 31 Mar 2016 17:25:49 +0000 Subject: [PATCH] Refactor --- source/net/filebot/ui/rename/RenamePanel.java | 19 +++++++------------ source/net/filebot/util/ui/SwingUI.java | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/source/net/filebot/ui/rename/RenamePanel.java b/source/net/filebot/ui/rename/RenamePanel.java index 490ff415..8b8b61db 100644 --- a/source/net/filebot/ui/rename/RenamePanel.java +++ b/source/net/filebot/ui/rename/RenamePanel.java @@ -275,29 +275,24 @@ public class RenamePanel extends JComponent { }); // reveal file location on double click - namesList.getListComponent().addMouseListener(new MouseAdapter() { - - @Override - public void mouseClicked(MouseEvent evt) { - if (evt.getClickCount() == 2) { - getWindow(evt.getSource()).setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + namesList.getListComponent().addMouseListener(mouseClicked(evt -> { + if (evt.getClickCount() == 2) { + JList list = (JList) evt.getSource(); + if (list.getSelectedIndex() >= 0) { try { - JList list = (JList) evt.getSource(); - if (list.getSelectedIndex() >= 0) { + withWaitCursor(list, () -> { Match match = renameModel.getMatch(list.getSelectedIndex()); Map context = renameModel.getMatchContext(match); MediaBindingBean sample = new MediaBindingBean(match.getValue(), match.getCandidate(), context); showFormatEditor(sample); - } + }); } catch (Exception e) { debug.log(Level.WARNING, e.getMessage(), e); - } finally { - getWindow(evt.getSource()).setCursor(Cursor.getDefaultCursor()); } } } - }); + })); setLayout(new MigLayout("fill, insets dialog, gapx 10px", "[fill][align center, pref!][fill]", "align 33%")); add(new LoadingOverlayPane(filesList, filesList, "37px", "30px"), "grow, sizegroupx list"); diff --git a/source/net/filebot/util/ui/SwingUI.java b/source/net/filebot/util/ui/SwingUI.java index 3b695e0e..e8475c6b 100644 --- a/source/net/filebot/util/ui/SwingUI.java +++ b/source/net/filebot/util/ui/SwingUI.java @@ -14,7 +14,9 @@ import java.awt.Point; import java.awt.Window; import java.awt.dnd.DnDConstants; import java.awt.event.ActionEvent; +import java.awt.event.InputEvent; import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.image.BufferedImage; import java.lang.reflect.InvocationTargetException; @@ -94,6 +96,10 @@ public final class SwingUI { return c == null ? "inherit" : String.format("#%02x%02x%02x", c.getRed(), c.getGreen(), c.getBlue()); } + public static boolean isShiftOrAltDown(InputEvent evt) { + return checkModifiers(evt.getModifiers(), ActionEvent.SHIFT_MASK) || checkModifiers(evt.getModifiers(), ActionEvent.ALT_MASK); + } + public static boolean isShiftOrAltDown(ActionEvent evt) { return checkModifiers(evt.getModifiers(), ActionEvent.SHIFT_MASK) || checkModifiers(evt.getModifiers(), ActionEvent.ALT_MASK); } @@ -272,6 +278,16 @@ public final class SwingUI { } } + public static MouseAdapter mouseClicked(Consumer handler) { + return new MouseAdapter() { + + @Override + public void mouseClicked(MouseEvent evt) { + handler.accept(evt); + } + }; + } + public static JButton newButton(String name, Icon icon, Consumer action) { return new JButton(new LambdaAction(name, icon, action)); }