Use commons-swing

This commit is contained in:
Lenni0451 2024-01-08 18:47:41 +01:00
parent 3d18dad3c8
commit c7527bb2f8
No known key found for this signature in database
GPG Key ID: 5D59B86635AD3F2F
10 changed files with 48 additions and 252 deletions

View File

@ -87,6 +87,7 @@ dependencies {
include("net.lenni0451:MCPing:1.4.0") {
exclude group: "com.google.code.gson", module: "gson"
}
include "net.lenni0451.commons:swing:1.4.0"
include("net.raphimc.netminecraft:all:2.4.0-SNAPSHOT") {
exclude group: "com.google.code.gson", module: "gson"
}

View File

@ -17,6 +17,7 @@
*/
package net.raphimc.viaproxy.ui.impl;
import net.lenni0451.commons.swing.GBC;
import net.lenni0451.lambdaevents.EventHandler;
import net.raphimc.minecraftauth.step.msa.StepMsaDeviceCode;
import net.raphimc.minecraftauth.util.MicrosoftConstants;
@ -30,7 +31,6 @@ import net.raphimc.viaproxy.ui.I18n;
import net.raphimc.viaproxy.ui.ViaProxyUI;
import net.raphimc.viaproxy.ui.events.UIInitEvent;
import net.raphimc.viaproxy.ui.popups.AddAccountPopup;
import net.raphimc.viaproxy.util.GBC;
import net.raphimc.viaproxy.util.TFunction;
import org.apache.http.impl.client.CloseableHttpClient;
@ -67,7 +67,7 @@ public class AccountsTab extends AUITab {
int gridy = 0;
{
JLabel infoLabel = new JLabel("<html><p>" + I18n.get("tab.accounts.description.line1") + "</p><br><p>" + I18n.get("tab.accounts.description.line2") + "</p></html>");
GBC.create(body).grid(0, gridy++).weightx(1).insets(BORDER_PADDING, BORDER_PADDING, 0, BORDER_PADDING).fill(GridBagConstraints.HORIZONTAL).add(infoLabel);
GBC.create(body).grid(0, gridy++).weightx(1).insets(BORDER_PADDING, BORDER_PADDING, 0, BORDER_PADDING).fill(GBC.HORIZONTAL).add(infoLabel);
}
{
JScrollPane scrollPane = new JScrollPane();
@ -156,7 +156,7 @@ public class AccountsTab extends AUITab {
contextMenu.add(moveDown);
}
this.accountsList.setComponentPopupMenu(contextMenu);
GBC.create(body).grid(0, gridy++).weight(1, 1).insets(BODY_BLOCK_PADDING, BORDER_PADDING, 0, BORDER_PADDING).fill(GridBagConstraints.BOTH).add(scrollPane);
GBC.create(body).grid(0, gridy++).weight(1, 1).insets(BODY_BLOCK_PADDING, BORDER_PADDING, 0, BORDER_PADDING).fill(GBC.BOTH).add(scrollPane);
}
{
final JPanel addButtons = new JPanel();
@ -202,9 +202,9 @@ public class AccountsTab extends AUITab {
JPanel border = new JPanel();
border.setLayout(new GridBagLayout());
border.setBorder(BorderFactory.createTitledBorder(I18n.get("tab.accounts.add.title")));
GBC.create(border).grid(0, 0).weightx(1).insets(2, 4, 4, 4).fill(GridBagConstraints.HORIZONTAL).add(addButtons);
GBC.create(border).grid(0, 0).weightx(1).insets(2, 4, 4, 4).fill(GBC.HORIZONTAL).add(addButtons);
GBC.create(body).grid(0, gridy++).weightx(1).insets(BODY_BLOCK_PADDING, BORDER_PADDING, BORDER_PADDING, BORDER_PADDING).fill(GridBagConstraints.HORIZONTAL).add(border);
GBC.create(body).grid(0, gridy++).weightx(1).insets(BODY_BLOCK_PADDING, BORDER_PADDING, BORDER_PADDING, BORDER_PADDING).fill(GBC.HORIZONTAL).add(border);
}
contentPane.setLayout(new BorderLayout());

View File

@ -20,6 +20,7 @@ package net.raphimc.viaproxy.ui.impl;
import com.viaversion.viaversion.util.DumpUtil;
import gs.mclo.api.MclogsClient;
import gs.mclo.api.response.UploadLogResponse;
import net.lenni0451.commons.swing.GBC;
import net.lenni0451.lambdaevents.EventHandler;
import net.raphimc.viaproxy.ViaProxy;
import net.raphimc.viaproxy.saves.impl.UISave;
@ -28,7 +29,6 @@ import net.raphimc.viaproxy.ui.I18n;
import net.raphimc.viaproxy.ui.ViaProxyUI;
import net.raphimc.viaproxy.ui.events.UICloseEvent;
import net.raphimc.viaproxy.ui.events.UIInitEvent;
import net.raphimc.viaproxy.util.GBC;
import net.raphimc.viaproxy.util.logging.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender;
@ -73,48 +73,48 @@ public class AdvancedTab extends AUITab {
{
JLabel bindPortLabel = new JLabel(I18n.get("tab.advanced.bind_port.label"));
bindPortLabel.setToolTipText(I18n.get("tab.advanced.bind_port.tooltip"));
GBC.create(body).grid(0, gridy++).insets(BORDER_PADDING, BORDER_PADDING, 0, 0).anchor(GridBagConstraints.NORTHWEST).add(bindPortLabel);
GBC.create(body).grid(0, gridy++).insets(BORDER_PADDING, BORDER_PADDING, 0, 0).anchor(GBC.NORTHWEST).add(bindPortLabel);
this.bindPort = new JSpinner(new SpinnerNumberModel(25568, 1, 65535, 1));
this.bindPort.setToolTipText(I18n.get("tab.advanced.bind_port.tooltip"));
ViaProxy.getSaveManager().uiSave.loadSpinner("bind_port", this.bindPort);
GBC.create(body).grid(0, gridy++).weightx(1).insets(0, BORDER_PADDING, 0, BORDER_PADDING).fill(GridBagConstraints.HORIZONTAL).add(this.bindPort);
GBC.create(body).grid(0, gridy++).weightx(1).insets(0, BORDER_PADDING, 0, BORDER_PADDING).fill(GBC.HORIZONTAL).add(this.bindPort);
}
{
JLabel proxyLabel = new JLabel(I18n.get("tab.advanced.proxy_url.label"));
proxyLabel.setToolTipText(I18n.get("tab.advanced.proxy_url.tooltip"));
GBC.create(body).grid(0, gridy++).insets(BODY_BLOCK_PADDING, BORDER_PADDING, 0, 0).anchor(GridBagConstraints.NORTHWEST).add(proxyLabel);
GBC.create(body).grid(0, gridy++).insets(BODY_BLOCK_PADDING, BORDER_PADDING, 0, 0).anchor(GBC.NORTHWEST).add(proxyLabel);
this.proxy = new JTextField();
this.proxy.setToolTipText(I18n.get("tab.advanced.proxy_url.tooltip"));
ViaProxy.getSaveManager().uiSave.loadTextField("proxy", this.proxy);
GBC.create(body).grid(0, gridy++).insets(0, BORDER_PADDING, 0, BORDER_PADDING).fill(GridBagConstraints.HORIZONTAL).add(this.proxy);
GBC.create(body).grid(0, gridy++).insets(0, BORDER_PADDING, 0, BORDER_PADDING).fill(GBC.HORIZONTAL).add(this.proxy);
}
{
this.proxyOnlineMode = new JCheckBox(I18n.get("tab.advanced.proxy_online_mode.label"));
this.proxyOnlineMode.setToolTipText(I18n.get("tab.advanced.proxy_online_mode.tooltip"));
ViaProxy.getSaveManager().uiSave.loadCheckBox("proxy_online_mode", this.proxyOnlineMode);
GBC.create(body).grid(0, gridy++).insets(BODY_BLOCK_PADDING, BORDER_PADDING, 0, 0).anchor(GridBagConstraints.NORTHWEST).add(this.proxyOnlineMode);
GBC.create(body).grid(0, gridy++).insets(BODY_BLOCK_PADDING, BORDER_PADDING, 0, 0).anchor(GBC.NORTHWEST).add(this.proxyOnlineMode);
}
{
this.legacySkinLoading = new JCheckBox(I18n.get("tab.advanced.legacy_skin_loading.label"));
this.legacySkinLoading.setToolTipText(I18n.get("tab.advanced.legacy_skin_loading.tooltip"));
ViaProxy.getSaveManager().uiSave.loadCheckBox("legacy_skin_loading", this.legacySkinLoading);
GBC.create(body).grid(0, gridy++).insets(BODY_BLOCK_PADDING, BORDER_PADDING, 0, 0).anchor(GridBagConstraints.NORTHWEST).add(this.legacySkinLoading);
GBC.create(body).grid(0, gridy++).insets(BODY_BLOCK_PADDING, BORDER_PADDING, 0, 0).anchor(GBC.NORTHWEST).add(this.legacySkinLoading);
}
{
this.chatSigning = new JCheckBox(I18n.get("tab.advanced.chat_signing.label"));
this.chatSigning.setToolTipText(I18n.get("tab.advanced.chat_signing.tooltip"));
this.chatSigning.setSelected(true);
ViaProxy.getSaveManager().uiSave.loadCheckBox("chat_signing", this.chatSigning);
GBC.create(body).grid(0, gridy++).insets(BODY_BLOCK_PADDING, BORDER_PADDING, 0, 0).anchor(GridBagConstraints.NORTHWEST).add(this.chatSigning);
GBC.create(body).grid(0, gridy++).insets(BODY_BLOCK_PADDING, BORDER_PADDING, 0, 0).anchor(GBC.NORTHWEST).add(this.chatSigning);
}
{
this.ignorePacketTranslationErrors = new JCheckBox(I18n.get("tab.advanced.ignore_packet_translation_errors.label"));
this.ignorePacketTranslationErrors.setToolTipText(I18n.get("tab.advanced.ignore_packet_translation_errors.tooltip"));
this.ignorePacketTranslationErrors.setSelected(false);
ViaProxy.getSaveManager().uiSave.loadCheckBox("ignore_packet_translation_errors", this.ignorePacketTranslationErrors);
GBC.create(body).grid(0, gridy++).insets(BODY_BLOCK_PADDING, BORDER_PADDING, 0, 0).anchor(GridBagConstraints.NORTHWEST).add(this.ignorePacketTranslationErrors);
GBC.create(body).grid(0, gridy++).insets(BODY_BLOCK_PADDING, BORDER_PADDING, 0, 0).anchor(GBC.NORTHWEST).add(this.ignorePacketTranslationErrors);
}
parent.add(body, BorderLayout.NORTH);
@ -178,7 +178,7 @@ public class AdvancedTab extends AUITab {
JPanel padding = new JPanel();
padding.setLayout(new GridBagLayout());
GBC.create(padding).grid(0, 0).weightx(1).insets(0, BORDER_PADDING, BORDER_PADDING, BORDER_PADDING).fill(GridBagConstraints.HORIZONTAL).add(footer);
GBC.create(padding).grid(0, 0).weightx(1).insets(0, BORDER_PADDING, BORDER_PADDING, BORDER_PADDING).fill(GBC.HORIZONTAL).add(footer);
container.add(padding, BorderLayout.SOUTH);
}

View File

@ -17,6 +17,7 @@
*/
package net.raphimc.viaproxy.ui.impl;
import net.lenni0451.commons.swing.GBC;
import net.lenni0451.lambdaevents.EventHandler;
import net.raphimc.vialoader.util.VersionEnum;
import net.raphimc.viaproxy.ViaProxy;
@ -29,7 +30,6 @@ import net.raphimc.viaproxy.ui.ViaProxyUI;
import net.raphimc.viaproxy.ui.events.UICloseEvent;
import net.raphimc.viaproxy.ui.events.UIInitEvent;
import net.raphimc.viaproxy.util.AddressUtil;
import net.raphimc.viaproxy.util.GBC;
import net.raphimc.viaproxy.util.logging.Logger;
import javax.swing.*;
@ -83,14 +83,14 @@ public class GeneralTab extends AUITab {
}
});
discord.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
GBC.create(header).grid(0, 0).width(0).insets(BORDER_PADDING, BORDER_PADDING, 0, 0).anchor(GridBagConstraints.NORTHWEST).add(discord);
GBC.create(header).grid(0, 0).width(0).insets(BORDER_PADDING, BORDER_PADDING, 0, 0).anchor(GBC.NORTHWEST).add(discord);
JLabel title = new JLabel("ViaProxy");
title.setFont(title.getFont().deriveFont(30F));
GBC.create(header).grid(1, 0).weightx(1).width(0).insets(BORDER_PADDING, 0, 0, 0).anchor(GridBagConstraints.CENTER).add(title);
GBC.create(header).grid(1, 0).weightx(1).width(0).insets(BORDER_PADDING, 0, 0, 0).anchor(GBC.CENTER).add(title);
JLabel copyright = new JLabel("© RK_01 & Lenni0451");
GBC.create(header).grid(2, 0).width(0).insets(BORDER_PADDING, 0, 0, BORDER_PADDING).anchor(GridBagConstraints.NORTHEAST).add(copyright);
GBC.create(header).grid(2, 0).width(0).insets(BORDER_PADDING, 0, 0, BORDER_PADDING).anchor(GBC.NORTHEAST).add(copyright);
parent.add(header, BorderLayout.NORTH);
}
@ -103,16 +103,16 @@ public class GeneralTab extends AUITab {
{
JLabel serverAddressLabel = new JLabel(I18n.get("tab.general.server_address.label"));
serverAddressLabel.setToolTipText(I18n.get("tab.general.server_address.tooltip"));
GBC.create(body).grid(0, gridy++).insets(BODY_BLOCK_PADDING, BORDER_PADDING, 0, 0).anchor(GridBagConstraints.NORTHWEST).add(serverAddressLabel);
GBC.create(body).grid(0, gridy++).insets(BODY_BLOCK_PADDING, BORDER_PADDING, 0, 0).anchor(GBC.NORTHWEST).add(serverAddressLabel);
this.serverAddress = new JTextField();
this.serverAddress.setToolTipText(I18n.get("tab.general.server_address.tooltip"));
ViaProxy.getSaveManager().uiSave.loadTextField("server_address", this.serverAddress);
GBC.create(body).grid(0, gridy++).weightx(1).insets(0, BORDER_PADDING, 0, BORDER_PADDING).fill(GridBagConstraints.HORIZONTAL).add(this.serverAddress);
GBC.create(body).grid(0, gridy++).weightx(1).insets(0, BORDER_PADDING, 0, BORDER_PADDING).fill(GBC.HORIZONTAL).add(this.serverAddress);
}
{
JLabel serverVersionLabel = new JLabel(I18n.get("tab.general.server_version.label"));
GBC.create(body).grid(0, gridy++).insets(BODY_BLOCK_PADDING, BORDER_PADDING, 0, 0).anchor(GridBagConstraints.NORTHWEST).add(serverVersionLabel);
GBC.create(body).grid(0, gridy++).insets(BODY_BLOCK_PADDING, BORDER_PADDING, 0, 0).anchor(GBC.NORTHWEST).add(serverVersionLabel);
this.serverVersion = new JComboBox<>(VersionEnum.SORTED_VERSIONS.toArray(new VersionEnum[0]));
this.serverVersion.setRenderer(new DefaultListCellRenderer() {
@ -135,21 +135,21 @@ public class GeneralTab extends AUITab {
}
});
ViaProxy.getSaveManager().uiSave.loadComboBoxVersionEnum("server_version", this.serverVersion);
GBC.create(body).grid(0, gridy++).weightx(1).insets(0, BORDER_PADDING, 0, BORDER_PADDING).fill(GridBagConstraints.HORIZONTAL).add(this.serverVersion);
GBC.create(body).grid(0, gridy++).weightx(1).insets(0, BORDER_PADDING, 0, BORDER_PADDING).fill(GBC.HORIZONTAL).add(this.serverVersion);
}
{
JLabel minecraftAccountLabel = new JLabel(I18n.get("tab.general.minecraft_account.label"));
GBC.create(body).grid(0, gridy++).insets(BODY_BLOCK_PADDING, BORDER_PADDING, 0, 0).anchor(GridBagConstraints.NORTHWEST).add(minecraftAccountLabel);
GBC.create(body).grid(0, gridy++).insets(BODY_BLOCK_PADDING, BORDER_PADDING, 0, 0).anchor(GBC.NORTHWEST).add(minecraftAccountLabel);
this.authMethod = new JComboBox<>(new String[]{I18n.get("tab.general.minecraft_account.option_select_account"), I18n.get("tab.general.minecraft_account.option_no_account"), I18n.get("tab.general.minecraft_account.option_openauthmod")});
ViaProxy.getSaveManager().uiSave.loadComboBox("auth_method", this.authMethod);
GBC.create(body).grid(0, gridy++).weightx(1).insets(0, BORDER_PADDING, 0, BORDER_PADDING).fill(GridBagConstraints.HORIZONTAL).add(this.authMethod);
GBC.create(body).grid(0, gridy++).weightx(1).insets(0, BORDER_PADDING, 0, BORDER_PADDING).fill(GBC.HORIZONTAL).add(this.authMethod);
}
{
this.betaCraftAuth = new JCheckBox(I18n.get("tab.general.betacraft_auth.label"));
this.betaCraftAuth.setToolTipText(I18n.get("tab.general.betacraft_auth.tooltip"));
ViaProxy.getSaveManager().uiSave.loadCheckBox("betacraft_auth", this.betaCraftAuth);
GBC.create(body).grid(0, gridy++).insets(BODY_BLOCK_PADDING, BORDER_PADDING, 0, 0).anchor(GridBagConstraints.NORTHWEST).add(this.betaCraftAuth);
GBC.create(body).grid(0, gridy++).insets(BODY_BLOCK_PADDING, BORDER_PADDING, 0, 0).anchor(GBC.NORTHWEST).add(this.betaCraftAuth);
// Simulate user action on serverVersion to update betaCraftAuth
final ActionEvent fakeAction = new ActionEvent(this.serverVersion, ActionEvent.ACTION_PERFORMED, "");
for (ActionListener listener : this.serverVersion.getActionListeners()) {
@ -166,7 +166,7 @@ public class GeneralTab extends AUITab {
this.stateLabel = new JLabel("");
this.stateLabel.setVisible(false);
GBC.create(footer).grid(0, 0).weightx(1).insets(0, BORDER_PADDING, 0, BORDER_PADDING).anchor(GridBagConstraints.WEST).fill(GridBagConstraints.HORIZONTAL).add(this.stateLabel);
GBC.create(footer).grid(0, 0).weightx(1).insets(0, BORDER_PADDING, 0, BORDER_PADDING).anchor(GBC.WEST).fill(GBC.HORIZONTAL).add(this.stateLabel);
this.stateButton = new JButton(I18n.get("tab.general.state.loading"));
this.stateButton.addActionListener(event -> {
@ -174,7 +174,7 @@ public class GeneralTab extends AUITab {
else if (this.stateButton.getText().equalsIgnoreCase(I18n.get("tab.general.state.stop"))) this.stop();
});
this.stateButton.setEnabled(false);
GBC.create(footer).grid(0, 1).weightx(1).insets(0, BORDER_PADDING, BORDER_PADDING, BORDER_PADDING).anchor(GridBagConstraints.WEST).fill(GridBagConstraints.HORIZONTAL).add(this.stateButton);
GBC.create(footer).grid(0, 1).weightx(1).insets(0, BORDER_PADDING, BORDER_PADDING, BORDER_PADDING).anchor(GBC.WEST).fill(GBC.HORIZONTAL).add(this.stateButton);
parent.add(footer, BorderLayout.SOUTH);
}

View File

@ -18,6 +18,8 @@
package net.raphimc.viaproxy.ui.impl;
import com.google.common.collect.Iterables;
import net.lenni0451.commons.swing.GBC;
import net.lenni0451.commons.swing.layouts.VerticalLayout;
import net.raphimc.minecraftauth.responsehandler.exception.RealmsResponseException;
import net.raphimc.minecraftauth.service.realms.AbstractRealmsService;
import net.raphimc.minecraftauth.service.realms.BedrockRealmsService;
@ -34,8 +36,6 @@ import net.raphimc.viaproxy.saves.impl.accounts.MicrosoftAccount;
import net.raphimc.viaproxy.ui.AUITab;
import net.raphimc.viaproxy.ui.I18n;
import net.raphimc.viaproxy.ui.ViaProxyUI;
import net.raphimc.viaproxy.util.GBC;
import net.raphimc.viaproxy.util.PaddedVerticalLayout;
import net.raphimc.viaproxy.util.logging.Logger;
import org.apache.http.impl.client.CloseableHttpClient;
@ -139,7 +139,7 @@ public class RealmsTab extends AUITab {
body.remove(statusLabel);
this.addHeader(body, realmsService instanceof JavaRealmsService);
final JPanel realmsPanel = new JPanel();
realmsPanel.setLayout(new PaddedVerticalLayout(5, 5));
realmsPanel.setLayout(new VerticalLayout(5, 5));
if (worlds.isEmpty()) {
JLabel label = new JLabel(I18n.get("tab.realms.no_worlds"));
label.setHorizontalAlignment(SwingConstants.CENTER);
@ -173,7 +173,7 @@ public class RealmsTab extends AUITab {
}
private void addHeader(final JPanel parent, final boolean showType) {
GBC.create(parent).grid(0, 0).weightx(1).insets(5, 5, 5, 5).fill(GridBagConstraints.HORIZONTAL).add(new JLabel(I18n.get("tab.realms.account", this.currentAccount.getDisplayString())));
GBC.create(parent).grid(0, 0).weightx(1).insets(5, 5, 5, 5).fill(GBC.HORIZONTAL).add(new JLabel(I18n.get("tab.realms.account", this.currentAccount.getDisplayString())));
if (showType && LATEST_JAVA_SNAPSHOT != null) {
JComboBox<String> type = new JComboBox<>();
type.addItem(I18n.get("tab.realms.release"));
@ -186,7 +186,7 @@ public class RealmsTab extends AUITab {
this.reinit();
}
});
GBC.create(parent).grid(1, 0).insets(5, 0, 5, 5).anchor(GridBagConstraints.LINE_END).add(type);
GBC.create(parent).grid(1, 0).insets(5, 0, 5, 5).anchor(GBC.LINE_END).add(type);
}
}
@ -207,9 +207,9 @@ public class RealmsTab extends AUITab {
if (!world.getOwnerName().isEmpty()) nameString += world.getOwnerName() + " - ";
String versionString = "";
if (!world.getActiveVersion().isEmpty()) versionString += " - " + world.getActiveVersion();
GBC.create(panel).grid(0, 0).weightx(1).insets(5, 5, 0, 5).fill(GridBagConstraints.HORIZONTAL).add(new JLabel(nameString + world.getName() + " (" + world.getState() + ")"));
GBC.create(panel).grid(1, 0).insets(5, 5, 0, 5).anchor(GridBagConstraints.LINE_END).add(new JLabel(world.getWorldType() + versionString));
GBC.create(panel).grid(0, 1).insets(5, 5, 0, 5).fill(GridBagConstraints.HORIZONTAL).add(new JLabel(world.getMotd()));
GBC.create(panel).grid(0, 0).weightx(1).insets(5, 5, 0, 5).fill(GBC.HORIZONTAL).add(new JLabel(nameString + world.getName() + " (" + world.getState() + ")"));
GBC.create(panel).grid(1, 0).insets(5, 5, 0, 5).anchor(GBC.LINE_END).add(new JLabel(world.getWorldType() + versionString));
GBC.create(panel).grid(0, 1).insets(5, 5, 0, 5).fill(GBC.HORIZONTAL).add(new JLabel(world.getMotd()));
final JButton join = new JButton(I18n.get("tab.realms.join"));
if (world.isExpired()) {
join.setEnabled(false);
@ -218,7 +218,7 @@ public class RealmsTab extends AUITab {
join.setEnabled(false);
join.setToolTipText(I18n.get("tab.realms.incompatible"));
}
GBC.create(panel).grid(1, 1).insets(5, 0, 5, 5).anchor(GridBagConstraints.LINE_END).add(join);
GBC.create(panel).grid(1, 1).insets(5, 0, 5, 5).anchor(GBC.LINE_END).add(join);
join.addActionListener(event -> {
join.setEnabled(false);
join.setText(I18n.get("tab.realms.joining"));

View File

@ -17,11 +17,11 @@
*/
package net.raphimc.viaproxy.ui.impl;
import net.lenni0451.commons.swing.GBC;
import net.raphimc.viaproxy.ViaProxy;
import net.raphimc.viaproxy.ui.AUITab;
import net.raphimc.viaproxy.ui.I18n;
import net.raphimc.viaproxy.ui.ViaProxyUI;
import net.raphimc.viaproxy.util.GBC;
import net.raphimc.viaproxy.util.logging.Logger;
import javax.swing.*;
@ -46,7 +46,7 @@ public class UISettingsTab extends AUITab {
int gridy = 0;
{
JLabel languageLabel = new JLabel(I18n.get("tab.ui_settings.language.label"));
GBC.create(body).grid(0, gridy++).insets(BORDER_PADDING, BORDER_PADDING, 0, BORDER_PADDING).anchor(GridBagConstraints.NORTHWEST).add(languageLabel);
GBC.create(body).grid(0, gridy++).insets(BORDER_PADDING, BORDER_PADDING, 0, BORDER_PADDING).anchor(GBC.NORTHWEST).add(languageLabel);
JComboBox<String> language = new JComboBox<>(I18n.getAvailableLocales().toArray(new String[0]));
language.setRenderer(new DefaultListCellRenderer() {
@ -74,7 +74,7 @@ public class UISettingsTab extends AUITab {
System.exit(1);
}
});
GBC.create(body).grid(0, gridy++).weightx(1).insets(0, BORDER_PADDING, 0, BORDER_PADDING).fill(GridBagConstraints.HORIZONTAL).add(language);
GBC.create(body).grid(0, gridy++).weightx(1).insets(0, BORDER_PADDING, 0, BORDER_PADDING).fill(GBC.HORIZONTAL).add(language);
}
contentPane.setLayout(new BorderLayout());

View File

@ -17,10 +17,10 @@
*/
package net.raphimc.viaproxy.ui.popups;
import net.lenni0451.commons.swing.GBC;
import net.raphimc.minecraftauth.step.msa.StepMsaDeviceCode;
import net.raphimc.viaproxy.ui.I18n;
import net.raphimc.viaproxy.ui.ViaProxyUI;
import net.raphimc.viaproxy.util.GBC;
import javax.swing.*;
import java.awt.*;
@ -70,7 +70,7 @@ public class AddAccountPopup extends JDialog {
contentPane.setLayout(new GridBagLayout());
{
JLabel browserLabel = new JLabel("<html><p>" + I18n.get("popup.login_account.instructions.browser") + "</p></html>");
GBC.create(contentPane).grid(0, 0).weightx(1).insets(BORDER_PADDING, BORDER_PADDING, 0, BORDER_PADDING).fill(GridBagConstraints.HORIZONTAL).add(browserLabel);
GBC.create(contentPane).grid(0, 0).weightx(1).insets(BORDER_PADDING, BORDER_PADDING, 0, BORDER_PADDING).fill(GBC.HORIZONTAL).add(browserLabel);
JLabel urlLabel = new JLabel("<html><a href=\"\">" + this.deviceCode.getDirectVerificationUri() + "</a></html>");
urlLabel.addMouseListener(new MouseAdapter() {
@ -79,10 +79,10 @@ public class AddAccountPopup extends JDialog {
AddAccountPopup.this.parent.openURL(AddAccountPopup.this.deviceCode.getDirectVerificationUri());
}
});
GBC.create(contentPane).grid(0, 1).weightx(1).insets(0, BORDER_PADDING, 0, BORDER_PADDING).fill(GridBagConstraints.HORIZONTAL).add(urlLabel);
GBC.create(contentPane).grid(0, 1).weightx(1).insets(0, BORDER_PADDING, 0, BORDER_PADDING).fill(GBC.HORIZONTAL).add(urlLabel);
JLabel closeInfo = new JLabel("<html><p>" + I18n.get("popup.login_account.instructions.close") + "</p></html>");
GBC.create(contentPane).grid(0, 2).weightx(1).insets(BODY_BLOCK_PADDING, BORDER_PADDING, BORDER_PADDING, BORDER_PADDING).fill(GridBagConstraints.HORIZONTAL).add(closeInfo);
GBC.create(contentPane).grid(0, 2).weightx(1).insets(BODY_BLOCK_PADDING, BORDER_PADDING, BORDER_PADDING, BORDER_PADDING).fill(GBC.HORIZONTAL).add(closeInfo);
}
this.setContentPane(contentPane);
}

View File

@ -17,10 +17,10 @@
*/
package net.raphimc.viaproxy.ui.popups;
import net.lenni0451.commons.swing.GBC;
import net.raphimc.viaproxy.ViaProxy;
import net.raphimc.viaproxy.ui.I18n;
import net.raphimc.viaproxy.ui.ViaProxyUI;
import net.raphimc.viaproxy.util.GBC;
import javax.swing.*;
import java.awt.*;
@ -81,12 +81,12 @@ public class DownloadPopup extends JDialog {
{
this.progressBar = new JProgressBar();
this.progressBar.setStringPainted(true);
GBC.create(contentPane).grid(0, 0).weightx(1).insets(BORDER_PADDING, BORDER_PADDING, 0, BORDER_PADDING).fill(GridBagConstraints.HORIZONTAL).add(this.progressBar);
GBC.create(contentPane).grid(0, 0).weightx(1).insets(BORDER_PADDING, BORDER_PADDING, 0, BORDER_PADDING).fill(GBC.HORIZONTAL).add(this.progressBar);
}
{
JButton cancelButton = new JButton(I18n.get("generic.cancel"));
cancelButton.addActionListener(event -> this.close(false));
GBC.create(contentPane).grid(0, 1).weightx(1).insets(BORDER_PADDING, BORDER_PADDING, BORDER_PADDING, BORDER_PADDING).fill(GridBagConstraints.HORIZONTAL).add(cancelButton);
GBC.create(contentPane).grid(0, 1).weightx(1).insets(BORDER_PADDING, BORDER_PADDING, BORDER_PADDING, BORDER_PADDING).fill(GBC.HORIZONTAL).add(cancelButton);
}
this.setContentPane(contentPane);
this.start();

View File

@ -1,121 +0,0 @@
/*
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
* Copyright (C) 2021-2024 RK_01/RaphiMC and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.raphimc.viaproxy.util;
import java.awt.*;
public class GBC {
public static GBC create() {
return new GBC(null);
}
public static GBC create(final Container parent) {
return new GBC(parent);
}
private final Container parent;
private final GridBagConstraints gbc;
private GBC(final Container parent) {
this.parent = parent;
this.gbc = new GridBagConstraints();
}
public GBC gridx(final int gridx) {
this.gbc.gridx = gridx;
return this;
}
public GBC gridy(final int gridy) {
this.gbc.gridy = gridy;
return this;
}
public GBC grid(final int gridx, final int gridy) {
this.gbc.gridx = gridx;
this.gbc.gridy = gridy;
return this;
}
public GBC width(final int gridwidth) {
this.gbc.gridwidth = gridwidth;
return this;
}
public GBC height(final int gridheight) {
this.gbc.gridheight = gridheight;
return this;
}
public GBC weightx(final double weightx) {
this.gbc.weightx = weightx;
return this;
}
public GBC weighty(final double weighty) {
this.gbc.weighty = weighty;
return this;
}
public GBC weight(final double weightx, final double weighty) {
this.gbc.weightx = weightx;
this.gbc.weighty = weighty;
return this;
}
public GBC anchor(final int anchor) {
this.gbc.anchor = anchor;
return this;
}
public GBC fill(final int fill) {
this.gbc.fill = fill;
return this;
}
public GBC insets(final Insets insets) {
this.gbc.insets = insets;
return this;
}
public GBC insets(final int top, final int left, final int bottom, final int right) {
this.gbc.insets = new Insets(top, left, bottom, right);
return this;
}
public GBC ipadx(final int ipadx) {
this.gbc.ipadx = ipadx;
return this;
}
public GBC ipady(final int ipady) {
this.gbc.ipady = ipady;
return this;
}
public void add(final Component component) {
this.parent.add(component, this.gbc);
}
public GridBagConstraints get() {
return this.gbc;
}
}

View File

@ -1,84 +0,0 @@
/*
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
* Copyright (C) 2021-2024 RK_01/RaphiMC and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.raphimc.viaproxy.util;
import java.awt.*;
public class PaddedVerticalLayout implements LayoutManager {
private final int gap;
private final int padding;
public PaddedVerticalLayout() {
this(0, 0);
}
public PaddedVerticalLayout(final int padding, final int gap) {
this.padding = padding;
this.gap = gap;
}
@Override
public void addLayoutComponent(String name, Component c) {
}
@Override
public void layoutContainer(Container parent) {
Insets insets = parent.getInsets();
Dimension size = parent.getSize();
int width = size.width - insets.left - insets.right;
int height = insets.top + this.padding;
for (int i = 0, c = parent.getComponentCount(); i < c; i++) {
Component m = parent.getComponent(i);
if (m.isVisible()) {
m.setBounds(insets.left + this.padding, height, width - this.padding * 2, m.getPreferredSize().height);
height += m.getSize().height + gap;
}
}
}
@Override
public Dimension minimumLayoutSize(Container parent) {
return this.preferredLayoutSize(parent);
}
@Override
public Dimension preferredLayoutSize(Container parent) {
Insets insets = parent.getInsets();
Dimension pref = new Dimension(0, 0);
for (int i = 0, c = parent.getComponentCount(); i < c; i++) {
Component m = parent.getComponent(i);
if (m.isVisible()) {
Dimension componentPreferredSize = parent.getComponent(i).getPreferredSize();
pref.height += componentPreferredSize.height + gap;
pref.width = Math.max(pref.width, componentPreferredSize.width);
}
}
pref.width += insets.left + insets.right;
pref.height += insets.top + insets.bottom;
return pref;
}
@Override
public void removeLayoutComponent(Component c) {
}
}