1 package com.jsql.view.swing.panel;
2
3 import com.jsql.util.I18nUtil;
4 import com.jsql.view.swing.panel.preferences.*;
5 import com.jsql.view.swing.panel.preferences.listener.ActionListenerSave;
6 import com.jsql.view.swing.util.MediatorHelper;
7 import com.jsql.view.swing.util.UiUtil;
8 import org.apache.commons.text.WordUtils;
9
10 import javax.swing.*;
11 import java.awt.*;
12 import java.awt.event.ActionListener;
13 import java.util.Arrays;
14
15 public class PanelPreferences extends JPanel {
16
17 private final transient ActionListener actionListenerSave = new ActionListenerSave(this);
18
19 private final PanelConnection panelConnection = new PanelConnection(this);
20 private final PanelStrategies panelStrategies = new PanelStrategies(this);
21 private final PanelInjection panelInjection = new PanelInjection(this);
22 private final PanelTampering panelTampering = new PanelTampering(this);
23 private final PanelUserAgent panelUserAgent = new PanelUserAgent(this);
24 private final PanelAuthentication panelAuthentication = new PanelAuthentication(this);
25 private final PanelProxy panelProxy = new PanelProxy(this);
26 private final PanelGeneral panelGeneral = new PanelGeneral(this);
27
28 private enum CategoryPreference {
29 CONNECTION,
30 STRATEGIES,
31 INJECTION,
32 TAMPERING,
33 EXPLOIT,
34 USER_AGENT,
35 AUTHENTICATION,
36 PROXY,
37 GENERAL;
38
39 @Override
40 public String toString() {
41 return " "+ WordUtils.capitalizeFully(this.name()).replace('_', ' ') +" ";
42 }
43 }
44
45 public PanelPreferences() {
46 this.setLayout(new BorderLayout());
47 this.setBorder(UiUtil.BORDER_5PX);
48
49 var cards = new JPanel(new CardLayout());
50 cards.setMinimumSize(new Dimension(0, 0));
51
52 JList<CategoryPreference> categories = PanelPreferences.getCategories(cards);
53 this.add(categories, BorderLayout.LINE_START);
54
55 this.addToCard(cards, this.panelConnection, CategoryPreference.CONNECTION);
56 this.addToCard(cards, this.panelStrategies, CategoryPreference.STRATEGIES);
57 this.addToCard(cards, this.panelInjection, CategoryPreference.INJECTION);
58 this.addToCard(cards, this.panelTampering, CategoryPreference.TAMPERING);
59 this.addToCard(cards, new PanelExploit(), CategoryPreference.EXPLOIT);
60 this.addToCard(cards, this.panelUserAgent, CategoryPreference.USER_AGENT);
61 this.addToCard(cards, this.panelAuthentication, CategoryPreference.AUTHENTICATION);
62 this.addToCard(cards, this.panelProxy, CategoryPreference.PROXY);
63 this.addToCard(cards, this.panelGeneral, CategoryPreference.GENERAL);
64 this.add(cards, BorderLayout.CENTER);
65
66 SwingUtilities.invokeLater(() -> MediatorHelper.menubar().switchLocale(I18nUtil.getCurrentLocale()));
67 }
68
69 private static JList<CategoryPreference> getCategories(JPanel cards) {
70 JList<CategoryPreference> categories = new JList<>(CategoryPreference.values());
71 categories.setMinimumSize(new Dimension(0, 0));
72 categories.setName("listCategoriesPreference");
73 categories.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
74 categories.setSelectedIndex(0);
75 categories.addListSelectionListener(e -> {
76 CardLayout cardLayout = (CardLayout) cards.getLayout();
77 cardLayout.show(cards, categories.getSelectedValue().name());
78 });
79 return categories;
80 }
81
82 private void addToCard(JPanel cards, JPanel panel, CategoryPreference category) {
83 panel.setBorder(BorderFactory.createEmptyBorder(10, 15, 10, 15));
84 if (Arrays.asList(CategoryPreference.USER_AGENT, CategoryPreference.EXPLOIT).contains(category)) {
85 cards.add(panel, category.name());
86 } else {
87 var scrollPane = new JScrollPane(panel);
88 scrollPane.setBorder(BorderFactory.createEmptyBorder());
89 scrollPane.getVerticalScrollBar().setUnitIncrement(16);
90 scrollPane.getHorizontalScrollBar().setUnitIncrement(16);
91 cards.add(scrollPane, category.name());
92 }
93 }
94
95
96
97
98 public PanelAuthentication getPanelAuthentication() {
99 return this.panelAuthentication;
100 }
101
102 public PanelProxy getPanelProxy() {
103 return this.panelProxy;
104 }
105
106 public PanelInjection getPanelInjection() {
107 return this.panelInjection;
108 }
109
110 public PanelTampering getPanelTampering() {
111 return this.panelTampering;
112 }
113
114 public PanelGeneral getPanelGeneral() {
115 return this.panelGeneral;
116 }
117
118 public PanelConnection getPanelConnection() {
119 return this.panelConnection;
120 }
121
122 public PanelStrategies getPanelStrategies() {
123 return this.panelStrategies;
124 }
125
126 public PanelUserAgent getPanelUserAgent() {
127 return this.panelUserAgent;
128 }
129
130 public ActionListener getActionListenerSave() {
131 return this.actionListenerSave;
132 }
133 }