diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/CloseButtonComponent.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/TabComponent.java similarity index 59% rename from src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/CloseButtonComponent.java rename to src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/TabComponent.java index e6563dd8..fe1bec2e 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/CloseButtonComponent.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/TabComponent.java @@ -1,28 +1,27 @@ package the.bytecode.club.bytecodeviewer.gui.resourceviewer; import com.github.weisj.darklaf.components.CloseButton; +import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.gui.components.listeners.MouseClickedListener; +import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ResourceViewer; import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings; import javax.swing.*; import java.awt.*; import java.awt.event.MouseEvent; -public class CloseButtonComponent extends JPanel { +public class TabComponent extends JPanel { - private final JTabbedPane pane; - - public CloseButtonComponent(final JTabbedPane pane) { + public TabComponent(final JTabbedPane pane) { super(new FlowLayout(FlowLayout.LEFT, 0, 0)); if (pane == null) { throw new NullPointerException("TabbedPane is null"); } - this.pane = pane; setOpaque(false); JLabel label = new JLabel() { public String getText() { - int i = pane.indexOfTabComponent(CloseButtonComponent.this); + int i = pane.indexOfTabComponent(TabComponent.this); if (i != -1) { return pane.getTitleAt(i); } @@ -31,8 +30,8 @@ public class CloseButtonComponent extends JPanel { } }; - add(label); label.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5)); + add(label); JButton button = new CloseButton(); add(button); @@ -49,15 +48,22 @@ public class CloseButtonComponent extends JPanel { if (e.getButton() != MouseEvent.BUTTON1) // left-click return; - if (pane.indexOfTabComponent(CloseButtonComponent.this) != -1) - pane.remove(pane.indexOfTabComponent(CloseButtonComponent.this)); + if (pane.indexOfTabComponent(TabComponent.this) != -1) { + int i = pane.indexOfTabComponent(TabComponent.this); + removeTab(i); + pane.remove(pane.indexOfTabComponent(TabComponent.this)); + } })); closeTab.addActionListener(e -> { - if (pane.indexOfTabComponent(CloseButtonComponent.this) != -1) - pane.remove(pane.indexOfTabComponent(CloseButtonComponent.this)); + if (pane.indexOfTabComponent(TabComponent.this) != -1) { + int i = pane.indexOfTabComponent(TabComponent.this); + removeTab(i); + pane.remove(pane.indexOfTabComponent(TabComponent.this)); + } }); + closeAllTabs.addActionListener(e -> { @@ -65,14 +71,22 @@ public class CloseButtonComponent extends JPanel { if (pane.getTabCount() <= 1) return; - if (pane.indexOfTabComponent(CloseButtonComponent.this) != 0) + if (pane.indexOfTabComponent(TabComponent.this) != 0) { + removeTab(0); pane.remove(0); - else + } else { + removeTab(1); pane.remove(1); + } } }); setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0)); } + private void removeTab(int index) { + ResourceViewer resourceViewer = (ResourceViewer) BytecodeViewer.viewer.workPane.tabs.getComponentAt(index); + BytecodeViewer.viewer.workPane.openedTabs.remove(resourceViewer.resource.workingName); + } + } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/TabRemovalEvent.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/TabRemovalEvent.java index 64664c48..58c7edc0 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/TabRemovalEvent.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/TabRemovalEvent.java @@ -27,6 +27,9 @@ import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ResourceViewer /** * @author Konloch * @since 6/24/2021 + * @deprecated Removal pending.
+ * Disabled due to a bug when dragging a component, it got "removed" resulting in another + * tab being opened when clicking the same class in the file resource rather than opening the already opened file. */ public class TabRemovalEvent implements ContainerListener { diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/Workspace.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/Workspace.java index 8db0c739..dc414cda 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/Workspace.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/Workspace.java @@ -15,13 +15,9 @@ import the.bytecode.club.uikit.tabpopup.closer.PopupMenuTabsCloseConfiguration; import javax.swing.*; import java.awt.*; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; import java.util.HashSet; import java.util.Set; -import static the.bytecode.club.bytecodeviewer.Constants.BLOCK_TAB_MENU; - /*************************************************************************** * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * * Copyright (C) 2014 Kalen 'Konloch' Kinloch - http://bytecodeviewer.com * @@ -83,7 +79,6 @@ public class Workspace extends TranslatedVisibleComponent { getContentPane().add(buttonPanel, BorderLayout.SOUTH); - tabs.addContainerListener(new TabRemovalEvent()); tabs.addChangeListener(arg0 -> buttonPanel.setVisible(tabs.getSelectedIndex() != -1)); this.setVisible(true); @@ -148,7 +143,7 @@ public class Workspace extends TranslatedVisibleComponent { resourceView.resource.workingName = workingName; //set the tabs index - tabs.setTabComponentAt(tabIndex, new CloseButtonComponent(tabs)); + tabs.setTabComponentAt(tabIndex, new TabComponent(tabs)); //open the tab that was just added tabs.setSelectedIndex(tabIndex);