Skip to content

Commit ae69116

Browse files
committed
Enabled tabs to be rearranged. Did not add functionality for a tab to be dropped out. We could possibly add it at a later time, also add a setting to toggle it on/off? Recommend to gather feedback to see if that is something wanted.
1 parent 218de05 commit ae69116

5 files changed

Lines changed: 45 additions & 172 deletions

File tree

src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,6 @@
129129

130130
public class BytecodeViewer
131131
{
132-
//TODO fix this for tab dragging & better tab controls
133-
public static boolean EXPERIMENTAL_TAB_CODE = true;
134132

135133
//the launch args called on BCV
136134
public static String[] launchArgs;

src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/CloseButtonComponent.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,23 @@
22

33
import com.android.tools.r8.internal.Cl;
44
import com.github.weisj.darklaf.components.CloseButton;
5+
import com.github.weisj.darklaf.listener.MouseClickListener;
6+
import the.bytecode.club.bytecodeviewer.gui.components.listeners.MouseClickedListener;
7+
import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings;
58

69
import javax.swing.*;
710
import java.awt.*;
11+
import java.awt.event.ActionEvent;
12+
import java.awt.event.ActionListener;
13+
import java.awt.event.MouseEvent;
14+
import java.awt.event.MouseListener;
815

916
public class CloseButtonComponent extends JPanel {
1017

1118
private final JTabbedPane pane;
1219

20+
String title = "";
21+
1322
public CloseButtonComponent(final JTabbedPane pane) {
1423
super(new FlowLayout(FlowLayout.LEFT, 0, 0));
1524
if (pane == null) {
@@ -33,6 +42,40 @@ public String getText() {
3342
label.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
3443
JButton button = new CloseButton();
3544
add(button);
45+
46+
JPopupMenu rightClickMenu = new JPopupMenu();
47+
JMenuItem closeAllTabs = new JMenuItem(String.valueOf(TranslatedStrings.CLOSE_ALL_BUT_THIS));
48+
JMenuItem closeTab = new JMenuItem(String.valueOf(TranslatedStrings.CLOSE_TAB));
49+
50+
rightClickMenu.add(closeAllTabs);
51+
rightClickMenu.add(closeTab);
52+
button.setComponentPopupMenu(rightClickMenu);
53+
54+
button.addMouseListener(new MouseClickedListener(e ->
55+
{
56+
if (pane.indexOfTabComponent(CloseButtonComponent.this) != -1)
57+
pane.remove(pane.indexOfTabComponent(CloseButtonComponent.this));
58+
}));
59+
60+
closeTab.addActionListener(e ->
61+
{
62+
if (pane.indexOfTabComponent(CloseButtonComponent.this) != -1)
63+
pane.remove(pane.indexOfTabComponent(CloseButtonComponent.this));
64+
});
65+
closeAllTabs.addActionListener(e ->
66+
{
67+
68+
while (true) {
69+
if (pane.getTabCount() <= 1)
70+
return;
71+
72+
if (pane.indexOfTabComponent(CloseButtonComponent.this) != 0)
73+
pane.remove(0);
74+
else
75+
pane.remove(1);
76+
}
77+
});
78+
3679
setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0));
3780
}
3881

src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/DraggableTabbedPane.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
package the.bytecode.club.bytecodeviewer.gui.resourceviewer;
22

3-
import com.github.weisj.darklaf.components.CloseButton;
43
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
54

65
import javax.swing.*;
76
import java.awt.*;
87
import java.awt.datatransfer.DataFlavor;
98
import java.awt.datatransfer.Transferable;
109
import java.awt.dnd.*;
11-
import java.awt.event.MouseAdapter;
12-
import java.awt.event.MouseEvent;
13-
import java.awt.event.MouseListener;
14-
import java.awt.event.MouseMotionAdapter;
1510
import java.awt.geom.Rectangle2D;
1611
import java.awt.image.BufferedImage;
1712

src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/TabbedPane.java

Lines changed: 2 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -76,166 +76,8 @@ public TabbedPane(int tabIndex, String tabWorkingName, String fileContainerName,
7676
this.add(label);
7777
// add more space between the label and the button
7878
label.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
79-
// tab button
80-
JButton exitButton = new CloseButton();
8179
// add more space to the top of the component
8280
setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0));
83-
84-
//define the right click pop-up menu
85-
JPopupMenu rightClickMenu = new JPopupMenu();
86-
this.putClientProperty("index", this.getTabIndex());
87-
JMenuItem closeAllTabs = new JMenuItem(TranslatedStrings.CLOSE_ALL_BUT_THIS + ": " + name);
88-
JMenuItem closeTab = new JMenuItem(TranslatedStrings.CLOSE_TAB + ": " + name);
89-
90-
rightClickMenu.add(closeAllTabs);
91-
rightClickMenu.add(closeTab);
92-
//setComponentPopupMenu(rightClickMenu);
93-
94-
exitButton.setComponentPopupMenu(rightClickMenu);
95-
exitButton.addMouseListener(new MouseClickedListener(e ->
96-
{
97-
if (this.getTabIndex() != -1)
98-
existingTabs.remove(this.getTabIndex());
99-
}));
100-
101-
closeTab.addActionListener(e ->
102-
{
103-
if (this.getTabIndex() != -1)
104-
existingTabs.remove(this.getTabIndex());
105-
});
106-
closeAllTabs.addActionListener(e ->
107-
{
108-
109-
while (true) {
110-
if (existingTabs.getTabCount() <= 1)
111-
return;
112-
113-
if (this.getTabIndex() != 0)
114-
existingTabs.remove(0);
115-
else
116-
existingTabs.remove(1);
117-
}
118-
});
119-
120-
//tab dragging
121-
if (BytecodeViewer.EXPERIMENTAL_TAB_CODE) {
122-
/*label.addMouseListener(new MouseListener() {
123-
@Override public void mouseClicked(MouseEvent e) {}
124-
@Override public void mouseEntered(MouseEvent arg0) {
125-
}
126-
@Override public void mouseExited(MouseEvent arg0) {
127-
}
128-
@Override public void mousePressed(MouseEvent e) {
129-
onMousePressed(e);
130-
}
131-
@Override public void mouseReleased(MouseEvent e) {
132-
stopDragging(e.getX(), e.getY());
133-
}
134-
});*/
135-
136-
this.addMouseListener(new MouseListener() {
137-
@Override
138-
public void mouseClicked(MouseEvent e) {
139-
}
140-
141-
@Override
142-
public void mouseEntered(MouseEvent arg0) {
143-
}
144-
145-
@Override
146-
public void mouseExited(MouseEvent arg0) {
147-
}
148-
149-
@Override
150-
public void mousePressed(MouseEvent e) {
151-
onMousePressed(e);
152-
}
153-
154-
@Override
155-
public void mouseReleased(MouseEvent e) {
156-
}
157-
});
158-
}
159-
160-
//middle click close
161-
if (BytecodeViewer.EXPERIMENTAL_TAB_CODE) {
162-
this.addMouseListener(new MouseAdapter() {
163-
@Override
164-
public void mouseReleased(MouseEvent e) {
165-
if (e.getButton() != MouseEvent.BUTTON2)
166-
return;
167-
168-
final int i = existingTabs.indexOfTabComponent(TabbedPane.this);
169-
if (i != -1)
170-
existingTabs.remove(i);
171-
}
172-
});
173-
}
174-
}
175-
176-
private void stopDragging(int mouseX, int mouseY) {
177-
if (System.currentTimeMillis() - startedDragging >= 210) {
178-
if (mouseX < 0) {
179-
mouseX = 0;
180-
}
181-
Rectangle bounds = new Rectangle(1, 1, mouseX, mouseY);
182-
System.out.println("debug-5: " + mouseX + ", " + mouseY);
183-
184-
int totalTabs = BytecodeViewer.viewer.workPane.tabs.getTabCount();
185-
int curIndex = getTabIndex();
186-
int toIndex = -1;
187-
188-
//Set up the indexes of our tabs.
189-
for (int i = 0; i < totalTabs; i++) {
190-
Component c = BytecodeViewer.viewer.workPane.tabs.getTabComponentAt(i);
191-
System.err.println("Our bounds: " + bounds + " component: " + c.getBounds() + " intersects: " + bounds.intersects(c.getBounds()));
192-
if (bounds.intersects(c.getBounds()) && c != this) {
193-
toIndex = i;
194-
}
195-
}
196-
197-
System.err.println(totalTabs + " " + curIndex + " " + toIndex);
198-
199-
if (toIndex == totalTabs) {
200-
System.err.println("here");
201-
} else if (curIndex > toIndex) {
202-
if (toIndex == -1) {
203-
toIndex = 0;
204-
}
205-
// [tab0=index0][tab1=index1]
206-
// ---> == remove(tab0)
207-
// [tab1=index0]
208-
// add(tab0)
209-
// [tab1=index0][tab0=index1]
210-
211-
Component c = BytecodeViewer.viewer.workPane.tabs.getTabComponentAt(toIndex + 1);
212-
System.err.println("here1");
213-
// BytecodeViewer.viewer.workPane.tabs.remove(curIndex - 1); // 0
214-
// BytecodeViewer.viewer.workPane.tabs.add(BytecodeViewer.viewer.workPane.op);
215-
// BytecodeViewer.viewer.workPane.tabs.setTabComponentAt(curIndex, BytecodeViewer.viewer.workPane.tabs.getTabComponentAt(curIndex - 1));
216-
} else {
217-
BytecodeViewer.viewer.workPane.tabs.remove(curIndex); // 0
218-
BytecodeViewer.viewer.workPane.tabs.add(resource);
219-
BytecodeViewer.viewer.workPane.tabs.setTabComponentAt(toIndex, this);
220-
}
221-
222-
if (toIndex == -1) {
223-
for (int i = 0; i < totalTabs; i++) {
224-
Component c = BytecodeViewer.viewer.workPane.tabs.getTabComponentAt(i);
225-
//do some check to see if it's past the X or Y
226-
if (c != null) {
227-
System.out.println("debug-6: " + c.getBounds());
228-
}
229-
}
230-
}
231-
232-
}
233-
234-
SwingUtilities.invokeLater(() ->
235-
{
236-
label.setBackground(BLANK_COLOR);
237-
label.updateUI();
238-
});
23981
}
24082

24183
public void onMousePressed(MouseEvent e)
@@ -260,15 +102,11 @@ public void onMousePressed(MouseEvent e)
260102
BytecodeViewer.viewer.workPane.tabs.setSelectedIndex(i);
261103
}
262104
}
263-
else
264-
{
265-
stopDragging(e.getX(), e.getY());
266-
}
267105
}
268106

269107
private static final long serialVersionUID = -4774885688297538774L;
270108

271-
public int getTabIndex() {
109+
/*public int getTabIndex() {
272110
return tabs.indexOfTabComponent(this);
273-
}
111+
}*/
274112
}

src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/Workspace.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ public void addResourceToTab(ResourceViewer resourceView, String workingName, St
230230
resourceView.resource.workingName = workingName;
231231

232232
//set the tabs index
233-
// tabs.setTabComponentAt(tabIndex, tabbedPane);
234233
tabs.setTabComponentAt(tabIndex, new CloseButtonComponent(tabs));
235234

236235
//open the tab that was just added

0 commit comments

Comments
 (0)