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