Merge pull request #415 from GraxCode/gui_fixes

Small UI fixes.
This commit is contained in:
Konloch 2022-04-20 13:04:14 -07:00 committed by GitHub
commit c93d2b58d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 53 additions and 36 deletions

View File

@ -32,13 +32,15 @@ import javax.swing.plaf.basic.BasicButtonUI;
/**
* @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;
@ -62,12 +64,12 @@ public class TabExitButton extends JButton implements ActionListener
// Close the proper tab by clicking the button
addActionListener(this);
}
public int getTabIndex()
{
return tabIndex;
}
@Override
public void actionPerformed(final ActionEvent e)
{
@ -77,11 +79,11 @@ public class TabExitButton extends JButton implements ActionListener
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)
@ -91,33 +93,33 @@ public class TabExitButton extends JButton implements ActionListener
// 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;
}

View File

@ -4,7 +4,6 @@ import java.awt.Color;
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;
@ -16,6 +15,8 @@ import javax.swing.JPanel;
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;
@ -84,7 +85,7 @@ public class TabbedPane extends JPanel
// 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));
@ -101,34 +102,24 @@ public class TabbedPane extends JPanel
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);
@ -257,5 +248,8 @@ public class TabbedPane extends JPanel
}
private static final long serialVersionUID = -4774885688297538774L;
public int getTabIndex() {
return tabs.indexOfTabComponent(this);
}
}

View File

@ -1,6 +1,7 @@
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;
@ -8,11 +9,10 @@ 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;
@ -175,4 +175,13 @@ public enum LAFTheme
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);
}
}
}

View File

@ -11,6 +11,7 @@ import org.objectweb.asm.tree.InsnList;
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;
@ -53,6 +54,7 @@ public class LDCSearch implements SearchPanel
{
searchText = new JTextField("");
searchText.addKeyListener(EnterKeyEvent.SINGLETON);
LAFTheme.registerThemeUpdate(searchText);
}
@Override
@ -63,6 +65,7 @@ public class LDCSearch implements SearchPanel
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;

View File

@ -4,6 +4,7 @@ import org.objectweb.asm.Type;
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;
@ -46,6 +47,7 @@ public class MemberWithAnnotationSearch implements SearchPanel {
public MemberWithAnnotationSearch() {
annotation = new JTextField("");
annotation.addKeyListener(EnterKeyEvent.SINGLETON);
LAFTheme.registerThemeUpdate(annotation);
}
@Override
@ -54,6 +56,7 @@ public class MemberWithAnnotationSearch implements SearchPanel {
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;

View File

@ -12,6 +12,7 @@ import org.objectweb.asm.tree.InsnList;
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;
@ -60,6 +61,7 @@ public class MethodCallSearch implements SearchPanel
mName.addKeyListener(EnterKeyEvent.SINGLETON);
mDesc = new JTextField("");
mDesc.addKeyListener(EnterKeyEvent.SINGLETON);
LAFTheme.registerThemeUpdate(mOwner, mName, mDesc);
}
public JPanel getPanel()
@ -79,6 +81,7 @@ public class MethodCallSearch implements SearchPanel
right.add(mDesc);
myPanel.add(left, BorderLayout.WEST);
myPanel.add(right, BorderLayout.CENTER);
LAFTheme.registerThemeUpdate(myPanel);
}
return myPanel;

View File

@ -9,6 +9,7 @@ import org.objectweb.asm.Type;
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;
@ -54,6 +55,7 @@ public class RegexSearch implements SearchPanel
{
searchText = new JTextField("");
searchText.addKeyListener(EnterKeyEvent.SINGLETON);
LAFTheme.registerThemeUpdate(searchText);
}
@Override
@ -64,6 +66,7 @@ public class RegexSearch implements SearchPanel
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;