From 374a130dec80c452ab95a77c6dd6b68a9267fb6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Thu, 8 May 2025 11:09:36 +0200 Subject: [PATCH] CheckStyle fix, FocusableJPanel renamed to FocusablePanel --- .../gui/ConfigurationColorSelection.java | 2 +- ...cusableJPanel.java => FocusablePanel.java} | 59 +++++++++++-------- 2 files changed, 35 insertions(+), 26 deletions(-) rename src/com/jpexs/decompiler/flash/gui/{FocusableJPanel.java => FocusablePanel.java} (78%) diff --git a/src/com/jpexs/decompiler/flash/gui/ConfigurationColorSelection.java b/src/com/jpexs/decompiler/flash/gui/ConfigurationColorSelection.java index ee70ba51a..47a01e7f2 100644 --- a/src/com/jpexs/decompiler/flash/gui/ConfigurationColorSelection.java +++ b/src/com/jpexs/decompiler/flash/gui/ConfigurationColorSelection.java @@ -32,7 +32,7 @@ import javax.swing.border.BevelBorder; * * @author JPEXS */ -public class ConfigurationColorSelection extends FocusableJPanel { +public class ConfigurationColorSelection extends FocusablePanel { private JPanel colorPanel; public ConfigurationColorSelection(ConfigurationItem item, Color value, String description) { diff --git a/src/com/jpexs/decompiler/flash/gui/FocusableJPanel.java b/src/com/jpexs/decompiler/flash/gui/FocusablePanel.java similarity index 78% rename from src/com/jpexs/decompiler/flash/gui/FocusableJPanel.java rename to src/com/jpexs/decompiler/flash/gui/FocusablePanel.java index 8ba650546..b923b19b2 100644 --- a/src/com/jpexs/decompiler/flash/gui/FocusableJPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/FocusablePanel.java @@ -33,7 +33,6 @@ import java.util.HashSet; import java.util.List; import java.util.Set; import javax.swing.AbstractAction; -import javax.swing.BorderFactory; import javax.swing.JCheckBox; import javax.swing.JPanel; import javax.swing.KeyStroke; @@ -45,10 +44,10 @@ import org.pushingpixels.substance.internal.utils.SubstanceSizeUtils; * * @author JPEXS */ -public class FocusableJPanel extends JPanel { +public class FocusablePanel extends JPanel { + private List listeners = new ArrayList<>(); - - + private static final Set pressedModifiers = new HashSet<>(); private static void setupGlobalKeyListener() { @@ -61,28 +60,33 @@ public class FocusableJPanel extends JPanel { return false; }); } - + private static int getCurrentModifiers() { int mods = 0; - if (pressedModifiers.contains(KeyEvent.VK_CONTROL)) mods |= InputEvent.CTRL_DOWN_MASK; - if (pressedModifiers.contains(KeyEvent.VK_SHIFT)) mods |= InputEvent.SHIFT_DOWN_MASK; - if (pressedModifiers.contains(KeyEvent.VK_ALT)) mods |= InputEvent.ALT_DOWN_MASK; + if (pressedModifiers.contains(KeyEvent.VK_CONTROL)) { + mods |= InputEvent.CTRL_DOWN_MASK; + } + if (pressedModifiers.contains(KeyEvent.VK_SHIFT)) { + mods |= InputEvent.SHIFT_DOWN_MASK; + } + if (pressedModifiers.contains(KeyEvent.VK_ALT)) { + mods |= InputEvent.ALT_DOWN_MASK; + } return mods; } - + public void addActionListener(ActionListener l) { listeners.add(l); } - + public void removeActionListener(ActionListener l) { listeners.remove(l); } - - - public FocusableJPanel() { + + public FocusablePanel() { setupGlobalKeyListener(); setFocusable(true); - + addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { @@ -109,14 +113,14 @@ public class FocusableJPanel extends JPanel { @Override public void mouseClicked(MouseEvent e) { requestFocusInWindow(); - fireAction(null); + fireAction(null); } }); } - + private void fireAction(ActionEvent e) { if (e == null) { - e = new ActionEvent(FocusableJPanel.this, ActionEvent.ACTION_PERFORMED, "CLICK", getCurrentModifiers()); + e = new ActionEvent(FocusablePanel.this, ActionEvent.ACTION_PERFORMED, "CLICK", getCurrentModifiers()); } for (ActionListener l : listeners) { l.actionPerformed(e); @@ -126,14 +130,19 @@ public class FocusableJPanel extends JPanel { @Override protected void paintBorder(Graphics g) { super.paintBorder(g); - + if (Configuration.useRibbonInterface.get() && isFocusOwner()) { - SubstanceCoreUtilities.paintFocus(g, this, this, (new SubstanceCheckBoxUI(new JCheckBox())), null, new Rectangle(), - 1.0f, SubstanceSizeUtils - .getFocusRingPadding(SubstanceSizeUtils - .getComponentFontSize(this))); - } + SubstanceCoreUtilities.paintFocus( + g, + this, + this, + (new SubstanceCheckBoxUI(new JCheckBox())), + null, + new Rectangle(), + 1.0f, + SubstanceSizeUtils.getFocusRingPadding(SubstanceSizeUtils.getComponentFontSize(this)) + ); + } } - - + }