Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,22 @@ public EditorTabbedPane(Gui gui) {

public EditorPanel openClass(ClassEntry entry) {
EditorPanel activeEditor = this.getActiveEditor();
EditorPanel editorPanel = this.editors.computeIfAbsent(entry, e -> {
ClassHandle ch = this.gui.getController().getClassHandleProvider().openClass(entry);
if (ch == null) return null;
EditorPanel entryEditor = this.editors.computeIfAbsent(entry, editing -> {
ClassHandle classHandle = this.gui.getController().getClassHandleProvider().openClass(editing);
if (classHandle == null) {
return null;
}

this.navigator = new NavigatorPanel(this.gui);
EditorPanel ed = new EditorPanel(this.gui, this.navigator);
ed.setClassHandle(ch);
this.openFiles.addTab(ed.getFileName(), ed.getUi());
EditorPanel newEditor = new EditorPanel(this.gui, this.navigator);
newEditor.setClassHandle(classHandle);
this.openFiles.addTab(newEditor.getSimpleClassName(), newEditor.getUi());

ClosableTabTitlePane titlePane = new ClosableTabTitlePane(ed.getFileName(), () -> this.closeEditor(ed));
this.openFiles.setTabComponentAt(this.openFiles.indexOfComponent(ed.getUi()), titlePane.getUi());
ClosableTabTitlePane titlePane = new ClosableTabTitlePane(newEditor.getSimpleClassName(), newEditor.getFullClassName(), () -> this.closeEditor(newEditor));
this.openFiles.setTabComponentAt(this.openFiles.indexOfComponent(newEditor.getUi()), titlePane.getUi());
titlePane.setTabbedPane(this.openFiles);

ed.addListener(new EditorActionListener() {
newEditor.addListener(new EditorActionListener() {
@Override
public void onCursorReferenceChanged(EditorPanel editor, EntryReference<Entry<?>, Entry<?>> ref) {
if (editor == EditorTabbedPane.this.getActiveEditor()) {
Expand All @@ -66,38 +69,39 @@ public void onClassHandleChanged(EditorPanel editor, ClassEntry old, ClassHandle

@Override
public void onTitleChanged(EditorPanel editor, String title) {
titlePane.setText(editor.getFileName());
titlePane.setText(editor.getSimpleClassName(), editor.getFullClassName());
}
});

ed.getEditor().addKeyListener(GuiUtil.onKeyPress(keyEvent -> {
newEditor.getEditor().addKeyListener(GuiUtil.onKeyPress(keyEvent -> {
if (KeyBinds.EDITOR_CLOSE_TAB.matches(keyEvent)) {
this.closeEditor(ed);
this.closeEditor(newEditor);
} else if (KeyBinds.ENTRY_NAVIGATOR_NEXT.matches(keyEvent)) {
ed.getNavigatorPanel().navigateDown();
newEditor.getNavigatorPanel().navigateDown();
keyEvent.consume();
} else if (KeyBinds.ENTRY_NAVIGATOR_LAST.matches(keyEvent)) {
ed.getNavigatorPanel().navigateUp();
newEditor.getNavigatorPanel().navigateUp();
keyEvent.consume();
}
}));

return ed;
return newEditor;
});

if (editorPanel != null && activeEditor != editorPanel) {
if (entryEditor != null && activeEditor != entryEditor) {
this.openFiles.setSelectedComponent(this.editors.get(entry).getUi());
this.gui.updateStructure(editorPanel);
this.gui.showCursorReference(editorPanel.getCursorReference());
this.gui.updateStructure(entryEditor);
this.gui.showCursorReference(entryEditor.getCursorReference());
}

return editorPanel;
return entryEditor;
}

public void closeEditor(EditorPanel ed) {
this.openFiles.remove(ed.getUi());
this.editors.inverse().remove(ed);
EditorPanel activeEditor = this.getActiveEditor();
activeEditor.getEditor().requestFocus();
this.gui.updateStructure(activeEditor);
this.gui.showCursorReference(activeEditor != null ? activeEditor.getCursorReference() : null);
ed.destroy();
Expand Down Expand Up @@ -151,6 +155,7 @@ private void onTabPressed(MouseEvent e) {
}

EditorPanel activeEditor = this.getActiveEditor();
activeEditor.getEditor().requestFocus();
this.gui.updateStructure(activeEditor);
this.gui.showCursorReference(activeEditor != null ? activeEditor.getCursorReference() : null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import javax.swing.event.ChangeListener;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Point;
Expand All @@ -20,16 +21,18 @@
public class ClosableTabTitlePane {
private final JPanel ui;
private final JButton closeButton;
private final JLabel label;
private final JLabel title;

private ChangeListener cachedChangeListener;
private JTabbedPane parent;

public ClosableTabTitlePane(String text, Runnable onClose) {
public ClosableTabTitlePane(String title, String tooltip, Runnable onClose) {
this.ui = new JPanel(new FlowLayout(FlowLayout.CENTER, 2, 2));
this.ui.setOpaque(false);
this.label = new JLabel(text);
this.ui.add(this.label);

this.title = new JLabel(title);
this.title.setToolTipText(tooltip);
this.ui.add(this.title);

// Adapted from javax.swing.plaf.metal.MetalTitlePane
this.closeButton = new JButton();
Expand Down Expand Up @@ -82,6 +85,22 @@ public void mousePressed(MouseEvent e) {
ClosableTabTitlePane.this.parent.dispatchEvent(e1);
}
}

@Override
public void mouseEntered(MouseEvent e) {
ClosableTabTitlePane.this.closeButton.setEnabled(true);
}

@Override
public void mouseExited(MouseEvent e) {
if (!ClosableTabTitlePane.this.isActive(ClosableTabTitlePane.this.parent)) {
final Component target = SwingUtilities.getDeepestComponentAt(e.getComponent(), e.getX(), e.getY());
if (target == null || !SwingUtilities.isDescendingFrom(target, ClosableTabTitlePane.this.ui)) {
// only disable if mouse is not over this ui or descendants
ClosableTabTitlePane.this.closeButton.setEnabled(false);
}
}
}
});

this.ui.putClientProperty(ClosableTabTitlePane.class, this);
Expand All @@ -101,26 +120,31 @@ public void setTabbedPane(JTabbedPane pane) {
this.parent = pane;
}

public void setText(String text) {
this.label.setText(text);
public void setText(String title, String tooltip) {
this.title.setText(title);
this.title.setToolTipText(tooltip);
}

public String getText() {
return this.label.getText();
public String getTitle() {
return this.title.getText();
}

private void updateState(JTabbedPane pane) {
int selectedIndex = pane.getSelectedIndex();
boolean isActive = selectedIndex != -1 && pane.getTabComponentAt(selectedIndex) == this.ui;
this.closeButton.setEnabled(isActive);
this.closeButton.putClientProperty("paintActive", isActive);
final boolean active = this.isActive(pane);
this.closeButton.setEnabled(active);
this.closeButton.putClientProperty("paintActive", active);

this.ui.remove(this.closeButton);
this.ui.add(this.closeButton);

this.ui.repaint();
}

private boolean isActive(JTabbedPane pane) {
int selectedIndex = pane.getSelectedIndex();
return selectedIndex != -1 && pane.getTabComponentAt(selectedIndex) == this.ui;
}

public JPanel getUi() {
return this.ui;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ private void setClassHandle0(ClassEntry old, ClassHandle handle) {
handle.addListener(new ClassHandleListener() {
@Override
public void onDeobfRefChanged(ClassHandle h, ClassEntry deobfRef) {
SwingUtilities.invokeLater(() -> EditorPanel.this.listeners.forEach(l -> l.onTitleChanged(EditorPanel.this, EditorPanel.this.getFileName())));
SwingUtilities.invokeLater(() -> EditorPanel.this.listeners.forEach(l -> l.onTitleChanged(EditorPanel.this, EditorPanel.this.getSimpleClassName())));
}

@Override
Expand Down Expand Up @@ -653,9 +653,17 @@ public ClassHandle getClassHandle() {
return this.classHandle;
}

public String getFileName() {
ClassEntry classEntry = this.classHandle.getDeobfRef() != null ? this.classHandle.getDeobfRef() : this.classHandle.getRef();
return classEntry.getSimpleName();
public String getSimpleClassName() {
return this.getDeobfOrObfHandleRef().getSimpleName();
}

public String getFullClassName() {
return this.getDeobfOrObfHandleRef().getFullName();
}

private ClassEntry getDeobfOrObfHandleRef() {
final ClassEntry deobfRef = this.classHandle.getDeobfRef();
return deobfRef == null ? this.classHandle.getRef() : deobfRef;
}

public void retranslateUi() {
Expand Down