/mcp/src/minecraft_server/net/minecraft/src/ServerGUI.java

https://bitbucket.org/vkorolik/twoleanfour-client · Java · 121 lines · 85 code · 13 blank · 23 comment · 0 complexity · d4a033264484409320d51bba8ee92b78 MD5 · raw file

  1. package net.minecraft.src;
  2. import java.awt.BorderLayout;
  3. import java.awt.Dimension;
  4. import java.util.logging.Logger;
  5. import javax.swing.*;
  6. import javax.swing.border.EtchedBorder;
  7. import javax.swing.border.TitledBorder;
  8. import net.minecraft.server.MinecraftServer;
  9. public class ServerGUI extends JComponent implements ICommandListener
  10. {
  11. /** Reference to the logger. */
  12. public static Logger logger = Logger.getLogger("Minecraft");
  13. /** Reference to the MinecraftServer object. */
  14. private MinecraftServer mcServer;
  15. /**
  16. * Initialises the GUI components.
  17. */
  18. public static void initGui(MinecraftServer par0MinecraftServer)
  19. {
  20. try
  21. {
  22. UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
  23. }
  24. catch (Exception exception) { }
  25. ServerGUI servergui = new ServerGUI(par0MinecraftServer);
  26. JFrame jframe = new JFrame("Minecraft server");
  27. jframe.add(servergui);
  28. jframe.pack();
  29. jframe.setLocationRelativeTo(null);
  30. jframe.setVisible(true);
  31. jframe.addWindowListener(new ServerWindowAdapter(par0MinecraftServer));
  32. }
  33. public ServerGUI(MinecraftServer par1MinecraftServer)
  34. {
  35. mcServer = par1MinecraftServer;
  36. setPreferredSize(new Dimension(854, 480));
  37. setLayout(new BorderLayout());
  38. try
  39. {
  40. add(getLogComponent(), "Center");
  41. add(getStatsComponent(), "West");
  42. }
  43. catch (Exception exception)
  44. {
  45. exception.printStackTrace();
  46. }
  47. }
  48. /**
  49. * Returns a new JPanel with a new GuiStatsComponent inside.
  50. */
  51. private JComponent getStatsComponent()
  52. {
  53. JPanel jpanel = new JPanel(new BorderLayout());
  54. jpanel.add(new GuiStatsComponent(mcServer), "North");
  55. jpanel.add(getPlayerListComponent(), "Center");
  56. jpanel.setBorder(new TitledBorder(new EtchedBorder(), "Stats"));
  57. return jpanel;
  58. }
  59. /**
  60. * Returns a new JScrollPane with a new PlayerListBox inside.
  61. */
  62. private JComponent getPlayerListComponent()
  63. {
  64. PlayerListBox playerlistbox = new PlayerListBox(mcServer);
  65. JScrollPane jscrollpane = new JScrollPane(playerlistbox, 22, 30);
  66. jscrollpane.setBorder(new TitledBorder(new EtchedBorder(), "Players"));
  67. return jscrollpane;
  68. }
  69. /**
  70. * Returns a new JPanel with a new GuiStatsComponent inside.
  71. */
  72. private JComponent getLogComponent()
  73. {
  74. JPanel jpanel = new JPanel(new BorderLayout());
  75. JTextArea jtextarea = new JTextArea();
  76. logger.addHandler(new GuiLogOutputHandler(jtextarea));
  77. JScrollPane jscrollpane = new JScrollPane(jtextarea, 22, 30);
  78. jtextarea.setEditable(false);
  79. JTextField jtextfield = new JTextField();
  80. jtextfield.addActionListener(new ServerGuiCommandListener(this, jtextfield));
  81. jtextarea.addFocusListener(new ServerGuiFocusAdapter(this));
  82. jpanel.add(jscrollpane, "Center");
  83. jpanel.add(jtextfield, "South");
  84. jpanel.setBorder(new TitledBorder(new EtchedBorder(), "Log and chat"));
  85. return jpanel;
  86. }
  87. /**
  88. * Logs the message with a level of INFO.
  89. */
  90. public void log(String par1Str)
  91. {
  92. logger.info(par1Str);
  93. }
  94. /**
  95. * Gets the players username.
  96. */
  97. public String getUsername()
  98. {
  99. return "CONSOLE";
  100. }
  101. /**
  102. * Returns the MinecraftServer associated with the ServerGui.
  103. */
  104. static MinecraftServer getMinecraftServer(ServerGUI par0ServerGUI)
  105. {
  106. return par0ServerGUI.mcServer;
  107. }
  108. }