Skip to content

Commit

Permalink
ui overhaul
Browse files Browse the repository at this point in the history
  • Loading branch information
aress31 committed Apr 10, 2023
1 parent b1578d9 commit 9e06ae3
Show file tree
Hide file tree
Showing 9 changed files with 383 additions and 144 deletions.
7 changes: 6 additions & 1 deletion lib/src/main/java/burp/MyBurpExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@

public class MyBurpExtension implements BurpExtension, PropertyChangeListener {

public static final Boolean DEBUG = false;

public static final String EXTENSION = "BurpGPT";
public static final Boolean DEBUG = true;
public static final String VERSION = "0.1";

private PropertyChangeSupport propertyChangeSupport;
@Getter
Logging logging;
@Getter
MontoyaApi montoyaApi;

@Getter
private String apiKey = "PLEASE_CHANGE_ME_OR_YOU_WILL_MAKE_THE_DEVELOPER_SAD";
Expand All @@ -46,6 +50,7 @@ public class MyBurpExtension implements BurpExtension, PropertyChangeListener {

@Override
public void initialize(MontoyaApi montoyaApi) {
this.montoyaApi = montoyaApi;
this.logging = montoyaApi.logging();
this.propertyChangeSupport = new PropertyChangeSupport(this);

Expand Down
100 changes: 0 additions & 100 deletions lib/src/main/java/burp/MyContextMenuItemsProvider.java

This file was deleted.

115 changes: 115 additions & 0 deletions lib/src/main/java/burpgpt/gui/ControllerDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package burpgpt.gui;

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Dimension;
import java.util.HashMap;
import java.util.Map;

import javax.swing.JDialog;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;

import burp.MyBurpExtension;
import burpgpt.gui.views.AboutView;
import burpgpt.gui.views.PlaceholdersView;
import burpgpt.gui.views.SettingsView;

public class ControllerDialog extends JDialog {

private final MyBurpExtension myBurpExtension;

private JList<String> listView;

private final SettingsView settingsView;
private final PlaceholdersView placeholdersView;
private final AboutView aboutView;

private Map<String, JPanel> viewMap = new HashMap<>();

public ControllerDialog(MyBurpExtension myBurpExtension) {
this.myBurpExtension = myBurpExtension;

settingsView = new SettingsView(myBurpExtension);
placeholdersView = new PlaceholdersView();
aboutView = new AboutView();

setupDialog();
initComponents();
registerApplyButtonListener();

myBurpExtension.getMontoyaApi().userInterface().applyThemeToComponent(this);

pack();
setLocationRelativeTo(myBurpExtension.getMontoyaApi().userInterface().swingUtils().suiteFrame());
}

private void setupDialog() {
setTitle(String.format("%s OpenAI API", MyBurpExtension.EXTENSION));
setLayout(new BorderLayout());
setResizable(false);
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
// setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
}

private void initComponents() {
listView = createListView();

JPanel listPanel = new JPanel(new BorderLayout());
listPanel.setPreferredSize(new Dimension(150, 0));
listPanel.add(new JScrollPane(listView), BorderLayout.CENTER);

add(listPanel, BorderLayout.WEST);

viewMap.put("OpenAI API", settingsView);
viewMap.put("Placeholder reference", placeholdersView);
viewMap.put("About", aboutView);

JPanel cardsPanel = new JPanel(new CardLayout());
for (JPanel view : viewMap.values()) {
view.setPreferredSize(settingsView.getPreferredSize());
cardsPanel.add(view, view.getClass().getName());
}
add(cardsPanel, BorderLayout.CENTER);

setDefaultView("OpenAI API");
}

private void registerApplyButtonListener() {
settingsView.setOnApplyButtonClickListener(() -> {
setVisible(false);
});
}

private void setDefaultView(String viewName) {
listView.setSelectedValue(viewName, true);
}

private JList<String> createListView() {
String[] listData = { "OpenAI API", "Placeholder reference", "About" };
JList<String> listView = new JList<>(listData);
listView.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

listView.addListSelectionListener(e -> {
if (!e.getValueIsAdjusting()) {
String selectedValue = listView.getSelectedValue();
updateView(selectedValue);
}
});

return listView;
}

private void updateView(String selectedValue) {
JPanel selectedPanel = viewMap.get(selectedValue);
if (selectedPanel != null) {
CardLayout cardLayout = (CardLayout) (((JPanel) getContentPane().getComponent(1)).getLayout());
cardLayout.show((JPanel) getContentPane().getComponent(1), selectedPanel.getClass().getName());
} else {
// Handle the case when the selected value is not found in the viewMap
System.err.println("View not found: " + selectedValue);
}
}
}
2 changes: 1 addition & 1 deletion lib/src/main/java/burpgpt/gui/MyMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class MyMenu {

public static Menu createMenu(MyBurpExtension myBurpExtension) {
BasicMenuItem basicMenuItem = BasicMenuItem.basicMenuItem("Settings").withAction(() -> {
SettingsPanel settingsPanel = new SettingsPanel(myBurpExtension);
ControllerDialog settingsPanel = new ControllerDialog(myBurpExtension);
settingsPanel.setVisible(true);
});
Menu menu = Menu.menu(MyBurpExtension.EXTENSION).withMenuItems(basicMenuItem);
Expand Down
70 changes: 70 additions & 0 deletions lib/src/main/java/burpgpt/gui/views/AboutView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package burpgpt.gui.views;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.text.MessageFormat;
import java.util.Calendar;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;

import burp.MyBurpExtension;
import burpgpt.utilities.HtmlResourceLoader;

public class AboutView extends JPanel {

private static final int COPYRIGHT_FONT_SIZE = 12;

public AboutView() {
setLayout(new BorderLayout());
setBorder(BorderFactory.createEmptyBorder(16, 16, 16, 16)); // add 16-pixel padding to the root panel
add(initComponents(), BorderLayout.WEST);
}

private JPanel initComponents() {
JPanel contentPanel = new JPanel();
contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.PAGE_AXIS));

contentPanel.add(createTitleLabel());
contentPanel.add(createCopyRightLabel());
contentPanel.add(Box.createRigidArea(new Dimension(0, 16)));
contentPanel.add(createDescriptionLabel());

return contentPanel;
}

private JLabel createTitleLabel() {
String title = String.format("<html><h1>%s v%s</h1></html>", MyBurpExtension.EXTENSION,
MyBurpExtension.VERSION);
JLabel titleLabel = new JLabel(title);
titleLabel.putClientProperty("html.disable", null);
return titleLabel;
}

private JLabel createDescriptionLabel() {
String description = HtmlResourceLoader.loadHtmlContent("aboutDescription.html");
String formattedDescription = MessageFormat.format(description, MyBurpExtension.EXTENSION);
// HACK: Need to get the width programatically
JLabel descriptionLabel = new JLabel("<html><div id='descriptionDiv' style='width: 800px;'>"
+ formattedDescription + "</div></html>");
descriptionLabel.putClientProperty("html.disable", null);
return descriptionLabel;
}

private JLabel createCopyRightLabel() {
String year = String.valueOf(Calendar.getInstance().get(Calendar.YEAR));
String copyRight = String.format(
"<html>Copyright &copy; %s - %s Alexandre Teyar, Aegis Cyber &lt;<a href=\"https://aegiscyber.co.uk\">www.aegiscyber.co.uk</a>&gt;. All Rights Reserved.</html>",
year, year);
JLabel copyRightLabel = new JLabel(copyRight);
copyRightLabel.setFont(new Font(copyRightLabel.getFont().getName(), Font.PLAIN, COPYRIGHT_FONT_SIZE));
copyRightLabel.setForeground(Color.GRAY);
copyRightLabel.putClientProperty("html.disable", null);
return copyRightLabel;
}
}
Loading

0 comments on commit 9e06ae3

Please sign in to comment.