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