File Source: SwingController.java

         /* 
    P/P   *  Method: com.dmdirc.addons.ui_swing.SwingController$1__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;
    24  
    25  import com.dmdirc.addons.ui_swing.components.frames.ServerFrame;
    26  import com.dmdirc.addons.ui_swing.components.frames.CustomFrame;
    27  import com.dmdirc.addons.ui_swing.components.frames.QueryFrame;
    28  import com.dmdirc.addons.ui_swing.components.frames.CustomInputFrame;
    29  import com.dmdirc.addons.ui_swing.components.frames.ChannelFrame;
    30  import com.dmdirc.Channel;
    31  import com.dmdirc.FrameContainer;
    32  import com.dmdirc.Main;
    33  import com.dmdirc.config.prefs.PreferencesInterface;
    34  import com.dmdirc.ui.IconManager;
    35  import com.dmdirc.Query;
    36  import com.dmdirc.Server;
    37  import com.dmdirc.WritableFrameContainer;
    38  import com.dmdirc.commandparser.parsers.CommandParser;
    39  import com.dmdirc.config.IdentityManager;
    40  import com.dmdirc.logger.ErrorLevel;
    41  import com.dmdirc.logger.Logger;
    42  import com.dmdirc.ui.core.dialogs.sslcertificate.SSLCertificateDialogModel;
    43  import com.dmdirc.ui.interfaces.ChannelWindow;
    44  import com.dmdirc.ui.interfaces.InputWindow;
    45  import com.dmdirc.ui.interfaces.QueryWindow;
    46  import com.dmdirc.ui.interfaces.ServerWindow;
    47  import com.dmdirc.ui.interfaces.StatusBar;
    48  import com.dmdirc.ui.interfaces.UIController;
    49  import com.dmdirc.ui.interfaces.Window;
    50  import com.dmdirc.addons.ui_swing.components.pluginpanel.PluginPanel;
    51  import com.dmdirc.addons.ui_swing.components.statusbar.FeedbackNag;
    52  import com.dmdirc.addons.ui_swing.components.statusbar.SwingStatusBar;
    53  import com.dmdirc.addons.ui_swing.components.themepanel.ThemePanel;
    54  import com.dmdirc.addons.ui_swing.dialogs.updater.SwingUpdaterDialog;
    55  import com.dmdirc.addons.ui_swing.dialogs.url.URLDialog;
    56  import com.dmdirc.addons.ui_swing.dialogs.channelsetting.ChannelSettingsDialog;
    57  import com.dmdirc.addons.ui_swing.dialogs.error.ErrorListDialog;
    58  import com.dmdirc.addons.ui_swing.dialogs.prefs.URLConfigPanel;
    59  import com.dmdirc.addons.ui_swing.dialogs.prefs.UpdateConfigPanel;
    60  import com.dmdirc.addons.ui_swing.wizard.firstrun.SwingFirstRunWizard;
    61  import com.dmdirc.addons.ui_swing.dialogs.serversetting.ServerSettingsDialog;
    62  import com.dmdirc.addons.ui_swing.dialogs.sslcertificate.SSLCertificateDialog;
    63  import com.dmdirc.addons.ui_swing.wizard.WizardListener;
    64  import com.dmdirc.plugins.Plugin;
    65  import com.dmdirc.updater.Update;
    66  import com.dmdirc.util.ReturnableThread;
    67  
    68  import java.awt.Font;
    69  import java.awt.GraphicsEnvironment;
    70  import java.awt.Toolkit;
    71  import java.net.URI;
    72  import java.util.ArrayList;
    73  import java.util.List;
    74  import java.util.concurrent.Semaphore;
    75  
    76  import java.util.concurrent.atomic.AtomicBoolean;
    77  import javax.swing.JOptionPane;
    78  import javax.swing.SwingUtilities;
    79  import javax.swing.UIManager;
    80  import javax.swing.UnsupportedLookAndFeelException;
    81  
    82  import net.miginfocom.layout.PlatformDefaults;
    83  
    84  /**
    85   * Controls the main swing UI.
    86   */
         /* 
    P/P   *  Method: ErrorListDialog access$202(SwingController, ErrorListDialog)
          * 
          *  Preconditions:
          *    x0 != null
          * 
          *  Postconditions:
          *    return_value == x1
          *    init'ed(return_value)
          *    x0.errorDialog == return_value
          */
    87  public final class SwingController extends Plugin implements UIController {
    88  
    89      /** Logger to use. */
             /* 
    P/P       *  Method: com.dmdirc.addons.ui_swing.SwingController__static_init
              * 
              *  Postconditions:
              *    init'ed(LOGGER)
              */
    90      private static final java.util.logging.Logger LOGGER =
    91              java.util.logging.Logger.getLogger(SwingController.class.getName());
    92      /** Singleton instance of MainFrame. */
    93      private MainFrame me;
    94      /** Status bar. */
    95      private SwingStatusBar statusBar;
    96      /** Top level window list. */
    97      private final List<java.awt.Window> windows;
    98      /** Waiting on mainframe creation. */
    99      private AtomicBoolean mainFrameCreated = new AtomicBoolean(false);
   100      /** Error dialog. */
   101      private ErrorListDialog errorDialog;
   102  
   103      /** Instantiates a new SwingController. */
             /* 
    P/P       *  Method: void com.dmdirc.addons.ui_swing.SwingController()
              * 
              *  Postconditions:
              *    this.mainFrameCreated == &amp;new AtomicBoolean(SwingController#1)
              *    this.windows == &amp;new ArrayList(SwingController#2)
              *    new ArrayList(SwingController#2) num objects == 1
              *    new AtomicBoolean(SwingController#1) num objects == 1
              */
   104      public SwingController() {
   105          windows = new ArrayList<java.awt.Window>();
   106      }
   107  
   108      /**
   109       * Does the main frame exist?
   110       *
   111       * @return true iif mainframe exists
   112       */
   113      protected boolean hasMainFrame() {
                 /* 
    P/P           *  Method: bool hasMainFrame()
                  * 
                  *  Preconditions:
                  *    this.mainFrameCreated != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   114          return mainFrameCreated.get();
   115      }
   116  
   117      /** {@inheritDoc} */
   118      @Override
   119      public MainFrame getMainWindow() {
                 /* 
    P/P           *  Method: MainFrame getMainWindow()
                  * 
                  *  Preconditions:
                  *    init'ed(this.me)
                  * 
                  *  Postconditions:
                  *    return_value == this.me
                  *    init'ed(return_value)
                  */
   120          return getMainFrame();
   121      }
   122  
   123      /**
   124       * Retrieves the main window used by this UI.
   125       *
   126       * @return This UI's main window
   127       */
   128      public MainFrame getMainFrame() {
                 /* 
    P/P           *  Method: MainFrame getMainFrame()
                  * 
                  *  Preconditions:
                  *    init'ed(this.me)
                  * 
                  *  Postconditions:
                  *    return_value == this.me
                  *    init'ed(return_value)
                  */
   129          return me;
   130      }
   131  
   132      /** {@inheritDoc} */
   133      @Override
   134      public StatusBar getStatusBar() {
                 /* 
    P/P           *  Method: StatusBar getStatusBar()
                  * 
                  *  Preconditions:
                  *    init'ed(this.statusBar)
                  * 
                  *  Postconditions:
                  *    return_value == this.statusBar
                  *    init'ed(return_value)
                  */
   135          return getSwingStatusBar();
   136      }
   137  
   138      /**
   139       * Retrieves the Swing Status Bar used by this UI.
   140       * 
   141       * @return This UI's status bar
   142       */
   143      public SwingStatusBar getSwingStatusBar() {
                 /* 
    P/P           *  Method: SwingStatusBar getSwingStatusBar()
                  * 
                  *  Preconditions:
                  *    init'ed(this.statusBar)
                  * 
                  *  Postconditions:
                  *    return_value == this.statusBar
                  *    init'ed(return_value)
                  */
   144          return statusBar;
   145      }
   146  
   147      /** {@inheritDoc} */
   148      @Override
   149      public ChannelWindow getChannel(final Channel channel) {
                 /* 
    P/P           *  Method: ChannelWindow getChannel(Channel)
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   150          return UIUtilities.invokeAndWait(new ReturnableThread<ChannelFrame>() {
   151  
   152              /** {@inheritDoc} */
   153              @Override
   154              public void run() {
                         /* 
    P/P                   *  Method: void run()
                          */
   155                  setObject(new ChannelFrame(channel, SwingController.this));
   156              }
   157          });
   158      }
   159  
   160      /** {@inheritDoc} */
   161      @Override
   162      public ServerWindow getServer(final Server server) {
                 /* 
    P/P           *  Method: ServerWindow getServer(Server)
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   163          return UIUtilities.invokeAndWait(new ReturnableThread<ServerFrame>() {
   164  
   165              /** {@inheritDoc} */
   166              @Override
   167              public void run() {
                         /* 
    P/P                   *  Method: void run()
                          * 
                          *  Preconditions:
                          *    this.val$server != null
                          */
   168                  setObject(new ServerFrame(server, SwingController.this));
   169              }
   170          });
   171      }
   172  
   173      /** {@inheritDoc} */
   174      @Override
   175      public QueryWindow getQuery(final Query query) {
                 /* 
    P/P           *  Method: QueryWindow getQuery(Query)
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   176          return UIUtilities.invokeAndWait(new ReturnableThread<QueryFrame>() {
   177  
   178              /** {@inheritDoc} */
   179              @Override
   180              public void run() {
                         /* 
    P/P                   *  Method: void run()
                          * 
                          *  Preconditions:
                          *    this.val$query != null
                          */
   181                  setObject(new QueryFrame(query, SwingController.this));
   182              }
   183          });
   184      }
   185  
   186      /** {@inheritDoc} */
   187      @Override
   188      public Window getWindow(final FrameContainer owner) {
                 /* 
    P/P           *  Method: Window getWindow(FrameContainer)
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   189          return UIUtilities.invokeAndWait(new ReturnableThread<CustomFrame>() {
   190  
   191              /** {@inheritDoc} */
   192              @Override
   193              public void run() {
                         /* 
    P/P                   *  Method: void run()
                          */
   194                  setObject(new CustomFrame(owner, SwingController.this));
   195              }
   196          });
   197      }
   198  
   199      /** {@inheritDoc} */
   200      @Override
   201      public InputWindow getInputWindow(final WritableFrameContainer owner,
   202              final CommandParser commandParser) {
                 /* 
    P/P           *  Method: InputWindow getInputWindow(WritableFrameContainer, CommandParser)
                  * 
                  *  Presumptions:
                  *    java.util.logging.Logger:getLogger(...)@90 != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   203          LOGGER.finest("getInputWindow()");
   204  
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.SwingController$5(SwingController, WritableFrameContainer, CommandParser)
                  * 
                  *  Postconditions:
                  *    this.val$commandParser == Param_3
                  *    init'ed(this.val$commandParser)
                  *    this.val$owner == Param_2
                  *    init'ed(this.val$owner)
                  */
   205          return UIUtilities.invokeAndWait(new ReturnableThread<CustomInputFrame>() {
   206  
   207              /** {@inheritDoc} */
   208              @Override
   209              public void run() {
                         /* 
    P/P                   *  Method: void run()
                          * 
                          *  Preconditions:
                          *    this.val$owner != null
                          * 
                          *  Presumptions:
                          *    java.util.logging.Logger:getLogger(...)@90 != null
                          */
   210                  LOGGER.finest("getInputWindow(): run");
   211                  setObject(new CustomInputFrame(owner, commandParser,
   212                          SwingController.this));
   213                  LOGGER.finest("getInputWindow(): object set: " + getObject());
   214              }
   215          });
   216      }
   217  
   218      /** {@inheritDoc} */
   219      @Override
   220      public SwingUpdaterDialog getUpdaterDialog(final List<Update> updates) {
                 /* 
    P/P           *  Method: SwingUpdaterDialog getUpdaterDialog(List)
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   221          return UIUtilities.invokeAndWait(new ReturnableThread<SwingUpdaterDialog>() {
   222  
   223              /** {@inheritDoc} */
   224              @Override
   225              public void run() {
                         /* 
    P/P                   *  Method: void run()
                          * 
                          *  Preconditions:
                          *    init'ed(this.me)
                          */
   226                  setObject(SwingUpdaterDialog.getSwingUpdaterDialog(updates, me));
   227              }
   228          });
   229      }
   230  
   231      /** {@inheritDoc} */
   232      @Override
   233      public void showFirstRunWizard() {
                 /* 
    P/P           *  Method: void showFirstRunWizard()
                  */
   234          showFirstRunWizard(true);
   235      }
   236  
   237      /** {@inheritDoc} */
   238      @Override
   239      public void showMigrationWizard() {
                 /* 
    P/P           *  Method: void showMigrationWizard()
                  */
   240          showFirstRunWizard(false);
   241      }
   242  
   243      /**
   244       * Shows a first run wizard, or a migration wizard.
   245       * 
   246       * @param firstRun First run?
   247       */
   248      private synchronized void showFirstRunWizard(final boolean firstRun) {
                 /* 
    P/P           *  Method: void showFirstRunWizard(bool)
                  */
   249          final Semaphore semaphore = new Semaphore(0);
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.SwingController$7(SwingController, Semaphore, bool)
                  * 
                  *  Postconditions:
                  *    this.val$firstRun == Param_3
                  *    init'ed(this.val$firstRun)
                  *    this.val$semaphore == Param_2
                  *    init'ed(this.val$semaphore)
                  */
   250          UIUtilities.invokeLater(new Runnable() {
   251  
   252              /** {@inheritDoc} */
   253              @Override
   254              public void run() {
                         /* 
    P/P                   *  Method: void run()
                          * 
                          *  Presumptions:
                          *    com.dmdirc.addons.ui_swing.wizard.firstrun.SwingFirstRunWizard:getWizardDialog(...)@271 != null
                          */
   255                  final WizardListener listener = new WizardListener() {
   256  
   257                      /** {@inheritDoc} */
   258                      @Override
   259                      public void wizardFinished() {
                                 /* 
    P/P                           *  Method: void wizardFinished()
                                  * 
                                  *  Preconditions:
                                  *    this.val$semaphore != null
                                  */
   260                          semaphore.release();
   261                      }
   262  
   263                      /** {@inheritDoc} */
   264                      @Override
   265                      public void wizardCancelled() {
                                 /* 
    P/P                           *  Method: void wizardCancelled()
                                  * 
                                  *  Preconditions:
                                  *    this.val$semaphore != null
                                  */
   266                          semaphore.release();
   267                      }
   268                  };
   269                  final SwingFirstRunWizard wizard =
   270                          new SwingFirstRunWizard(firstRun);
   271                  wizard.getWizardDialog().addWizardListener(listener);
   272                  wizard.display();
   273              }
   274          });
   275          semaphore.acquireUninterruptibly();
   276      }
   277  
   278      /** {@inheritDoc} */
   279      @Override
   280      public void showChannelSettingsDialog(final Channel channel) {
                 /* 
    P/P           *  Method: void showChannelSettingsDialog(Channel)
                  */
   281          UIUtilities.invokeLater(new Runnable() {
   282  
   283              /** {@inheritDoc} */
   284              @Override
   285              public void run() {
                         /* 
    P/P                   *  Method: void run()
                          * 
                          *  Preconditions:
                          *    init'ed(this.me)
                          */
   286                  ChannelSettingsDialog.showChannelSettingsDialog(channel, me);
   287              }
   288          });
   289      }
   290  
   291      /** {@inheritDoc} */
   292      @Override
   293      public void showServerSettingsDialog(final Server server) {
                 /* 
    P/P           *  Method: void showServerSettingsDialog(Server)
                  */
   294          UIUtilities.invokeLater(new Runnable() {
   295  
   296              /** {@inheritDoc} */
   297              @Override
   298              public void run() {
                         /* 
    P/P                   *  Method: void run()
                          * 
                          *  Preconditions:
                          *    init'ed(this.me)
                          */
   299                  ServerSettingsDialog.showServerSettingsDialog(server, me);
   300              }
   301          });
   302      }
   303  
   304      /**
   305       * Updates the look and feel to the current config setting.
   306       */
   307      void updateLookAndFeel() {
   308          try {
                     /* 
    P/P               *  Method: void updateLookAndFeel()
                      * 
                      *  Preconditions:
                      *    (soft) this.windows != null
                      * 
                      *  Presumptions:
                      *    com.dmdirc.config.IdentityManager:getGlobalConfig(...)@309 != null
                      *    init'ed(com.dmdirc.logger.ErrorLevel.LOW)
                      *    com.dmdirc.util.ReturnableThread:getObject(...)@203 != null
                      *    invokeAndWait(...)@311 init'ed
                      * 
                      *  Test Vectors:
                      *    java.util.Iterator:hasNext(...)@327: {0}, {1}
                      */
   309              UIManager.setLookAndFeel(UIUtilities.getLookAndFeel(IdentityManager.
   310                      getGlobalConfig().getOption("ui", "lookandfeel")));
                     /* 
    P/P               *  Method: void com.dmdirc.addons.ui_swing.SwingController$10(SwingController)
                      */
   311              final int state = UIUtilities.invokeAndWait(new ReturnableThread<Integer>() {
   312  
   313                  /** {@inheritDoc} */
   314                  @Override
   315                  public void run() {
                             /* 
    P/P                       *  Method: void run()
                              * 
                              *  Preconditions:
                              *    this.me != null
                              */
   316                      setObject(me.getExtendedState());
   317                  }
   318              });
                     /* 
    P/P               *  Method: void com.dmdirc.addons.ui_swing.SwingController$11(SwingController)
                      */
   319              UIUtilities.invokeLater(new Runnable() {
   320  
   321                  /** {@inheritDoc} */
   322                  @Override
   323                  public void run() {
                             /* 
    P/P                       *  Method: void run()
                              * 
                              *  Preconditions:
                              *    init'ed(this.errorDialog)
                              */
   324                      SwingUtilities.updateComponentTreeUI(errorDialog);
   325                  }
   326              });
   327              for (final java.awt.Window window : getTopLevelWindows()) {
                         /* 
    P/P                   *  Method: void com.dmdirc.addons.ui_swing.SwingController$12(SwingController, Window)
                          * 
                          *  Postconditions:
                          *    this.val$window == Param_2
                          *    init'ed(this.val$window)
                          */
   328                  UIUtilities.invokeLater(new Runnable() {
   329  
   330                      /** {@inheritDoc} */
   331                      @Override
   332                      public void run() {
                                 /* 
    P/P                           *  Method: void run()
                                  * 
                                  *  Preconditions:
                                  *    init'ed(this.me)
                                  *    (soft) this.val$window != null
                                  * 
                                  *  Test Vectors:
                                  *    this.val$window == this.me: {1}, {0}
                                  */
   333                          SwingUtilities.updateComponentTreeUI(window);
   334                          if (window != me) {
   335                              window.pack();
   336                          }
   337                      }
   338                  });
   339              }
                     /* 
    P/P               *  Method: void com.dmdirc.addons.ui_swing.SwingController$13(SwingController, int)
                      * 
                      *  Postconditions:
                      *    this.val$state == Param_2
                      *    init'ed(this.val$state)
                      */
   340              UIUtilities.invokeLater(new Runnable() {
   341  
   342                  /** {@inheritDoc} */
   343                  @Override
   344                  public void run() {
                             /* 
    P/P                       *  Method: void run()
                              * 
                              *  Preconditions:
                              *    this.me != null
                              */
   345                      me.setExtendedState(state);
   346                  }
   347              });
   348          } catch (ClassNotFoundException ex) {
   349              Logger.userError(ErrorLevel.LOW,
   350                      "Unable to change Look and Feel: " +
   351                      ex.getMessage());
   352          } catch (InstantiationException ex) {
   353              Logger.userError(ErrorLevel.LOW,
   354                      "Unable to change Look and Feel: " +
   355                      ex.getMessage());
   356          } catch (IllegalAccessException ex) {
   357              Logger.userError(ErrorLevel.LOW,
   358                      "Unable to change Look and Feel: " +
   359                      ex.getMessage());
   360          } catch (UnsupportedLookAndFeelException ex) {
   361              Logger.userError(ErrorLevel.LOW,
   362                      "Unable to change Look and Feel: " +
   363                      ex.getMessage());
   364          }
   365      }
   366  
   367      /** {@inheritDoc} */
   368      @Override
   369      public void initUISettings() {
   370          // For this to work it *HAS* to be before anything else UI related.
                 /* 
    P/P           *  Method: void initUISettings()
                  * 
                  *  Preconditions:
                  *    (soft) init'ed(com/dmdirc/addons/ui_swing/Apple.me)
                  * 
                  *  Presumptions:
                  *    com.dmdirc.config.IdentityManager:getGlobalConfig(...)@371 != null
                  *    com.dmdirc.config.IdentityManager:getGlobalConfig(...)@401 != null
                  *    init'ed(com.dmdirc.logger.ErrorLevel.LOW)
                  *    com.dmdirc.ui.IconManager:getIconManager(...)@394 != null
                  *    com.dmdirc.ui.IconManager:getIconManager(...)@396 != null
                  *    ...
                  * 
                  *  Postconditions:
                  *    possibly_updated(com/dmdirc/addons/ui_swing/Apple.application)
                  *    com/dmdirc/addons/ui_swing/Apple.me == One-of{old com/dmdirc/addons/ui_swing/Apple.me, &amp;new Apple(getApple#1)}
                  *    init'ed(com/dmdirc/addons/ui_swing/Apple.me)
                  *    init'ed(com/dmdirc/addons/ui_swing/Apple.me.isListener)
                  *    new Apple(getApple#1) num objects <= 1
                  *    init'ed(new Apple(getApple#1).addresses)
                  *    new Apple(getApple#1).clientOpened == 0
                  *    init'ed(new Apple(getApple#1).isListener)
                  *    init'ed(new Apple(getApple#1).menuBar)
                  *    new ArrayList(Apple#1) num objects <= 1
                  * 
                  *  Test Vectors:
                  *    java.lang.String:equals(...)@416: {0}, {1}
                  *    javax.swing.UIManager:getFont(...)@387: Inverse{null}, Addr_Set{null}
                  *    javax.swing.UIManager:getFont(...)@390: Inverse{null}, Addr_Set{null}
                  */
   371          final boolean aaSetting = IdentityManager.getGlobalConfig().
   372                  getOptionBool("ui", "antialias");
   373          System.setProperty("awt.useSystemAAFontSettings",
   374                  Boolean.toString(aaSetting));
   375          System.setProperty("swing.aatext", Boolean.toString(aaSetting));
   376  
   377          // This will do nothing on non OS X Systems
   378          if (Apple.isApple()) {
   379              final Apple apple = Apple.getApple();
   380  
   381              apple.setUISettings();
   382              apple.setListener();
   383          }
   384  
   385          final Font defaultFont = new Font(Font.DIALOG, Font.TRUETYPE_FONT,
   386                  12);
   387          if (UIManager.getFont("TextField.font") == null) {
   388              UIManager.put("TextField.font", defaultFont);
   389          }
   390          if (UIManager.getFont("TextPane.font") == null) {
   391              UIManager.put("TextPane.font", defaultFont);
   392          }
   393  
   394          UIManager.put("Tree.collapsedIcon",
   395                  IconManager.getIconManager().getIcon("nothing"));
   396          UIManager.put("Tree.expandedIcon",
   397                  IconManager.getIconManager().getIcon("nothing"));
   398  
   399          try {
   400              UIUtilities.initUISettings();
   401              UIManager.setLookAndFeel(UIUtilities.getLookAndFeel(IdentityManager.
   402                      getGlobalConfig().getOption("ui", "lookandfeel")));
   403  
   404          } catch (UnsupportedOperationException ex) {
   405              Logger.userError(ErrorLevel.LOW, "Unable to set UI Settings");
   406          } catch (UnsupportedLookAndFeelException ex) {
   407              Logger.userError(ErrorLevel.LOW, "Unable to set UI Settings");
   408          } catch (IllegalAccessException ex) {
   409              Logger.userError(ErrorLevel.LOW, "Unable to set UI Settings");
   410          } catch (InstantiationException ex) {
   411              Logger.userError(ErrorLevel.LOW, "Unable to set UI Settings");
   412          } catch (ClassNotFoundException ex) {
   413              Logger.userError(ErrorLevel.LOW, "Unable to set UI Settings");
   414          }
   415  
   416          if ("Metal".equals(UIManager.getLookAndFeel().getName())) {
   417              PlatformDefaults.setPlatform(PlatformDefaults.WINDOWS_XP);
   418          }
   419          
   420          //Toolkit.getDefaultToolkit().getSystemEventQueue().
   421          //        push(new TracingEventQueue());
   422      }
   423  
   424      /** {@inheritDoc} */
   425      @Override
   426      public Window getActiveWindow() {
                 /* 
    P/P           *  Method: Window getActiveWindow()
                  * 
                  *  Preconditions:
                  *    this.me != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   427          return me.getActiveFrame();
   428      }
   429  
   430      /** {@inheritDoc} */
   431      @Override
   432      public Server getActiveServer() {
                 /* 
    P/P           *  Method: Server getActiveServer()
                  * 
                  *  Preconditions:
                  *    this.mainFrameCreated != null
                  *    (soft) this.me != null
                  * 
                  *  Presumptions:
                  *    com.dmdirc.ui.interfaces.Window:getContainer(...)@440 != null
                  *    com.dmdirc.util.ReturnableThread:getObject(...)@203 != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  * 
                  *  Test Vectors:
                  *    com.dmdirc.util.ReturnableThread:getObject(...)@203: Inverse{null}, Addr_Set{null}
                  *    java.util.concurrent.atomic.AtomicBoolean:get(...)@433: {1}, {0}
                  */
   433          if (!mainFrameCreated.get()) {
   434              return null;
   435          }
   436  
   437          if (getActiveWindow() == null) {
   438              return null;
   439          } else {
   440              return getActiveWindow().getContainer().getServer();
   441          }
   442  
   443      }
   444  
   445      /** {@inheritDoc} */
   446      @Override
   447      public void showURLDialog(final URI url) {
                 /* 
    P/P           *  Method: void showURLDialog(URI)
                  */
   448          UIUtilities.invokeLater(new Runnable() {
   449  
   450              /** {@inheritDoc} */
   451              @Override
   452              public void run() {
                         /* 
    P/P                   *  Method: void run()
                          * 
                          *  Preconditions:
                          *    init'ed(this.me)
                          */
   453                  URLDialog.showURLDialog(url, me);
   454  
   455              }
   456          });
   457      }
   458  
   459      /** {@inheritDoc} */
   460      @Override
   461      public void showSSLCertificateDialog(final SSLCertificateDialogModel model) {
                 /* 
    P/P           *  Method: void showSSLCertificateDialog(SSLCertificateDialogModel)
                  */
   462          UIUtilities.invokeLater(new Runnable() {
   463  
   464              /** {@inheritDoc} */
   465              @Override
   466              public void run() {
                         /* 
    P/P                   *  Method: void run()
                          * 
                          *  Preconditions:
                          *    init'ed(this.me)
                          */
   467                  new SSLCertificateDialog(me, model).setVisible(true);
   468              }
   469          });
   470      }
   471  
   472      /** {@inheritDoc} */
   473      @Override
   474      public void showFeedbackNag() {
                 /* 
    P/P           *  Method: void showFeedbackNag()
                  */
   475          UIUtilities.invokeLater(new Runnable() {
   476  
   477              /** {@inheritDoc} */
   478              @Override
   479              public void run() {
                         /* 
    P/P                   *  Method: void run()
                          */
   480                  new FeedbackNag(SwingController.this);
   481              }
   482          });
   483      }
   484  
   485      /** {@inheritDoc} */
   486      @Override
   487      public void showMessageDialog(final String title, final String message) {
                 /* 
    P/P           *  Method: void showMessageDialog(String, String)
                  */
   488          UIUtilities.invokeLater(new Runnable() {
   489  
   490              /** {@inheritDoc} */
   491              @Override
   492              public void run() {
                         /* 
    P/P                   *  Method: void run()
                          */
   493                  JOptionPane.showMessageDialog(null, message, title,
   494                          JOptionPane.PLAIN_MESSAGE);
   495              }
   496          });
   497      }
   498  
   499      /**
   500       * Shows the error dialog.
   501       */
   502      public void showErrorDialog() {
                 /* 
    P/P           *  Method: void showErrorDialog()
                  * 
                  *  Preconditions:
                  *    this.errorDialog != null
                  */
   503          errorDialog.display();
   504      }
   505  
   506      /** {@inheritDoc} */
   507      @Override
   508      public String getUserInput(final String prompt) {
                 /* 
    P/P           *  Method: String getUserInput(String)
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   509          return JOptionPane.showInputDialog(prompt);
   510      }
   511  
   512      /** {@inheritDoc} */
   513      @Override
   514      public PreferencesInterface getPluginPrefsPanel() {
                 /* 
    P/P           *  Method: PreferencesInterface getPluginPrefsPanel()
                  * 
                  *  Postconditions:
                  *    return_value == &amp;new PluginPanel(getPluginPrefsPanel#1)
                  *    new PluginPanel(getPluginPrefsPanel#1) num objects == 1
                  */
   515          return new PluginPanel();
   516      }
   517  
   518      /** {@inheritDoc} */
   519      @Override
   520      public PreferencesInterface getUpdatesPrefsPanel() {
                 /* 
    P/P           *  Method: PreferencesInterface getUpdatesPrefsPanel()
                  * 
                  *  Postconditions:
                  *    return_value == &amp;new UpdateConfigPanel(getUpdatesPrefsPanel#1)
                  *    new UpdateConfigPanel(getUpdatesPrefsPanel#1) num objects == 1
                  */
   521          return new UpdateConfigPanel();
   522      }
   523  
   524      /** {@inheritDoc} */
   525      @Override
   526      public PreferencesInterface getUrlHandlersPrefsPanel() {
                 /* 
    P/P           *  Method: PreferencesInterface getUrlHandlersPrefsPanel()
                  * 
                  *  Preconditions:
                  *    init'ed(this.me)
                  * 
                  *  Postconditions:
                  *    return_value == &amp;new URLConfigPanel(getUrlHandlersPrefsPanel#1)
                  *    new URLConfigPanel(getUrlHandlersPrefsPanel#1) num objects == 1
                  */
   527          return new URLConfigPanel(me);
   528      }
   529  
   530      /** {@inheritDoc} */
   531      @Override
   532      public PreferencesInterface getThemesPrefsPanel() {
                 /* 
    P/P           *  Method: PreferencesInterface getThemesPrefsPanel()
                  * 
                  *  Postconditions:
                  *    return_value == &amp;new ThemePanel(getThemesPrefsPanel#1)
                  *    new ThemePanel(getThemesPrefsPanel#1) num objects == 1
                  */
   533          return new ThemePanel();
   534      }
   535  
   536      /**
   537       * Returns the current look and feel.
   538       * 
   539       * @return Current look and feel
   540       */
   541      public static String getLookAndFeel() {
                 /* 
    P/P           *  Method: String getLookAndFeel()
                  * 
                  *  Presumptions:
                  *    javax.swing.UIManager:getLookAndFeel(...)@542 != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   542          return UIManager.getLookAndFeel().getName();
   543      }
   544  
   545      /** {@inheritDoc} */
   546      @Override
   547      public void onLoad() {
                 /* 
    P/P           *  Method: void onLoad()
                  * 
                  *  Preconditions:
                  *    this.mainFrameCreated != null
                  * 
                  *  Presumptions:
                  *    java.awt.GraphicsEnvironment:isHeadless(...)@548 == 0
                  *    java.awt.Toolkit:getDefaultToolkit(...)@553 != null
                  *    java.awt.Toolkit:getSystemEventQueue(...)@553 != null
                  *    java.util.concurrent.atomic.AtomicBoolean:get(...)@569 == 1
                  */
   548          if (GraphicsEnvironment.isHeadless()) {
   549              throw new IllegalStateException(
   550                      "Swing UI can't be run in a headless environment");
   551          }
   552  
   553          Toolkit.getDefaultToolkit().getSystemEventQueue().
   554                  push(new DMDircEventQueue(this));
   555          
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.SwingController$18(SwingController)
                  */
   556          UIUtilities.invokeAndWait(new Runnable() {
   557  
   558              /** {@inheritDoc} */
   559              @Override
   560              public void run() {
                         /* 
    P/P                   *  Method: void run()
                          * 
                          *  Preconditions:
                          *    this.mainFrameCreated != null
                          *    (soft) init'ed(com/dmdirc/addons/ui_swing/Apple.me)
                          * 
                          *  Postconditions:
                          *    possibly_updated(com/dmdirc/addons/ui_swing/Apple.application)
                          *    com/dmdirc/addons/ui_swing/Apple.me == One-of{old com/dmdirc/addons/ui_swing/Apple.me, &amp;new Apple(getApple#1)}
                          *    init'ed(com/dmdirc/addons/ui_swing/Apple.me)
                          *    init'ed(com/dmdirc/addons/ui_swing/Apple.me.isListener)
                          *    init'ed(this.statusBar)
                          *    new Apple(getApple#1) num objects <= 1
                          *    new ArrayList(Apple#1) num objects == new Apple(getApple#1) num objects
                          *    init'ed(new Apple(getApple#1).addresses)
                          *    new Apple(getApple#1).clientOpened == 0
                          *    init'ed(new Apple(getApple#1).isListener)
                          *    ...
                          */
   561                  initUISettings();
   562                  me = new MainFrame(SwingController.this);
   563                  mainFrameCreated.set(true);
   564                  statusBar = me.getStatusBar();
   565                  errorDialog = new ErrorListDialog(me);
   566              }
   567          });
   568  
   569          if (!mainFrameCreated.get()) {
   570              throw new IllegalStateException(
   571                      "Main frame not created. Unable to continue.");
   572          }
   573  
   574          Main.setUI(this);
   575      }
   576  
   577      /** {@inheritDoc} */
   578      @Override
   579      public void onUnload() {
   580          // Do nothing
             /* 
    P/P       *  Method: void onUnload()
              */
   581      }
   582  
   583      /**
   584       * Adds a top level window to the window list.
   585       * 
   586       * @param source New window
   587       */
   588      protected void addTopLevelWindow(final java.awt.Window source) {
                 /* 
    P/P           *  Method: void addTopLevelWindow(Window)
                  * 
                  *  Preconditions:
                  *    this.windows != null
                  */
   589          synchronized (windows) {
   590              windows.add(source);
   591          }
   592      }
   593  
   594      /**
   595       * Deletes a top level window to the window list.
   596       * 
   597       * @param source Old window
   598       */
   599      protected void delTopLevelWindow(final java.awt.Window source) {
                 /* 
    P/P           *  Method: void delTopLevelWindow(Window)
                  * 
                  *  Preconditions:
                  *    this.windows != null
                  */
   600          synchronized (windows) {
   601              windows.remove(source);
   602          }
   603      }
   604  
   605      /**
   606       * Returns a list of top level windows.
   607       *
   608       * @return Top level window list
   609       */
   610      public List<java.awt.Window> getTopLevelWindows() {
                 /* 
    P/P           *  Method: List getTopLevelWindows()
                  * 
                  *  Postconditions:
                  *    return_value == this.windows
                  *    init'ed(return_value)
                  */
   611          synchronized (windows) {
   612              return windows;
   613          }
   614      }
   615  }








SofCheck Inspector Build Version : 2.17854
SwingController.java 2009-Jun-25 01:54:24
SwingController.class 2009-Sep-02 17:04:17
SwingController$1.class 2009-Sep-02 17:04:17
SwingController$10.class 2009-Sep-02 17:04:17
SwingController$11.class 2009-Sep-02 17:04:17
SwingController$12.class 2009-Sep-02 17:04:17
SwingController$13.class 2009-Sep-02 17:04:17
SwingController$14.class 2009-Sep-02 17:04:17
SwingController$15.class 2009-Sep-02 17:04:17
SwingController$16.class 2009-Sep-02 17:04:17
SwingController$17.class 2009-Sep-02 17:04:17
SwingController$18.class 2009-Sep-02 17:04:17
SwingController$2.class 2009-Sep-02 17:04:17
SwingController$3.class 2009-Sep-02 17:04:17
SwingController$4.class 2009-Sep-02 17:04:17
SwingController$5.class 2009-Sep-02 17:04:17
SwingController$6.class 2009-Sep-02 17:04:17
SwingController$7.class 2009-Sep-02 17:04:17
SwingController$7$1.class 2009-Sep-02 17:04:17
SwingController$8.class 2009-Sep-02 17:04:17
SwingController$9.class 2009-Sep-02 17:04:17