File Source: ChannelSettingsDialog.java

         /* 
    P/P   *  Method: com.dmdirc.addons.ui_swing.dialogs.channelsetting.ChannelSettingsDialog__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.dialogs.channelsetting;
    24  
    25  import com.dmdirc.Channel;
    26  import com.dmdirc.config.Identity;
    27  import com.dmdirc.config.IdentityManager;
    28  import com.dmdirc.addons.ui_swing.UIUtilities;
    29  import com.dmdirc.addons.ui_swing.components.StandardDialog;
    30  import com.dmdirc.addons.ui_swing.components.expandingsettings.SettingsPanel;
    31  import com.dmdirc.addons.ui_swing.components.expandingsettings.SettingsPanel.OptionType;
    32  
    33  import java.awt.Window;
    34  import java.awt.event.ActionEvent;
    35  import java.awt.event.ActionListener;
    36  
    37  import javax.swing.JButton;
    38  import javax.swing.JScrollPane;
    39  import javax.swing.JTabbedPane;
    40  import javax.swing.WindowConstants;
    41  
    42  import net.miginfocom.swing.MigLayout;
    43  
    44  /**
    45   * Allows the user to modify channel settings (modes, topics, etc).
    46   */
    47  public final class ChannelSettingsDialog extends StandardDialog implements 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 = 8;
    55  
    56      /** Channel settings dialogs, semi singleton use. */
    57      private static volatile ChannelSettingsDialog me;
    58  
    59      /** The channel object that this dialog belongs to. */
    60      private final Channel channel;
    61  
    62      /** Tabbed pane. */
    63      private JTabbedPane tabbedPane;
    64  
    65      /** Client settings panel. */
    66      private SettingsPanel channelSettingsPane;
    67  
    68      /** List modes panel. */
    69      private ChannelModesPane channelModesPane;
    70  
    71      /** List modes panel. */
    72      private TopicPane topicModesPane;
    73  
    74      /** List modes panel. */
    75      private ChannelListModesPane channelListModesPane;
    76  
    77      /** Channel identity file. */
    78      private final Identity identity;
    79  
    80      /**
    81       * Creates a new instance of ChannelSettingsDialog.
    82       *
    83       * @param newChannel The channel object that we're editing settings for
    84       */
    85      private ChannelSettingsDialog(final Channel newChannel, 
    86              final Window parentWindow) {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.dialogs.channelsetting.ChannelSettingsDialog(Channel, Window)
                  * 
                  *  Preconditions:
                  *    newChannel != null
                  * 
                  *  Presumptions:
                  *    com.dmdirc.Channel:getChannelInfo(...)@90 != null
                  *    com.dmdirc.Channel:getServer(...)@90 != null
                  *    init'ed(java.awt.Dialog$ModalityType.MODELESS)
                  * 
                  *  Postconditions:
                  *    this.channel == newChannel
                  *    this.channel != null
                  *    init'ed(this.identity)
                  */
    87          super(parentWindow, ModalityType.MODELESS);
    88  
    89          channel = newChannel;
    90          identity = IdentityManager.getChannelConfig(channel.getServer().
    91                  getNetwork(), channel.getChannelInfo().getName());
    92  
    93          initComponents();
    94          initListeners();
    95      }
    96  
    97      /**
    98       * Creates the dialog if one doesn't exist, and displays it.
    99       *
   100       * @param channel The channel object that we're editing settings for
   101       * @param parentWindow Parent window
   102       */
   103      public static void showChannelSettingsDialog(
   104              final Channel channel, final Window parentWindow) {
                 /* 
    P/P           *  Method: void showChannelSettingsDialog(Channel, Window)
                  * 
                  *  Preconditions:
                  *    init'ed(me)
                  *    (soft) channel != null
                  * 
                  *  Postconditions:
                  *    me == One-of{old me, &new ChannelSettingsDialog(getChannelSettingsDialog#1)}
                  *    me != null
                  *    new ChannelSettingsDialog(getChannelSettingsDialog#1) num objects <= 1
                  *    new ChannelSettingsDialog(getChannelSettingsDialog#1).channel == channel
                  *    new ChannelSettingsDialog(getChannelSettingsDialog#1).channel != null
                  *    init'ed(new ChannelSettingsDialog(getChannelSettingsDialog#1).identity)
                  */
   105          me = getChannelSettingsDialog(channel, parentWindow);
   106  
   107          me.pack();
   108          me.setLocationRelativeTo(parentWindow);
   109          me.setVisible(true);
   110          me.requestFocusInWindow();
   111      }
   112  
   113      /**
   114       * Returns the current instance of the ChannelSettingsDialog.
   115       *
   116       * @param channel The channel object that we're editing settings for
   117       * @param parentWindow Parent window
   118       *
   119       * @return The current ChannelSettingsDialog instance
   120       */
   121      public static ChannelSettingsDialog getChannelSettingsDialog(
   122              final Channel channel, final Window parentWindow) {
                 /* 
    P/P           *  Method: ChannelSettingsDialog getChannelSettingsDialog(Channel, Window)
                  * 
                  *  Preconditions:
                  *    init'ed(me)
                  *    (soft) channel != null
                  * 
                  *  Postconditions:
                  *    me == One-of{old me, &amp;new ChannelSettingsDialog(getChannelSettingsDialog#1)}
                  *    me != null
                  *    return_value == One-of{old me, &amp;new ChannelSettingsDialog(getChannelSettingsDialog#1)}
                  *    return_value != null
                  *    new ChannelSettingsDialog(getChannelSettingsDialog#1) num objects <= 1
                  *    new ChannelSettingsDialog(getChannelSettingsDialog#1).channel == channel
                  *    new ChannelSettingsDialog(getChannelSettingsDialog#1).channel != null
                  *    init'ed(new ChannelSettingsDialog(getChannelSettingsDialog#1).identity)
                  */
   123          synchronized (ChannelSettingsDialog.class) {
   124              if (me == null) {
   125                  me = new ChannelSettingsDialog(channel, parentWindow);
   126              }
   127          }
   128  
   129          return me;
   130      }
   131  
   132      /** Initialises the main UI components. */
   133      private void initComponents() {
                 /* 
    P/P           *  Method: void initComponents()
                  * 
                  *  Preconditions:
                  *    this.channel != null
                  * 
                  *  Presumptions:
                  *    com.dmdirc.Channel:getConfigManager(...)@155 != null
                  *    com.dmdirc.addons.ui_swing.dialogs.channelsetting.ChannelSettingsDialog:getContentPane(...)@142 != null
                  *    com.dmdirc.addons.ui_swing.dialogs.channelsetting.ChannelSettingsDialog:getContentPane(...)@143 != null
                  *    com.dmdirc.addons.ui_swing.dialogs.channelsetting.ChannelSettingsDialog:getContentPane(...)@144 != null
                  *    com.dmdirc.addons.ui_swing.dialogs.channelsetting.ChannelSettingsDialog:getContentPane(...)@145 != null
                  * 
                  *  Postconditions:
                  *    this.channelListModesPane == &amp;new ChannelListModesPane(initListModesTab#1)
                  *    this.channelModesPane == &amp;new ChannelModesPane(initIrcTab#1)
                  *    this.channelSettingsPane == &amp;new SettingsPanel(initSettingsPanel#1)
                  *    this.tabbedPane == &amp;new JTabbedPane(initComponents#1)
                  *    this.topicModesPane == &amp;new TopicPane(initTopicTab#1)
                  *    new ArrayList(ChannelListModesPane#4) num objects == 1
                  *    new ChannelListModesPane(initListModesTab#1) num objects == 1
                  *    new ChannelModesPane(initIrcTab#1) num objects == 1
                  *    new Hashtable(initModesPanel#14) num objects == 1
                  *    new Hashtable(initModesPanel#2) num objects == 1
                  *    ...
                  */
   134          tabbedPane = new JTabbedPane();
   135  
   136          setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
   137          setTitle("Channel settings for " + channel);
   138          setResizable(false);
   139  
   140          orderButtons(new JButton(), new JButton());
   141  
   142          getContentPane().setLayout(new MigLayout("fill, wrap 1, ins panel, hmax 80sp"));
   143          getContentPane().add(tabbedPane, "growy, pushy, wmin 460, wmax 460");
   144          getContentPane().add(getLeftButton(), "split 3, right");
   145          getContentPane().add(getRightButton(), "right");
   146  
   147          initTopicTab();
   148  
   149          initIrcTab();
   150  
   151          initListModesTab();
   152  
   153          initSettingsTab();
   154  
   155          tabbedPane.setSelectedIndex(channel.getConfigManager().
   156                  getOptionInt("dialogstate", "channelsettingsdialog"));
   157      }
   158  
   159      /** Initialises the Topic tab. */
   160      private void initTopicTab() {
                 /* 
    P/P           *  Method: void initTopicTab()
                  * 
                  *  Preconditions:
                  *    this.channel != null
                  *    this.tabbedPane != null
                  * 
                  *  Postconditions:
                  *    this.topicModesPane == &amp;new TopicPane(initTopicTab#1)
                  *    new JComboBox(initTopicsPanel#3) num objects == 1
                  *    new JLabel(initTopicsPanel#1) num objects == 1
                  *    new SimpleAttributeSet(TextLabel#6) num objects == 1
                  *    new TextAreaInputField(initTopicsPanel#2) num objects == 1
                  *    new TextLabel(initTopicsPanel#5) num objects == 1
                  *    new TopicPane(initTopicTab#1) num objects == 1
                  *    new TextLabel(initTopicsPanel#5).sas == &amp;new SimpleAttributeSet(TextLabel#6)
                  *    this.topicModesPane.channel == this.channel
                  *    this.topicModesPane.channel != null
                  *    ...
                  */
   161          topicModesPane = new TopicPane(channel, this);
   162          tabbedPane.addTab("Topic", topicModesPane);
   163      }
   164  
   165      /** Initialises the IRC Settings tab. */
   166      private void initIrcTab() {
                 /* 
    P/P           *  Method: void initIrcTab()
                  * 
                  *  Preconditions:
                  *    this.channel != null
                  *    this.tabbedPane != null
                  * 
                  *  Presumptions:
                  *    javax.swing.JScrollPane:getViewport(...)@172 != null
                  * 
                  *  Postconditions:
                  *    this.channelModesPane == &amp;new ChannelModesPane(initIrcTab#1)
                  *    new ChannelModesPane(initIrcTab#1) num objects == 1
                  *    new Hashtable(initModesPanel#14) num objects == 1
                  *    new Hashtable(initModesPanel#2) num objects == 1
                  *    this.channelModesPane.channel == this.channel
                  *    this.channelModesPane.channel != null
                  *    this.channelModesPane.modeCheckBoxes == &amp;new Hashtable(initModesPanel#2)
                  *    this.channelModesPane.modeInputs == &amp;new Hashtable(initModesPanel#14)
                  */
   167          channelModesPane = new ChannelModesPane(channel);
   168  
   169          final JScrollPane channelModesSP = new JScrollPane(channelModesPane);
   170          channelModesSP.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
   171          channelModesSP.setOpaque(UIUtilities.getTabbedPaneOpaque());
   172          channelModesSP.getViewport().setOpaque(UIUtilities.getTabbedPaneOpaque());
   173          channelModesSP.setBorder(null);
   174  
   175          tabbedPane.addTab("Channel Modes", channelModesSP);
   176      }
   177  
   178      /** Initialises the IRC Settings tab. */
   179      private void initListModesTab() {
                 /* 
    P/P           *  Method: void initListModesTab()
                  * 
                  *  Preconditions:
                  *    this.channel != null
                  *    this.tabbedPane != null
                  * 
                  *  Postconditions:
                  *    this.channelListModesPane == &amp;new ChannelListModesPane(initListModesTab#1)
                  *    new ArrayList(ChannelListModesPane#4) num objects == 1
                  *    new ChannelListModesPane(initListModesTab#1) num objects == 1
                  *    new JButton(ChannelListModesPane#8) num objects == 1
                  *    new JButton(ChannelListModesPane#9) num objects == 1
                  *    new JCheckBox(ChannelListModesPane#11) num objects == 1
                  *    new JComboBox(ChannelListModesPane#6) num objects == 1
                  *    new JLabel(ChannelListModesPane#10) num objects == 1
                  *    new JScrollPane(ChannelListModesPane#3) num objects == 1
                  *    new MapList(ChannelListModesPane#5) num objects == 1
                  *    ...
                  */
   180          channelListModesPane = new ChannelListModesPane(channel);
   181          tabbedPane.addTab("List Modes", channelListModesPane);
   182      }
   183  
   184      /** Initialises the channel Settings (identities) tab. */
   185      private void initSettingsTab() {
                 /* 
    P/P           *  Method: void initSettingsTab()
                  * 
                  *  Preconditions:
                  *    this.tabbedPane != null
                  * 
                  *  Postconditions:
                  *    this.channelSettingsPane == &amp;new SettingsPanel(initSettingsPanel#1)
                  *    new SettingsPanel(initSettingsPanel#1) num objects == 1
                  */
   186          initSettingsPanel();
   187  
   188          tabbedPane.addTab("Client Settings", channelSettingsPane);
   189      }
   190  
   191      /** Initialises the channel settings. */
   192      private void initSettingsPanel() {
                 /* 
    P/P           *  Method: void initSettingsPanel()
                  * 
                  *  Presumptions:
                  *    init'ed(com.dmdirc.addons.ui_swing.components.expandingsettings.SettingsPanel$OptionType.CHECKBOX)
                  *    init'ed(com.dmdirc.addons.ui_swing.components.expandingsettings.SettingsPanel$OptionType.COLOUR)
                  *    init'ed(com.dmdirc.addons.ui_swing.components.expandingsettings.SettingsPanel$OptionType.SPINNER)
                  *    init'ed(com.dmdirc.addons.ui_swing.components.expandingsettings.SettingsPanel$OptionType.TEXTFIELD)
                  * 
                  *  Postconditions:
                  *    this.channelSettingsPane == &amp;new SettingsPanel(initSettingsPanel#1)
                  *    new SettingsPanel(initSettingsPanel#1) num objects == 1
                  */
   193          channelSettingsPane = new SettingsPanel(identity,
   194                  "These settings are specific to this channel on this network," +
   195                  " any settings specified here will overwrite global settings");
   196  
   197          channelSettingsPane.addOption("channel.splitusermodes",
   198                  "Split user modes", OptionType.CHECKBOX);
   199          channelSettingsPane.addOption("channel.sendwho",
   200                  "Send channel WHOs", OptionType.CHECKBOX);
   201          channelSettingsPane.addOption("channel.showmodeprefix",
   202                  "Show mode prefixes", OptionType.CHECKBOX);
   203          channelSettingsPane.addOption("ui.shownickcoloursinnicklist",
   204                  "Show colours in nicklist", OptionType.CHECKBOX);
   205          channelSettingsPane.addOption("ui.shownickcoloursintext",
   206                  "Show colours in textpane", OptionType.CHECKBOX);
   207          channelSettingsPane.addOption("general.cyclemessage",
   208                  "Cycle message", OptionType.TEXTFIELD);
   209          channelSettingsPane.addOption("general.kickmessage",
   210                  "Kick message", OptionType.TEXTFIELD);
   211          channelSettingsPane.addOption("general.partmessage",
   212                  "Part message", OptionType.TEXTFIELD);
   213          channelSettingsPane.addOption("ui.backgroundcolour",
   214                  "Background colour", OptionType.COLOUR);
   215          channelSettingsPane.addOption("ui.foregroundcolour",
   216                  "Foreground colour", OptionType.COLOUR);
   217          channelSettingsPane.addOption("ui.frameBufferSize",
   218                  "Frame buffer size", OptionType.SPINNER);
   219          channelSettingsPane.addOption("ui.textPaneFontName", "Textpane font name",
   220                  OptionType.TEXTFIELD);
   221          //TODO issue 2251
   222          //channelSettingsPane.addOption("ui.textPaneFontSize", "Textpane font size",
   223          //        OptionType.SPINNER);
   224          channelSettingsPane.addOption("ui.inputbuffersize",
   225                  "Input buffer size", OptionType.SPINNER);
   226          channelSettingsPane.addOption("ui.inputbackgroundcolour",
   227                  "Inputfield background colour", OptionType.COLOUR);
   228          channelSettingsPane.addOption("ui.inputforegroundcolour",
   229                  "Inputfield foreground colour", OptionType.COLOUR);
   230          channelSettingsPane.addOption("ui.nicklistbackgroundcolour",
   231                  "Nicklist background colour", OptionType.COLOUR);
   232          channelSettingsPane.addOption("ui.nicklistforegroundcolour",
   233                  "Nicklist foreground colour", OptionType.COLOUR);
   234          channelSettingsPane.addOption("channel.encoding", "Encoding",
   235                  OptionType.TEXTFIELD);
   236      }
   237  
   238      /** Initialises listeners for this dialog. */
   239      private void initListeners() {
                 /* 
    P/P           *  Method: void initListeners()
                  * 
                  *  Presumptions:
                  *    com.dmdirc.addons.ui_swing.dialogs.channelsetting.ChannelSettingsDialog:getCancelButton(...)@241 != null
                  *    com.dmdirc.addons.ui_swing.dialogs.channelsetting.ChannelSettingsDialog:getOkButton(...)@240 != null
                  */
   240          getOkButton().addActionListener(this);
   241          getCancelButton().addActionListener(this);
   242      }
   243  
   244      /**
   245       * Called whenever the user clicks on one of the two buttons.
   246       *
   247       * @param actionEvent Event generated by this action
   248       */
   249      @Override
   250      public void actionPerformed(final ActionEvent actionEvent) {
                 /* 
    P/P           *  Method: void actionPerformed(ActionEvent)
                  * 
                  *  Preconditions:
                  *    actionEvent != null
                  *    (soft) init'ed(me)
                  *    (soft) this.channelListModesPane != null
                  *    (soft) this.channelListModesPane.channel != null
                  *    (soft) this.channelListModesPane.existingListItems != null
                  *    (soft) this.channelListModesPane.listModesArray != null
                  *    (soft) this.channelListModesPane.listModesArray.length <= 232-1
                  *    (soft) init'ed(this.channelListModesPane.listModesArray[...])
                  *    (soft) this.channelListModesPane.listModesPanels != null
                  *    (soft) this.channelListModesPane.toggle != null
                  *    ...
                  * 
                  *  Presumptions:
                  *    com.dmdirc.addons.ui_swing.dialogs.channelsetting.ChannelSettingsDialog:getCancelButton(...)@253 != null
                  *    com.dmdirc.addons.ui_swing.dialogs.channelsetting.ChannelSettingsDialog:getOkButton(...)@251 != null
                  * 
                  *  Postconditions:
                  *    me == One-of{old me, null}
                  *    init'ed(me)
                  * 
                  *  Test Vectors:
                  *    java.lang.Object:equals(...)@251: {0}, {1}
                  *    java.lang.Object:equals(...)@253: {0}, {1}
                  */
   251          if (getOkButton().equals(actionEvent.getSource())) {
   252              save();
   253          } else if (getCancelButton().equals(actionEvent.getSource())) {
   254              dispose();
   255          }
   256      }
   257  
   258      /** Saves the settings. */
   259      protected void save() {
                 /* 
    P/P           *  Method: void save()
                  * 
                  *  Preconditions:
                  *    init'ed(me)
                  *    this.channelListModesPane != null
                  *    this.channelListModesPane.channel != null
                  *    this.channelListModesPane.listModesArray != null
                  *    this.channelListModesPane.listModesArray.length <= 232-1
                  *    this.channelListModesPane.toggle != null
                  *    this.channelModesPane != null
                  *    this.channelModesPane.channel != null
                  *    this.channelSettingsPane != null
                  *    this.identity != null
                  *    ...
                  * 
                  *  Postconditions:
                  *    me == null
                  */
   260          channelModesPane.setChangedBooleanModes();
   261          topicModesPane.setChangedTopic();
   262          channelSettingsPane.save();
   263          channelListModesPane.save();
   264  
   265          identity.setOption("dialogstate", "channelsettingsdialog",
   266                  String.valueOf(tabbedPane.getSelectedIndex()));
   267  
   268          dispose();
   269      }
   270      
   271      /** {@inheritDoc} */
   272      @Override
   273      public void dispose() {
                 /* 
    P/P           *  Method: void dispose()
                  * 
                  *  Preconditions:
                  *    init'ed(me)
                  * 
                  *  Postconditions:
                  *    me == null
                  * 
                  *  Test Vectors:
                  *    me: Inverse{null}, Addr_Set{null}
                  */
   274          if (me == null) {
   275              return;
   276          }
   277          synchronized (me) {
   278              super.dispose();
   279              me = null;
   280          }
   281      }
   282  }








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