Search in sources :

Example 1 with PopupMouseAdapter

use of com.sk89q.mclauncher.util.PopupMouseAdapter in project SKMCLauncher by SKCraft.

the class LaunchOptions method addComponents.

private void addComponents() {
    setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0));
    GridBagLayout layout = new GridBagLayout();
    setLayout(layout);
    final JLabel jarLabel = new JLabel("Active JAR:", SwingConstants.LEFT);
    JLabel userLabel = new JLabel("Username:", SwingConstants.LEFT);
    JLabel passLabel = new JLabel("Password:", SwingConstants.LEFT);
    jarCombo = new JComboBox();
    userText = new JComboBox();
    userText.setModel(options.getIdentities());
    userText.setEditable(true);
    passText = new JPasswordField(20);
    jarLabel.setLabelFor(jarCombo);
    userLabel.setLabelFor(userText);
    passLabel.setLabelFor(passText);
    layout.setConstraints(jarCombo, fieldC);
    layout.setConstraints(userText, fieldC);
    layout.setConstraints(passText, fieldC);
    rememberPass = new JCheckBox("Remember my password");
    rememberPass.setBorder(null);
    autoConnectCheck = new JCheckBox("Auto-connect");
    autoConnectCheck.setBorder(null);
    forceUpdateCheck = new JCheckBox("Force a game update");
    forceUpdateCheck.setBorder(null);
    changeComponentsCheck = new JCheckBox("Re-select install options (if any)");
    changeComponentsCheck.setBorder(null);
    playOfflineCheck = new JCheckBox("Play in offline mode");
    playOfflineCheck.setBorder(null);
    showConsoleCheck = new JCheckBox("Show messages and errors");
    showConsoleCheck.setBorder(null);
    expandBtn = new LinkButton("More options...");
    final JPanel expandContainer = new JPanel();
    expandContainer.setLayout(new BoxLayout(expandContainer, BoxLayout.X_AXIS));
    expandContainer.setBorder(null);
    expandContainer.add(expandBtn);
    expandContainer.add(Box.createHorizontalGlue());
    add(jarLabel, labelC);
    add(jarCombo, fieldC);
    add(userLabel, labelC);
    add(userText, fieldC);
    add(passLabel, labelC);
    add(passText, fieldC);
    add(rememberPass, checkboxC);
    add(autoConnectCheck, checkboxC);
    add(forceUpdateCheck, checkboxC);
    add(changeComponentsCheck, checkboxC);
    add(playOfflineCheck, checkboxC);
    add(showConsoleCheck, checkboxC);
    add(expandContainer, checkboxC);
    autoConnectCheck.setVisible(false);
    jarLabel.setVisible(false);
    jarCombo.setVisible(false);
    forceUpdateCheck.setVisible(false);
    changeComponentsCheck.setVisible(false);
    showConsoleCheck.setVisible(false);
    playOfflineCheck.setVisible(false);
    userText.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            loadSavedPassword();
        }
    });
    loadSavedPassword();
    userText.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                frame.launch();
            }
        }
    });
    userText.getEditor().getEditorComponent().addMouseListener(new PopupMouseAdapter() {

        @Override
        protected void showPopup(MouseEvent e) {
            popupIdentityMenu(e.getComponent(), e.getX(), e.getY());
        }
    });
    passText.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                frame.launch();
            }
        }
    });
    playOfflineCheck.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            boolean selected = ((JCheckBox) e.getSource()).isSelected();
            userText.setEnabled(!selected);
            passText.setEnabled(!selected);
            rememberPass.setEnabled(!selected);
        }
    });
    expandBtn.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            expandContainer.setVisible(false);
            jarLabel.setVisible(true);
            jarCombo.setVisible(true);
            forceUpdateCheck.setVisible(true);
            changeComponentsCheck.setVisible(true);
            showConsoleCheck.setVisible(true);
            playOfflineCheck.setVisible(true);
        // registerAccount.setVisible(true);
        }
    });
}
Also used : JPanel(javax.swing.JPanel) MouseEvent(java.awt.event.MouseEvent) GridBagLayout(java.awt.GridBagLayout) JComboBox(javax.swing.JComboBox) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) KeyAdapter(java.awt.event.KeyAdapter) JLabel(javax.swing.JLabel) LinkButton(com.sk89q.mclauncher.util.LinkButton) JCheckBox(javax.swing.JCheckBox) KeyEvent(java.awt.event.KeyEvent) PopupMouseAdapter(com.sk89q.mclauncher.util.PopupMouseAdapter) ActionListener(java.awt.event.ActionListener) JPasswordField(javax.swing.JPasswordField)

Aggregations

LinkButton (com.sk89q.mclauncher.util.LinkButton)1 PopupMouseAdapter (com.sk89q.mclauncher.util.PopupMouseAdapter)1 GridBagLayout (java.awt.GridBagLayout)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 KeyAdapter (java.awt.event.KeyAdapter)1 KeyEvent (java.awt.event.KeyEvent)1 MouseEvent (java.awt.event.MouseEvent)1 BoxLayout (javax.swing.BoxLayout)1 JCheckBox (javax.swing.JCheckBox)1 JComboBox (javax.swing.JComboBox)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 JPasswordField (javax.swing.JPasswordField)1