File Source: ServerFrame.java

         /* 
    P/P   *  Method: com.dmdirc.addons.ui_swing.components.frames.ServerFrame__static_init
          */
     1  /*
     2   * Copyright (c) 2006-2009 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  
    23  package com.dmdirc.addons.ui_swing.components.frames;
    24  
    25  import com.dmdirc.Server;
    26  import com.dmdirc.ServerState;
    27  import com.dmdirc.addons.ui_swing.SwingController;
    28  import com.dmdirc.commandparser.PopupType;
    29  import com.dmdirc.commandparser.parsers.CommandParser;
    30  import com.dmdirc.commandparser.parsers.ServerCommandParser;
    31  import com.dmdirc.ui.interfaces.ServerWindow;
    32  import com.dmdirc.addons.ui_swing.components.SwingInputHandler;
    33  import com.dmdirc.addons.ui_swing.dialogs.serversetting.ServerSettingsDialog;
    34  
    35  import java.awt.event.ActionEvent;
    36  import java.awt.event.ActionListener;
    37  
    38  import javax.swing.JMenuItem;
    39  import javax.swing.JPopupMenu;
    40  
    41  import net.miginfocom.swing.MigLayout;
    42  
    43  /**
    44   * The ServerFrame is the MDI window that shows server messages to the user.
    45   */
    46  public final class ServerFrame extends InputTextFrame implements ServerWindow,
    47          ActionListener {
    48  
    49      /**
    50       * A version number for this class. It should be changed whenever the class
    51       * structure is changed (or anything else that would prevent serialized
    52       * objects being unserialized with the new class).
    53       */
    54      private static final long serialVersionUID = 9;
    55      /** This channel's command parser. */
    56      private final ServerCommandParser commandParser;
    57      /** popup menu item. */
    58      private JMenuItem settingsMI;
    59  
    60      /**
    61       * Creates a new ServerFrame.
    62       * 
    63       * @param owner Parent Frame container
    64       * @param controller Swing controller
    65       */
    66      public ServerFrame(final Server owner, final SwingController controller) {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.components.frames.ServerFrame(Server, SwingController)
                  * 
                  *  Preconditions:
                  *    owner != null
                  * 
                  *  Postconditions:
                  *    this.awayLabel == &new JLabel(initComponents#3)
                  *    this.commandParser == &new ServerCommandParser(ServerFrame#1)
                  *    this.inputField == &new SwingInputField(initComponents#1)
                  *    this.inputFieldPopup == &new JPopupMenu(initPopupMenu#1)
                  *    this.inputHandler == &new SwingInputHandler(ServerFrame#2)
                  *    this.inputPanel == &new JPanel(initComponents#4)
                  *    this.nickPopup == &new JPopupMenu(initComponents#2)
                  *    this.settingsMI == &new JMenuItem(initComponents#1)
                  *    new JLabel(SwingInputField#3) num objects == 1
                  *    new JLabel(SwingInputField#4) num objects == 1
                  *    ...
                  */
    67          super(owner, controller);
    68  
    69          initComponents();
    70          
    71          commandParser = new ServerCommandParser((Server) getContainer());
    72  
    73          setInputHandler(new SwingInputHandler(getInputField(), commandParser, this));
    74      }
    75  
    76      /**
    77       * Retrieves the command Parser for this command window.
    78       * @return This window's command Parser
    79       */
    80      @Override
    81      public CommandParser getCommandParser() {
                 /* 
    P/P           *  Method: CommandParser getCommandParser()
                  * 
                  *  Postconditions:
                  *    return_value == this.commandParser
                  *    init'ed(return_value)
                  */
    82          return commandParser;
    83      }
    84  
    85      /**
    86       * Initialises components in this frame.
    87       */
    88      private void initComponents() {
                 /* 
    P/P           *  Method: void initComponents()
                  * 
                  *  Preconditions:
                  *    init'ed(this.inputPanel)
                  * 
                  *  Presumptions:
                  *    com.dmdirc.addons.ui_swing.components.frames.ServerFrame:getContentPane(...)@94 != null
                  *    com.dmdirc.addons.ui_swing.components.frames.ServerFrame:getContentPane(...)@95 != null
                  *    com.dmdirc.addons.ui_swing.components.frames.ServerFrame:getContentPane(...)@96 != null
                  *    com.dmdirc.addons.ui_swing.components.frames.ServerFrame:getContentPane(...)@97 != null
                  * 
                  *  Postconditions:
                  *    this.settingsMI == &new JMenuItem(initComponents#1)
                  *    new JMenuItem(initComponents#1) num objects == 1
                  */
    89          settingsMI = new JMenuItem("Settings");
    90          settingsMI.addActionListener(this);
    91  
    92          setTitle("Server Frame");
    93  
    94          getContentPane().setLayout(new MigLayout("ins 0, fill, hidemode 3, wrap 1"));
    95          getContentPane().add(getTextPane(), "grow, push");
    96          getContentPane().add(getSearchBar(), "growx, pushx");
    97          getContentPane().add(inputPanel, "growx, pushx");
    98  
    99          pack();
   100      }
   101  
   102      /** 
   103       * {@inheritDoc}.
   104       * 
   105       * @param actionEvent Action event
   106       */
   107      @Override
   108      public void actionPerformed(final ActionEvent actionEvent) {
                 /* 
    P/P           *  Method: void actionPerformed(ActionEvent)
                  * 
                  *  Preconditions:
                  *    actionEvent != null
                  *    init'ed(this.settingsMI)
                  * 
                  *  Presumptions:
                  *    com.dmdirc.addons.ui_swing.components.frames.ServerFrame:getController(...)@110 != null
                  *    com.dmdirc.addons.ui_swing.components.frames.TextFrame:getContainer(...)@187 != null
                  */
   109          if (actionEvent.getSource() == settingsMI) {
   110              ServerSettingsDialog.showServerSettingsDialog(getContainer().
   111                      getServer(), getController().getMainFrame());
   112          }
   113      }
   114  
   115      /** {@inheritDoc} */
   116      @Override
   117      public PopupType getNicknamePopupType() {
                 /* 
    P/P           *  Method: PopupType getNicknamePopupType()
                  * 
                  *  Presumptions:
                  *    init'ed(com.dmdirc.commandparser.PopupType.CHAN_NICK)
                  * 
                  *  Postconditions:
                  *    return_value == com.dmdirc.commandparser.PopupType.CHAN_NICK
                  *    init'ed(return_value)
                  */
   118          return PopupType.CHAN_NICK;
   119      }
   120  
   121      /** {@inheritDoc} */
   122      @Override
   123      public PopupType getChannelPopupType() {
                 /* 
    P/P           *  Method: PopupType getChannelPopupType()
                  * 
                  *  Presumptions:
                  *    init'ed(com.dmdirc.commandparser.PopupType.CHAN_NORMAL)
                  * 
                  *  Postconditions:
                  *    return_value == com.dmdirc.commandparser.PopupType.CHAN_NORMAL
                  *    init'ed(return_value)
                  */
   124          return PopupType.CHAN_NORMAL;
   125      }
   126  
   127      /** {@inheritDoc} */
   128      @Override
   129      public PopupType getHyperlinkPopupType() {
                 /* 
    P/P           *  Method: PopupType getHyperlinkPopupType()
                  * 
                  *  Presumptions:
                  *    init'ed(com.dmdirc.commandparser.PopupType.CHAN_HYPERLINK)
                  * 
                  *  Postconditions:
                  *    return_value == com.dmdirc.commandparser.PopupType.CHAN_HYPERLINK
                  *    init'ed(return_value)
                  */
   130          return PopupType.CHAN_HYPERLINK;
   131      }
   132  
   133      /** {@inheritDoc} */
   134      @Override
   135      public PopupType getNormalPopupType() {
                 /* 
    P/P           *  Method: PopupType getNormalPopupType()
                  * 
                  *  Presumptions:
                  *    init'ed(com.dmdirc.commandparser.PopupType.CHAN_NORMAL)
                  * 
                  *  Postconditions:
                  *    return_value == com.dmdirc.commandparser.PopupType.CHAN_NORMAL
                  *    init'ed(return_value)
                  */
   136          return PopupType.CHAN_NORMAL;
   137      }
   138  
   139      /** {@inheritDoc} */
   140      @Override
   141      public void addCustomPopupItems(final JPopupMenu popupMenu) {
                 /* 
    P/P           *  Method: void addCustomPopupItems(JPopupMenu)
                  * 
                  *  Preconditions:
                  *    popupMenu != null
                  *    this.settingsMI != null
                  * 
                  *  Presumptions:
                  *    com.dmdirc.Server:getState(...)@142 != null
                  *    init'ed(com.dmdirc.ServerState.CONNECTED)
                  *    com.dmdirc.WritableFrameContainer:getServer(...)@142 != null
                  *    com.dmdirc.addons.ui_swing.components.frames.TextFrame:getContainer(...)@187 != null
                  * 
                  *  Test Vectors:
                  *    com.dmdirc.ServerState:equals(...)@142: {0}, {1}
                  *    javax.swing.JPopupMenu:getComponentCount(...)@148: {-231..0}, {1..232-1}
                  */
   142          if (getContainer().getServer().getState().equals(ServerState.CONNECTED)) {
   143              settingsMI.setEnabled(true);
   144          } else {
   145              settingsMI.setEnabled(false);
   146          }
   147  
   148          if (popupMenu.getComponentCount() > 0) {
   149              popupMenu.addSeparator();
   150          }
   151          
   152          popupMenu.add(settingsMI);
   153      }
   154  }








SofCheck Inspector Build Version : 2.17854
ServerFrame.java 2009-Jun-25 01:54:24
ServerFrame.class 2009-Sep-02 17:04:17