forked from aress31/burpgpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
383 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 © %s - %s Alexandre Teyar, Aegis Cyber <<a href=\"https://aegiscyber.co.uk\">www.aegiscyber.co.uk</a>>. 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; | ||
} | ||
} |
Oops, something went wrong.