    001    package net.minecraft.src;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005    import java.awt.BorderLayout;
    006    import java.awt.Component;
    007    import java.awt.Dimension;
    008    import java.util.logging.Logger;
    009    import javax.swing.JComponent;
    010    import javax.swing.JFrame;
    011    import javax.swing.JPanel;
    012    import javax.swing.JScrollPane;
    013    import javax.swing.JTextArea;
    014    import javax.swing.JTextField;
    015    import javax.swing.UIManager;
    016    import javax.swing.border.EtchedBorder;
    017    import javax.swing.border.TitledBorder;
    018
    019    @SideOnly(Side.SERVER)
    020    public class ServerGUI extends JComponent
    021    {
    022        /** Reference to the logger. */
    023        public static Logger logger = Logger.getLogger("Minecraft");
    024
    025        /** This is set to true after server GUI window has been initialized. */
    026        private static boolean serverGuiInitialized = false;
    027        private DedicatedServer serverInstance;
    028
    029        /**
    030         * Sets up the server GUI
    031         */
    032        public static void initGUI(DedicatedServer par0DedicatedServer)
    033        {
    034            try
    035            {
    036                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    037            }
    038            catch (Exception var3)
    039            {
    040                ;
    041            }
    042
    043            ServerGUI var1 = new ServerGUI(par0DedicatedServer);
    044            serverGuiInitialized = true;
    045            JFrame var2 = new JFrame("Minecraft server");
    046            var2.add(var1);
    047            var2.pack();
    048            var2.setLocationRelativeTo((Component)null);
    049            var2.setVisible(true);
    050            var2.addWindowListener(new ServerWindowAdapter(par0DedicatedServer));
    051        }
    052
    053        public ServerGUI(DedicatedServer par1DedicatedServer)
    054        {
    055            this.serverInstance = par1DedicatedServer;
    056            this.setPreferredSize(new Dimension(854, 480));
    057            this.setLayout(new BorderLayout());
    058
    059            try
    060            {
    061                this.add(this.getLogComponent(), "Center");
    062                this.add(this.getStatsComponent(), "West");
    063            }
    064            catch (Exception var3)
    065            {
    066                var3.printStackTrace();
    067            }
    068        }
    069
    070        /**
    071         * Returns a new JPanel with a new GuiStatsComponent inside.
    072         */
    073        private JComponent getStatsComponent()
    074        {
    075            JPanel var1 = new JPanel(new BorderLayout());
    076            var1.add(new GuiStatsComponent(this.serverInstance), "North");
    077            var1.add(this.getPlayerListComponent(), "Center");
    078            var1.setBorder(new TitledBorder(new EtchedBorder(), "Stats"));
    079            return var1;
    080        }
    081
    082        /**
    083         * Returns a new JScrollPane with a new PlayerListBox inside.
    084         */
    085        private JComponent getPlayerListComponent()
    086        {
    087            PlayerListBox var1 = new PlayerListBox(this.serverInstance);
    088            JScrollPane var2 = new JScrollPane(var1, 22, 30);
    089            var2.setBorder(new TitledBorder(new EtchedBorder(), "Players"));
    090            return var2;
    091        }
    092
    093        /**
    094         * Returns a new JPanel with a new GuiStatsComponent inside.
    095         */
    096        private JComponent getLogComponent()
    097        {
    098            JPanel var1 = new JPanel(new BorderLayout());
    099            JTextArea var2 = new JTextArea();
    100            logger.addHandler(new GuiLogOutputHandler(var2));
    101            JScrollPane var3 = new JScrollPane(var2, 22, 30);
    102            var2.setEditable(false);
    103            JTextField var4 = new JTextField();
    104            var4.addActionListener(new ServerGuiCommandListener(this, var4));
    105            var2.addFocusListener(new ServerGuiFocusAdapter(this));
    106            var1.add(var3, "Center");
    107            var1.add(var4, "South");
    108            var1.setBorder(new TitledBorder(new EtchedBorder(), "Log and chat"));
    109            return var1;
    110        }
    111
    112        static DedicatedServer getDedicatedServer(ServerGUI par0ServerGUI)
    113        {
    114            return par0ServerGUI.serverInstance;
    115        }
    116    }