Package com.wakachamo.jrcon

Source Code of com.wakachamo.jrcon.MainWindow

/*
* MainWindow.java
*
* Created on Aug 31, 2012, 1:32:02 AM
*/
package com.wakachamo.jrcon;

import com.github.koraktor.steamcondenser.steam.SteamPlayer;

/**
*
* @author Joaquim
*/
public class MainWindow extends javax.swing.JFrame {

    /** Creates new form MainWindow */
    public MainWindow() {
        initComponents();
        updateServerDetails();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mapLabel = new javax.swing.JLabel();
        mapComboBox = new javax.swing.JComboBox();
        hostnameLabel = new javax.swing.JLabel();
        hostnameTextField = new javax.swing.JTextField();
        playersInfoLabel = new javax.swing.JLabel();
        playersLabel = new javax.swing.JLabel();
        playerListScrollPane = new javax.swing.JScrollPane();
        playerList = new javax.swing.JList();
        kickSelectedButton = new javax.swing.JButton();
        banSelectedButton = new javax.swing.JButton();
        advancedServerCommandsButton = new javax.swing.JButton();
        botCommandsButton = new javax.swing.JButton();
        changeHostnameButton = new javax.swing.JButton();
        changeMapButton = new javax.swing.JButton();
        refreshButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("jRCON - Server Address");

        mapLabel.setText("Map:");

        mapComboBox.setModel(new javax.swing.DefaultComboBoxModel(SourceHelper.getHelper().getMapNames()));

        hostnameLabel.setText("Hostname:");

        hostnameTextField.setText("Server Name");

        playersInfoLabel.setText("Players:");

        playersLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        playersLabel.setText("24/24 (6 bots)");

        playerList.setModel(new javax.swing.AbstractListModel() {
            Object[] players = SourceHelper.getHelper().getPlayersArray();
            public int getSize() { return players.length; }
            public Object getElementAt(int i) { return players[i]; }
        });
        playerListScrollPane.setViewportView(playerList);

        kickSelectedButton.setText("Kick Selected");
        kickSelectedButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                kickSelectedButtonActionPerformed(evt);
            }
        });

        banSelectedButton.setText("Ban Selected");
        banSelectedButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                banSelectedButtonActionPerformed(evt);
            }
        });

        advancedServerCommandsButton.setText("Advanced Server Commands");
        advancedServerCommandsButton.setEnabled(false);

        botCommandsButton.setText("Bot Commands");
        botCommandsButton.setEnabled(false);

        changeHostnameButton.setText("Change Hostname");
        changeHostnameButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                changeHostnameButtonActionPerformed(evt);
            }
        });

        changeMapButton.setText("Change Map");
        changeMapButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                changeMapButtonActionPerformed(evt);
            }
        });

        refreshButton.setText("Refresh");
        refreshButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                refreshButtonActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(layout.createSequentialGroup()
                                .add(kickSelectedButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 154, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(banSelectedButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, playerListScrollPane)
                            .add(layout.createSequentialGroup()
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                    .add(playersInfoLabel)
                                    .add(mapLabel)
                                    .add(hostnameLabel))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                    .add(playersLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .add(hostnameTextField)
                                    .add(mapComboBox, 0, 211, Short.MAX_VALUE))))
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 38, Short.MAX_VALUE)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                    .add(advancedServerCommandsButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 216, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(botCommandsButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 216, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                .addContainerGap())
                            .add(layout.createSequentialGroup()
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                                    .add(org.jdesktop.layout.GroupLayout.LEADING, changeMapButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .add(org.jdesktop.layout.GroupLayout.LEADING, changeHostnameButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addContainerGap(103, Short.MAX_VALUE))))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, refreshButton)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(hostnameLabel)
                    .add(hostnameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(changeHostnameButton))
                .add(9, 9, 9)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(50, 50, 50)
                        .add(advancedServerCommandsButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 81, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(28, 28, 28)
                        .add(botCommandsButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 81, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(mapLabel)
                            .add(mapComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(changeMapButton))
                        .add(18, 18, 18)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(playersInfoLabel)
                            .add(playersLabel))
                        .add(18, 18, 18)
                        .add(playerListScrollPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(kickSelectedButton)
                            .add(banSelectedButton))))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 5, Short.MAX_VALUE)
                .add(refreshButton))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void changeHostnameButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_changeHostnameButtonActionPerformed
        SourceHelper.getHelper().setHostname(hostnameTextField.getText());
    }//GEN-LAST:event_changeHostnameButtonActionPerformed

    private void changeMapButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_changeMapButtonActionPerformed
        String selectedMapName = (String)this.mapComboBox.getSelectedObjects()[0];
        SourceHelper.getHelper().setMap(selectedMapName);
    }//GEN-LAST:event_changeMapButtonActionPerformed

    private void kickSelectedButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_kickSelectedButtonActionPerformed
        SourceHelper helper = SourceHelper.getHelper();
        for (Object playerObj : this.playerList.getSelectedValues()) {
            SteamPlayer player = (SteamPlayer)playerObj;
            helper.kickPlayer(player);
        }
    }//GEN-LAST:event_kickSelectedButtonActionPerformed

    private void banSelectedButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_banSelectedButtonActionPerformed
        SourceHelper helper = SourceHelper.getHelper();
        for (Object playerObj : this.playerList.getSelectedValues()) {
            SteamPlayer player = (SteamPlayer)playerObj;
            helper.banPlayer(player);
        }
    }//GEN-LAST:event_banSelectedButtonActionPerformed

    private void refreshButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_refreshButtonActionPerformed
        this.updateServerDetails();
    }//GEN-LAST:event_refreshButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        /*try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }*/
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new MainWindow().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton advancedServerCommandsButton;
    private javax.swing.JButton banSelectedButton;
    private javax.swing.JButton botCommandsButton;
    private javax.swing.JButton changeHostnameButton;
    private javax.swing.JButton changeMapButton;
    private javax.swing.JLabel hostnameLabel;
    private javax.swing.JTextField hostnameTextField;
    private javax.swing.JButton kickSelectedButton;
    private javax.swing.JComboBox mapComboBox;
    private javax.swing.JLabel mapLabel;
    private javax.swing.JList playerList;
    private javax.swing.JScrollPane playerListScrollPane;
    private javax.swing.JLabel playersInfoLabel;
    private javax.swing.JLabel playersLabel;
    private javax.swing.JButton refreshButton;
    // End of variables declaration//GEN-END:variables

    private void updateServerDetails() {
        SourceHelper helper = SourceHelper.getHelper();
        this.mapComboBox.setSelectedItem(helper.getCurrentMap());
        this.hostnameTextField.setText(helper.getHostname());
        this.playersLabel.setText(helper.getNumberOfPlayers() + "/" + helper.getMaxPlayers() + " (" + helper.getNumberOfBots() + " bots)");
        this.playerList.setModel(helper.getPlayerListModel());
    }
}
TOP

Related Classes of com.wakachamo.jrcon.MainWindow

TOP
Copyright © 2018 www.massapi.com. 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.