Tabs: Renamed CloseButtonComponent to a more suitable name and close button popup didn't remove the tab from the openedTabs array (which wouldn't allow that resource to be opened again).

This commit is contained in:
Cody 2024-04-13 12:15:55 -06:00
parent 6ef288f4c4
commit f6bacdacef

AI 샘플 코드 생성 중입니다

Loading...
3 changed files with 31 additions and 19 deletions

View File

@ -1,28 +1,27 @@
package the.bytecode.club.bytecodeviewer.gui.resourceviewer; package the.bytecode.club.bytecodeviewer.gui.resourceviewer;
import com.github.weisj.darklaf.components.CloseButton; 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.components.listeners.MouseClickedListener;
import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ResourceViewer;
import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings; import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
public class CloseButtonComponent extends JPanel { public class TabComponent extends JPanel {
private final JTabbedPane pane; public TabComponent(final JTabbedPane pane) {
public CloseButtonComponent(final JTabbedPane pane) {
super(new FlowLayout(FlowLayout.LEFT, 0, 0)); super(new FlowLayout(FlowLayout.LEFT, 0, 0));
if (pane == null) { if (pane == null) {
throw new NullPointerException("TabbedPane is null"); throw new NullPointerException("TabbedPane is null");
} }
this.pane = pane;
setOpaque(false); setOpaque(false);
JLabel label = new JLabel() { JLabel label = new JLabel() {
public String getText() { public String getText() {
int i = pane.indexOfTabComponent(CloseButtonComponent.this); int i = pane.indexOfTabComponent(TabComponent.this);
if (i != -1) { if (i != -1) {
return pane.getTitleAt(i); return pane.getTitleAt(i);
} }
@ -31,8 +30,8 @@ public class CloseButtonComponent extends JPanel {
} }
}; };
add(label);
label.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5)); label.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
add(label);
JButton button = new CloseButton(); JButton button = new CloseButton();
add(button); add(button);
@ -49,15 +48,22 @@ public class CloseButtonComponent extends JPanel {
if (e.getButton() != MouseEvent.BUTTON1) // left-click if (e.getButton() != MouseEvent.BUTTON1) // left-click
return; return;
if (pane.indexOfTabComponent(CloseButtonComponent.this) != -1) if (pane.indexOfTabComponent(TabComponent.this) != -1) {
pane.remove(pane.indexOfTabComponent(CloseButtonComponent.this)); int i = pane.indexOfTabComponent(TabComponent.this);
removeTab(i);
pane.remove(pane.indexOfTabComponent(TabComponent.this));
}
})); }));
closeTab.addActionListener(e -> closeTab.addActionListener(e ->
{ {
if (pane.indexOfTabComponent(CloseButtonComponent.this) != -1) if (pane.indexOfTabComponent(TabComponent.this) != -1) {
pane.remove(pane.indexOfTabComponent(CloseButtonComponent.this)); int i = pane.indexOfTabComponent(TabComponent.this);
removeTab(i);
pane.remove(pane.indexOfTabComponent(TabComponent.this));
}
}); });
closeAllTabs.addActionListener(e -> closeAllTabs.addActionListener(e ->
{ {
@ -65,14 +71,22 @@ public class CloseButtonComponent extends JPanel {
if (pane.getTabCount() <= 1) if (pane.getTabCount() <= 1)
return; return;
if (pane.indexOfTabComponent(CloseButtonComponent.this) != 0) if (pane.indexOfTabComponent(TabComponent.this) != 0) {
removeTab(0);
pane.remove(0); pane.remove(0);
else } else {
removeTab(1);
pane.remove(1); pane.remove(1);
}
} }
}); });
setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0)); 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);
}
} }

View File

@ -27,6 +27,9 @@ import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ResourceViewer
/** /**
* @author Konloch * @author Konloch
* @since 6/24/2021 * @since 6/24/2021
* @deprecated Removal pending. <br>
* 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 public class TabRemovalEvent implements ContainerListener
{ {

View File

@ -15,13 +15,9 @@ import the.bytecode.club.uikit.tabpopup.closer.PopupMenuTabsCloseConfiguration;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import static the.bytecode.club.bytecodeviewer.Constants.BLOCK_TAB_MENU;
/*************************************************************************** /***************************************************************************
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
* Copyright (C) 2014 Kalen 'Konloch' Kinloch - http://bytecodeviewer.com * * Copyright (C) 2014 Kalen 'Konloch' Kinloch - http://bytecodeviewer.com *
@ -83,7 +79,6 @@ public class Workspace extends TranslatedVisibleComponent {
getContentPane().add(buttonPanel, BorderLayout.SOUTH); getContentPane().add(buttonPanel, BorderLayout.SOUTH);
tabs.addContainerListener(new TabRemovalEvent());
tabs.addChangeListener(arg0 -> buttonPanel.setVisible(tabs.getSelectedIndex() != -1)); tabs.addChangeListener(arg0 -> buttonPanel.setVisible(tabs.getSelectedIndex() != -1));
this.setVisible(true); this.setVisible(true);
@ -148,7 +143,7 @@ public class Workspace extends TranslatedVisibleComponent {
resourceView.resource.workingName = workingName; resourceView.resource.workingName = workingName;
//set the tabs index //set the tabs index
tabs.setTabComponentAt(tabIndex, new CloseButtonComponent(tabs)); tabs.setTabComponentAt(tabIndex, new TabComponent(tabs));
//open the tab that was just added //open the tab that was just added
tabs.setSelectedIndex(tabIndex); tabs.setSelectedIndex(tabIndex);