/*
* ATLauncher - https://github.com/ATLauncher/ATLauncher
* Copyright (C) 2013 ATLauncher
*
* 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 com.atlauncher.gui.dialogs;
import com.atlauncher.App;
import com.atlauncher.data.Language;
import com.atlauncher.utils.Utils;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class AddPackDialog extends JDialog {
private JPanel top;
private JPanel middle;
private JPanel bottom;
private JLabel packCodeLabel;
private JTextField packCode;
private JButton saveButton;
public AddPackDialog() {
super(null, Language.INSTANCE.localize("pack.addpack"), ModalityType.APPLICATION_MODAL);
setSize(350, 150);
setLocationRelativeTo(null);
setLayout(new BorderLayout());
setIconImage(Utils.getImage("/assets/image/Icon.png"));
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
setResizable(false);
// Top Panel Stuff
top = new JPanel();
top.add(new JLabel(Language.INSTANCE.localize("pack.addpack")));
// Middle Panel Stuff
middle = new JPanel();
middle.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.anchor = GridBagConstraints.BASELINE_TRAILING;
packCodeLabel = new JLabel(Language.INSTANCE.localize("pack.packcode") + ": ");
middle.add(packCodeLabel, gbc);
gbc.gridx++;
gbc.anchor = GridBagConstraints.BASELINE_LEADING;
packCode = new JTextField(16);
middle.add(packCode, gbc);
// Bottom Panel Stuff
bottom = new JPanel();
bottom.setLayout(new FlowLayout());
saveButton = new JButton(Language.INSTANCE.localize("common.save"));
saveButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (App.settings.semiPublicPackExistsFromCode(packCode.getText())) {
if (App.settings.addPack(packCode.getText())) {
JOptionPane.showMessageDialog(AddPackDialog.this, Language.INSTANCE.localize("pack" + "" +
".packaddedmessage"), Language.INSTANCE.localize("pack.packadded"),
JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(AddPackDialog.this, Language.INSTANCE.localize("pack" + "" +
".packalreadyaddedmessage"), Language.INSTANCE.localize("pack" +
".packalreadyadded"), JOptionPane.ERROR_MESSAGE);
}
setVisible(false);
dispose();
} else {
JOptionPane.showMessageDialog(AddPackDialog.this, Language.INSTANCE.localize("pack" + "" +
".packdoesntexist"), Language.INSTANCE.localize("pack.packaddederror"),
JOptionPane.ERROR_MESSAGE);
}
}
});
bottom.add(saveButton);
add(top, BorderLayout.NORTH);
add(middle, BorderLayout.CENTER);
add(bottom, BorderLayout.SOUTH);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent arg0) {
setVisible(false);
dispose();
}
});
setVisible(true);
}
}