You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SwingController.java 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * Copyright (c) 2006-2007 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. package com.dmdirc.ui.swing;
  23. import com.dmdirc.Channel;
  24. import com.dmdirc.FrameContainer;
  25. import com.dmdirc.Main;
  26. import com.dmdirc.Query;
  27. import com.dmdirc.Server;
  28. import com.dmdirc.WritableFrameContainer;
  29. import com.dmdirc.commandparser.parsers.CommandParser;
  30. import com.dmdirc.config.IdentityManager;
  31. import com.dmdirc.logger.ErrorLevel;
  32. import com.dmdirc.logger.Logger;
  33. import com.dmdirc.ui.interfaces.ChannelWindow;
  34. import com.dmdirc.ui.interfaces.FrameManager;
  35. import com.dmdirc.ui.interfaces.InputWindow;
  36. import com.dmdirc.ui.interfaces.PreferencesInterface;
  37. import com.dmdirc.ui.interfaces.PreferencesPanel;
  38. import com.dmdirc.ui.interfaces.QueryWindow;
  39. import com.dmdirc.ui.interfaces.ServerWindow;
  40. import com.dmdirc.ui.interfaces.StatusBar;
  41. import com.dmdirc.ui.interfaces.UIController;
  42. import com.dmdirc.ui.interfaces.UpdaterDialog;
  43. import com.dmdirc.ui.interfaces.Window;
  44. import com.dmdirc.ui.swing.components.SwingPreferencesPanel;
  45. import com.dmdirc.ui.swing.components.SwingStatusBar;
  46. import com.dmdirc.ui.swing.dialogs.SwingUpdaterDialog;
  47. import com.dmdirc.ui.swing.dialogs.channelsetting.ChannelSettingsDialog;
  48. import com.dmdirc.ui.swing.dialogs.error.ErrorListDialog;
  49. import com.dmdirc.ui.swing.dialogs.firstrunwizard.SwingFirstRunWizard;
  50. import com.dmdirc.ui.swing.dialogs.serversetting.ServerSettingsDialog;
  51. import com.dmdirc.updater.Update;
  52. import java.awt.Toolkit;
  53. import java.util.List;
  54. import javax.swing.UIManager;
  55. import javax.swing.UnsupportedLookAndFeelException;
  56. /**
  57. * Controls the main swing UI.
  58. */
  59. public final class SwingController implements UIController {
  60. /**
  61. * Singleton instance of MainFrame.
  62. */
  63. private static MainFrame me;
  64. /** Status bar. */
  65. private SwingStatusBar statusBar;
  66. /** Instantiates a new SwingController. */
  67. public SwingController() {
  68. //Do nothing
  69. }
  70. /** {@inheritDoc} */
  71. public synchronized MainFrame getMainWindow() {
  72. if (me == null) {
  73. statusBar = new SwingStatusBar();
  74. me = new MainFrame(statusBar);
  75. ErrorListDialog.getErrorListDialog();
  76. }
  77. return me;
  78. }
  79. /** {@inheritDoc} */
  80. public synchronized StatusBar getStatusBar() {
  81. if (statusBar == null) {
  82. getMainWindow();
  83. }
  84. return statusBar;
  85. }
  86. /** {@inheritDoc} */
  87. public FrameManager getFrameManager() {
  88. return getMainWindow().getFrameManager();
  89. }
  90. /** {@inheritDoc} */
  91. public ChannelWindow getChannel(final Channel channel) {
  92. return new ChannelFrame(channel);
  93. }
  94. /** {@inheritDoc} */
  95. public ServerWindow getServer(final Server server) {
  96. return new ServerFrame(server);
  97. }
  98. /** {@inheritDoc} */
  99. public QueryWindow getQuery(final Query query) {
  100. return new QueryFrame(query);
  101. }
  102. /** {@inheritDoc} */
  103. public Window getWindow(final FrameContainer owner) {
  104. return new CustomFrame(owner);
  105. }
  106. /** {@inheritDoc} */
  107. public InputWindow getInputWindow(final WritableFrameContainer owner,
  108. final CommandParser commandParser) {
  109. return new CustomInputFrame(owner, commandParser);
  110. }
  111. /** {@inheritDoc} */
  112. public PreferencesPanel getPreferencesPanel(
  113. final PreferencesInterface parent, final String title) {
  114. return new SwingPreferencesPanel(parent, title);
  115. }
  116. /** {@inheritDoc} */
  117. public UpdaterDialog getUpdaterDialog(final List<Update> updates) {
  118. return new SwingUpdaterDialog(updates);
  119. }
  120. /** {@inheritDoc} */
  121. public void showFirstRunWizard() {
  122. new SwingFirstRunWizard().display();
  123. }
  124. /** {@inheritDoc} */
  125. public void showMigrationWizard() {
  126. new SwingFirstRunWizard(false).display();
  127. }
  128. /** {@inheritDoc} */
  129. public void showChannelSettingsDialog(final Channel channel) {
  130. ChannelSettingsDialog.getChannelSettingDialog(channel).setVisible(true);
  131. }
  132. /** {@inheritDoc} */
  133. public void showServerSettingsDialog(final Server server) {
  134. new ServerSettingsDialog(server).setVisible(true);
  135. }
  136. /** {@inheritDoc} */
  137. public void initUISettings() {
  138. // For this to work it *HAS* to be before anything else UI related.
  139. if (IdentityManager.getGlobalConfig().hasOption("ui", "antialias")) {
  140. final String aaSetting = IdentityManager.getGlobalConfig().getOption("ui", "antialias");
  141. System.setProperty("awt.useSystemAAFontSettings", aaSetting);
  142. System.setProperty("swing.aatext", aaSetting);
  143. } else {
  144. IdentityManager.getConfigIdentity().setOption("ui", "antialias", "true");
  145. System.setProperty("awt.useSystemAAFontSettings", "true");
  146. System.setProperty("swing.aatext", "true");
  147. }
  148. try {
  149. UIUtilities.initUISettings();
  150. final String lnfName = UIUtilities.getLookAndFeel(
  151. IdentityManager.getGlobalConfig().getOption("ui", "lookandfeel"));
  152. if (IdentityManager.getGlobalConfig().hasOption("ui", "lookandfeel") && !lnfName.isEmpty()) {
  153. UIManager.setLookAndFeel(lnfName);
  154. }
  155. //These are likely to change lots, and i cant test them - Greboid
  156. UIManager.put("apple.awt.showGrowBox", true);
  157. UIManager.put("apple.laf.useScreenMenuBar", true);
  158. UIManager.put("com.apple.mrj.application.apple.menu.about.name", "DMDirc: " + Main.VERSION);
  159. UIManager.put("com.apple.mrj.application.growbox.intrudes", false);
  160. UIManager.put("com.apple.mrj.application.live-resize", true);
  161. } catch (UnsupportedOperationException ex) {
  162. Logger.userError(ErrorLevel.LOW, "Unable to set UI Settings");
  163. } catch (UnsupportedLookAndFeelException ex) {
  164. Logger.userError(ErrorLevel.LOW, "Unable to set UI Settings");
  165. } catch (IllegalAccessException ex) {
  166. Logger.userError(ErrorLevel.LOW, "Unable to set UI Settings");
  167. } catch (InstantiationException ex) {
  168. Logger.userError(ErrorLevel.LOW, "Unable to set UI Settings");
  169. } catch (ClassNotFoundException ex) {
  170. Logger.userError(ErrorLevel.LOW, "Unable to set UI Settings");
  171. }
  172. Toolkit.getDefaultToolkit().getSystemEventQueue().push(new DMDircEventQueue());
  173. }
  174. }