Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ServerFrame.java 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 java.awt.GridBagConstraints;
  24. import java.awt.GridBagLayout;
  25. import java.awt.Insets;
  26. import javax.swing.ScrollPaneConstants;
  27. import com.dmdirc.Config;
  28. import com.dmdirc.FrameContainer;
  29. import com.dmdirc.Server;
  30. import com.dmdirc.commandparser.CommandParser;
  31. import com.dmdirc.commandparser.ServerCommandParser;
  32. import com.dmdirc.identities.ConfigManager;
  33. import com.dmdirc.ui.components.Frame;
  34. import com.dmdirc.ui.input.InputHandler;
  35. import static com.dmdirc.ui.UIUtilities.SMALL_BORDER;
  36. /**
  37. * The ServerFrame is the MDI window that shows server messages to the user.
  38. */
  39. public final class ServerFrame extends Frame {
  40. /**
  41. * A version number for this class. It should be changed whenever the class
  42. * structure is changed (or anything else that would prevent serialized
  43. * objects being unserialized with the new class).
  44. */
  45. private static final long serialVersionUID = 7;
  46. /** max length a line can be. */
  47. private final int maxLineLength;
  48. /** This channel's command parser. */
  49. private final ServerCommandParser commandParser;
  50. /** This frame's parent. */
  51. private final Server parent;
  52. /**
  53. * Creates a new ServerFrame.
  54. * @param owner Parent Frame container
  55. */
  56. public ServerFrame(final Server owner) {
  57. super(owner);
  58. parent = owner;
  59. maxLineLength = this.getServer().getParser().MAX_LINELENGTH;
  60. initComponents();
  61. commandParser = new ServerCommandParser((Server) getFrameParent());
  62. setInputHandler(new InputHandler(getInputField(), commandParser, this));
  63. }
  64. /**
  65. * Retrieves the config manager for this command window.
  66. * @return This window's config manager
  67. */
  68. public ConfigManager getConfigManager() {
  69. return parent.getConfigManager();
  70. }
  71. /**
  72. * Retrieves the command Parser for this command window.
  73. * @return This window's command Parser
  74. */
  75. public CommandParser getCommandParser() {
  76. return commandParser;
  77. }
  78. /**
  79. * Retrieves the server associated with this command window.
  80. * @return This window's associated server instance
  81. */
  82. public Server getServer() {
  83. return parent;
  84. }
  85. /** {@inheritDoc} */
  86. public FrameContainer getContainer() {
  87. return parent;
  88. }
  89. /**
  90. * Sets the away status for this and all associated frames.
  91. * @param newAwayState away state
  92. */
  93. public void setAway(final boolean newAwayState) {
  94. if (Config.hasOption("ui", "awayindicator")
  95. && Config.getOptionBool("ui", "awayindicator")) {
  96. setAwayIndicator(newAwayState);
  97. if (getServer().getRaw() != null) {
  98. ((Frame) getServer().getRaw().getFrame()).setAwayIndicator(newAwayState);
  99. }
  100. for (String channel : getServer().getChannels()) {
  101. ((Frame) getServer().getChannel(channel).getFrame()).setAwayIndicator(newAwayState);
  102. }
  103. for (String query : getServer().getQueries()) {
  104. ((Frame) getServer().getQuery(query).getFrame()).setAwayIndicator(newAwayState);
  105. }
  106. }
  107. }
  108. /**
  109. * Initialises components in this frame.
  110. */
  111. private void initComponents() {
  112. final GridBagConstraints constraints = new GridBagConstraints();
  113. setTitle("Server Frame");
  114. getScrollPane().setVerticalScrollBarPolicy(
  115. ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
  116. getTextPane().setEditable(false);
  117. getScrollPane().setViewportView(getTextPane());
  118. getContentPane().setLayout(new GridBagLayout());
  119. constraints.weightx = 1.0;
  120. constraints.weighty = 1.0;
  121. constraints.fill = GridBagConstraints.BOTH;
  122. constraints.insets = new Insets(0, 0, 0, 0);
  123. getContentPane().add(getScrollPane(), constraints);
  124. constraints.weighty = 0.0;
  125. constraints.fill = GridBagConstraints.HORIZONTAL;
  126. constraints.gridy = 1;
  127. getContentPane().add(getSearchBar(), constraints);
  128. constraints.gridy = 2;
  129. constraints.insets = new Insets(SMALL_BORDER, 0, 0, 0);
  130. getContentPane().add(getInputPanel(), constraints);
  131. pack();
  132. }
  133. /** {@inheritDoc}. */
  134. public void sendLine(final String line) {
  135. this.parent.getParser().sendLine(line);
  136. this.getInputHandler().addToBuffer(line);
  137. }
  138. /** {@inheritDoc}. */
  139. public int getMaxLineLength() {
  140. return maxLineLength;
  141. }
  142. }