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.

ChannelSettingsDialog.java 9.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. * Copyright (c) 2006-2017 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
  5. * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
  6. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
  7. * permit persons to whom the Software is furnished to do so, subject to the following conditions:
  8. *
  9. * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
  10. * Software.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  13. * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
  14. * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  15. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. */
  17. package com.dmdirc.addons.ui_swing.dialogs.channelsetting;
  18. import com.dmdirc.addons.ui_swing.PrefsComponentFactory;
  19. import com.dmdirc.addons.ui_swing.SwingWindowFactory;
  20. import com.dmdirc.addons.ui_swing.UIUtilities;
  21. import com.dmdirc.addons.ui_swing.components.IconManager;
  22. import com.dmdirc.addons.ui_swing.components.expandingsettings.SettingsPanel;
  23. import com.dmdirc.addons.ui_swing.components.modes.ChannelModesPane;
  24. import com.dmdirc.addons.ui_swing.dialogs.StandardDialog;
  25. import com.dmdirc.config.prefs.PreferencesManager;
  26. import com.dmdirc.interfaces.CommandController;
  27. import com.dmdirc.interfaces.GroupChat;
  28. import com.dmdirc.interfaces.WindowModel;
  29. import com.dmdirc.config.provider.ConfigProvider;
  30. import com.dmdirc.interfaces.config.IdentityFactory;
  31. import com.dmdirc.plugins.ServiceManager;
  32. import com.dmdirc.ui.input.TabCompleterUtils;
  33. import com.dmdirc.ui.messages.ColourManagerFactory;
  34. import java.awt.Window;
  35. import java.awt.datatransfer.Clipboard;
  36. import java.awt.event.ActionEvent;
  37. import java.awt.event.ActionListener;
  38. import javax.swing.JButton;
  39. import javax.swing.JScrollPane;
  40. import javax.swing.JTabbedPane;
  41. import javax.swing.ScrollPaneConstants;
  42. import javax.swing.WindowConstants;
  43. import net.miginfocom.swing.MigLayout;
  44. import static com.google.common.base.Preconditions.checkNotNull;
  45. /**
  46. * Allows the user to modify channel settings (modes, topics, etc).
  47. */
  48. public class ChannelSettingsDialog extends StandardDialog implements ActionListener {
  49. /** Serial version UID. */
  50. private static final long serialVersionUID = 8;
  51. /** The channel object that this dialog belongs to. */
  52. private final GroupChat channel;
  53. /** Channel identity file. */
  54. private final ConfigProvider identity;
  55. /** Channel window. */
  56. private final WindowModel channelWindow;
  57. private final IconManager iconManager;
  58. /** Tabbed pane. */
  59. private JTabbedPane tabbedPane;
  60. /** Client settings panel. */
  61. private SettingsPanel channelSettingsPane;
  62. /** List modes panel. */
  63. private ChannelModesPane channelModesPane;
  64. /** List modes panel. */
  65. private TopicPane topicModesPane;
  66. /** List modes panel. */
  67. private ChannelListModesPane channelListModesPane;
  68. /** The config to write settings to. */
  69. private final ConfigProvider userConfig;
  70. /** Service manager. */
  71. private final ServiceManager serviceManager;
  72. /** Preferences Manager. */
  73. private final PreferencesManager preferencesManager;
  74. /** Preferences setting component factory. */
  75. private final PrefsComponentFactory compFactory;
  76. /** Clipboard to copy and paste from. */
  77. private final Clipboard clipboard;
  78. /** The controller to use to retrieve command information. */
  79. private final CommandController commandController;
  80. /** Colour manager factory. */
  81. private final ColourManagerFactory colourManagerFactory;
  82. /**
  83. * Creates a new instance of ChannelSettingsDialog.
  84. *
  85. * @param identityFactory Identity factory
  86. * @param windowFactory Swing window factory
  87. * @param userConfig The config to write global settings to.
  88. * @param serviceManager Service manager
  89. * @param preferencesManager Preferences Manager
  90. * @param compFactory Preferences setting component factory
  91. * @param groupChat The group chat object that we're editing settings for
  92. * @param parentWindow Parent window
  93. * @param clipboard Clipboard to copy and paste from
  94. * @param commandController The controller to use to retrieve command information.
  95. */
  96. public ChannelSettingsDialog(
  97. final IdentityFactory identityFactory,
  98. final SwingWindowFactory windowFactory,
  99. final ConfigProvider userConfig,
  100. final ServiceManager serviceManager,
  101. final PreferencesManager preferencesManager,
  102. final PrefsComponentFactory compFactory,
  103. final GroupChat groupChat,
  104. final Window parentWindow,
  105. final Clipboard clipboard,
  106. final CommandController commandController,
  107. final ColourManagerFactory colourManagerFactory,
  108. final TabCompleterUtils tabCompleterUtils,
  109. final IconManager iconManager) {
  110. super(parentWindow, ModalityType.MODELESS);
  111. this.userConfig = checkNotNull(userConfig);
  112. this.serviceManager = checkNotNull(serviceManager);
  113. this.preferencesManager = checkNotNull(preferencesManager);
  114. this.compFactory = checkNotNull(compFactory);
  115. this.channel = checkNotNull(groupChat);
  116. this.clipboard = clipboard;
  117. this.commandController = checkNotNull(commandController);
  118. this.colourManagerFactory = colourManagerFactory;
  119. this.iconManager = iconManager;
  120. identity = identityFactory.createChannelConfig(groupChat.getConnection().get().getNetwork(),
  121. groupChat.getName());
  122. channelWindow = groupChat.getWindowModel();
  123. initComponents(tabCompleterUtils);
  124. initListeners();
  125. }
  126. /** Initialises the main UI components. */
  127. private void initComponents(final TabCompleterUtils tabCompleterUtils) {
  128. tabbedPane = new JTabbedPane();
  129. setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
  130. setTitle("Channel settings for " + channel.getName());
  131. setResizable(false);
  132. orderButtons(new JButton(), new JButton());
  133. getContentPane().setLayout(new MigLayout(
  134. "fill, wrap 1, ins panel, hmax 80sp, wmin 460, wmax 460"));
  135. getContentPane().add(tabbedPane, "growy, pushy");
  136. getContentPane().add(getLeftButton(), "split 3, right");
  137. getContentPane().add(getRightButton(), "right");
  138. initTopicTab(tabCompleterUtils);
  139. initIrcTab();
  140. initListModesTab();
  141. initSettingsTab();
  142. tabbedPane.setSelectedIndex(channel.getWindowModel().getConfigManager().
  143. getOptionInt("dialogstate", "channelsettingsdialog"));
  144. }
  145. /** Initialises the Topic tab. */
  146. private void initTopicTab(final TabCompleterUtils tabCompleterUtils) {
  147. topicModesPane = new TopicPane(channel, iconManager,
  148. commandController, serviceManager,
  149. this, channelWindow, clipboard, colourManagerFactory, tabCompleterUtils);
  150. tabbedPane.addTab("Topic", topicModesPane);
  151. }
  152. /** Initialises the IRC Settings tab. */
  153. private void initIrcTab() {
  154. channelModesPane = new ChannelModesPane(channel, iconManager);
  155. final JScrollPane channelModesSP = new JScrollPane(channelModesPane);
  156. channelModesSP.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
  157. channelModesSP.setOpaque(UIUtilities.getTabbedPaneOpaque());
  158. channelModesSP.getViewport().setOpaque(UIUtilities.getTabbedPaneOpaque());
  159. channelModesSP.setBorder(null);
  160. tabbedPane.addTab("Channel Modes", channelModesSP);
  161. }
  162. /** Initialises the IRC Settings tab. */
  163. private void initListModesTab() {
  164. channelListModesPane = new ChannelListModesPane(channel.getWindowModel().getConfigManager(),
  165. userConfig, iconManager, channel, this);
  166. tabbedPane.addTab("List Modes", channelListModesPane);
  167. }
  168. /** Initialises the channel Settings (identities) tab. */
  169. private void initSettingsTab() {
  170. initSettingsPanel();
  171. tabbedPane.addTab("Client Settings", channelSettingsPane);
  172. }
  173. /** Initialises the channel settings. */
  174. private void initSettingsPanel() {
  175. channelSettingsPane = new SettingsPanel(iconManager, compFactory,
  176. "These settings are specific to this channel on this network,"
  177. + " any settings specified here will overwrite global settings");
  178. channelSettingsPane.addOption(preferencesManager.getChannelSettings(
  179. channel.getWindowModel().getConfigManager(), identity));
  180. }
  181. /** Initialises listeners for this dialog. */
  182. private void initListeners() {
  183. getOkButton().addActionListener(this);
  184. getCancelButton().addActionListener(this);
  185. }
  186. /**
  187. * Called whenever the user clicks on one of the two buttons.
  188. *
  189. * @param actionEvent Event generated by this action
  190. */
  191. @Override
  192. public void actionPerformed(final ActionEvent actionEvent) {
  193. if (getOkButton().equals(actionEvent.getSource())) {
  194. save();
  195. } else if (getCancelButton().equals(actionEvent.getSource())) {
  196. dispose();
  197. }
  198. }
  199. /** Saves the settings. */
  200. public void save() {
  201. channelModesPane.save();
  202. topicModesPane.setChangedTopic();
  203. channelSettingsPane.save();
  204. channelListModesPane.save();
  205. identity.setOption("dialogstate", "channelsettingsdialog",
  206. String.valueOf(tabbedPane.getSelectedIndex()));
  207. dispose();
  208. }
  209. }