Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify settings UI code. #44

Merged
merged 1 commit into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/main/java/ui/view/pane/settings/DebugSettingsComponent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package ui.view.pane.settings;

import settings.debug.DebugSettings;

import javax.swing.*;
import java.awt.*;

import static java.awt.BorderLayout.CENTER;

class DebugSettingsComponent implements SettingsComponent {
private final JComponent component;

DebugSettingsComponent(DebugSettings debugSettings) {
this.component = new JPanel(new BorderLayout());

JCheckBox loggingCheckbox = new JCheckBox("Enabled");
loggingCheckbox.setSelected(debugSettings.logging());
loggingCheckbox.addActionListener(e -> debugSettings.setLogging(loggingCheckbox.isSelected()));

component.add(loggingCheckbox, CENTER);
}

@Override
public String title() {
return "Logging";
}

@Override
public String description() {
return "Use this setting to enable or disable logging";
}

@Override
public JComponent component() {
return component;
}
}
47 changes: 0 additions & 47 deletions src/main/java/ui/view/pane/settings/DebugSettingsPanel.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ui.view.pane.settings;

import settings.defaultsavelocation.DefaultSaveLocationSettings;
import ui.view.component.HeaderLabel;
import ui.view.component.filechooser.FileChooser;

import javax.swing.*;
Expand All @@ -10,19 +9,16 @@
import java.util.Optional;

import static java.awt.GridBagConstraints.FIRST_LINE_START;
import static java.awt.GridBagConstraints.HORIZONTAL;
import static ui.view.component.filechooser.ChooseMode.DIRECTORIES_ONLY;

class DefaultSaveLocationSettingsPanel extends JPanel {
private final JLabel headerLabel = new HeaderLabel("Default save location for BChecks");
private final JLabel descriptionLabel = new JLabel("Use this setting to define where BChecks should be saved to by default. If you don't use this setting, you'll be asked where to save the BCheck to every time that you save one");
class DefaultSaveLocationSettingsComponent implements SettingsComponent {
private final JPanel component = new JPanel();
private final JButton chooseFileButton = new JButton("Choose directory");
private final JCheckBox useSettingCheckbox = new JCheckBox("Enabled");

private final DefaultSaveLocationSettings defaultSaveLocationSettings;
private final JTextField pathField = new JTextField();
private final DefaultSaveLocationSettings defaultSaveLocationSettings;

DefaultSaveLocationSettingsPanel(DefaultSaveLocationSettings defaultSaveLocationSettings) {
DefaultSaveLocationSettingsComponent(DefaultSaveLocationSettings defaultSaveLocationSettings) {
this.defaultSaveLocationSettings = defaultSaveLocationSettings;

initialiseUi();
Expand All @@ -41,8 +37,8 @@ private void initialiseUi() {
private void setupLayout() {
GridBagLayout layout = new GridBagLayout();
layout.columnWidths = new int[]{0, 20, 0};
layout.rowHeights = new int[]{0, 10, 0, 5, 0, 5, 0};
setLayout(layout);
layout.rowHeights = new int[]{0, 5, 0};
component.setLayout(layout);
}

private void setupPathLabel() {
Expand Down Expand Up @@ -81,8 +77,7 @@ private void setupUseSettingCheckbox() {
pathField.setVisible(true);

defaultSaveLocationSettings.setUseSetting(true);
}
else {
} else {
chooseFileButton.setVisible(false);
pathField.setVisible(false);

Expand All @@ -98,33 +93,33 @@ private void addElements() {
constraints.gridx = 0;
constraints.gridy = 0;
constraints.anchor = FIRST_LINE_START;
constraints.gridwidth = 3;
add(headerLabel, constraints);

constraints.gridx = 0;
constraints.gridy = 2;
constraints.anchor = FIRST_LINE_START;
constraints.gridwidth = 3;
constraints.weightx = 1.0;
constraints.fill = HORIZONTAL;
add(descriptionLabel, constraints);

constraints.gridx = 0;
constraints.gridy = 4;
constraints.anchor = FIRST_LINE_START;
constraints.gridwidth = 3;
add(useSettingCheckbox, constraints);
component.add(useSettingCheckbox, constraints);

constraints = new GridBagConstraints();
constraints.gridx = 0;
constraints.gridy = 6;
constraints.gridy = 2;
constraints.anchor = FIRST_LINE_START;
add(pathField, constraints);
component.add(pathField, constraints);

constraints = new GridBagConstraints();
constraints.gridx = 2;
constraints.gridy = 6;
constraints.gridy = 2;
constraints.anchor = FIRST_LINE_START;
add(chooseFileButton, constraints);
component.add(chooseFileButton, constraints);
}

@Override
public String title() {
return "Default save location for BChecks";
}

@Override
public String description() {
return "Use this setting to define where BChecks should be saved to by default. If you don't use this setting, you'll be asked where to save the BCheck to every time that you save one";
}

@Override
public JComponent component() {
return component;
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package ui.view.pane.settings;

import settings.github.GitHubSettings;
import ui.view.component.HeaderLabel;
import ui.view.listener.SingleHandlerDocumentListener;

import javax.swing.*;
import java.awt.*;

import static java.awt.GridBagConstraints.FIRST_LINE_START;

class GitHubSettingsPanel extends JPanel {
private final JLabel headerLabel = new HeaderLabel("GitHub configuration");
private final JLabel descriptionLabelFirstLine = new JLabel("Use these settings to define which GitHub repo the extension looks at to find BChecks.");
class GitHubSettingsComponent implements SettingsComponent {
private final JPanel component = new JPanel();
private final JLabel descriptionLabelSecondLine = new JLabel("If the repo isn't public, you'll need to specify an API key too. You can look at GitHub's documentation to find out how to create one.");
private final JLabel descriptionLabelThirdLine = new JLabel("If you're using the same API key across multiple applications, you might exceed GitHub's rate limit, meaning that this extension will no longer work until the rate limit resets.");
private final JLabel descriptionLabelFourthLine = new JLabel("Once you've changed these settings, you'll need to refresh the store for them to take effect.");
Expand All @@ -22,7 +20,7 @@ class GitHubSettingsPanel extends JPanel {

private final GitHubSettings gitHubSettings;

GitHubSettingsPanel(GitHubSettings gitHubSettings) {
GitHubSettingsComponent(GitHubSettings gitHubSettings) {
this.gitHubSettings = gitHubSettings;

initialiseUi();
Expand All @@ -40,9 +38,9 @@ private void initialiseUi() {
private void setupLayout() {
GridBagLayout layout = new GridBagLayout();
layout.columnWidths = new int[]{0, 20, 0};
layout.rowHeights = new int[]{0, 10, 0, 5, 0, 5, 0, 5, 0, 30, 0, 5, 0};
layout.rowHeights = new int[]{0, 5, 0, 5, 0, 30, 0, 5, 0};

setLayout(layout);
component.setLayout(layout);
}

private void setupRepoNameField() {
Expand All @@ -63,58 +61,61 @@ private void setupApiKeyField() {

private void addElements() {
GridBagConstraints constraints = new GridBagConstraints();

constraints.anchor = FIRST_LINE_START;
constraints.gridx = 0;
constraints.gridy = 0;
constraints.gridwidth = 3;
add(headerLabel, constraints);
component.add(descriptionLabelSecondLine, constraints);

constraints = new GridBagConstraints();
constraints.anchor = FIRST_LINE_START;
constraints.gridy = 2;
constraints.gridwidth = 3;
add(descriptionLabelFirstLine, constraints);
component.add(descriptionLabelThirdLine, constraints);

constraints = new GridBagConstraints();
constraints.anchor = FIRST_LINE_START;
constraints.gridy = 4;
constraints.gridwidth = 3;
add(descriptionLabelSecondLine, constraints);
component.add(descriptionLabelFourthLine, constraints);

constraints = new GridBagConstraints();
constraints.anchor = FIRST_LINE_START;
constraints.gridy = 6;
constraints.gridwidth = 3;
add(descriptionLabelThirdLine, constraints);

constraints = new GridBagConstraints();
constraints.anchor = FIRST_LINE_START;
constraints.gridy = 8;
constraints.gridwidth = 3;
add(descriptionLabelFourthLine, constraints);

constraints = new GridBagConstraints();
constraints.anchor = FIRST_LINE_START;
constraints.gridy = 10;
add(repoNameDescription, constraints);
component.add(repoNameDescription, constraints);

constraints = new GridBagConstraints();
constraints.anchor = FIRST_LINE_START;
constraints.gridx = 2;
constraints.gridy = 10;
constraints.gridy = 6;
constraints.weightx = 1;
add(repoNameField, constraints);
component.add(repoNameField, constraints);

constraints = new GridBagConstraints();
constraints.anchor = FIRST_LINE_START;
constraints.gridy = 12;
add(apiKeyDescription, constraints);
constraints.gridy = 8;
component.add(apiKeyDescription, constraints);

constraints = new GridBagConstraints();
constraints.anchor = FIRST_LINE_START;
constraints.gridx = 2;
constraints.gridy = 12;
add(apiKeyField, constraints);
constraints.gridy = 8;
constraints.insets = new Insets(0, 0, 10, 0);

component.add(apiKeyField, constraints);
}

@Override
public String title() {
return "GitHub configuration";
}

@Override
public String description() {
return "Use these settings to define which GitHub repo the extension looks at to find BChecks.";
}

@Override
public JComponent component() {
return component;
}
}
Loading