Package com.atlauncher.data

Examples of com.atlauncher.data.Account


        openFolder = new JButton(Language.INSTANCE.localize("common.openfolder"));
        updateData = new JButton(Language.INSTANCE.localize("common.updatedata"));

        username = new JComboBox<Account>();
        username.setRenderer(new AccountsDropDownRenderer());
        fillerAccount = new Account(Language.INSTANCE.localize("account.select"));
        username.addItem(fillerAccount);
        for (Account account : App.settings.getAccounts()) {
            username.addItem(account);
        }
        Account active = App.settings.getAccount();
        if (active == null) {
            username.setSelectedIndex(0);
        } else {
            username.setSelectedItem(active);
        }
View Full Code Here


        gbc.gridy = 0;
        gbc.gridwidth = 2;
        gbc.insets = TOP_INSETS;
        gbc.anchor = GridBagConstraints.CENTER;

        fillerAccount = new Account(Language.INSTANCE.localize("account.add"));

        accountsComboBox = new JComboBox<Account>();
        accountsComboBox.addItem(fillerAccount);
        for (Account account : App.settings.getAccounts()) {
            accountsComboBox.addItem(account);
        }
        accountsComboBox.setSelectedIndex(0);
        accountsComboBox.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    Account account = (Account) accountsComboBox.getSelectedItem();
                    if (accountsComboBox.getSelectedIndex() == 0) {
                        usernameField.setText("");
                        passwordField.setText("");
                        rememberField.setSelected(false);
                        leftButton.setText(Language.INSTANCE.localize("common.add"));
                        rightButton.setText(Language.INSTANCE.localize("common.clear"));
                    } else {
                        usernameField.setText(account.getUsername());
                        passwordField.setText(account.getPassword());
                        rememberField.setSelected(account.isRemembered());
                        leftButton.setText(Language.INSTANCE.localize("common.save"));
                        rightButton.setText(Language.INSTANCE.localize("common.delete"));
                    }
                    userSkin.setIcon(account.getMinecraftSkin());
                }
            }
        });
        bottomPanel.add(accountsComboBox, gbc);

        gbc.gridx = 0;
        gbc.gridy++;
        gbc.gridwidth = 1;
        gbc.insets = LABEL_INSETS;
        gbc.anchor = GridBagConstraints.BASELINE_TRAILING;
        usernameLabel = new JLabel(Language.INSTANCE.localize("account.usernameemail") + ":");
        bottomPanel.add(usernameLabel, gbc);

        gbc.gridx++;
        gbc.insets = FIELD_INSETS;
        gbc.anchor = GridBagConstraints.BASELINE_LEADING;
        usernameField = new JTextField(16);
        bottomPanel.add(usernameField, gbc);

        gbc.gridx = 0;
        gbc.gridy++;
        gbc.insets = LABEL_INSETS;
        gbc.anchor = GridBagConstraints.BASELINE_TRAILING;
        passwordLabel = new JLabel(Language.INSTANCE.localize("account.password") + ":");
        bottomPanel.add(passwordLabel, gbc);

        gbc.gridx++;
        gbc.insets = FIELD_INSETS;
        gbc.anchor = GridBagConstraints.BASELINE_LEADING;
        passwordField = new JPasswordField(16);
        bottomPanel.add(passwordField, gbc);

        gbc.gridx = 0;
        gbc.gridy++;
        gbc.insets = LABEL_INSETS;
        gbc.anchor = GridBagConstraints.BASELINE_TRAILING;
        rememberLabel = new JLabel(Language.INSTANCE.localize("account.remember") + ":");
        bottomPanel.add(rememberLabel, gbc);

        gbc.gridx++;
        gbc.insets = FIELD_INSETS;
        gbc.anchor = GridBagConstraints.BASELINE_LEADING;
        rememberField = new JCheckBox();
        bottomPanel.add(rememberField, gbc);
        rememberField.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (rememberField.isSelected()) {
                    String[] options = {Language.INSTANCE.localize("common.yes"), Language.INSTANCE.localize("common"
                            + ".no")};
                    int ret = JOptionPane.showOptionDialog(App.settings.getParent(),
                            "<html><p align=\"center\">" + Language.INSTANCE.localizeWithReplace("account" + "" +
                                    ".rememberpasswordwarning", "<br/><br/>") + "</p></html>",
                            Language.INSTANCE.localize("account.securitywarningtitle"), JOptionPane.DEFAULT_OPTION,
                            JOptionPane.ERROR_MESSAGE, null, options, options[0]);
                    if (ret != 0) {
                        rememberField.setSelected(false);
                    }
                }
            }
        });

        gbc.gridx = 0;
        gbc.gridy++;
        gbc.gridwidth = 2;
        gbc.insets = BOTTOM_INSETS;
        gbc.anchor = GridBagConstraints.CENTER;
        buttons = new JPanel();
        buttons.setLayout(new FlowLayout());
        leftButton = new JButton(Language.INSTANCE.localize("common.add"));
        leftButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (App.settings.isInOfflineMode()) {
                    String[] options = {Language.INSTANCE.localize("common.ok")};
                    JOptionPane.showOptionDialog(App.settings.getParent(), Language.INSTANCE.localize("account" + "" +
                                    ".offlinemode"), Language.INSTANCE.localize("common.offline"),
                            JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[0]);
                } else {
                    Account account;
                    String username = usernameField.getText();
                    String password = new String(passwordField.getPassword());
                    boolean remember = rememberField.isSelected();
                    if (App.settings.isAccountByName(username) && accountsComboBox.getSelectedIndex() == 0) {
                        String[] options = {Language.INSTANCE.localize("common.ok")};
                        JOptionPane.showOptionDialog(App.settings.getParent(), Language.INSTANCE.localize("account" +
                                ".exists"), Language.INSTANCE.localize("account.notadded"),
                                JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[0]);
                        return;
                    }

                    LogManager.info("Logging into Minecraft!");
                    final ProgressDialog dialog = new ProgressDialog(Language.INSTANCE.localize("account" + "" +
                            ".loggingin"), 0, Language.INSTANCE.localize("account.loggingin"),
                            "Aborting login for " + usernameField.getText());
                    dialog.addThread(new Thread() {
                        public void run() {
                            AuthenticationResponse resp = Authentication.checkAccount(usernameField.getText(),
                                    new String(passwordField.getPassword()));
                            dialog.setReturnValue(resp);
                            dialog.close();
                        }
                    });
                    dialog.start();
                    AuthenticationResponse response = (AuthenticationResponse) dialog.getReturnValue();
                    if (response != null && !response.hasError()) {

                        if (accountsComboBox.getSelectedIndex() == 0) {
                            account = new Account(username, password, response.getSelectedProfile().getName(),
                                    response.getSelectedProfile().getId(), remember);
                            App.settings.addAccount(account);
                            LogManager.info("Added Account " + account);
                            String[] options = {Language.INSTANCE.localize("common.yes"),
                                    Language.INSTANCE.localize("common.no")};
                            int ret = JOptionPane.showOptionDialog(App.settings.getParent(),
                                    Language.INSTANCE.localize("account.addedswitch"),
                                    Language.INSTANCE.localize("account.added"), JOptionPane.DEFAULT_OPTION,
                                    JOptionPane.INFORMATION_MESSAGE, null, options, options[0]);
                            if (ret == 0) {
                                App.settings.switchAccount(account);
                            }
                        } else {
                            account = (Account) accountsComboBox.getSelectedItem();
                            account.setUsername(username);
                            account.setMinecraftUsername(response.getSelectedProfile().getName());
                            account.setUUID(response.getSelectedProfile().getId());
                            if (remember) {
                                account.setPassword(password);
                            }
                            account.setRemember(remember);
                            LogManager.info("Edited Account " + account);
                            String[] options = {Language.INSTANCE.localize("common.ok")};
                            JOptionPane.showOptionDialog(App.settings.getParent(),
                                    Language.INSTANCE.localize("account.editeddone"),
                                    Language.INSTANCE.localize("account.edited"), JOptionPane.DEFAULT_OPTION,
                                    JOptionPane.INFORMATION_MESSAGE, null, options, options[0]);
                        }
                        App.settings.saveAccounts();
                        App.settings.reloadAccounts();
                        accountsComboBox.removeAllItems();
                        accountsComboBox.addItem(fillerAccount);
                        for (Account accountt : App.settings.getAccounts()) {
                            accountsComboBox.addItem(accountt);
                        }
                        accountsComboBox.setSelectedItem(account);
                    } else {
                        LogManager.error((response == null ? "Unknown Error Logging In" : response.getErrorMessage()));
                        String[] options = {Language.INSTANCE.localize("common.ok")};
                        JOptionPane.showOptionDialog(App.settings.getParent(),
                                "<html><p align=\"center\">" + Language.INSTANCE.localize("account.incorrect") +
                                        "<br/><br/>" + (response == null ? "Unknown Error" : response.getErrorMessage
                                        ()) + "</p></html>", Language.INSTANCE.localize("account.notadded"),
                                JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[0]);
                    }
                }
            }
        });
        rightButton = new JButton(Language.INSTANCE.localize("common.clear"));
        rightButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (accountsComboBox.getSelectedIndex() == 0) {
                    usernameField.setText("");
                    passwordField.setText("");
                    rememberField.setSelected(false);
                } else {
                    Account account = (Account) accountsComboBox.getSelectedItem();
                    int res = JOptionPane.showConfirmDialog(App.settings.getParent(),
                            Language.INSTANCE.localizeWithReplace("account.deletesure", usernameField.getText()),
                            Language.INSTANCE.localize("account.delete"), JOptionPane.YES_NO_OPTION);
                    if (res == JOptionPane.YES_OPTION) {
                        App.settings.removeAccount(account);
                        accountsComboBox.removeAllItems();
                        accountsComboBox.addItem(fillerAccount);
                        for (Account accountt : App.settings.getAccounts()) {
                            accountsComboBox.addItem(accountt);
                        }
                        accountsComboBox.setSelectedIndex(0);
                    }
                }
            }
        });
        buttons.add(leftButton);
        buttons.add(rightButton);
        bottomPanel.add(buttons, gbc);

        rightPanel.add(topPanel, BorderLayout.NORTH);
        rightPanel.add(bottomPanel, BorderLayout.CENTER);

        contextMenu = new JPopupMenu();

        updateSkin = new JMenuItem(Language.INSTANCE.localize("account.reloadskin"));
        updateSkin.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                final Account account = ((Account) accountsComboBox.getSelectedItem());
                account.updateSkin();
                userSkin.setIcon(account.getMinecraftSkin());
            }
        });
        contextMenu.add(updateSkin);

        userSkin = new JLabel(fillerAccount.getMinecraftSkin());
View Full Code Here

TOP

Related Classes of com.atlauncher.data.Account

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.