diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/TabExitButton.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/TabExitButton.java index 7b8889ab..75ca650b 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/TabExitButton.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/TabExitButton.java @@ -32,13 +32,15 @@ import javax.swing.plaf.basic.BasicButtonUI; /** * @author Konloch * @since 6/25/2021 + * Using CloseButton of darklaf instead. 4/17/2022 */ +@Deprecated public class TabExitButton extends JButton implements ActionListener { private final TabbedPane tabbedPane; private final int tabIndex; private final String tabWorkingName; - + public TabExitButton(TabbedPane tabbedPane, int tabIndex, String tabWorkingName) { this.tabbedPane = tabbedPane; @@ -62,12 +64,12 @@ public class TabExitButton extends JButton implements ActionListener // Close the proper tab by clicking the button addActionListener(this); } - + public int getTabIndex() { return tabIndex; } - + @Override public void actionPerformed(final ActionEvent e) { @@ -77,11 +79,11 @@ public class TabExitButton extends JButton implements ActionListener tabbedPane.tabs.remove(i); } } - + // we don't want to update UI for this button @Override public void updateUI() { } - + // paint the cross @Override protected void paintComponent(final Graphics g) @@ -91,33 +93,33 @@ public class TabExitButton extends JButton implements ActionListener // shift the image for pressed buttons if (getModel().isPressed()) g2.translate(1, 1); - + g2.setStroke(new BasicStroke(2)); g2.setColor(Color.BLACK); - + if (getModel().isRollover()) g2.setColor(Color.MAGENTA); - + final int delta = 6; g2.drawLine(delta, delta, getWidth() - delta - 1, getHeight() - delta - 1); g2.drawLine(getWidth() - delta - 1, delta, delta, getHeight() - delta - 1); g2.dispose(); } - + public TabbedPane getTabbedPane() { return tabbedPane; } - + public String getTabWorkingName() { return tabWorkingName; } - + public static long getSerialVersionUID() { return serialVersionUID; } - + private static final long serialVersionUID = -4492967978286454159L; } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/TabbedPane.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/TabbedPane.java index 582353a3..d054c8ff 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/TabbedPane.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/TabbedPane.java @@ -4,7 +4,6 @@ import java.awt.Color; import java.awt.Component; import java.awt.FlowLayout; import java.awt.Rectangle; -import java.awt.event.InputEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; @@ -16,6 +15,8 @@ import javax.swing.JPanel; import javax.swing.JPopupMenu; import javax.swing.JTabbedPane; import javax.swing.SwingUtilities; + +import com.github.weisj.darklaf.components.CloseButton; import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.gui.components.ButtonHoverAnimation; import the.bytecode.club.bytecodeviewer.gui.components.MaxWidthJLabel; @@ -84,7 +85,7 @@ public class TabbedPane extends JPanel // add more space between the label and the button label.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5)); // tab button - JButton exitButton = new TabExitButton(this, tabIndex, tabWorkingName); + JButton exitButton = new CloseButton(); this.add(exitButton); // add more space to the top of the component setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0)); @@ -101,34 +102,24 @@ public class TabbedPane extends JPanel exitButton.setComponentPopupMenu(rightClickMenu); exitButton.addMouseListener(new MouseClickedListener(e -> { - if (e.getModifiersEx() != InputEvent.ALT_DOWN_MASK || System.currentTimeMillis() - lastMouseClick < 100) - return; - - lastMouseClick = System.currentTimeMillis(); - final int i = existingTabs.indexOfTabComponent(TabbedPane.this); - if (i != -1) - existingTabs.remove(i); + if (this.getTabIndex() != -1) + existingTabs.remove(this.getTabIndex()); })); closeTab.addActionListener(e -> { - TabExitButton tabExitButton = (TabExitButton) ((JPopupMenu)((JMenuItem) e.getSource()).getParent()).getInvoker(); - final int index = tabExitButton.getTabIndex(); - - if (index != -1) - existingTabs.remove(index); + if (this.getTabIndex() != -1) + existingTabs.remove(this.getTabIndex()); }); closeAllTabs.addActionListener(e -> { - TabExitButton tabExitButton = (TabExitButton) ((JPopupMenu)((JMenuItem) e.getSource()).getParent()).getInvoker(); - final int index = tabExitButton.getTabIndex(); - + while (true) { if (existingTabs.getTabCount() <= 1) return; - if (index != 0) + if (this.getTabIndex() != 0) existingTabs.remove(0); else existingTabs.remove(1); @@ -257,5 +248,8 @@ public class TabbedPane extends JPanel } private static final long serialVersionUID = -4774885688297538774L; - + + public int getTabIndex() { + return tabs.indexOfTabComponent(this); + } }