File Source: NickColourInputDialog.java

         /* 
    P/P   *  Method: com.dmdirc.addons.nickcolours.NickColourInputDialog__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.nickcolours;
    24  
    25  import com.dmdirc.Main;
    26  import com.dmdirc.addons.ui_swing.MainFrame;
    27  import com.dmdirc.addons.ui_swing.components.StandardDialog;
    28  import com.dmdirc.addons.ui_swing.components.ColourChooser;
    29  
    30  import java.awt.event.ActionEvent;
    31  import java.awt.event.ActionListener;
    32  
    33  import javax.swing.JButton;
    34  import javax.swing.JLabel;
    35  import javax.swing.JTextField;
    36  import javax.swing.WindowConstants;
    37  
    38  import net.miginfocom.swing.MigLayout;
    39  
    40  /**
    41   * New nick colour input dialog.
    42   */
    43  public class NickColourInputDialog extends StandardDialog
    44          implements ActionListener {
    45      
    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 = 1;
    52      
    53      /** Whether or not this is a new entry (as opposed to editing an old one). */
    54      private boolean isnew;
    55      /** The row we're editing, if this isn't a new entry. */
    56      private int row;
    57      
    58      /** The NickColourPanel we're reporting to. */
    59      private final NickColourPanel panel;
    60      
    61      /** nickname textfield. */
    62      private JTextField nickname;
    63      /** network textfield. */
    64      private JTextField network;
    65      /** text colour input. */
    66      private ColourChooser textColour;
    67      /** nicklist colour input. */
    68      private ColourChooser nicklistColour;
    69      
    70      /**
    71       * Creates a new instance of NickColourInputDialog.
    72       *
    73       * @param panel The panel that's opening this dialog
    74       * @param row The row of the table we're editing
    75       * @param nickname The nickname that's currently set
    76       * @param network The network that's currently set
    77       * @param textcolour The text colour that's currently set
    78       * @param nickcolour The nicklist colour that's currently set
    79       */
    80      public NickColourInputDialog(final NickColourPanel panel, final int row,
    81              final String nickname, final String network,
    82              final String textcolour, final String nickcolour) {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.nickcolours.NickColourInputDialog(NickColourPanel, int, String, String, String, String)
                  * 
                  *  Presumptions:
                  *    com.dmdirc.Main:getUI(...)@83 != null
                  *    com.dmdirc.Main:getUI(...)@96 != null
                  * 
                  *  Postconditions:
                  *    this.cancelButton == One-of{&new JButton(initComponents#2), &new JButton(initComponents#1)}
                  *    this.cancelButton in Addr_Set{&new JButton(initComponents#1),&new JButton(initComponents#2)}
                  *    this.network == &new JTextField(initComponents#4)
                  *    this.nicklistColour == &new ColourChooser(initComponents#6)
                  *    this.nickname == &new JTextField(initComponents#3)
                  *    this.okButton == One-of{&new JButton(initComponents#1), &new JButton(initComponents#2)}
                  *    this.okButton in Addr_Set{&new JButton(initComponents#1),&new JButton(initComponents#2)}
                  *    this.panel == panel
                  *    init'ed(this.panel)
                  *    this.row == row
                  *    ...
                  */
    83          super((MainFrame) Main.getUI().getMainWindow(), false);
    84          
    85          this.panel = panel;
    86          this.row = row;
    87          
    88          setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    89          
    90          initComponents(nickname, network, textcolour, nickcolour);
    91          initListeners();
    92          layoutComponents();
    93          
    94          setTitle("Nick colour editor");
    95          
    96          setLocationRelativeTo((MainFrame) Main.getUI().getMainWindow());
    97          setVisible(true);
    98      }
    99      
   100      /**
   101       * Creates a new instance of NickColourInputDialog.
   102       *
   103       * @param panel The panel that's opening this dialog
   104       */
   105      public NickColourInputDialog(final NickColourPanel panel) {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.nickcolours.NickColourInputDialog(NickColourPanel)
                  * 
                  *  Postconditions:
                  *    this.cancelButton == One-of{&new JButton(initComponents#2), &new JButton(initComponents#1)}
                  *    this.cancelButton in Addr_Set{&new JButton(initComponents#1),&new JButton(initComponents#2)}
                  *    this.isnew == 1
                  *    new ColourChooser(initComponents#5) num objects == 1
                  *    new ColourChooser(initComponents#5).showHex == 1
                  *    new ColourChooser(initComponents#5).showIRC == 1
                  *    new ColourChooser(initComponents#6) num objects == 1
                  *    new ColourChooser(initComponents#6).showHex == 1
                  *    new ColourChooser(initComponents#6).showIRC == 1
                  *    new EventListenerList(ColourChooser#1) num objects == 1
                  *    ...
                  */
   106          this(panel, -1, "", "", "", "");
   107          
   108          isnew = true;
   109      }
   110      
   111      /**
   112       * Initialises the components.
   113       *
   114       * @param defaultNickname The default value for the nickname text field
   115       * @param defaultNetwork The default value for the network text field
   116       * @param defaultTextColour The default value for the text colour option
   117       * @param defaultNickColour The default value for the nick colour option
   118       */
   119      private void initComponents(final String defaultNickname,
   120              final String defaultNetwork, final String defaultTextColour,
   121              final String defaultNickColour) {        
                 /* 
    P/P           *  Method: void initComponents(String, String, String, String)
                  * 
                  *  Postconditions:
                  *    this.cancelButton == One-of{&new JButton(initComponents#2), &new JButton(initComponents#1)}
                  *    this.cancelButton in Addr_Set{&new JButton(initComponents#1),&new JButton(initComponents#2)}
                  *    this.network == &new JTextField(initComponents#4)
                  *    this.nicklistColour == &new ColourChooser(initComponents#6)
                  *    this.nickname == &new JTextField(initComponents#3)
                  *    this.okButton == One-of{&new JButton(initComponents#1), &new JButton(initComponents#2)}
                  *    this.okButton in Addr_Set{&new JButton(initComponents#1),&new JButton(initComponents#2)}
                  *    this.textColour == &new ColourChooser(initComponents#5)
                  *    new ColourChooser(initComponents#5) num objects == 1
                  *    this.textColour.showHex == 1
                  *    ...
                  */
   122          orderButtons(new JButton(), new JButton());
   123          
   124          nickname = new JTextField(defaultNickname);
   125          network = new JTextField(defaultNetwork);
   126          textColour = new ColourChooser(defaultTextColour, true, true);
   127          nicklistColour = new ColourChooser(defaultNickColour, true, true);
   128      }
   129      
   130      /** Initialises the listeners. */
   131      private void initListeners() {
                 /* 
    P/P           *  Method: void initListeners()
                  * 
                  *  Preconditions:
                  *    this.cancelButton != null
                  *    this.okButton != null
                  */
   132          getOkButton().addActionListener(this);
   133          getCancelButton().addActionListener(this);
   134      }
   135      
   136      /** Lays out the components. */
   137      private void layoutComponents() {        
                 /* 
    P/P           *  Method: void layoutComponents()
                  * 
                  *  Preconditions:
                  *    init'ed(this.network)
                  *    init'ed(this.nicklistColour)
                  *    init'ed(this.nickname)
                  *    init'ed(this.textColour)
                  *    (soft) init'ed(this.cancelButton)
                  *    (soft) init'ed(this.okButton)
                  */
   138          setLayout(new MigLayout("wrap 2"));
   139          
   140          add(new JLabel("Nickname: "));
   141          add(nickname, "growx");
   142          
   143          add(new JLabel("Network: "));
   144          add(network, "growx");
   145          
   146          add(new JLabel("Text colour: "));
   147          add(textColour, "growx");
   148          
   149          add(new JLabel("Nicklist colour: "));
   150          add(nicklistColour, "growx");
   151          
   152          add(getLeftButton(), "right");
   153          add(getRightButton(), "right");
   154          
   155          pack();
   156      }
   157      
   158      /** 
   159       * {@inheritDoc} 
   160       * 
   161       * @param e Action event
   162       */
   163      @Override
   164      public void actionPerformed(final ActionEvent e) {
                 /* 
    P/P           *  Method: void actionPerformed(ActionEvent)
                  * 
                  *  Preconditions:
                  *    e != null
                  *    init'ed(this.okButton)
                  *    (soft) init'ed(this.isnew)
                  *    (soft) this.network != null
                  *    (soft) this.nicklistColour != null
                  *    (soft) init'ed(this.nicklistColour.value)
                  *    (soft) this.nickname != null
                  *    (soft) this.panel != null
                  *    (soft) this.panel.table != null
                  *    (soft) init'ed(this.row)
                  *    ...
                  */
   165          if (e.getSource() == getOkButton()) {
   166              saveSettings();
   167          }
   168          dispose();
   169      }
   170      
   171      /** Saves settings. */
   172      public void saveSettings() {
                 /* 
    P/P           *  Method: void saveSettings()
                  * 
                  *  Preconditions:
                  *    init'ed(this.isnew)
                  *    this.network != null
                  *    this.nicklistColour != null
                  *    init'ed(this.nicklistColour.value)
                  *    this.nickname != null
                  *    this.panel != null
                  *    this.panel.table != null
                  *    this.textColour != null
                  *    init'ed(this.textColour.value)
                  *    (soft) init'ed(this.row)
                  * 
                  *  Presumptions:
                  *    javax.swing.JTextField:getText(...)@173 != null
                  *    javax.swing.JTextField:getText(...)@174 != null
                  * 
                  *  Test Vectors:
                  *    this.isnew: {1}, {0}
                  */
   173          final String myNetwork = network.getText().toLowerCase();
   174          final String myNickname = nickname.getText().toLowerCase();
   175          final String myTextColour = textColour.getColour();
   176          final String myNickColour = nicklistColour.getColour();
   177          
   178          if (!isnew) {
   179              panel.removeRow(row);
   180          }
   181          
   182          panel.addRow(myNetwork, myNickname, myTextColour, myNickColour);
   183      }
   184      
   185  }








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