Skip to content

Commit

Permalink
Merge pull request #415 from GraxCode/gui_fixes
Browse files Browse the repository at this point in the history
Small UI fixes.
  • Loading branch information
Konloch authored Apr 20, 2022
2 parents c9f8771 + 7c8edb3 commit c93d2b5
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@
/**
* @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;
Expand All @@ -62,12 +64,12 @@ public TabExitButton(TabbedPane tabbedPane, int tabIndex, String tabWorkingName)
// Close the proper tab by clicking the button
addActionListener(this);
}

public int getTabIndex()
{
return tabIndex;
}

@Override
public void actionPerformed(final ActionEvent e)
{
Expand All @@ -77,11 +79,11 @@ public void actionPerformed(final ActionEvent e)
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)
Expand All @@ -91,33 +93,33 @@ protected void paintComponent(final Graphics g)
// 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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
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;
Expand All @@ -16,6 +15,8 @@
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;
Expand Down Expand Up @@ -84,7 +85,7 @@ public TabbedPane(int tabIndex, String tabWorkingName, String fileContainerName,
// 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));
Expand All @@ -101,34 +102,24 @@ public TabbedPane(int tabIndex, String tabWorkingName, String fileContainerName,
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);
Expand Down Expand Up @@ -257,5 +248,8 @@ public void onMousePressed(MouseEvent e)
}

private static final long serialVersionUID = -4774885688297538774L;


public int getTabIndex() {
return tabs.indexOfTabComponent(this);
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package the.bytecode.club.bytecodeviewer.gui.theme;

import com.github.weisj.darklaf.LafManager;
import com.github.weisj.darklaf.listener.UIUpdater;
import com.github.weisj.darklaf.theme.DarculaTheme;
import com.github.weisj.darklaf.theme.HighContrastDarkTheme;
import com.github.weisj.darklaf.theme.HighContrastLightTheme;
import com.github.weisj.darklaf.theme.IntelliJTheme;
import com.github.weisj.darklaf.theme.OneDarkTheme;
import com.github.weisj.darklaf.theme.SolarizedDarkTheme;
import com.github.weisj.darklaf.theme.SolarizedLightTheme;
import java.awt.Dialog;
import javax.swing.JInternalFrame;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import java.awt.*;
import javax.swing.*;

import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.Configuration;
import the.bytecode.club.bytecodeviewer.gui.components.SettingsDialog;
Expand Down Expand Up @@ -175,4 +175,13 @@ private static void failSafe() throws ClassNotFoundException, UnsupportedLookAnd
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
}

/**
* Make sure that theme changes also affect components that are not in the UI tree.
*/
public static void registerThemeUpdate(JComponent... components) {
for (JComponent comp : components) {
UIUpdater.registerComponent(comp);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.objectweb.asm.tree.LdcInsnNode;
import org.objectweb.asm.tree.MethodNode;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.gui.theme.LAFTheme;
import the.bytecode.club.bytecodeviewer.resources.ResourceContainer;
import the.bytecode.club.bytecodeviewer.searching.EnterKeyEvent;
import the.bytecode.club.bytecodeviewer.searching.LDCSearchTreeNodeResult;
Expand Down Expand Up @@ -53,6 +54,7 @@ public LDCSearch()
{
searchText = new JTextField("");
searchText.addKeyListener(EnterKeyEvent.SINGLETON);
LAFTheme.registerThemeUpdate(searchText);
}

@Override
Expand All @@ -63,6 +65,7 @@ public JPanel getPanel()
myPanel = new JPanel(new BorderLayout(16, 16));
myPanel.add(new TranslatedJLabel("Search String: ", TranslatedComponents.SEARCH_STRING), BorderLayout.WEST);
myPanel.add(searchText, BorderLayout.CENTER);
LAFTheme.registerThemeUpdate(myPanel);
}

return myPanel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.ClassNode;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.gui.theme.LAFTheme;
import the.bytecode.club.bytecodeviewer.resources.ResourceContainer;
import the.bytecode.club.bytecodeviewer.searching.EnterKeyEvent;
import the.bytecode.club.bytecodeviewer.searching.LDCSearchTreeNodeResult;
Expand Down Expand Up @@ -46,6 +47,7 @@ public class MemberWithAnnotationSearch implements SearchPanel {
public MemberWithAnnotationSearch() {
annotation = new JTextField("");
annotation.addKeyListener(EnterKeyEvent.SINGLETON);
LAFTheme.registerThemeUpdate(annotation);
}

@Override
Expand All @@ -54,6 +56,7 @@ public JPanel getPanel() {
myPanel = new JPanel(new BorderLayout(16, 16));
myPanel.add(new TranslatedJLabel("Annotation name: ", TranslatedComponents.ANNOTATION_NAME), BorderLayout.WEST);
myPanel.add(annotation, BorderLayout.CENTER);
LAFTheme.registerThemeUpdate(myPanel);
}

return myPanel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.gui.theme.LAFTheme;
import the.bytecode.club.bytecodeviewer.resources.ResourceContainer;
import the.bytecode.club.bytecodeviewer.searching.EnterKeyEvent;
import the.bytecode.club.bytecodeviewer.searching.LDCSearchTreeNodeResult;
Expand Down Expand Up @@ -60,6 +61,7 @@ public MethodCallSearch()
mName.addKeyListener(EnterKeyEvent.SINGLETON);
mDesc = new JTextField("");
mDesc.addKeyListener(EnterKeyEvent.SINGLETON);
LAFTheme.registerThemeUpdate(mOwner, mName, mDesc);
}

public JPanel getPanel()
Expand All @@ -79,6 +81,7 @@ public JPanel getPanel()
right.add(mDesc);
myPanel.add(left, BorderLayout.WEST);
myPanel.add(right, BorderLayout.CENTER);
LAFTheme.registerThemeUpdate(myPanel);
}

return myPanel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.gui.theme.LAFTheme;
import the.bytecode.club.bytecodeviewer.resources.ResourceContainer;
import the.bytecode.club.bytecodeviewer.searching.EnterKeyEvent;
import the.bytecode.club.bytecodeviewer.searching.LDCSearchTreeNodeResult;
Expand Down Expand Up @@ -54,6 +55,7 @@ public RegexSearch()
{
searchText = new JTextField("");
searchText.addKeyListener(EnterKeyEvent.SINGLETON);
LAFTheme.registerThemeUpdate(searchText);
}

@Override
Expand All @@ -64,6 +66,7 @@ public JPanel getPanel()
myPanel = new JPanel(new BorderLayout(16, 16));
myPanel.add(new TranslatedJLabel("Search Regex: ", TranslatedComponents.SEARCH_REGEX), BorderLayout.WEST);
myPanel.add(searchText, BorderLayout.CENTER);
LAFTheme.registerThemeUpdate(myPanel);
}

return myPanel;
Expand Down

0 comments on commit c93d2b5

Please sign in to comment.