You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ServerFrame.java 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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.swing;
  23. import com.dmdirc.Server;
  24. import com.dmdirc.commandparser.parsers.CommandParser;
  25. import com.dmdirc.commandparser.parsers.ServerCommandParser;
  26. import com.dmdirc.config.IdentityManager;
  27. import com.dmdirc.ui.input.InputHandler;
  28. import com.dmdirc.ui.interfaces.ServerWindow;
  29. import com.dmdirc.ui.swing.components.InputFrame;
  30. import com.dmdirc.ui.swing.dialogs.serversetting.ServerSettingsDialog;
  31. import static com.dmdirc.ui.swing.UIUtilities.SMALL_BORDER;
  32. import java.awt.BorderLayout;
  33. import java.awt.GridBagConstraints;
  34. import java.awt.GridBagLayout;
  35. import java.awt.Insets;
  36. import java.awt.event.ActionEvent;
  37. import java.awt.event.ActionListener;
  38. import javax.swing.JMenuItem;
  39. import javax.swing.event.PopupMenuEvent;
  40. import javax.swing.event.PopupMenuListener;
  41. /**
  42. * The ServerFrame is the MDI window that shows server messages to the user.
  43. */
  44. public final class ServerFrame extends InputFrame implements ServerWindow,
  45. ActionListener, PopupMenuListener {
  46. /**
  47. * A version number for this class. It should be changed whenever the class
  48. * structure is changed (or anything else that would prevent serialized
  49. * objects being unserialized with the new class).
  50. */
  51. private static final long serialVersionUID = 9;
  52. /** This channel's command parser. */
  53. private final ServerCommandParser commandParser;
  54. /** popup menu item. */
  55. private JMenuItem settingsMI;
  56. /**
  57. * Creates a new ServerFrame.
  58. * @param owner Parent Frame container
  59. */
  60. public ServerFrame(final Server owner) {
  61. super(owner);
  62. initComponents();
  63. commandParser = new ServerCommandParser((Server) getContainer());
  64. setInputHandler(new InputHandler(getInputField(), commandParser, this));
  65. }
  66. /**
  67. * Retrieves the command Parser for this command window.
  68. * @return This window's command Parser
  69. */
  70. public CommandParser getCommandParser() {
  71. return commandParser;
  72. }
  73. /**
  74. * Sets the away status for this and all associated frames.
  75. *
  76. * @param newAwayState away state
  77. */
  78. @Override
  79. public void setAwayIndicator(final boolean newAwayState) {
  80. if (IdentityManager.getGlobalConfig().getOptionBool("ui", "awayindicator")) {
  81. if (newAwayState) {
  82. inputPanel.add(awayLabel, BorderLayout.LINE_START);
  83. awayLabel.setVisible(true);
  84. } else {
  85. awayLabel.setVisible(false);
  86. }
  87. if (getContainer().getServer().getRaw() != null) {
  88. getContainer().getServer().getRaw().getFrame().setAwayIndicator(newAwayState);
  89. }
  90. for (String channel : getContainer().getServer().getChannels()) {
  91. getContainer().getServer().getChannel(channel).getFrame().setAwayIndicator(newAwayState);
  92. }
  93. for (String query : getContainer().getServer().getQueries()) {
  94. getContainer().getServer().getQuery(query).getFrame().setAwayIndicator(newAwayState);
  95. }
  96. }
  97. }
  98. /**
  99. * Initialises components in this frame.
  100. */
  101. private void initComponents() {
  102. settingsMI = new JMenuItem("Settings");
  103. settingsMI.addActionListener(this);
  104. getPopup().addSeparator();
  105. getPopup().add(settingsMI);
  106. getPopup().addPopupMenuListener(this);
  107. final GridBagConstraints constraints = new GridBagConstraints();
  108. setTitle("Server Frame");
  109. getContentPane().setLayout(new GridBagLayout());
  110. constraints.weightx = 1.0;
  111. constraints.weighty = 1.0;
  112. constraints.fill = GridBagConstraints.BOTH;
  113. constraints.insets = new Insets(0, 0, SMALL_BORDER, 0);
  114. getContentPane().add(getTextPane(), constraints);
  115. constraints.weighty = 0.0;
  116. constraints.fill = GridBagConstraints.HORIZONTAL;
  117. constraints.gridy = 1;
  118. constraints.insets = new Insets(0, 0, 0, 0);
  119. getContentPane().add(getSearchBar(), constraints);
  120. constraints.gridy = 2;
  121. getContentPane().add(inputPanel, constraints);
  122. pack();
  123. }
  124. /** {@inheritDoc}. */
  125. public void actionPerformed(final ActionEvent actionEvent) {
  126. super.actionPerformed(actionEvent);
  127. if (actionEvent.getSource() == settingsMI) {
  128. new ServerSettingsDialog(getContainer().getServer()).setVisible(true);
  129. }
  130. }
  131. /** {@inheritDoc}. */
  132. public void popupMenuWillBecomeVisible(final PopupMenuEvent e) {
  133. if (getContainer().getServer().getState().equals(Server.STATE.CONNECTED)) {
  134. settingsMI.setEnabled(true);
  135. } else {
  136. settingsMI.setEnabled(false);
  137. }
  138. }
  139. /** {@inheritDoc}. */
  140. public void popupMenuWillBecomeInvisible(final PopupMenuEvent e) {
  141. //Ignore
  142. }
  143. /** {@inheritDoc}. */
  144. public void popupMenuCanceled(final PopupMenuEvent e) {
  145. //Ignore
  146. }
  147. }