title: Which design pattern could I use for showing dialog boxes?
body: <p>I do sometimes show Dialog boxes in my Java application.</p>
  
  <p>Currently the Controller classes are (expect some exceptions where only getters are called on my model) used like mediators between my model and my UI.</p>
  
  <p>But my UI knows my controllers and my controllers know my UI.</p>
  
  <p>Whenever I add a new dialog I add a method in a controller and in the view class. </p>
  
  <p>Is there a more elegant way to extend my program with new user dialogs by using a design pattern?</p>
  
  <p>To illustrate you how my interaction looks right now I will append some code snippets.</p>
  
  <p><strong>Code from my UI</strong></p>
  
  <pre><code>    itmEmailSettings.addActionListener( new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
              controller.showEmailSettingsDialog();
          }
      } );
  </code></pre>
  
  <p><strong>More UI Code</strong></p>
  
  <pre><code>    public void showEmailSettingsDialog(String host, int port, int authMode,
              String user, String pass, String fromEMail, String fromName) {
          EmailSettingsDialog d = new EmailSettingsDialog(
                  host, port, authMode,
                  user, pass, fromEMail, fromName
                  );
          d.createJDialog( mainFrame.getFrame() ).setVisible(true);
          if(d.isValid()){
              controller.changeEmailSettings(  d.getHost(), d.getPort(), d.getAuthMode(), d.getFromEMail(), d.getFromName(), d.getUser(), d.getPass()  );
          }
      }
  </code></pre>
  
  <p><strong>Controller code:</strong></p>
  
  <pre><code>public void showEmailSettingsDialog() {
      try{
          if(!pm.hasProjectFileAccess()){
              mainFrame.showNoProjectfileAccess();
              return;
          }
          ProgrammSettingsRepository pr = Utils.getProgrammSettingsRepository(pm);
          String host = pr.retreive(ProgrammSettingsRepository.KEY_EMAIL_HOST);
          int port = pr.retreive(ProgrammSettingsRepository.KEY_EMAIL_PORT)==null?0:Integer.parseInt( pr.retreive(ProgrammSettingsRepository.KEY_EMAIL_PORT) );
          int authMode = pr.retreive(ProgrammSettingsRepository.KEY_EMAIL_SSL_MODE)==null?0:Integer.parseInt( pr.retreive(ProgrammSettingsRepository.KEY_EMAIL_SSL_MODE) );
          String user = pr.retreive(ProgrammSettingsRepository.KEY_EMAIL_USER);
          String pass = pr.retreive(ProgrammSettingsRepository.KEY_EMAIL_PASSWORD);
          String fromEMail = pr.retreive(ProgrammSettingsRepository.KEY_EMAIL_FROM_EMAIL);
          String fromName = pr.retreive(ProgrammSettingsRepository.KEY_EMAIL_FROM_NAME);
  
          menuView.showEmailSettingsDialog(host, port, authMode, user, pass, fromEMail, fromName);
      }catch(SQLException e){
          throw new RuntimeException(e.getMessage(), e);
      }
  }
  
  public void changeEmailSettings(String host, int port, int authMode,
          String fromEMail, String fromName, String user, String pass) {
      try {
          ProgrammSettingsRepository pr = Utils.getProgrammSettingsRepository(pm);
          pr.store( ProgrammSettingsRepository.KEY_EMAIL_HOST , String.valueOf( host ));
          pr.store( ProgrammSettingsRepository.KEY_EMAIL_PORT , String.valueOf( port ));
          pr.store( ProgrammSettingsRepository.KEY_EMAIL_SSL_MODE , String.valueOf( authMode ));
          pr.store( ProgrammSettingsRepository.KEY_EMAIL_USER , String.valueOf( user ));
          pr.store( ProgrammSettingsRepository.KEY_EMAIL_PASSWORD, String.valueOf( pass ));
          pr.store( ProgrammSettingsRepository.KEY_EMAIL_FROM_EMAIL , String.valueOf( fromEMail ));
          pr.store( ProgrammSettingsRepository.KEY_EMAIL_FROM_NAME , String.valueOf( fromName ));
          pr.store(ProgrammSettingsRepository.KEY_EMAIL_SETTINGS_CONFIGURED, "true");
      } catch (SQLException e) {
          throw new RuntimeException(e.getMessage(), e);
      }
  }
  </code></pre>