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 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /*
  2. * Copyright (c) 2006-2010 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.addons.ui_swing.dialogs.channelsetting;
  23. import com.dmdirc.Channel;
  24. import com.dmdirc.config.Identity;
  25. import com.dmdirc.config.IdentityManager;
  26. import com.dmdirc.addons.ui_swing.UIUtilities;
  27. import com.dmdirc.addons.ui_swing.dialogs.StandardDialog;
  28. import com.dmdirc.addons.ui_swing.components.expandingsettings.SettingsPanel;
  29. import com.dmdirc.addons.ui_swing.components.expandingsettings.SettingsPanel.OptionType;
  30. import java.awt.Window;
  31. import java.awt.event.ActionEvent;
  32. import java.awt.event.ActionListener;
  33. import javax.swing.JButton;
  34. import javax.swing.JScrollPane;
  35. import javax.swing.JTabbedPane;
  36. import javax.swing.WindowConstants;
  37. import net.miginfocom.swing.MigLayout;
  38. /**
  39. * Allows the user to modify channel settings (modes, topics, etc).
  40. */
  41. public final class ChannelSettingsDialog extends StandardDialog implements
  42. ActionListener {
  43. /**
  44. * A version number for this class. It should be changed whenever the class
  45. * structure is changed (or anything else that would prevent serialized
  46. * objects being unserialized with the new class).
  47. */
  48. private static final long serialVersionUID = 8;
  49. /** Channel settings dialogs, semi singleton use. */
  50. private static volatile ChannelSettingsDialog me;
  51. /** The channel object that this dialog belongs to. */
  52. private final Channel channel;
  53. /** Tabbed pane. */
  54. private JTabbedPane tabbedPane;
  55. /** Client settings panel. */
  56. private SettingsPanel channelSettingsPane;
  57. /** List modes panel. */
  58. private ChannelModesPane channelModesPane;
  59. /** List modes panel. */
  60. private TopicPane topicModesPane;
  61. /** List modes panel. */
  62. private ChannelListModesPane channelListModesPane;
  63. /** Channel identity file. */
  64. private final Identity identity;
  65. /**
  66. * Creates a new instance of ChannelSettingsDialog.
  67. *
  68. * @param newChannel The channel object that we're editing settings for
  69. */
  70. private ChannelSettingsDialog(final Channel newChannel,
  71. final Window parentWindow) {
  72. super(parentWindow, ModalityType.MODELESS);
  73. channel = newChannel;
  74. identity = IdentityManager.getChannelConfig(channel.getServer().
  75. getNetwork(), channel.getChannelInfo().getName());
  76. initComponents();
  77. initListeners();
  78. }
  79. /**
  80. * Creates the dialog if one doesn't exist, and displays it.
  81. *
  82. * @param channel The channel object that we're editing settings for
  83. * @param parentWindow Parent window
  84. */
  85. public static void showChannelSettingsDialog(
  86. final Channel channel, final Window parentWindow) {
  87. me = getChannelSettingsDialog(channel, parentWindow);
  88. me.display();
  89. me.requestFocusInWindow();
  90. }
  91. /**
  92. * Returns the current instance of the ChannelSettingsDialog.
  93. *
  94. * @param channel The channel object that we're editing settings for
  95. * @param parentWindow Parent window
  96. *
  97. * @return The current ChannelSettingsDialog instance
  98. */
  99. public static ChannelSettingsDialog getChannelSettingsDialog(
  100. final Channel channel, final Window parentWindow) {
  101. synchronized (ChannelSettingsDialog.class) {
  102. if (me == null) {
  103. me = new ChannelSettingsDialog(channel, parentWindow);
  104. }
  105. }
  106. return me;
  107. }
  108. /** Initialises the main UI components. */
  109. private void initComponents() {
  110. tabbedPane = new JTabbedPane();
  111. setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
  112. setTitle("Channel settings for " + channel);
  113. setResizable(false);
  114. orderButtons(new JButton(), new JButton());
  115. getContentPane().setLayout(new MigLayout(
  116. "fill, wrap 1, ins panel, hmax 80sp"));
  117. getContentPane().add(tabbedPane, "growy, pushy, wmin 460, wmax 460");
  118. getContentPane().add(getLeftButton(), "split 3, right");
  119. getContentPane().add(getRightButton(), "right");
  120. initTopicTab();
  121. initIrcTab();
  122. initListModesTab();
  123. initSettingsTab();
  124. tabbedPane.setSelectedIndex(channel.getConfigManager().
  125. getOptionInt("dialogstate", "channelsettingsdialog"));
  126. }
  127. /** Initialises the Topic tab. */
  128. private void initTopicTab() {
  129. topicModesPane = new TopicPane(channel, this);
  130. tabbedPane.addTab("Topic", topicModesPane);
  131. }
  132. /** Initialises the IRC Settings tab. */
  133. private void initIrcTab() {
  134. channelModesPane = new ChannelModesPane(channel);
  135. final JScrollPane channelModesSP = new JScrollPane(channelModesPane);
  136. channelModesSP.setHorizontalScrollBarPolicy(
  137. JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
  138. channelModesSP.setOpaque(UIUtilities.getTabbedPaneOpaque());
  139. channelModesSP.getViewport().setOpaque(UIUtilities.getTabbedPaneOpaque());
  140. channelModesSP.setBorder(null);
  141. tabbedPane.addTab("Channel Modes", channelModesSP);
  142. }
  143. /** Initialises the IRC Settings tab. */
  144. private void initListModesTab() {
  145. channelListModesPane = new ChannelListModesPane(channel);
  146. tabbedPane.addTab("List Modes", channelListModesPane);
  147. }
  148. /** Initialises the channel Settings (identities) tab. */
  149. private void initSettingsTab() {
  150. initSettingsPanel();
  151. tabbedPane.addTab("Client Settings", channelSettingsPane);
  152. }
  153. /** Initialises the channel settings. */
  154. private void initSettingsPanel() {
  155. channelSettingsPane = new SettingsPanel(identity,
  156. "These settings are specific to this channel on this network,"
  157. + " any settings specified here will overwrite global settings");
  158. channelSettingsPane.addOption("channel.splitusermodes",
  159. "Split user modes", OptionType.CHECKBOX);
  160. channelSettingsPane.addOption("channel.sendwho",
  161. "Send channel WHOs", OptionType.CHECKBOX);
  162. channelSettingsPane.addOption("channel.showmodeprefix",
  163. "Show mode prefixes", OptionType.CHECKBOX);
  164. channelSettingsPane.addOption("ui.shownickcoloursinnicklist",
  165. "Show colours in nicklist", OptionType.CHECKBOX);
  166. channelSettingsPane.addOption("ui.shownickcoloursintext",
  167. "Show colours in textpane", OptionType.CHECKBOX);
  168. channelSettingsPane.addOption("general.cyclemessage",
  169. "Cycle message", OptionType.TEXTFIELD);
  170. channelSettingsPane.addOption("general.kickmessage",
  171. "Kick message", OptionType.TEXTFIELD);
  172. channelSettingsPane.addOption("general.partmessage",
  173. "Part message", OptionType.TEXTFIELD);
  174. channelSettingsPane.addOption("ui.backgroundcolour",
  175. "Background colour", OptionType.COLOUR);
  176. channelSettingsPane.addOption("ui.foregroundcolour",
  177. "Foreground colour", OptionType.COLOUR);
  178. channelSettingsPane.addOption("ui.frameBufferSize",
  179. "Frame buffer size", OptionType.SPINNER);
  180. channelSettingsPane.addOption("ui.textPaneFontName",
  181. "Textpane font name",
  182. OptionType.FONT);
  183. channelSettingsPane.addOption("ui.textPaneFontSize",
  184. "Textpane font size",
  185. OptionType.SPINNER);
  186. channelSettingsPane.addOption("ui.inputbuffersize",
  187. "Input buffer size", OptionType.SPINNER);
  188. channelSettingsPane.addOption("ui.inputbackgroundcolour",
  189. "Inputfield background colour", OptionType.COLOUR);
  190. channelSettingsPane.addOption("ui.inputforegroundcolour",
  191. "Inputfield foreground colour", OptionType.COLOUR);
  192. channelSettingsPane.addOption("ui.nicklistbackgroundcolour",
  193. "Nicklist background colour", OptionType.COLOUR);
  194. channelSettingsPane.addOption("ui.nicklistforegroundcolour",
  195. "Nicklist foreground colour", OptionType.COLOUR);
  196. channelSettingsPane.addOption("channel.encoding", "Encoding",
  197. OptionType.COMBOBOX);
  198. }
  199. /** Initialises listeners for this dialog. */
  200. private void initListeners() {
  201. getOkButton().addActionListener(this);
  202. getCancelButton().addActionListener(this);
  203. }
  204. /**
  205. * Called whenever the user clicks on one of the two buttons.
  206. *
  207. * @param actionEvent Event generated by this action
  208. */
  209. @Override
  210. public void actionPerformed(final ActionEvent actionEvent) {
  211. if (getOkButton().equals(actionEvent.getSource())) {
  212. save();
  213. } else if (getCancelButton().equals(actionEvent.getSource())) {
  214. dispose();
  215. }
  216. }
  217. /** Saves the settings. */
  218. public void save() {
  219. channelModesPane.setChangedBooleanModes();
  220. topicModesPane.setChangedTopic();
  221. channelSettingsPane.save();
  222. channelListModesPane.save();
  223. identity.setOption("dialogstate", "channelsettingsdialog",
  224. String.valueOf(tabbedPane.getSelectedIndex()));
  225. dispose();
  226. }
  227. /** {@inheritDoc} */
  228. @Override
  229. public void dispose() {
  230. if (me == null) {
  231. return;
  232. }
  233. synchronized (me) {
  234. super.dispose();
  235. me = null;
  236. }
  237. }
  238. }