Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ServerFrame.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack, Gregory Holmes
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.ui;
  23. import com.dmdirc.Config;
  24. import com.dmdirc.Server;
  25. import com.dmdirc.commandparser.CommandParser;
  26. import com.dmdirc.commandparser.ServerCommandParser;
  27. import com.dmdirc.ui.components.InputFrame;
  28. import com.dmdirc.ui.input.InputHandler;
  29. import com.dmdirc.ui.interfaces.ServerWindow;
  30. import static com.dmdirc.ui.UIUtilities.SMALL_BORDER;
  31. import java.awt.BorderLayout;
  32. import java.awt.GridBagConstraints;
  33. import java.awt.GridBagLayout;
  34. import java.awt.Insets;
  35. /**
  36. * The ServerFrame is the MDI window that shows server messages to the user.
  37. */
  38. public final class ServerFrame extends InputFrame implements ServerWindow {
  39. /**
  40. * A version number for this class. It should be changed whenever the class
  41. * structure is changed (or anything else that would prevent serialized
  42. * objects being unserialized with the new class).
  43. */
  44. private static final long serialVersionUID = 8;
  45. /** This channel's command parser. */
  46. private final ServerCommandParser commandParser;
  47. /** This frame's parent. */
  48. private final Server parent;
  49. /**
  50. * Creates a new ServerFrame.
  51. * @param owner Parent Frame container
  52. */
  53. public ServerFrame(final Server owner) {
  54. super(owner);
  55. parent = owner;
  56. initComponents();
  57. commandParser = new ServerCommandParser((Server) getContainer());
  58. setInputHandler(new InputHandler(getInputField(), commandParser, this));
  59. }
  60. /**
  61. * Retrieves the command Parser for this command window.
  62. * @return This window's command Parser
  63. */
  64. public CommandParser getCommandParser() {
  65. return commandParser;
  66. }
  67. /**
  68. * Sets the away status for this and all associated frames.
  69. *
  70. * @param newAwayState away state
  71. */
  72. @Override
  73. public void setAwayIndicator(final boolean newAwayState) {
  74. if (Config.getOptionBool("ui", "awayindicator")) {
  75. if (newAwayState) {
  76. inputPanel.add(awayLabel, BorderLayout.LINE_START);
  77. awayLabel.setVisible(true);
  78. } else {
  79. awayLabel.setVisible(false);
  80. }
  81. if (getContainer().getServer().getRaw() != null) {
  82. getContainer().getServer().getRaw().getFrame().setAwayIndicator(newAwayState);
  83. }
  84. for (String channel : getContainer().getServer().getChannels()) {
  85. getContainer().getServer().getChannel(channel).getFrame().setAwayIndicator(newAwayState);
  86. }
  87. for (String query : getContainer().getServer().getQueries()) {
  88. getContainer().getServer().getQuery(query).getFrame().setAwayIndicator(newAwayState);
  89. }
  90. }
  91. }
  92. /**
  93. * Initialises components in this frame.
  94. */
  95. private void initComponents() {
  96. final GridBagConstraints constraints = new GridBagConstraints();
  97. setTitle("Server Frame");
  98. getContentPane().setLayout(new GridBagLayout());
  99. constraints.weightx = 1.0;
  100. constraints.weighty = 1.0;
  101. constraints.fill = GridBagConstraints.BOTH;
  102. constraints.insets = new Insets(0, 0, 0, 0);
  103. getContentPane().add(getTextPane(), constraints);
  104. constraints.weighty = 0.0;
  105. constraints.fill = GridBagConstraints.HORIZONTAL;
  106. constraints.gridy = 1;
  107. getContentPane().add(getSearchBar(), constraints);
  108. constraints.gridy = 2;
  109. constraints.insets = new Insets(SMALL_BORDER, 0, 0, 0);
  110. getContentPane().add(inputPanel, constraints);
  111. pack();
  112. }
  113. }