diff --git a/src/main/java/gui/src/panels/ConnectToServerPanel.java b/src/main/java/gui/src/panels/ConnectToServerPanel.java new file mode 100644 index 0000000..bf920a1 --- /dev/null +++ b/src/main/java/gui/src/panels/ConnectToServerPanel.java @@ -0,0 +1,119 @@ +/** + * @author Aaron Moser + * @date 02.12.2023 + */ +package gui.src.panels; + +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; + +import javax.swing.JPanel; +import javax.swing.JRadioButton; + +import gui.src.constants.GUIConstants.Languages; +import gui.src.constants.GUIConstants.Theme; +import gui.src.interfaces.Themeable; +import gui.src.interfaces.Translateable; + +public final class ConnectToServerPanel extends JPanel implements Themeable, Translateable { + private static ConnectToServerPanel instance; + + private JRadioButton[] ipVersionRadioButtons; + + private final String[] translationsDE = { + "Verbinden Sie sich mit dem Server", + "IPv4", + "IPv6" + }; + private final String[] translationsEN = { + "Connect to server", + "IPv4", + "IPv6" + }; + + public static ConnectToServerPanel getInstance() { + if (null == instance) { + instance = new ConnectToServerPanel(); + } + return instance; + } + + private ConnectToServerPanel() { + this.build(); + } + + /** + * Builds ConnectToServerPanel by setting the layout, creating + * interactable elements, setting their language and theme. + */ + private void build() { + this.setLayout(new GridBagLayout()); + GridBagConstraints gridBagConstraints = new GridBagConstraints(); + + this.buildIPVersionRadioButtons(); + this.changeLanguage(Languages.German); + } + + private void buildIPVersionRadioButtons() { + this.ipVersionRadioButtons = new JRadioButton[2]; + + this.ipVersionRadioButtons[0] = new JRadioButton(); + this.ipVersionRadioButtons[1] = new JRadioButton(); + } + + public void setThemeColor(Theme themeColor) { + try { + switch (themeColor) { + case Dark: { + + }break; + case Light: { + + }break; + default: { + throw new Exception("Unknown kind of theme color."); + } + } + } catch (Exception e) { + System.err.println(e.getMessage()); + this.setThemeColor(Theme.Light); + } + } + + /** + * Changes text of panel elements. + * Panel elements are: descriptive text, ip version radio buttons, + * ip address field descriptive text, port field descriptive text, + * connect button text. + * @param language the language the elements to set to. + */ + public void changeLanguage(Languages language) { + changeLanguageIPVersionRadioButtons(language); + } + + /** + * Changes translation of radio buttons for selection of ip-version. + * Prints an error message if the language is unknown. + * @param language the language the elements to set to. + */ + private void changeLanguageIPVersionRadioButtons(Languages language) { + try { + switch (language) { + case German: { + ipVersionRadioButtons[0].setText(translationsDE[1]); + ipVersionRadioButtons[1].setText(translationsDE[2]); + }break; + case English: { + ipVersionRadioButtons[0].setText(translationsEN[1]); + ipVersionRadioButtons[1].setText(translationsEN[2]); + }break; + default: { + throw new Exception("Unknown kind of language."); + } + } + } catch (Exception e) { + System.err.println(e.getMessage()); + this.changeLanguageIPVersionRadioButtons(Languages.German); + } + } +}