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