File Source: ActionsManagerDialog.java

         /* 
    P/P   *  Method: com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsManagerDialog__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.actionsmanager;
    24  
    25  import com.dmdirc.actions.Action;
    26  import com.dmdirc.actions.ActionGroup;
    27  import com.dmdirc.actions.ActionManager;
    28  import com.dmdirc.actions.CoreActionType;
    29  import com.dmdirc.actions.interfaces.ActionType;
    30  import com.dmdirc.config.IdentityManager;
    31  import com.dmdirc.config.prefs.validator.ActionGroupValidator;
    32  import com.dmdirc.config.prefs.validator.FileNameValidator;
    33  import com.dmdirc.config.prefs.validator.ValidatorChain;
    34  import com.dmdirc.addons.ui_swing.components.text.TextLabel;
    35  import com.dmdirc.addons.ui_swing.components.ListScroller;
    36  import com.dmdirc.addons.ui_swing.components.StandardDialog;
    37  import com.dmdirc.addons.ui_swing.components.StandardInputDialog;
    38  import com.dmdirc.addons.ui_swing.components.renderers.ActionGroupListCellRenderer;
    39  import com.dmdirc.addons.ui_swing.dialogs.actioneditor.ActionEditorDialog;
    40  
    41  import java.awt.Window;
    42  import java.awt.event.ActionEvent;
    43  import java.awt.event.ActionListener;
    44  import java.awt.event.WindowAdapter;
    45  import java.awt.event.WindowEvent;
    46  import java.util.HashMap;
    47  import java.util.Map;
    48  
    49  import javax.swing.BorderFactory;
    50  import javax.swing.DefaultListModel;
    51  import javax.swing.JButton;
    52  import javax.swing.JList;
    53  import javax.swing.JOptionPane;
    54  import javax.swing.JPanel;
    55  import javax.swing.JScrollPane;
    56  import javax.swing.ListSelectionModel;
    57  import javax.swing.event.ListSelectionEvent;
    58  import javax.swing.event.ListSelectionListener;
    59  
    60  import net.miginfocom.swing.MigLayout;
    61  
    62  /**
    63   * Allows the user to manage actions.
    64   */
         /* 
    P/P   *  Method: void access$100(ActionsManagerDialog)
          * 
          *  Preconditions:
          *    x0 != null
          *    x0.groups != null
          */
    65  public final class ActionsManagerDialog extends StandardDialog implements ActionListener,
    66          ListSelectionListener, com.dmdirc.interfaces.ActionListener {
    67  
    68      /**
    69       * A version number for this class. It should be changed whenever the class
    70       * structure is changed (or anything else that would prevent serialized
    71       * objects being unserialized with the new class).
    72       */
    73      private static final long serialVersionUID = 1;
    74      /** Previously created instance of ActionsManagerDialog. */
    75      private static volatile ActionsManagerDialog me;
    76      /** Info label. */
    77      private TextLabel infoLabel;
    78      /** Group list. */
    79      private JList groups;
    80      /** Add button. */
    81      private JButton add;
    82      /** Edit button. */
    83      private JButton edit;
    84      /** Delete button. */
    85      private JButton delete;
    86      /** Info panel. */
    87      private ActionGroupInformationPanel info;
    88      /** Actions panel. */
    89      private ActionsGroupPanel actions;
    90      /** Settings panels. */
    91      private Map<ActionGroup, ActionGroupSettingsPanel> settings;
    92      /** Active s panel. */
    93      private ActionGroupSettingsPanel activeSettings;
    94      /** Group panel. */
    95      private JPanel groupPanel;
    96  
    97      /** Creates a new instance of ActionsManagerDialog. */
    98      private ActionsManagerDialog() {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsManagerDialog()
                  * 
                  *  Presumptions:
                  *    init'ed(java.awt.Dialog$ModalityType.MODELESS)
                  *    this.activeSettings != null
                  *    this.add != null
                  *    this.delete != null
                  *    this.edit != null
                  *    ...
                  * 
                  *  Postconditions:
                  *    init'ed(this.actions)
                  *    init'ed(this.activeSettings)
                  *    init'ed(this.add)
                  *    init'ed(this.delete)
                  *    init'ed(this.edit)
                  *    init'ed(this.groupPanel)
                  *    init'ed(this.groups)
                  *    init'ed(this.info)
                  *    init'ed(this.infoLabel)
                  */
    99          super(null, ModalityType.MODELESS);
   100  
   101          initComponents();
   102          addListeners();
   103          layoutGroupPanel();
   104          layoutComponents();
   105  
   106          setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
   107          setTitle("DMDirc: Action Manager");
   108          setResizable(false);
   109      }
   110  
   111      /** 
   112       * Creates the dialog if one doesn't exist, and displays it. 
   113       * 
   114       * @param parentWindow Parent window
   115       */
   116      public static void showActionsManagerDialog(final Window parentWindow) {
                 /* 
    P/P           *  Method: void showActionsManagerDialog(Window)
                  * 
                  *  Preconditions:
                  *    init'ed(me)
                  *    parentWindow != null
                  * 
                  *  Presumptions:
                  *    com.dmdirc.config.IdentityManager:getGlobalConfig(...)@125 != null
                  *    javax.swing.JList:getModel(...)@127 != null
                  *    javax.swing.JList:getModel(...)@129 != null
                  *    me.actions != null
                  *    me.actions.add != null
                  *    ...
                  * 
                  *  Postconditions:
                  *    me == One-of{&amp;new ActionsManagerDialog(getActionsManagerDialog#1), old me}
                  *    me != null
                  *    init'ed(me.actions.group)
                  *    init'ed(me.actions.model.actions)
                  *    init'ed(me.activeSettings)
                  *    init'ed(me.info.group)
                  *    new ActionsManagerDialog(getActionsManagerDialog#1) num objects <= 1
                  *    init'ed(new ActionsManagerDialog(getActionsManagerDialog#1).actions)
                  *    init'ed(new ActionsManagerDialog(getActionsManagerDialog#1).activeSettings)
                  *    init'ed(new ActionsManagerDialog(getActionsManagerDialog#1).add)
                  *    ...
                  * 
                  *  Test Vectors:
                  *    com.dmdirc.config.ConfigManager:getOptionInt(...)@125: {-231..-1}, {0..232-2}
                  */
   117          getActionsManagerDialog();
   118  
   119          me.setIconImages(parentWindow.getIconImages());
   120          me.pack();
   121          me.setLocationRelativeTo(parentWindow);
   122          me.setVisible(true);
   123          me.requestFocusInWindow();
   124  
   125          final int selected = IdentityManager.getGlobalConfig().
   126                  getOptionInt("dialogstate", "actionsmanagerdialog");
   127          if (selected >= 0 && selected < me.groups.getModel().getSize()) {
   128              me.groups.setSelectedIndex(selected);
   129              me.changeActiveGroup((ActionGroup) me.groups.getModel().getElementAt(selected));
   130          }
   131      }
   132  
   133      /**
   134       * Returns the current instance of the ActionsManagerDialog.
   135       *
   136       * @return The current ActionsManagerDialog instance
   137       */
   138      public static ActionsManagerDialog getActionsManagerDialog() {
                 /* 
    P/P           *  Method: ActionsManagerDialog getActionsManagerDialog()
                  * 
                  *  Preconditions:
                  *    init'ed(me)
                  * 
                  *  Presumptions:
                  *    me.groups != null
                  * 
                  *  Postconditions:
                  *    me == One-of{&amp;new ActionsManagerDialog(getActionsManagerDialog#1), old me}
                  *    me != null
                  *    return_value == One-of{&amp;new ActionsManagerDialog(getActionsManagerDialog#1), old me}
                  *    return_value != null
                  *    new ActionsManagerDialog(getActionsManagerDialog#1) num objects <= 1
                  *    init'ed(new ActionsManagerDialog(getActionsManagerDialog#1).actions)
                  *    init'ed(new ActionsManagerDialog(getActionsManagerDialog#1).activeSettings)
                  *    init'ed(new ActionsManagerDialog(getActionsManagerDialog#1).add)
                  *    init'ed(new ActionsManagerDialog(getActionsManagerDialog#1).delete)
                  *    init'ed(new ActionsManagerDialog(getActionsManagerDialog#1).edit)
                  *    ...
                  * 
                  *  Test Vectors:
                  *    me: Inverse{null}, Addr_Set{null}
                  */
   139          synchronized (ActionsManagerDialog.class) {
   140              if (me == null) {
   141                  me = new ActionsManagerDialog();
   142              } else {
   143                  me.reloadGroups();
   144              }
   145          }
   146  
   147          return me;
   148      }
   149  
   150      /**
   151       * Initialises the components.
   152       */
   153      private void initComponents() {
                 /* 
    P/P           *  Method: void initComponents()
                  * 
                  *  Postconditions:
                  *    this.actions == &amp;new ActionsGroupPanel(initComponents#6)
                  *    this.activeSettings == &amp;new ActionGroupSettingsPanel(initComponents#9)
                  *    this.add == &amp;new JButton(initComponents#10)
                  *    this.delete == &amp;new JButton(initComponents#12)
                  *    this.edit == &amp;new JButton(initComponents#11)
                  *    this.groupPanel == &amp;new JPanel(initComponents#13)
                  *    this.groups == &amp;new JList(initComponents#4)
                  *    this.info == &amp;new ActionGroupInformationPanel(initComponents#7)
                  *    this.infoLabel == &amp;new TextLabel(initComponents#3)
                  *    this.settings == &amp;new HashMap(initComponents#8)
                  *    ...
                  */
   154          orderButtons(new JButton(), new JButton());
   155          infoLabel = new TextLabel("Actions allow you to make DMDirc" +
   156                  " intelligently respond to various events.");
   157          groups = new JList(new DefaultListModel());
   158          actions = new ActionsGroupPanel(this, null);
   159          info = new ActionGroupInformationPanel(null);
   160          settings = new HashMap<ActionGroup, ActionGroupSettingsPanel>();
   161          activeSettings = new ActionGroupSettingsPanel(null, this);
   162          settings.put(null, activeSettings);
   163          add = new JButton("Add");
   164          edit = new JButton("Edit");
   165          delete = new JButton("Delete");
   166          groupPanel = new JPanel();
   167          groupPanel.setName("Groups");
   168  
   169          groupPanel.setBorder(BorderFactory.createTitledBorder(groupPanel.getBorder(),
   170                  "Groups"));
   171          info.setBorder(BorderFactory.createTitledBorder(info.getBorder(),
   172                  "Information"));
   173          actions.setBorder(BorderFactory.createTitledBorder(actions.getBorder(),
   174                  "Actions"));
   175  
   176          groups.setCellRenderer(new ActionGroupListCellRenderer());
   177          groups.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
   178          edit.setEnabled(false);
   179          delete.setEnabled(false);
   180  
   181          info.setVisible(false);
   182          activeSettings.setVisible(false);
   183  
   184          new ListScroller(groups);
   185  
   186          reloadGroups();
   187      }
   188  
   189      /**
   190       * Adds listeners.
   191       */
   192      private void addListeners() {
                 /* 
    P/P           *  Method: void addListeners()
                  * 
                  *  Preconditions:
                  *    this.add != null
                  *    this.delete != null
                  *    this.edit != null
                  *    this.groups != null
                  * 
                  *  Presumptions:
                  *    init'ed(com.dmdirc.actions.CoreActionType.ACTION_CREATED)
                  *    init'ed(com.dmdirc.actions.CoreActionType.ACTION_DELETED)
                  *    init'ed(com.dmdirc.actions.CoreActionType.ACTION_UPDATED)
                  *    com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsManagerDialog:getCancelButton(...)@194 != null
                  *    com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsManagerDialog:getOkButton(...)@193 != null
                  *    ...
                  */
   193          getOkButton().addActionListener(this);
   194          getCancelButton().addActionListener(this);
   195          add.addActionListener(this);
   196          edit.addActionListener(this);
   197          delete.addActionListener(this);
   198          groups.getSelectionModel().addListSelectionListener(this);
   199          ActionManager.addListener(this, CoreActionType.ACTION_CREATED);
   200          ActionManager.addListener(this, CoreActionType.ACTION_UPDATED);
   201          ActionManager.addListener(this, CoreActionType.ACTION_DELETED);
   202  
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsManagerDialog$1(ActionsManagerDialog)
                  */
   203          addWindowListener(new WindowAdapter() {
   204  
   205              /** {@inheritDoc} */
   206              @Override
   207              public void windowClosing(final WindowEvent e) {
                         /* 
    P/P                   *  Method: void windowClosing(WindowEvent)
                          * 
                          *  Presumptions:
                          *    com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsManagerDialog:getOkButton(...)@208 != null
                          */
   208                  getOkButton().doClick();
   209              }
   210          });
   211      }
   212  
   213      /**
   214       * Lays out the group panel.
   215       */
   216      private void layoutGroupPanel() {
                 /* 
    P/P           *  Method: void layoutGroupPanel()
                  * 
                  *  Preconditions:
                  *    init'ed(this.add)
                  *    init'ed(this.delete)
                  *    init'ed(this.edit)
                  *    this.groupPanel != null
                  *    init'ed(this.groups)
                  */
   217          groupPanel.setLayout(new MigLayout("fill, wrap 1"));
   218  
   219          groupPanel.add(new JScrollPane(groups), "growy, pushy, w 150!");
   220          groupPanel.add(add, "sgx button, w 150!");
   221          groupPanel.add(edit, "sgx button, w 150!");
   222          groupPanel.add(delete, "sgx button, w 150!");
   223      }
   224  
   225      /**
   226       * Lays out the components.
   227       */
   228      private void layoutComponents() {
   229  
                 /* 
    P/P           *  Method: void layoutComponents()
                  * 
                  *  Preconditions:
                  *    init'ed(this.actions)
                  *    init'ed(this.groupPanel)
                  *    this.info != null
                  *    init'ed(this.infoLabel)
                  *    (soft) this.activeSettings != null
                  * 
                  *  Presumptions:
                  *    com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsManagerDialog:getContentPane(...)@230 != null
                  *    com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsManagerDialog:getContentPane(...)@232 != null
                  *    com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsManagerDialog:getContentPane(...)@234 != null
                  *    com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsManagerDialog:getContentPane(...)@236 != null
                  *    com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsManagerDialog:getContentPane(...)@238 != null
                  *    ...
                  * 
                  *  Test Vectors:
                  *    com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionGroupInformationPanel:isVisible(...)@233: {0}, {1}
                  *    com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionGroupInformationPanel:isVisible(...)@235: {1}, {0}
                  *    com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionGroupSettingsPanel:isVisible(...)@233: {0}, {1}
                  *    com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionGroupSettingsPanel:isVisible(...)@235: {0}, {1}
                  */
   230          getContentPane().setLayout(new MigLayout("fill, wrap 2, hidemode 3"));
   231  
   232          getContentPane().add(infoLabel, "spanx 2, growx, pushx");
   233          if (info.isVisible() && activeSettings.isVisible()) {
   234              getContentPane().add(groupPanel, "growy, pushy, spany 3");
   235          } else if (info.isVisible() || activeSettings.isVisible()) {
   236              getContentPane().add(groupPanel, "growy, pushy, spany 2");
   237          } else {
   238              getContentPane().add(groupPanel, "growy, pushy");
   239          }
   240          getContentPane().add(info, "growx, pushx");
   241          getContentPane().add(actions, "grow, pushx, pushx");
   242          getContentPane().add(activeSettings, "growx, pushx");
   243          getContentPane().add(getOkButton(), "skip, right, sgx button");
   244      }
   245  
   246      /**
   247       * Reloads the action groups.
   248       */
   249      private void reloadGroups() {
                 /* 
    P/P           *  Method: void reloadGroups()
                  * 
                  *  Preconditions:
                  *    this.groups != null
                  */
   250          reloadGroups(null);
   251      }
   252  
   253      /**
   254       * Reloads the action groups.
   255       * 
   256       * @param selectedGroup Newly selected group
   257       */
   258      private void reloadGroups(final ActionGroup selectedGroup) {
                 /* 
    P/P           *  Method: void reloadGroups(ActionGroup)
                  * 
                  *  Preconditions:
                  *    this.groups != null
                  * 
                  *  Presumptions:
                  *    com.dmdirc.actions.ActionManager:getGroups(...)@260 != null
                  *    java.util.Map:values(...)@260 != null
                  *    javax.swing.JList:getModel(...)@259 != null
                  *    javax.swing.JList:getModel(...)@261 != null
                  * 
                  *  Test Vectors:
                  *    java.util.Iterator:hasNext(...)@260: {0}, {1}
                  */
   259          ((DefaultListModel) groups.getModel()).clear();
   260          for (ActionGroup group : ActionManager.getGroups().values()) {
   261              ((DefaultListModel) groups.getModel()).addElement(group);
   262          }
   263          groups.setSelectedValue(selectedGroup, true);
   264      }
   265  
   266      /**
   267       * Changes the active group.
   268       *
   269       * @param group New group
   270       */
   271      private void changeActiveGroup(final ActionGroup group) {
                 /* 
    P/P           *  Method: void changeActiveGroup(ActionGroup)
                  * 
                  *  Preconditions:
                  *    init'ed(this.actions.model.actions)
                  *    this.actions != null
                  *    this.actions.add != null
                  *    this.actions.model != null
                  *    init'ed(this.groupPanel)
                  *    this.info != null
                  *    this.info.author != null
                  *    this.info.infoLabel != null
                  *    this.info.version != null
                  *    init'ed(this.infoLabel)
                  *    ...
                  * 
                  *  Presumptions:
                  *    com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsManagerDialog:getContentPane(...)@286 != null
                  *    com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsManagerDialog:getContentPane(...)@287 != null
                  *    com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsManagerDialog:getContentPane(...)@291 != null
                  *    java.util.Map:get(...)@281 != null
                  *    this.activeSettings.settings@281 != null
                  * 
                  *  Postconditions:
                  *    this.actions.group == group
                  *    init'ed(this.actions.group)
                  *    this.info.group == this.actions.group
                  *    init'ed(this.actions.model.actions)
                  *    this.activeSettings != null
                  *    new ArrayList(setActionGroup#1*) num objects <= 1
                  * 
                  *  Test Vectors:
                  *    java.util.Map:containsKey(...)@274: {1}, {0}
                  */
   272          info.setActionGroup(group);
   273          actions.setActionGroup(group);
   274          if (!settings.containsKey(group)) {
   275              final ActionGroupSettingsPanel currentSettings =
   276                      new ActionGroupSettingsPanel(group, this);
   277              settings.put(group, currentSettings);
   278              currentSettings.setBorder(BorderFactory.createTitledBorder(currentSettings.getBorder(),
   279                      "Settings"));
   280          }
   281          activeSettings = settings.get(group);
   282  
   283          info.setVisible(info.shouldDisplay());
   284          activeSettings.setVisible(activeSettings.shouldDisplay());
   285  
   286          getContentPane().setVisible(false);
   287          getContentPane().removeAll();
   288          layoutComponents();
   289          validate();
   290          layoutComponents();
   291          getContentPane().setVisible(true);
   292      }
   293  
   294      /**
   295       * {@inheritDoc}
   296       *
   297       * @param e Action event
   298       */
   299      @Override
   300      public void actionPerformed(final ActionEvent e) {
                 /* 
    P/P           *  Method: void actionPerformed(ActionEvent)
                  * 
                  *  Preconditions:
                  *    e != null
                  *    init'ed(this.add)
                  *    (soft) init'ed(com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionEditorDialog.me)
                  *    (soft) init'ed(me)
                  *    (soft) init'ed(this.delete)
                  *    (soft) init'ed(this.edit)
                  *    (soft) this.groups != null
                  *    (soft) this.settings != null
                  * 
                  *  Presumptions:
                  *    com.dmdirc.config.IdentityManager:getConfigIdentity(...)@322 != null
                  *    java.util.Iterator:next(...)@319 != null
                  *    java.util.Map:values(...)@319 != null
                  *    loopSettings.settings@319 != null
                  * 
                  *  Postconditions:
                  *    com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionEditorDialog.me == One-of{old com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionEditorDialog.me, null}
                  *    init'ed(com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionEditorDialog.me)
                  *    me == One-of{old me, null}
                  *    init'ed(me)
                  *    new ActionEditorDialog(getActionEditorDialog#1*) num objects <= 1
                  *    init'ed(new ActionEditorDialog(getActionEditorDialog#1*).action)
                  *    init'ed(new ActionEditorDialog(getActionEditorDialog#1*).conditions)
                  *    init'ed(new ActionEditorDialog(getActionEditorDialog#1*).conditionsValid)
                  *    init'ed(new ActionEditorDialog(getActionEditorDialog#1*).group)
                  *    init'ed(new ActionEditorDialog(getActionEditorDialog#1*).name)
                  *    ...
                  * 
                  *  Test Vectors:
                  *    com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionEditorDialog.me: Addr_Set{null}, Inverse{null}
                  *    java.util.Iterator:hasNext(...)@319: {0}, {1}
                  *    javax.swing.JOptionPane:showConfirmDialog(...)@310: {-231..-1, 1..232-1}, {0}
                  */
   301          if (e.getSource() == add) {
   302              addGroup();
   303          } else if (e.getSource() == edit) {
   304              editGroup();
   305          } else if (e.getSource() == delete) {
   306              delGroup();
   307          } else if (e.getSource() == getOkButton() || e.getSource() ==
   308                  getCancelButton()) {
   309              if (ActionEditorDialog.isOpen()) {
   310                  if (JOptionPane.showConfirmDialog(this,
   311                          "The action editor is currently open, do you want to cotinue and lose any unsaved changes?",
   312                          "Confirm close?", JOptionPane.YES_NO_OPTION,
   313                          JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
   314                      ActionEditorDialog.getActionEditorDialog(this, "").dispose();
   315                  } else {
   316                      return;
   317                  }
   318              }
   319              for (ActionGroupSettingsPanel loopSettings : settings.values()) {
   320                  loopSettings.save();
   321              }
   322              IdentityManager.getConfigIdentity().setOption("dialogstate",
   323                      "actionsmanagerdialog", groups.getSelectedIndex());
   324              dispose();
   325          }
   326      }
   327  
   328      /**
   329       * Prompts then adds an action group.
   330       */
   331      @SuppressWarnings("unchecked")
   332      private void addGroup() {
                 /* 
    P/P           *  Method: void addGroup()
                  * 
                  *  Presumptions:
                  *    init'ed(java.awt.Dialog$ModalityType.DOCUMENT_MODAL)
                  */
   333          final StandardInputDialog inputDialog = new StandardInputDialog(this,
   334                  ModalityType.DOCUMENT_MODAL, "New action group",
   335                  "Please enter the name of the new action group",
   336                  new ValidatorChain<String>(new FileNameValidator(),
                         /* 
    P/P                   *  Method: void com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsManagerDialog$2(ActionsManagerDialog, Window, Dialog$ModalityType, String, String, Validator)
                          */
   337                  new ActionGroupValidator())) {
   338  
   339              /**
   340               * A version number for this class. It should be changed whenever the class
   341               * structure is changed (or anything else that would prevent serialized
   342               * objects being unserialized with the new class).
   343               */
   344              private static final long serialVersionUID = 1;
   345  
   346              /** {@inheritDoc} */
   347              @Override
   348              public boolean save() {
                         /* 
    P/P                   *  Method: bool save()
                          * 
                          *  Preconditions:
                          *    (soft) this.groups != null
                          * 
                          *  Presumptions:
                          *    com.dmdirc.actions.ActionManager:getGroups(...)@349 != null
                          *    com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsManagerDialog_2:getText(...)@349 != null
                          * 
                          *  Postconditions:
                          *    init'ed(return_value)
                          * 
                          *  Test Vectors:
                          *    com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsManagerDialog_2:getText(...)@349: Addr_Set{null}, Inverse{null}
                          *    java.lang.String:isEmpty(...)@349: {0}, {1}
                          *    java.util.Map:containsKey(...)@349: {1}, {0}
                          */
   349                  if (getText() == null || getText().isEmpty() && !ActionManager.getGroups().
   350                          containsKey(getText())) {
   351                      return false;
   352                  } else {
   353                      final ActionGroup group =
   354                              ActionManager.makeGroup(getText());
   355                      reloadGroups(group);
   356                      return true;
   357                  }
   358              }
   359  
   360              /** {@inheritDoc} */
   361              @Override
   362              public void cancelled() {
   363              //Ignore
                     /* 
    P/P               *  Method: void cancelled()
                      */
   364              }
   365          };
   366          inputDialog.display(this);
   367      }
   368  
   369      /**
   370       * Prompts then edits an action group.
   371       */
   372      @SuppressWarnings("unchecked")
   373      private void editGroup() {
                 /* 
    P/P           *  Method: void editGroup()
                  * 
                  *  Preconditions:
                  *    this.groups != null
                  * 
                  *  Presumptions:
                  *    init'ed(java.awt.Dialog$ModalityType.DOCUMENT_MODAL)
                  *    javax.swing.JList:getSelectedValue(...)@374 != null
                  */
   374          final String oldName =
   375                  ((ActionGroup) groups.getSelectedValue()).getName();
   376          final StandardInputDialog inputDialog = new StandardInputDialog(this,
   377                  ModalityType.DOCUMENT_MODAL,
   378                  "Edit action group",
   379                  "Please enter the new name of the action group",
   380                  new ValidatorChain<String>(new FileNameValidator(),
                         /* 
    P/P                   *  Method: void com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsManagerDialog$3(ActionsManagerDialog, Window, Dialog$ModalityType, String, String, Validator, String)
                          * 
                          *  Postconditions:
                          *    this.val$oldName == Param_7
                          *    init'ed(this.val$oldName)
                          */
   381                  new ActionGroupValidator())) {
   382  
   383              /**
   384               * A version number for this class. It should be changed whenever the class
   385               * structure is changed (or anything eloh blese that would prevent serialized
   386               * objects being unserialized with the new class).
   387               */
   388              private static final long serialVersionUID = 1;
   389  
   390              /** {@inheritDoc} */
   391              @Override
   392              public boolean save() {
                         /* 
    P/P                   *  Method: bool save()
                          * 
                          *  Preconditions:
                          *    (soft) this.groups != null
                          * 
                          *  Presumptions:
                          *    com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsManagerDialog_3:getText(...)@393 != null
                          * 
                          *  Postconditions:
                          *    init'ed(return_value)
                          * 
                          *  Test Vectors:
                          *    com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsManagerDialog_3:getText(...)@393: Addr_Set{null}, Inverse{null}
                          *    java.lang.String:isEmpty(...)@393: {0}, {1}
                          */
   393                  if (getText() == null || getText().isEmpty()) {
   394                      return false;
   395                  } else {
   396                      ActionManager.renameGroup(oldName, getText());
   397                      reloadGroups();
   398                      return true;
   399                  }
   400              }
   401  
   402              /** {@inheritDoc} */
   403              @Override
   404              public void cancelled() {
   405              //Ignore
                     /* 
    P/P               *  Method: void cancelled()
                      */
   406              }
   407          };
   408          inputDialog.setText(oldName);
   409          inputDialog.display(this);
   410      }
   411  
   412      /**
   413       * Prompts then deletes an action group.
   414       */
   415      private void delGroup() {
                 /* 
    P/P           *  Method: void delGroup()
                  * 
                  *  Preconditions:
                  *    this.groups != null
                  * 
                  *  Presumptions:
                  *    javax.swing.JList:getModel(...)@423 != null
                  *    javax.swing.JList:getModel(...)@427 != null
                  *    javax.swing.JList:getModel(...)@429 != null
                  *    javax.swing.JList:getModel(...)@430 != null
                  *    javax.swing.JList:getSelectedValue(...)@416 != null
                  * 
                  *  Test Vectors:
                  *    javax.swing.DefaultListModel:indexOf(...)@423: {1..232-2}, {-231..0}
                  *    javax.swing.JOptionPane:showConfirmDialog(...)@418: {-231..-1, 1..232-1}, {0}
                  *    javax.swing.ListModel:getSize(...)@427: {-231..-1, 1..232-1}, {0}
                  */
   416          final String group =
   417                  ((ActionGroup) groups.getSelectedValue()).getName();
   418          final int response = JOptionPane.showConfirmDialog(this,
   419                  "Are you sure you wish to delete the '" + group +
   420                  "' group and all actions within it?",
   421                  "Confirm deletion", JOptionPane.YES_NO_OPTION);
   422          if (response == JOptionPane.YES_OPTION) {
   423              int location =
   424                      ((DefaultListModel) groups.getModel()).indexOf(ActionManager.getGroup(group));
   425              ActionManager.removeGroup(group);
   426              reloadGroups();
   427              if (groups.getModel().getSize() == 0) {
   428                  location = -1;
   429              } else if (location >= groups.getModel().getSize()) {
   430                  location = groups.getModel().getSize();
   431              } else if (location <= 0) {
   432                  location = 0;
   433              }
   434              groups.setSelectedIndex(location);
   435          }
   436      }
   437  
   438      /** {@inheritDoc} */
   439      @Override
   440      public void valueChanged(final ListSelectionEvent e) {
                 /* 
    P/P           *  Method: void valueChanged(ListSelectionEvent)
                  * 
                  *  Preconditions:
                  *    e != null
                  *    (soft) init'ed(this.actions.model.actions)
                  *    (soft) this.actions != null
                  *    (soft) this.actions.add != null
                  *    (soft) this.actions.model != null
                  *    (soft) this.delete != null
                  *    (soft) this.edit != null
                  *    (soft) init'ed(this.groupPanel)
                  *    (soft) this.groups != null
                  *    (soft) this.info != null
                  *    ...
                  * 
                  *  Presumptions:
                  *    javax.swing.JList:getSelectedValue(...)@446 != null
                  * 
                  *  Postconditions:
                  *    possibly_updated(this.actions.group)
                  *    init'ed(this.actions.model.actions)
                  *    possibly_updated(this.activeSettings)
                  *    possibly_updated(this.info.group)
                  *    new ArrayList(setActionGroup#1*) num objects <= 1
                  * 
                  *  Test Vectors:
                  *    com.dmdirc.actions.ActionGroup:isDelible(...)@446: {1}, {0}
                  *    javax.swing.JList:getSelectedIndex(...)@446: {-1}, {-231..-2, 0..232-1}
                  *    javax.swing.event.ListSelectionEvent:getValueIsAdjusting(...)@441: {0}, {1}
                  */
   441          if (e.getValueIsAdjusting()) {
   442              return;
   443          }
   444  
   445          changeActiveGroup((ActionGroup) groups.getSelectedValue());
   446          if (groups.getSelectedIndex() == -1 ||
   447                  !((ActionGroup) groups.getSelectedValue()).isDelible()) {
   448              edit.setEnabled(false);
   449              delete.setEnabled(false);
   450          } else {
   451              edit.setEnabled(true);
   452              delete.setEnabled(true);
   453          }
   454      }
   455  
   456      /** {@inheritDoc} */
   457      @Override
   458      public void processEvent(final ActionType type, final StringBuffer format,
   459              final Object... arguments) {
                 /* 
    P/P           *  Method: void processEvent(ActionType, StringBuffer, Object[])
                  * 
                  *  Preconditions:
                  *    this.groups != null
                  *    (soft) arguments != null
                  *    (soft) arguments.length >= 2
                  *    (soft) arguments[0] != null
                  *    (soft) init'ed(arguments[1])
                  *    (soft) this.actions != null
                  *    (soft) this.actions.model != null
                  *    (soft) this.actions.model.actions != null
                  *    (soft) type != null
                  * 
                  *  Presumptions:
                  *    com.dmdirc.actions.Action:getGroup(...)@466 != null
                  *    init'ed(com.dmdirc.actions.CoreActionType.ACTION_CREATED)
                  *    init'ed(com.dmdirc.actions.CoreActionType.ACTION_UPDATED)
                  *    javax.swing.JList:getSelectedValue(...)@466 != null
                  *    javax.swing.JList:getSelectedValue(...)@470 != null
                  * 
                  *  Test Vectors:
                  *    java.lang.Object:equals(...)@463: {1}, {0}
                  *    java.lang.Object:equals(...)@463: {0}, {1}
                  *    java.lang.Object:equals(...)@470: {0}, {1}
                  *    java.lang.String:equals(...)@466: {0}, {1}
                  *    javax.swing.JList:getSelectedValue(...)@460: Inverse{null}, Addr_Set{null}
                  */
   460          if (groups.getSelectedValue() == null) {
   461              return;
   462          }
   463          if (type.equals(CoreActionType.ACTION_CREATED) ||
   464                  type.equals(CoreActionType.ACTION_UPDATED)) {
   465              final Action action = (Action) arguments[0];
   466              if (action.getGroup().equals(((ActionGroup) groups.getSelectedValue()).getName())) {
   467                  actions.actionChanged(action);
   468              }
   469          } else {
   470              if (arguments[0].equals(((ActionGroup) groups.getSelectedValue()).getName())) {
   471                  actions.actionDeleted((String) arguments[1]);
   472              }
   473          }
   474      }
   475  
   476      /** {@inheritDoc} */
   477      @Override
   478      public void dispose() {
                 /* 
    P/P           *  Method: void dispose()
                  * 
                  *  Preconditions:
                  *    init'ed(me)
                  * 
                  *  Postconditions:
                  *    me == null
                  * 
                  *  Test Vectors:
                  *    me: Inverse{null}, Addr_Set{null}
                  */
   479          if (me == null) {
   480              return;
   481          }
   482          synchronized (me) {
   483              super.dispose();
   484              me = null;
   485          }
   486      }
   487  }








SofCheck Inspector Build Version : 2.17854
ActionsManagerDialog.java 2009-Jun-25 01:54:24
ActionsManagerDialog.class 2009-Sep-02 17:04:16
ActionsManagerDialog$1.class 2009-Sep-02 17:04:16
ActionsManagerDialog$2.class 2009-Sep-02 17:04:16
ActionsManagerDialog$3.class 2009-Sep-02 17:04:16